File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 24199

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
It's not a secret anymore!