Reflection_JavaLangClass1
Objectives :
  • Java Reflection tenders a java application to inspect and modify runtime behavior of the application.
  • Did we know ? yes but overlooked ; All Reflection API has one entry point via an immutable instance of java.lang.Class
  • import java.io
    • getSimpleName()
    • getCanonicalName()
    • getName() Process
  • java.lang
  •  
Complete Code:


import java.io.*;
public class ClassTemplate1 extends Process {
/**
*
*/
public ClassTemplate1() {// TODO Auto-generated constructor stub
}
public static void main(String[] args) throws IOException
{
try {
Class<?> cls1 = Class.forName("Process");
System.out.println("cls1 " + cls1);
System.out.println("getSimpleName() " + cls1.getSimpleName());
System.out.println("getCanonicalName() " + cls1.getCanonicalName());
System.out.println("getName() " + cls1.getName());
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
class Process{

Process(){ System.out.println("Constructor invoked");
}
public String str= "manas";
private int n1 = 23;
public int n2 = 34;
}