There are eight primitive data types in Java:
booleanbyteshortintlongfloatdoublecharHowever there are only seven kinds of literals, and one of those is not a primitive data type:
boolean: true or falseint: 89, -945, 37865long: 89L, -945L, 5123567876Lfloat: 89.5f, -32.5f,double: 89.5, -32.5, 87.6E45char: 'c', '9', 't'String: "This is a string literal"
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!";
}
}