Java Reference
In-Depth Information
No, Java is a free-form language.
Chapter 2: Introducing Data Types and Operators
1 . Why does Java strictly specify the range and behavior of its primitive types?
Java strictly specifies the range and behavior of its primitive types to ensure portabil-
ity across platforms.
2 . What is Java's character type, and how does it differ from the character type used by
some other programming languages?
Java's character type is char . Java characters are Unicode rather than ASCII, which
is used by some other computer languages.
3 . A boolean value can have any value you like because any non-zero value is true.
True or False?
False. A boolean value must be either true or false .
4 . Given this output,
use a single string to show the println( ) statement that produced it.
5 . What is wrong with this fragment?
There are two fundamental flaws in the fragment. First, sum is created each time the
block defined by the for loop is entered and destroyed on exit. Thus, it will not hold
its value between iterations. Attempting to use sum to hold a running sum of the iter-
ations is pointless. Second, sum will not be known outside of the block in which it is
declared. Thus, the reference to it in the println( ) statement is invalid.
6 . Explain the difference between the prefix and postfix forms of the increment operator.
Search WWH ::




Custom Search