Java Data Types



Variables in Java must be objects, arrays, or one of the primitive data types
    Java has 8 primitive data types:

      (boolean, byte, short, int, long, double, float, char)

    Notes:
    • All integer types are signed (and there is no unsigned keyword)
    • Unlike C and C++ char variables are 16 rather than 8 bits
    • Primitive data types are passed by value

	boolean like6837 = true;	// boolean likewise have values {true, false}
	byte teeth = 32;			// bytes go from -128 to 127
	
	if (!like6837) teeth = teeth - 1;
	
	float pi = 3.141592f;		// you need the "f" here
	short classes = 0xbad;		// hexadecimal
	
	
Lecture 2 Slide 8 6.837 Fall '98

All variables in Java must be declared as an object, an array, or a primitive data types.

Java has 8 primitive data types: