• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

How To Get Current Class Loader Name

April 24, 2014 //  by Krishna Srinivasan//  Leave a Comment

This example shows how to get the name of the class loader and parent class loader for the currently executing class. If you are not aware of the class loaders, please read our previous article about ClassLoader.

What is the ClassLoader ?

As its name implies, ClassLoader is a class that loads other classes. More scientific: The Classloader loads the bytecodes in its class to memory, so it can be used throughout your application. The ClassLoader is in the java.lang.ClassLoader package. Understanding the classloader is important for working on the server development or any product developments which is more often design the custom classloaders to load the classes. You would have come across the ClassNotFoundExecption many times while you are writing Java programming. Classloader is the culprit which causes this exception.

Lets look at the simple example for getting the current class loader and parent class loader.

GetClassLoaderExample.java

package javabeat.net.lang;

/**
 * Get ClassLoader Example
 *
 * @author Krishna
 *
 */
public class GetClassLoaderExample {

	public static void main(String[] args) {
		Class<?> classVar = GetClassLoaderExample.class;

		//Print class loader name loaded this class
		System.out.println("Current Class Loader : "
				+ classVar.getClassLoader().getClass().getName());

		//Print parent class loader name for the current class loader
		System.out.println("Parent Class Loader : "
				+ classVar.getClassLoader().getParent().getClass().getName());
	}

}

Output…

When you run the above code, you would get the output something like this. Note this will be depend on your Java environment.

Current Class Loader : sun.misc.Launcher$AppClassLoader
Parent Class Loader : sun.misc.Launcher$ExtClassLoader

Category: JavaTag: Java Classloader

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « How To Get Implementing Interfaces Name For A Class
Next Post: How To Get Class Loaded Path »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

EJB 3.0 Timer Services

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact