GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  J2EE  >  OOPS
Go To First  |  Previous Question  |  Next Question 
 OOPS  |  Question 17 of 30    Print  
How is memory allocated by new ?
a) In a heap b) in a stack b) both a & b c) None of these.
a)


  
Total Answers and Comments: 19 Last Update: July 14, 2008     Asked by: lakshmi 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
  Sorting Options  
  Page 1 of 2   « First    1    2    >     Last »  
July 13, 2006 01:55:41   #1  
lavanyachagantipati Member Since: July 2006   Contribution: 1    

RE: How is memory allocated by new ?a) In a h...
sir ,please tell me wt exactly this new will do
 
Is this answer useful? Yes | No
July 14, 2006 02:06:16   #2  
bharath kumar        

RE: How is memory allocated by new ?a) In a h...
ans:a)heap
 
Is this answer useful? Yes | No
July 14, 2006 02:10:01   #3  
bharath kumar        

RE: How is memory allocated by new ?a) In a h...
 new is a keyword that creates the instance of the class
 
Is this answer useful? Yes | No
July 21, 2006 03:59:12   #4  
pratap        

RE: How is memory allocated by new ?a) In a h...
java object create in heap but stored in stack
 
Is this answer useful? Yes | No
August 02, 2006 09:00:14   #5  
manna bhai        

RE: How is memory allocated by new ?a) In a h...

   if u have instance variables in class so memory for all instance variable will be allocated in heap. not in stack stack is for method variable


 
Is this answer useful? Yes | No
August 09, 2006 14:39:17   #6  
siva kumar reddy        

RE: How is memory allocated by new ?a) In a h...

hi,

actually static variables ,local variables ,method parameters are stored in stack.somany stacks are created(one stack per one thread)

instance variables and java objects are stored in heap.only heap is created.

cheers

siva


 
Is this answer useful? Yes | No
August 12, 2006 13:52:05   #7  
k.r        

RE: How is memory allocated by new ?a) In a h...
The JVM allocates memory in two ways1) Stack: for local variables (declared in methods and constructors). this is deallocated once the method exits.2) heap: everytime an object is created using new keyword, it is allocated in the heap. theses have a longer lifespan. it the JVM runs out of space in the heap it gives a Java out-of-memory error.
 
Is this answer useful? Yes | No
August 16, 2006 02:24:33   #8  
janmejay        

RE: How is memory allocated by new ?a) In a h...
Hey!NO NO........everytime an object is created using new keyword, it is allocated in the heap. these have a longer lifespan. if the JVM runs out of space in the heap it gives a Java out-of-memory error........................and local variables and methods goes to stack...and this is deallocated once the method exits and variables goes out of scope......
 
Is this answer useful? Yes | No
August 19, 2006 19:31:39   #9  
durga prasad reddy        

RE: How is memory allocated by new ?a) In a h...

stored in heap and the reference variables are stored in stack.if heap is filled then out of memory exception occurs


 
Is this answer useful? Yes | No
August 27, 2006 05:06:30   #10  
C.R.Venkatesh        

RE: How is memory allocated by new ?a) In a h...
Here is my 2 cents worth.



(a) Simply put, all Java Objects are allocated memory in Heap.




(b) Primitives types (not *array* of primitives) and references to objects are allocated on the stack.




(c) Importantly, each thread in the JVM gets it own stack and the VM option




-Xss decides the stack size for each thread.




Note: If the stack size is too small, eventually you see "StackOverflowError".


Example:class FooBar{    
public void get(MyTest obj)   // obj a reference to an object - stack.   
{          
int x = 10;    // Stack         
Vector tmpObj=new Vector(); // Heap         
...         
...   
}
}
 
Note:  tmpObj will be garbage collection based on the rules 
(like reference count and others) that GC maintains to check its life span.
HTH.


 
Is this answer useful? Yes | No
  Page 1 of 2   « First    1    2    >     Last »  


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape