Differentiate between Primitives and Objects
- Everything in Java is an "Object", as every class by default inherits from class
"Object", except a few primitive data types, which are there for efficiency reasons.
Primitive Data types of java
boolean, byte 1 byte
char, short 2 bytes
int, float 4 bytes
long, double 8 bytes
- Primitive data types are normally used for local variables, parameters and instance variables (properties of an object)
- Primitive datatype are located on stack and we can only access their value whereas objects are located on heap and we have a reference to these objects
- Additionally primitive data types are always passed by value while objects are always passed by reference in java. There is no C++ like methods
- void someMethod (int &a, int & b) // not available in java