How do I get the name of a class?

package org.kodejava.lang;

import java.util.Calendar;
import java.math.BigDecimal;

public class ClassName {
    public static void main(String[] args) {
        // Get the name of the classes below.
        Class<?> clazz = String.class;
        System.out.println("Class Name: " + clazz.getName());

        clazz = Calendar.class;
        System.out.println("Class Name: " + clazz.getName());

        clazz = BigDecimal.class;
        System.out.println("Class Name: " + clazz.getName());
    }
}

The result of the code snippet above are:

Class Name: java.lang.String
Class Name: java.util.Calendar
Class Name: java.math.BigDecimal
Wayan

Leave a Reply

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