Java Reference
In-Depth Information
You can use any HTML tags within a documentation comment except for header tags. The HTML tags you
insert are used to structure and format the documentation appropriately when it is viewed, and javadoc will
add HTML tags to format the comments that include the special @ tags that we mentioned above.
The few comments I have made here really don't do justice to the power and scope of javadoc. For that
you need to look into it in detail. The JDK comes with the javadoc program and documentation.
Javadoc also has its own home page on the Javasoft web site at
http://java.sun.com/products/jdk/javadoc/ .
Summary
In this chapter you have seen all of the basic types of variables available in Java. The discussion of
boolean variables will be more meaningful in the context of the next chapter since their primary use is
in decision making and modifying the execution sequence in a program.
The important points you have learned in this chapter are:
The integer types are byte , short , int , and long , occupying 1, 2, 4, and 8 bytes
respectively.
Variables of type char occupy 2 bytes and can store a single Unicode character code.
Integer expressions are evaluated using 64-bit operations for variables of type long , and using
32-bit operations for all other integer types. You must therefore add a cast for all assignment
operations storing a result of type byte , short , or char .
A cast will be automatically supplied where necessary for op = assignment operations.
The floating-point types are float and double , occupying 4 and 8 bytes respectively.
Values that are outside the range of a floating-point type are represented by a special value
that is displayed as either Infinity or - Infinity .
Where the result of a floating point calculation is indeterminate, the value is displayed as NaN .
Such values are referred to as not-a-number.
Variables of type boolean can only have either the value true or the value false.
The order of execution of operators in an expression is determined by their precedence. Where
operators are of equal precedence, the order of execution is determined by their associativity.
Exercises
1.
Write a console program to define and initialize a variable of type byte to 1, and then successively
multiply it by 2 and display its value 8 times. Explain the reason for the last result.
2.
Write a console program to declare and initialize a double variable with some value such as
1234.5678. Then retrieve the integral part of the value and store it in a variable of type long ,
and the first four digits of the fractional part and store them in an integer of type short .
Display the value of the double variable by outputting the two values stored as integers.
Search WWH ::




Custom Search