Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Data type in java are not object?

Tags:

java

oop

I have studied about java datatype very earlier and found that they are primitive type. As java is object oriented but its data types are not. why is it so?

like image 362
kundan bora Avatar asked Sep 16 '25 03:09

kundan bora


2 Answers

It is said that everything in Java is an Object at the same time the Java Programming Language is meant to be simple. Since the primitive data types consume less memory and can be accessed faster, they are not objects. The equivalent Wrapper classes are also available in java like "Integer" "Short" etc. They can be used as objects if you want. However, the wrapper classes will be stored in Heap and they are slow.

like image 100
Shiva Avatar answered Sep 18 '25 16:09

Shiva


It is more efficient to deal with primitive types than making each variable a full fledged object. The most common types (ie. int, char, float etc.) are simple primitives. The rest are objects.

like image 29
Madara's Ghost Avatar answered Sep 18 '25 16:09

Madara's Ghost