
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How Does a ClassLoader Work in Java
A Java Class is stored in the form of byte code in a .class file after it is compiled. The ClassLoader loads the class of the Java program into memory when it is required. The ClassLoader is hierarchical and so if there is a request to load a class, it is delegated to the parent class loader.
The types of ClassLoader in Java are given as follows
- Bootstrap ClassLoader
- Extensions ClassLoader
- System ClassLoader
Example
public class ClassLoaderTest { public static void main(String[] args) { System.out.println("class loader for this class: " + ClassLoaderTest.class.getClassLoader()); System.out.println("class loader for DNSNameService: " + sun.net.spi.nameservice.dns.DNSNameService.class.getClassLoader()); System.out.println("class loader for HashMap: " + java.util.HashMap.class.getClassLoader()); } }
Output
class loader for this class: sun.misc.Launcher$AppClassLoader@73d16e93 class loader for DNSNameService: sun.misc.Launcher$ExtClassLoader@70dea4e class loader for HashMap: null
Advertisements