- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get the unqualified name of a class in Java
A qualified class name in Java contains the package that the class originated from. In contrast to this, the unqualified class name contains only the class name without any package information.
A program that gets the unqualified name of a class is given as follows:
Example
public class Demo { public static void main(String[] argv) throws Exception { Class c = java.util.ArrayList.class; String className = c.getName(); System.out.println("The qualified class name is: " + className); if (className.lastIndexOf('.') < 0) { className = className.substring(className.lastIndexOf('.') + 1); className = className.replace('$', '.'); } System.out.println("The unqualified class name is: " + className); } }
Output
The qualified class name is: java.util.ArrayList The unqualified class name is: ArrayList
Now let us understand the above program.
First the qualified class name is displayed using the getName() method. A code snippet which demonstrates this is as follows −
Class c = java.util.ArrayList.class; String className = c.getName(); System.out.println("The qualified class name is: " + className);
The unqualified class name is obtained using the substring() method that provides the substring of the className from the last index of ‘.’ Then the unqualified class name is displayed. A code snippet which demonstrates this is as follows −
if (className.lastIndexOf('.') < 0) { className = className.substring(className.lastIndexOf('.') + 1); className = className.replace('$', '.'); } System.out.println("The unqualified class name is: " + className);
- Related Articles
- Get the fully-qualified name of a class in Java
- Get Canonical Name for a class in Java
- Get the class name for various objects in Java
- Get the fully-qualified name of an inner class in Java
- Display the package name of a class in Java
- What is the difference between simple name, canonical name and class name in a Java class?
- How many ways can get the instance of a Class class in Java?
- Get the Name of a Member Object in Java
- Get the name of a primitive type in Java
- The get() method of AbstractList class in Java
- The get() method of Java AbstractSequentialList class
- How to get the class name of an instance in Python?
- Using predefined class name as Class or Variable name in Java
- How to access the object of a class without using the class name from a static context in java?
- Get super class of an object in Java

Advertisements