Java Quick Reference
  Language Fundamentals
  Operators and Assignments
  Flow Control and Exceptions
  Declarations and Access Control
  Garbage Collection
  Overloading and Overriding
  Threads
  The java.lang Package
  The java.util Package
  The java.awt Package
  The java.io Package
  References
  Miscellaneous Notes
  Tips & Traps
  Mock Exams

Language Fundamentals - Class Literals

  • new in JDK 1.1
  • class literals are created by appending .class to the name of a primitive or reference type
        System.out.println(int.class);    
        // output: int
        System.out.println(System.class); 
        // output: java.lang.System
    
  • you cannot use a variable with .class
    int i = 5;
    String s = "Hello";
    
    System.out.println(i.class);  // compile error
    System.out.println(s.class);  // compile error
Source Package Import Class Interface Constructors
  Methods main() Identifiers Keywords Defaults Arrays
  Primitives # Literals char Literal String Literals Class Literals