Primitive Data Types in Java

Java's primitive data types are very similar to those of C. They include boolean, byte, short, int, long, float, double, and char. The boolean type has been added. However the implementation of the data types has been substantially cleaned up in several ways.

  1. Where C and C++ leave a number of issues to be machine and compiler dependent (for instance the size of an int) Java specifies everything.
  2. Java prevents casting between arbitrary variables. Only casts between numeric variables and between sub and superclasses of the same object are allowed.
  3. All numeric variables in Java are signed.

sizeof isn't necessary in Java because all sizes are precisely defined. For instance, an int is always 4 bytes. This may not seem to be adequate when dealing with objects that aren't base data types. However even if you did know the size of a particular object, you couldn't do anything with it anyway. You cannot convert an arbitrary object into bytes and back again.

Next | Top | Cafe au Lait

Copyright 1997-8 Elliotte Rusty Harold
Last Modified January 26, 1998