Integer Floating Point String Character Boolean Null -2147483648 -1.0 "A" 'a' true null -1 0.0 "Hello World" '0' false 0 39.95 "\n new line" '?' 1 1.23e09 "1.23" ' ' 2147483647 -1e6 "The answer is: " '7' Note: Other literals are possible such as for integers > 2,147,483,647. 12345678901L Comments Comments are portions of text that annotate a program, and fulfill any or all of the following expectations: Provide internal documentation to help one programmer read and understand another’s program. Explain the purpose of a method. Describe what a method expects of the input arguments (n must be > 0, for example). Describe a wide variety of program elements. Comments may be added anywhere within a program. They may begin with the two-character special symbol when closed with the corresponding symbol /* */. /* A comment may extend over many lines when using slash start at the beginning and ending the comment with a star slash. */ An alternate form for comments is to use before a line of text. Such a comment may appear at // the beginning of a line, in which case the entire line is by the program, or at the end of “ignored” a line, in which case all code prior to the special symbol will be executed. // This Java program displays "hello, world to the console. Comments can help clarify and document the purpose of code. Using intention-revealing identifiers and writing code that is easy to understand, however, can also do this. Self-Check 2-1 List each of the following as a valid identifier or explain why it is not valid. -a -i abc H.P. -b -j 123 double -c -k ABC 55_mph -d _.$ -l sales Tax -e -m my Age $$$$ -f -n identifier ______ -g -o (identifier) Mile/Hour -h -p mispellted Scanner 2-2 Which of the following are valid Java comments?
Integer Floating Point String Character Boolean Null -2147483648 -1.0 "A" 'a' true null -1 0.0 "Hello World" '0' false 0 39.95 "\n new line" '?' 1 1.23e09 "1.23" ' ' 2147483647 -1e6 "The answer is: " '7' Note: Other literals are possible such as 12345678901L for integers > 2,147,483,647. Comments Comments are portions of text that annotate a program, and fulfill any or all of the following expectations: Provide internal documentation to help one programmer read and understand another’s program. Explain the purpose of a method. Describe what a method expects of the input arguments (n must be > 0, for example). Describe a wide variety of program elements. Comments may be added anywhere within a program. They may begin with the two-character special symbol /* when closed with the corresponding symbol */. /* A comment may extend over many lines when using slash start at the beginning and ending the comment with a star slash. */ An alternate form for comments is to use // before a line of text. Such a comment may appear at the beginning of a line, in which case the entire line is “ignored” by the program, or at the end of a line, in which case all code prior to the special symbol will be executed. // This Java program displays "hello, world to the console. Comments can help clarify and document the purpose of code. Using intention-revealing identifiers and writing code that is easy to understand, however, can also do this. Self-Check 2-1 List each of the following as a valid identifier or explain why it is not valid. -a abc -i H.P. -b 123 -j double -c ABC -k 55_mph -d _.$ -l sales Tax -e my Age -m $$$$ -f identifier -n ______ -g (identifier) -o Mile/Hour -h mispellted -p Scanner 2-2 Which of the following are valid Java comments?
227Sum15.docx