Main Page

Previous Next


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.

Previous Next
JavaScript Editor Java Tutorials Free JavaScript Editor