1 / 46

Chapter 1: Introduction

Object-Oriented Program Development Using Java: A Class-Centered Approach . 2. Objectives. Computer Science and Programming LanguagesObjects and ClassesConstructing a Java ProgramThe PrintStream Class's print() and println() MethodsUsing the javax.swing PackageProgramming StyleCommon Programmi

gavin
Download Presentation

Chapter 1: Introduction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


    1. Chapter 1: Introduction Object-Oriented Program Development Using Java: A Class-Centered Approach

    2. Object-Oriented Program Development Using Java: A Class-Centered Approach 2 Objectives Computer Science and Programming Languages Objects and Classes Constructing a Java Program The PrintStream Class’s print() and println() Methods Using the javax.swing Package Programming Style Common Programming Errors

    3. Object-Oriented Program Development Using Java: A Class-Centered Approach 3 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 the scientific method

    4. Object-Oriented Program Development Using Java: A Class-Centered Approach 4 Fundamental Areas of Computer Science This text will focus on: An introduction to computer architecture The Java programming language Class development and design Algorithm development An introduction to data structures

    5. Object-Oriented Program Development Using Java: A Class-Centered Approach 5 Programming Languages Computer program A self-contained set of instructions and data used to operate a computer to produce specific results Also called software Programming is the process of developing and writing a program A programming language is a set of instructions that can be used to construct a program

    6. Object-Oriented Program Development Using Java: A Class-Centered Approach 6 Programming Languages (continued) Low-level languages: Machine language Assembly language

    7. Object-Oriented Program Development Using Java: A Class-Centered Approach 7 Programming Languages (continued) High-level languages: Use instructions that resemble natural languages Can be run on a variety of computer types Examples: Pascal Visual Basic C C++ Java

    8. Object-Oriented Program Development Using Java: A Class-Centered Approach 8 Programming Languages (continued) Source program Programs written in a computer language Interpreted language Each statement is translated individually and executed immediately upon translation Compiled language All statements are translated as a complete unit before any one statement is executed

    9. Object-Oriented Program Development Using Java: A Class-Centered Approach 9 Programming Languages (continued) Java is both: Compiled Interpreted Java Virtual Machine Software program that can read bytecode produced by the compiler and execute it

    10. Object-Oriented Program Development Using Java: A Class-Centered Approach 10

    11. Object-Oriented Program Development Using Java: A Class-Centered Approach 11 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 is object-oriented

    12. Object-Oriented Program Development Using Java: A Class-Centered Approach 12 The Development of Java History: Fortran COBOL BASIC Pascal C++ Java

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

    14. Object-Oriented Program Development Using Java: A Class-Centered Approach 14

    15. Object-Oriented Program Development Using Java: A Class-Centered Approach 15 Objects and Classes Objects Part of the Java programming language as component types Can be custom tailored by programmers Programmers can define custom objects

    16. Object-Oriented Program Development Using Java: A Class-Centered Approach 16 A Class Is a Plan The structure for a class of objects must be created at the start of the programming process Class Explicitly written plan Complete set of parts and instructions needed to create items

    17. Object-Oriented Program Development Using Java: A Class-Centered Approach 17 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

    18. Object-Oriented Program Development Using Java: A Class-Centered Approach 18

    19. Object-Oriented Program Development Using Java: A Class-Centered Approach 19 A First Java Class A class consists of a class header line and a body The class header line includes the words public class nameofclass Class body Encloses data and methods that make up class Typically two sections of code: The types of data that will be used Procedures that will be used on the data

    20. Object-Oriented Program Development Using Java: A Class-Centered Approach 20

    21. Object-Oriented Program Development Using Java: A Class-Centered Approach 21

    22. Object-Oriented Program Development Using Java: A Class-Centered Approach 22 Constructing a Java Program Programs can use existing classes A Java program is: Considered an executable applications program A class that must contain a method named main

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

    24. Object-Oriented Program Development Using Java: A Class-Centered Approach 24

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

    26. Object-Oriented Program Development Using Java: A Class-Centered Approach 26

    27. Object-Oriented Program Development Using Java: A Class-Centered Approach 27 Standard Identifiers Java-defined words that have predefined purpose Can be redefined by a programmer Names of classes and methods provided in Java A good programming practice is to only use standard identifiers for their intended purpose

    28. Object-Oriented Program Development Using Java: A Class-Centered Approach 28

    29. Object-Oriented Program Development Using Java: A Class-Centered Approach 29 Identifiers Programmer-supplied words Can be made up of any combination of: Letters Digits Underscores (_) Dollar signs ($) Common practice: The first letter of each word, starting with the second word in a multiword identifier, is capitalized

    30. Object-Oriented Program Development Using Java: A Class-Centered Approach 30 Rules for Identifiers in Java The first character of the identifier cannot be a digit Only letters, digits, underscores, and dollar signs may follow the initial character Blank spaces are not allowed Identifiers cannot be reserved words Maximum number of characters in the identifier name is unlimited

    31. Object-Oriented Program Development Using Java: A Class-Centered Approach 31 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

    32. Object-Oriented Program Development Using Java: A Class-Centered Approach 32 The PrintStream Class’s print() and println() Methods print() and println() are in the PrintStream class and are print methods: Display data to standard output Package One or more individual classes stored in the same directory

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

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

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

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

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

    38. Object-Oriented Program Development Using Java: A Class-Centered Approach 38 JOptionPane.showMessageDialog(null,"message","title",icon-type);

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

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

    41. Object-Oriented Program Development Using Java: A Class-Centered Approach 41 Static and non-static Methods (continued) Static Does not operate on objects Receives all of its data as arguments Example: showMessageDialog() Syntax: ClassName.methodName(arguments);

    42. Object-Oriented Program Development Using Java: A Class-Centered Approach 42 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; }

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

    44. Object-Oriented Program Development Using Java: A Class-Centered Approach 44 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 the program Omitting a semicolon at the end of each statement Forgetting \n to indicate a new line

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

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

More Related