Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

The Web Warrior Guide to Web Design Technologies
IT151: Introduction to Programming
Dale Roberts Introduction to Java - First Program Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
Objectives You should be able to describe: Introduction to Programming
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Chapter 1 Introduction to JAVA. Why Learn JAVA? Java is one of the fastest growing programming language in the world. Java is one of the fastest growing.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Chapter 1: Introduction
Introduction To Computers and Programming Lecture 2: Your first program Professor: Evan Korth New York University.
Using Visual Basic 6.0 to Create Web-Based Database Applications
Introduction to Java Programming, 4E
Computer Concepts 5th Edition Parsons/Oja Page 546 CHAPTER 11 Software Engineering Section A PARSONS/OJA Computer Programming.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
©2004 Brooks/Cole Chapter 1: Getting Started Sections Covered: 1.1Introduction to Programming 1.2Constructing a Java Program 1.3The print() and println()
Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”
Outline Java program structure Basic program elements
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
A First Program Using C#
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Object Oriented Systems Lecture 01 First Java Programming Jaeki Song.
Chapter 1: Creating Java Programs
1Object-Oriented Program Development Using C++ Computer Science and Programming Languages Computers are ubiquitous Computer literacy is essential Computer.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
Chapter 1: Introduction to Computers and Programming.
Java Language and SW Dev’t
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
Chapter 3: Completing the Problem- Solving Process and Getting Started with C++ Introduction to Programming with C++ Fourth Edition.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Chapter One: Introduction.
© 2006 Pearson Education 1 Obj: cont 1.3 and 1.4, to become familiar with identifiers and to understand how programming languages work HW: p.51 #1.8 –
The Java Programming Language
Programming With C.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
Chapter 1: Introduction to Programs, and Java 1. Objectives To review programs (§ ). To understand the relationship between Java and the World Wide.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Introduction to Java Programming with Forte Y. Daniel Liang.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Fall 2006Slides adapted from Java Concepts companion slides1 Introduction Advanced Programming ICOM 4015 Lecture 1 Reading: Java Concepts Chapter 1.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Introduction to programming in the Java programming language.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
CSC1200 INTRODUCTION TO PROGRAMMING Dr. Maureen Markel
Introduction to Java Programming. 2 Chapter 1 Introduction to Java and Forte F What Is Java? F Getting Started With Java Programming –Create, Compile.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
Introducing Java Chapter 3 Review. Why Program in Java? Java, is an object-oriented programming language. OOP languages evolved out of the need to better.
PROGRAMMING FUNDAMENTALS INTRODUCTION TO PROGRAMMING. Computer Programming Concepts. Flowchart. Structured Programming Design. Implementation Documentation.
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
Chapter 1: Introduction to Computers and Programming.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Introduction to 1. What is Java ? Sun Microsystems Java is a programming language and computing platform first released by Sun Microsystems in The.
Software Engineering Algorithms, Compilers, & Lifecycle.
Introduction to Java Programming, 4E Y. Daniel Liang.
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
Working with Java.
GC101 Introduction to computer and program
CSCI-235 Micro-Computer Applications
Chapter 1 Introduction to Computers, Programs, and Java
Chapter 1: Computer Systems
Computer Programming-1 CSC 111
Instructor: Alexander Stoytchev
Presentation transcript:

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition

