This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Primitive types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Primitive types" Watch "Primitive types" New topic

Primitive types

raj joe
Ranch Hand

Joined: Mar 17, 2005
Posts: 99
What is the difference between the following statements.How memory is allocated.

int i=1;
Integer i=new Integer(1)
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

The int is either held in a local variable -- i.e., a slot in the stack frame of the method -- or as part of a heap object, if it's a member. The Integer is an object, allocated on the Java heap. The reference to the Integer (the second variable "i") is held in one of the same two places, depending.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Primitive types
Similar Threads
Integer Constant Pool ????
parameter passing question for array reference
Question of Arrays.asList()
Casting an array
converting string to integer