How do I get information regarding class name?

package org.kodejava.example.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

Wayan Saryada

Founder at Kode Java Org
I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. If these posts help, you can support me, buy me a cup of coffee or tea. Thank you 🥳

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.