Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Get the fully-qualified name of a class in Java
A fully-qualified class name in Java contains the package that the class originated from. An example of this is java.util.ArrayList. The fully-qualified class name can be obtained using the getName() method.
A program that demonstrates this 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 fully-qualified name of the class is: " + className);
}
}
Output
The fully-qualified name of the class is: java.util.ArrayList
Now let us understand the above program.
The getName() method is used to get the fully-qualified name of the class c which is stored in className. Then this is displayed. A code snippet which demonstrates this is as follows −
Class c = java.util.ArrayList.class;
String className = c.getName();
System.out.println("The fully-qualified name of the class is: " + className); Advertisements
