File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes memory allocation problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "memory allocation problem" Watch "memory allocation problem" New topic
Author

memory allocation problem

krishnaraja Puranika
Greenhorn

Joined: Feb 06, 2003
Posts: 5
hi...consider this simple program
public class Test
{
public static void main(String[] args)
{
System.out.println("Hello All");
}
}
the question is ..i know that memory is allocated to a perticular object whenever it is instantiated and this case we wont....where the memory is allocated for this perticular program ? pls clarify ...
thanx in advance.....
Vijayakumar Arya
Ranch Hand

Joined: Jan 27, 2003
Posts: 76
Hi Krishnaraja,
In fact, there is a step prior to instantiation of objects and that is called class loading. The JVM uses the class loader to load the class into the memory, it loads the class variables and the methods of the class.
When you instantiate an object, VM will allocate only the memory for the instance variables.
The memory for the methods are not allocated for each instance of the class. At a higher level we can say that the bytecode loaded into the memory is reused. The memory management, semaphores, threads, local variables are all managed internally by the JVM.
Hope this answers your question


Thanks,<p>Vijay<p>The Hand that gives, Gathers.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Well I think that it goes like this.
The Classfile for class Test gets loaded first. Where it is placed is not specified by the JLS Specs but probably on a reserved section of the heap. The methods (all one of them ) get loaded to the Method area.
Then there is a String created for "Hello All" which is placed in the String Pool.
Because you are invoking the main method of this class a thread is started dedicated to it. When that thread is over (pretty darn soon in this case) everything is released by the JVM, the class is unloaded and the process ends.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Oh, I see that Vijay got here first .
In that case - yeah - what HE said .
krishnaraja Puranika
Greenhorn

Joined: Feb 06, 2003
Posts: 5
thanx a lot...........vijay...bye
 
 
subject: memory allocation problem
 
Threads others viewed
Can a object contain another object?
Polymorphism question
Array doubt
about static variable
doubt in Array construction
MyEclipse, The Clear Choice