O'Reilly logo

Ivor Horton's Beginning Java™ 2, JDK™ 5th Edition by Ivor Horton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required