Reference types in Java - ilya-khadykin/notes-outdated GitHub Wiki

There is actually no such thing as an object variable, there is only an object reference variable.

Wrapper classes

Primitive Class
boolean Boolean
byte Byte
short Short
int Integer !
long Long
char Character !
float Float
double Double
int primitive = 0;

Integer reference = Integer.valueOf(primitive);
int backToPrimitive = reference.intValue();

boxing

Integer reference = Integer.valueOf(primitive);

unboxing

int backToPrimitive = reference.intValue();

Implicit conversion

Integer a = 1;
int b = a;

Integer c = 10;
Integer d = 10;
Integer e = c + d; // much slower than primitives due to overhead of boxing/unboxing

Conversion to/from String

long fromString = Long.parseLong("12345"); // static method

String fromLong = Long.toString(12345); // static method

String concatenation = "area" + 51; // automatic conversion

Useful methods

short maxShortValue = Short.MAX_VALUE;

int bitCount = Integer.bitCount(123);

boolean isLetter = Character.isLetter('a');

float floatInfinity = Float.POSITIVE_INFINITY;

double doubleNaN = Double.NaN;

boolean isNaN = Double.isNaN(doubleNaN);