File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes doubt regarding primitives in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "doubt regarding primitives in Java" Watch "doubt regarding primitives in Java" New topic

doubt regarding primitives in Java

Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157


Are primitives also Objects in Java? If not , then what are they? Where are they stored in the memory? Stack?

~ Mansukh
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11957

They are not Objects. They are primitives.

And I believe the answer to where are they stored depends on how they are used. If an object has a primitive member variable, then I believe that the primitive will be stored in the heap with the rest of the Object.

For a method variable, they would be on the stack.

But does it really matter where they are stored? What do you gain by knowing?

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Winston Gutkowski

Joined: Mar 17, 2011
Posts: 8956

Mansukhdeep Thind wrote:Are primitives also Objects in Java? If not , then what are they? Where are they stored in the memory? Stack?


This forum is meant to be a source of help; not your own personal reference library. The answers to all those questions can be found in the JLS, the tutorials, or (if you need it) the JVM spec; and I'd suggest that you get used to Searching First before you ask questions, otherwise people are likely to stop helping you.

My answer: No, primitives are not objects. The rest is either irrelevant, or a waste of your valuable time, because it's not something you need to know at the moment.


Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
Articles by Winston can be found here
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: doubt regarding primitives in Java
jQuery in Action, 3rd edition