Chapter 3 Classes and Objects 2007 Lawrenceville Press
Chapter 3 Classes and Objects © 2007 Lawrenceville Press
Chapter 3 Package © 2007 Lawrenceville Press
Chapter 3 Application Package © 2007 Lawrenceville Press
Chapter 3 A Java Application package first. Application package name /** * The Greeting class displays a greeting comment */ public class Greeting { class declaration public static void main(String[] args) { method System. out. println("Hello, world!"); statement } } © 2007 Lawrenceville Press
Chapter 3 Executing a Java Application source code public class Greeting public static void System. out. printl } } compiler. . . c cilbup bytecode 03 3 b 84 01 ff f 9 68 05 1 a JVM. . . 48 b 3 30 Hello, world! © 2007 Lawrenceville Press
Chapter 3 Escape Sequences An escape sequence is a backslash () followed by a symbol that together represent a character. Commonly used escape sequences: n newline t tab (8 spaces) \ backslash " double quotation mark © 2007 Lawrenceville Press
Chapter 3 The format() Method § A method in the System class § Used to control the way output is displayed § Requires a format string and an argument list § The format string specifier takes the form: %[alignment][width]s § For example System. out. format("%-6 s %4 s", "Test 1", "90"); displays: Test 1 90 © 2007 Lawrenceville Press
Chapter 3 Code Conventions § An introductory comment should begin a program. § Package names should begin with a lowercase letter and then an uppercase letter should begin each word within the name. § Class names should be nouns and begin with an uppercase letter and an uppercase letter should begin each word within the name. § A comment block should be included before each class. © 2007 Lawrenceville Press
Chapter 3 Code Conventions(con't) § Comments should not reiterate what is clear from the code. § Statements in a method should be indented. § An open curly brace ({) should be placed on the same line as the class or method declaration, and the closing curly brace (}) should be on a separate line and aligned with the class or method declaration. 9 © 2007 Lawrenceville Press
Chapter 3 Flowchart Symbols start/end 10 input/output © 2007 Lawrenceville Press
Chapter 3 The Triangle Flowchart 11 © 2007 Lawrenceville Press
- Slides: 11