• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Top level classes

 
gauraw gupta
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50289
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic