Saturday, September 25, 2010

• Class. forName(……):

  • (……): Every reflection API program should load given class or interface dynamically into application from memory at runtime in order to get internal details of that class or interface for this our reflection API program will use as predefined method. Eg:-Class c = Class.forName (“java.lang.system”);
When the above statement is executed class for name method loads java.lang.system class from the memory to java application and returns object of java.lang class ‘c’. This object represents or pointer the class that is loaded java.lang.system class. In the above system ‘c’ is not the object of loaded class called java.lang.system. It is the object of java.lang.class representing loaded class called java.lang.system. 
Class c= Class.forName (“java.lang.system”);
String s=”java.lang.system”;
When object of java.lang.class represents certain class we can use that object to gather internal details of that class. In the above statement we can use object ‘c’ to gather internal details of system class. When string variable represent class name we cannot use that string variable together internal details of that class. In the above statement variable‘s’ cannot be used to gather internal details of system class.

No comments:

Post a Comment