The title is a lie.
Boolean, char, byte, short, int, long, float, and double are all primitive data types in Java. These are all words that Java knows. These values are stored in the stack, as opposed to the heap. Variables that are on the stack are accessible directly from memory, and can run very fast. Objects are on the heap, and take more time to access.
Every primitive type in Java has a wrapper class.
The wrappers have methods attached to them that the primitive types do not have. These include…
public static void main(String args)
//declearing a boolean, this returns true or false
boolean t = true;
// declaring character
char a = ‘G’;
// declaring byte
byte b = 4;
// declaring short
short s = 56;
// declaring int
//declaring a long
long l = 244843984;
// declaring a float — for float use ‘f’ as suffix
float f = 4.7333434f;
// declaring a double — default fraction value is double in java
double d = 4.355453532;
System.out.println(“boolean: “ + t);
System.out.println(“char: “ + a);
System.out.println(“byte: “ + b);
System.out.println(“short: “ + s);
System.out.println(“int: “ + i);
System.out.println(“long: “ + l);
System.out.println(“float: “ + f);
System.out.println(“double: “ + d);
Create your free account to unlock your custom reading experience.