Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Primitive types

 
raj joe
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic