Simple Data Types
Home Up Access Modifiers Arrays Simple Data Types

 

Integer Types

  1. byte (1 byte)
       e.g.  byte whatever;           // default initial value (0)
       e.g.  byte whatever = 10;   // initial value
  2. short (2 bytes)
  3. int (4 bytes)
  4. long (8 bytes)

Floating Point Types

  1. float (4 bytes)
    e.g.   float money;  
    e.g.   float money = 100.00;
  2. double (8 bytes)

Character Types

  1. char (2 bytes, Unicode)
       e.g. char initial;
       e.g. char initial = 'a';

    Unicode characters can also be specified using '\u0000' through '\uFFFF'.  '\u0000' through '\u00FF' correspond to ordinary ASCII/ANSI characters.  If you would like to find out more about Unicode, visit www.unicode.org.
  2. String (an array of characters, strictly speaking this is not a simple data type, but since it is built-in to the language, it at least appears "simple")
       e.g. String name;                  // array still not created
       e.g. String name = "java";     // array created and initialized
       e.g. char letter = name[0];    // letter assigned the character j

Boolean Types

  1. boolean (legal values: true, false)
       e.g.   boolean flag = true;    // initial value of true