It represents the Class
object of that class. Once you get the Class
object, you can do a host of things like get the fields of the class, methods of the class, package of the class and so on.
Most commonly, you will use it to get resources as stream. That is, when you want to retrieve an embedded resource from your jar file. For more detailed information, have a look at the documentation
Run the code below directly at: http://ideone.com/h1czR5
SSCCE
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.lang.reflect.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Class string = String.class;
System.out.println("Package: " + string.getPackage());
System.out.println("Fields: " + java.util.Arrays.toString(string.getFields()));
Method[] methods = string.getMethods();
for(int i = 0; i < 10; i++){
System.out.println(methods[i]);
}
}
}
Output:
Package: package java.lang, Java Platform API Specification, version 1.7
Fields: [public static final java.util.Comparator java.lang.String.CASE_INSENSITIVE_ORDER]
public boolean java.lang.String.equals(java.lang.Object)
public java.lang.String java.lang.String.toString()
public int java.lang.String.hashCode()
public int java.lang.String.compareTo(java.lang.Object)
public int java.lang.String.compareTo(java.lang.String)
public int java.lang.String.indexOf(java.lang.String,int)
public int java.lang.String.indexOf(int)
public int java.lang.String.indexOf(int,int)
public int java.lang.String.indexOf(java.lang.String)
public static java.lang.String java.lang.String.valueOf(float)