Transcript PPTX
Comments are for people Header comments supply basic information about the artifact Comments also used to describe class elements Whitespace is also for people Blank lines make elements stand out Indentation is a form of whitespace Indentation is used to indicate that what follows is a part of what proceeded Indentation is a form of whitespace Indentation is used to indicate that what follows is a part of what proceeded Keywords are reserved lowercase words that have special meaning public – what follows is shareable class – program or object definition static – not part of an object definition void – method does not return a value Name of the class A Java name must be an identifier Java has syntax rules for stating what is a valid name; e.g., identifiers begin with letter and can be followed letters and numerals To encourage program understanding style rules give name understanding Convention to capitalize the first letter in a class name General convention to capitalize successive words in a name PrintQuote, main, String, args, System, out, and println are all names Convention that identifiers not indicating a class begin with a lower case letter Braces delimit a class definition Braces delimit a block of code A program begins executing the code in method main() Method main() must be public, static, and void Every method has a parameter list following its name. The list is contained with a pair of parentheses. For some methods, the list is empty Method main() takes a single parameter of type String[] Everybody who is anybody calls that parameter, args Following the parameter list is the body of the method The method body lists the statements (i.e., actions) it is to perform when invoked (started up) The statements are performed from top to bottom The statements are performed from top to bottom Because statements are allowed in general to span multiple lines an indicator is needed for separating statements from one another Java statements are terminated with a semicolon The dot is the selection operator Sometimes multiple selecting is needed to get a hold of the desired component System is the name of a class library whose elements are automatically available to a program The System library has an element named out out represents an object configured to be associated with your display out has a println() behavior println() is a method println() displays text to its display println() displays the value of its argument This use of println() says to print the literal string ”I’m never going to the Louvre again.” to its display A literal string is a sequence of characters within a pair of the double-quote characters This use of println() says to print the literal string ”-- Joanne Cohoon” to its display A program terminates when all of the statements in method main() are completed