Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes Top level classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Top level classes" Watch "Top level classes" New topic
Author

Top level classes

gauraw gupta
Greenhorn

Joined: Apr 10, 2011
Posts: 5
Which is the top level class either Class java.lang.Object or Class java.lang.Object or Class java.lang.Class and please can you explain me the Classloader works.

Thanks
Gauraw Kumar Gupta
Ashutosh Limaye
Ranch Hand

Joined: Oct 24, 2005
Posts: 58
java.lang.Object is the supermost class. Classloader is a class itself in the java.lang package. It contains a method called loadClass(String classname) which is also overloaded as loadClass(String name,boolean resolve). The JVM would instantiate the Classloader when it is created (That's how java.lang is imported by default). Then whenever a class which is not there on the heap is referred to by the code, the JVM calls the loadClass method and pass the name of the class as the argument.
But this may not actually load the .class file in the heap, it may simply locate the desired class and create a Class class object for it (which is the meta-data). When the object of the desired class needs to be created, the JVM may call the loadClass method with name=[classname ] and resolve=[true] this will make the loadClass method call the defineClass() method which contains the magic of creating the in memory image of the .class file.
Hope this helps please read the white paper on ClassLoader for further details....
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38517
    
  23
Both are top level classes. You have misunderstood what top level class means. It means a class which is not inside another class.
You should have a look at the Java™ tutorials, where you find out about the Object class; that second link will give you some useful information, too.
There isn't much about class loaders in the Java™ Tutorials, but you can doubtless find lots by Googling.
 
jQuery in Action, 2nd edition
 
subject: Top level classes