GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes What is ClassLoader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is ClassLoader" Watch "What is ClassLoader" New topic
Author

What is ClassLoader

vijay shanker
Ranch Hand

Joined: Oct 26, 2007
Posts: 88
I just wanted to understand what is java.lang.Class object and how does it work i am having problem to work with becouse i am not understanding the concept behind this
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14193
    
  20

A ClassLoader is an object that is responsible for loading *.class files and turning them into classes that the JVM can use.

See the API documentation of class ClassLoader, it explains it in more detail.

Google for "java classloader" and you'll find some documents that go deeper into the concept of classloaders.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

Since a classLoader object is an object of type ClassLoader, how does a classLoader get loaded?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

Originally posted by Kaydell Leavitt:
Since a classLoader object is an object of type ClassLoader, how does a classLoader get loaded?


If memory serves, there is a bootstrap class loader, in the JVM. This class loader is responsible for loading the runtime classes. In these classes is another classloader that is responsible for loading the classes from the classpath.

And if you intend to write your own classloader, so that you can load classes from another source, you are supposed to place your classloader in the classpath.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
vijay shanker
Ranch Hand

Joined: Oct 26, 2007
Posts: 88
Originally posted by Henry Wong:


If memory serves, there is a bootstrap class loader, in the JVM. This class loader is responsible for loading the runtime classes. In these classes is another classloader that is responsible for loading the classes from the classpath.

And if you intend to write your own classloader, so that you can load classes from another source, you are supposed to place your classloader in the classpath.

Henry



But what does it mean when you say "load the classes". is this same as making an object of class that will be available to program to call methods
of that class.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

Originally posted by vijay shanker:

But what does it mean when you say "load the classes". is this same as making an object of class that will be available to program to call methods
of that class.


If you wamt to write your own class loader, please google for information on how to do this.... basically... the class loader will load the bytecodes (the class file). Once the class loader has the byte codes in a byte array, it will call a method called defineClass(), which does all the stuff need by Java -- including creating the Class object.

It also does other stuff, which is why I recommend that you google for more information, if you are interested.

Henry
 
GeeCON Prague 2014
 
subject: What is ClassLoader