aspose file tools*
The moose likes Java in General and the fly likes Class loaders Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Class loaders" Watch "Class loaders" New topic
Author

Class loaders

Bhairava Surya
Ranch Hand

Joined: Aug 19, 2007
Posts: 45
Hi All,

I found so many posts regarding the Java Class Loaders in the forum, but nothing is there completely in the forum.
For that reason, I again started this post.

For the best of my knowledge,

Whenever a JVM is started, class loaders are responsible for loading the classes.

Three class loaders are used
1) Bootstrap class loader
2) Extensions class loader
3) System class loader

The bootstrap class loader loads the core Java libraries[5] (<JAVA_HOME>/lib directory). This class loader, which is part of the core JVM, is written in native code.

The extensions class loader loads the code in the extensions directories (<JAVA_HOME>/lib/ext or any other directory specified by the java.ext.dirs system property). It is implemented by the sun.misc.Launcher$ExtClassLoader class.

The system class loader loads code found on java.class.path, which maps to the system CLASSPATH variable. This is implemented by the sun.misc.Launcher$AppClassLoader class.

So consider I have an application of around 10 classes, which are compiled. And the path for this class files is given in the CLASSPATH variable.

So my question here is,

1) Now if the JVM is started, does all the 10 classes will be loaded in the JVM or not (at the time of starting JVM itself)?

2) COnsider all the classes are loaded. Then in one of my classes, consider a statement is there like A a = new A();
the 'new' keyword is used to instantiate the class which is already loaded in JVM right?

3) what are the phases does a class will go before execution, I mean like JSP life cycle thattranslation compilation etc. the same ways what are the phases for a class

Please reply.

Thanks & Regards,
Ravi.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

Chinna Ravindra wrote:So consider I have an application of around 10 classes, which are compiled. And the path for this class files is given in the CLASSPATH variable.

So my question here is,

1) Now if the JVM is started, does all the 10 classes will be loaded in the JVM or not (at the time of starting JVM itself)?

All classes are loaded once they are needed. You can prove this with the following example:

2) COnsider all the classes are loaded. Then in one of my classes, consider a statement is there like A a = new A();
the 'new' keyword is used to instantiate the class which is already loaded in JVM right?

The "new" keyword will cause the class to be loaded if it isn't loaded already. If it is already loaded it will not re-load the class. See my earlier examle.

3) what are the phases does a class will go before execution, I mean like JSP life cycle thattranslation compilation etc. the same ways what are the phases for a class

There is no translation in Java classes. Compilation is done manually by invoking the compiler. After that it's loading and (possibly) instantiating.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class loaders