Primitives

Unlike some programming languages in which everything is an object, Java includes eight so-called primitive data types that are not strictly speaking classes (although the java.lang packages includes shadow classes for each). The eight primitive data types are:
  1. boolean
  2. int
  3. byte
  4. short
  5. long
  6. float
  7. double
  8. char

Byte, short, and long are alternative versions of the primary integer type, int, whereas double is the preferred alternative to float. While not a primitive type, String is the more appropriate choice in many contexts than char. Thus, of the eight, you are likely to use boolean, int, and double much more frequently than the others.

Variables that use primitive types must be specifically declared. This is usually done at the beginning of the program or some logical segment of the program, although they may also be declared in context. The following statements illustrate both options for several different types:

Applet context

The data types discussed above are illustrated within the context of an applet, below:
import java.applet.Applet;

public class primitives extends Applet{

boolean aTest;
int nItems;

  public void init ( ){
    aTest = false;
    nItems = 16;
    double howMuch = 1.23e2;

    System.out.println("aTest = "+aTest);
    System.out.println("nItems = "+nItems);
    System.out.println("howMuch = "+howMuch);

  } // end init

}// end primitives