Java Reference
In-Depth Information
method are indented two levels. We prefer to use four spaces for each level of indent-
ing. More than four spaces eats up too much line length. It is possible to get by with
indenting only two or three spaces for each level so long as you are consistent. One
space for a level of indenting is not enough to be clearly visible.
Self-Test Exercises
32. What are the two kinds of comments in Java?
33. 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");
34. What is the normal spelling convention for named constants?
35. 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 lan-
guage 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, like 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 state-
ment 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 prec-
edence 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.
Search WWH ::




Custom Search