package org.kodejava.lang.reflect;
import java.util.Date;
public class ClassNameDemo {
public static void main(String[] args) {
Date date = new Date();
// Gets the Class of the date instance.
Class<?> clazz = date.getClass();
// Gets the name of the class.
String name = clazz.getName();
System.out.println("Class name : " + name);
// Gets the canonical name of the class.
String canonical = clazz.getCanonicalName();
System.out.println("Canonical name : " + canonical);
// Gets the simple name of the class.
String simple = clazz.getSimpleName();
System.out.println("Simple name : " + simple);
}
}
Here are the information printed out by the program:
Class name : java.util.Date
Canonical name : java.util.Date
Simple name : Date
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024