- 3 parts universal to Java programs - comments - help programmers understand program - state purpose of program - explain meaning of code - 3 comment types - comment markers syntax: - start: /* - end :*/ - single-line comment extends from // to end of line - javadoc comments covered later - computer ignores - not necessary for execution - important for documentation - changes always made - often by somebody else - particular uses - header - beginning of program/method - describe program/method - explain code w/ ambiguous purpose - note modifications - id/summarize code block - disable sections of code during testing - import - use pre-defined classes whenever possible - group classes into packages - java comes w/ many packages - use class from package - syntax: . - dot notation - fully qualified name - hierarchy of packages - package includes subpackages - multiple dots - use import to avoid fully qualified name - allows to just use class name - asterisk to import all classes in a package - syntax: import .*; - conventional (as opposed to importing each class) - doesn't copy classes into program - class declaration - syntax: class { } - "class" reserved word - class member: data val or method - every program must include at least one - use name of main class + "application" to refer to whole application - java automatically executes main method of main class first - method declaration - syntax: () { } - modifiers: state which kind of method (there are many) - return type: states type of data value returned by method - use program template for now - completely different programs can be created readily by using dif objs Quick Check: 1. comments, import statements, class declarations 2. a main method 3. The comments are green, between /* and */; the import statement is the line "import javabook.*;", and the class declaration runs from "class Ch2FunTime {" to the end of the code. 4. They import different packages and use different classes. Ch2Sample1 actually uses more methods. 5. This arrow line is meant to be dotted. _________________ | | | Ch2MyWebBrowser | | | | | |_________________| | | | _______\/________ | | | Ch2MyWebBrowser | | | | | |_________________|