Get class name

ReturnMethodSummary
StringgetCanonicalName()Returns the canonical name of the underlying class as defined by the Java Language Specification.
StringgetName()Returns the name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String.
StringgetSimpleName()Returns the simple name of the underlying class as given in the source code.

public class Main {

  public static void main(String[] args) {
    Class c = new String().getClass();
    String s = c.getName();
    System.out.println(s);
  }
}

The output:


java.lang.String
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.