2 Objectives You should be able to describe: Computer Science and Programming Languages Objects and Classes Constructing a Java Program The PrintStream Class’s print() and println() Methods

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition3 Objectives (continued) Using the javax.swing Package Programming Style Common Programming Errors

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition4 Computer Science and Programming Languages Information age –Almost totally dependent and driven by information technology Computer science –Science of computers and computing Computer scientists –Solve problems using scientific method

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition5 Computer Science and Programming Languages (continued) Fundamental areas of computer science: –Introduction to computer architecture –The Java programming language –Class development and design –Algorithm development –Introduction to data structures

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition6 Programming Languages Computer program –Self-contained set of instructions and data used to operate computer to produce specific result –Also called software Programming –Process of developing and writing programs Programming language –Set of instructions that can be used to construct program

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition7 Programming Languages (continued) Low-level languages –Run on only one type of computer –Machine language Sequence of binary numbers –Assembly language Substitution of words for binary codes of machine language Translated into machine language program before being executed on computer

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition8 Programming Languages (continued) High-level languages –Use instructions that resemble natural languages –Run on variety of computer types –Examples: Pascal Visual Basic C C++ Java

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition9 Programming Languages (continued) Source program –Programs written in computer language Interpreted language –Each statement translated individually –Executed immediately upon translation Compiled language –Translated as complete unit before any one statement executed

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition10 Programming Languages (continued) Java is both: –Compiled –Interpreted Java Virtual Machine –Software program –Reads bytecodes produced by compiler and executes them

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition11 Programming Languages (continued) Figure 1.2: Translating a Java program

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition12 Procedure and Object Orientations Procedure-oriented language –Available instructions are used to create self- contained units Object-oriented language –Program must first define objects it will be manipulating Java object-oriented

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition13 Application and System Software Application software –Programs written to perform particular tasks required by users System software –Collection of programs that must be readily available to computer system for it to operate at all –Operating system

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition14 The Development of Java History: –FORTRAN –COBOL –BASIC –Pascal –C++ –Java

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition15 The Development of Java (continued) Web browser –Program located and run on user’s computer to display Web pages –Java can run from Web browser Java provides: –Cross-platform compatibility –Write-once-run-anywhere

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition16 The Development of Java (continued) Figure 1.6: The two distinct Java environments

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition17 Objects and Classes Objects –Part of Java programming language as component types –Can be custom tailored by programmer –Programmer can define custom objects

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition18 A Class Is a Plan Structure for class of objects must be created at start of programming process Class –Explicitly written plan –Complete set of parts and instructions needed to create items

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition19 From Recipe to Class Data declaration section –Description of data to be used Methods section –Defines how to combine data components to produce desired result

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition20 From Recipe to Class (continued) Figure 1.11: A programming plan for address labels

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition21 A First Java Class Class consists of: –Class header line public class nameofclass –Body Class body –Encloses data and methods that make up class –Typically two sections of code: Types of data that will be used Procedures that will be used on data

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition22 A First Java Class (continued) Figure 1.13: A sample Java class

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition23 A First Java Class (continued) Table 1.1: Java Class Components

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition24 Constructing a Java Program Programs can use existing classes Java program: –Considered executable applications program –Class must contain method named main

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition25 The main Method public static void main(String [] args) Every program must have main method Methods begin and end with {}

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition26 The main Method (continued) Figure 1.17: The structure of a main() method

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition27 The main Method (continued) Figure 1.18: The structure of a Java program

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition28 Reserved Words Predefined by programming language for special purpose Can only be used in specified manner for intended purpose Also called keywords in Java

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition29 Reserved Words (continued) Table 1.2: Java Reserved Words

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition30 Standard Identifiers Java-defined words with predefined purpose –Can be redefined by programmer Names of classes and methods provided in Java Good programming practice –Only use standard identifiers for intended purpose

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition31 Standard Identifiers (continued) Table 1.3: Subset of Java Standard Identifiers

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition32 Identifiers Programmer-supplied words Common practice: –First letter of each word capitalized Starting with second word Case sensitive –identifiers TOTAL, total, and TotaL represent three distinct and different names

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition33 Identifiers (continued) Rules for identifiers: –First character of identifier cannot be digit –Only letters, digits, underscores, and dollar signs may follow initial character Blank spaces not allowed –Identifier cannot be reserved word –Maximum number of characters in identifier name unlimited

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition34 What Is Syntax? Set of rules for formulating grammatically correct language statements Program has proper form specified for compiler Individual statement or program can be syntactically correct and still be logically incorrect

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition35 The PrintStream Class’s print() and println() Methods PrintStream class, methods: –print() –println() –Display data to standard output Package –One or more individual classes –Stored in same directory

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition36 The PrintStream Class’s print() and println() Methods (continued) General syntax: –objectName.print(data) –System.out.print("Hello World!"); Parameters –Items passed to method through parenthesis –Also called: Arguments Actual arguments

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition37 The PrintStream Class’s print() and println() Methods (continued) print() –Prints output only println() –Prints output and appends new line \n –Newline escape character

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition38 Java Documentation Sources for documentation: –http//java.sun.com/docs/search.html –Hard copy books: The Java Class Libraries JFC Swing Tutorial

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition39 The System Class Provides methods for examining system-related information such as: –Name of operating system –Java version number Supports basic input and output services

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition40 Using the javax.swing Package Classes in package provide means of specifying fully functional GUI with typical components such as: –Check boxes –Data entry fields –Command buttons –Dialogs: Modal Modeless

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition41 Using the javax.swing Package (continued) JOptionPane.showMessageDialog(null, "message", "title", icon-type);

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition42 Using the javax.swing Package (continued) Figure 1.21: showMessageDialog() dialog boxes

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition43 Using the javax.swing Package (continued) Import statement –Found at beginning of program after package declaration –Compiler searches for classes in packages listed for import

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition44 Static and Non-Static Methods Non-static –Must be used with objects –Examples: println() displayMessage() –Syntax: objectName.methodName(arguments);

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition45 Static and Non-Static Methods (continued) Static –Does not operate on object –Receives all data as arguments –Example: showMessageDialog() –Syntax: ClassName.methodName(arguments);

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition46 Programming Style Java ignores whitespace Proper programming style: –Makes programs easy to read –Minimizes mistakes Proper style for main method: public static void main(String[] args) { program statements in here; }

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition47 Comments Explanatory remarks made within program Comment types in Java: –Line –Block // Line comment /* Block comment Spans lines */

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition48 Common Programming Errors Knowing about common errors helps programmers avoid them Most common errors: –Forgetting to save program with same file name as class name used within program –Omitting semicolon at end of each statement –Forgetting \n to indicate new line

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition49 Summary Programming languages come in variety of forms and types In object-oriented languages, basic program unit is a class –Java is object-oriented All Java classes use basic structure consisting of: –Class header line –Class body

Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition50 Summary (continued) Java program must have main() method PrintStream class provides two methods print() and println() –Used to display text and numerical results Java package consists of one or more individual classes stored in same directory –javax.swing package provides GUI classes