Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Class loaders

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 22563
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic