Java Program to Get the Simple Name of the Class

You are currently viewing Java Program to Get the Simple Name of the Class

Java program to get the simple name of the class

// Java program to get the simple name of 
// the class

public class Main {
  public static void main(String[] args) throws ClassNotFoundException {
    Class cls = Class.forName("java.lang.String");

    System.out.println("The class name associated with cls: " + cls.getName());
    System.out.println("The simple class name associated with cls: " + cls.getSimpleName());
  }
}

Output

The class name associated with cls1: A
The class name associated with cls2: Main

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply