This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

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: 11853

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: 8661

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.


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
I agree. Here's the link:
subject: doubt regarding primitives in Java
It's not a secret anymore!