Variables and Data Types

There are eight primitive data types in Java:

However there are only seven kinds of literals, and one of those is not a primitive data type:

There are no short or byte literals.

Strings are a reference or object type, not a primitive type. However the Java compiler has special support for strings so this sometimes appears not to be the case.

class Variables {

  public static void main (String args[]) {
    boolean b = true;
    int low = 1;
    long high = 76L;
    long middle = 74;
    float pi = 3.1415292f;
    double e = 2.71828;
    String s = "Hello World!";

Previous | Next | Top | Cafe au Lait

Copyright 1997-2006 Elliotte Rusty Harold
Last Modified February 3, 1999