2.15. Summary

In this chapter you have seen all of the basic types of variables that are 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, type short, or type 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.

  • You use an enumeration type to define variables that can be assigned values only from a fixed set that you specified as part of the enumeration.

  • Variables of type boolean can have only either the value true or the value false.

  • The order of execution ...

Get Ivor Horton's Beginning Java™ 2, JDK™ 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.