Are composite data types and reference data types the same thing in java??
Answers
Answered by
6
In Java there are 8 primitive types which are basic data types :
byteshortintlongfloatdoublecharbooleanreference types are any instantiable class as well as arrays.
Class types, Object types and Reference types all mean exact same; an object of a class. Examples : Object of a class Car, String, Integer,etc.
Every variable irrespective of whether it is primitive or reference type is stored in the computer memory.For a primitive type of variable if you visit it's memory location you will find the value of the variable.int x = 3;
Now if you visit the location where x is stored you can find the value 3.
For a reference type of variable if you visit it's memory location unlike the primitive type you will find a memory address pointing to other location and not the values of variables in Object. This memory address points to a location where the details of Object and values of variables inside it reside.Now once you understand this the differences between them should be obvious ones.
Assignment - the primitive value is copied in primitive type where as in reference type the address is copiedComparisons - the primitive values are compared in primitive type where as in reference type the addresses are compared to check if they point to same object.Return - the primitive value is returned in primitive type where as in reference type the address is returned.Now each of the above mentioned primitive types has an equivalent reference type called Wrapper classe. These wrapper classes provide further useful methods,constructors and functions over and above storing values and are instantiated just like an object of a class. (Integer,Byte,Short,Boolean,Character,etc.)
Similar questions