Java Reference
In-Depth Information
Self-Test Exercises
33. What are the two kinds of comments in Java?
34. What is the output produced by the following Java code?
/**
Code for Exercise.
*/
System.out.println("Hello");
//System.out.print("Mr. or Ms. ");
System.out.println("Student");
35. What is the normal spelling convention for named constants?
36. Write a line of Java code that will give the name ANSWER to the int value 42 .
In other words, make ANSWER a named constant for 42 .
Chapter Summary
Compiling a Java class or program produces byte-code , which is the machine language for a
fictitious computer. When you run the byte-code, a program called an interpreter translates
and executes the byte-code instructions on your computer one instruction at a time.
A variable can be used to hold values, such as numbers. The type of the variable must
match the type of the value stored in the variable. All variables must be declared
before they are used.
The equal sign, = , is used as the assignment operator in Java. An assignment statement
is an instruction to change the value of a variable.
Each variable should be initialized before the program uses its value.
Parentheses in arithmetic expressions indicate which arguments are given to an operator.
When parentheses are omitted, Java adds implicit parentheses using precedence rules
and associativity rules .
You can have variables and constants of type String . String is a class type, not a
primitive type .
You can use the plus sign to concatenate two strings.
There are methods in the class String that can be used for string processing.
Variables (and all other items in a program) should be given names that indicate how
they are used.
You should define names for number constants in a program and use these names
rather than writing out the numbers within your program.
Programs should be self-documenting to the extent possible. However, you should
also insert comments to explain any unclear points.
 
Search WWH ::




Custom Search