Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you're unsure about something, try writing a test first.</p> <p>I did this:</p> <pre class="lang-java prettyprint-override"><code>//primitive System.out.println(int.class.getName()); System.out.println(int.class.getCanonicalName()); System.out.println(int.class.getSimpleName()); System.out.println(); //class System.out.println(String.class.getName()); System.out.println(String.class.getCanonicalName()); System.out.println(String.class.getSimpleName()); System.out.println(); //inner class System.out.println(HashMap.SimpleEntry.class.getName()); System.out.println(HashMap.SimpleEntry.class.getCanonicalName()); System.out.println(HashMap.SimpleEntry.class.getSimpleName()); System.out.println(); //anonymous inner class System.out.println(new Serializable(){}.getClass().getName()); System.out.println(new Serializable(){}.getClass().getCanonicalName()); System.out.println(new Serializable(){}.getClass().getSimpleName()); </code></pre> <p>Prints:</p> <pre> int int int java.lang.String java.lang.String String java.util.AbstractMap$SimpleEntry java.util.AbstractMap.SimpleEntry SimpleEntry ClassnameTest$1 null </pre> <p>There's an empty line in the last block where <code>getSimpleName</code> returns an empty string.</p> <p>The upshot looking at this is:</p> <ul> <li>the <strong>name</strong> is the name that you'd use to dynamically load the class with, for example, a call to <code>Class.forName</code> with the default <code>ClassLoader</code>.</li> <li>the <strong>canonical name</strong> is the name that would be used in an import statement and uniquely identifies the class. Might be useful during <code>toString</code> or logging operations.</li> <li>the <strong>simple name</strong> loosely identifies the class, again might be useful during <code>toString</code> or logging operations but is not guaranteed to be unique.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload