To get the name of a class in Java, you can use the getName()
method of the Class
class. This method returns a string that represents the fully qualified name of the class.
Here's an example of how to use the getName()
method to get the name of a class:
public class Main { public static void main(String[] args) { Class cls = java.util.Date.class; String className = cls.getName(); System.out.println(className); // prints "java.util.Date" } }Sourww:ecw.lautturi.com
In this example, the getName()
method is called on the Class
object for the java.util.Date
class to get the name of the class as a string.
You can also use the getSimpleName()
method of the Class
class to get the simple name of the class (i.e., the name of the class without the package name).