jQuery in Action, 3rd edition
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 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: 24193

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: http://aspose.com/file-tools
subject: Primitive types
It's not a secret anymore!