HOW TO USE CLASS CLASS OBJECT CREATED BY JVM AT THE RUN TIME:
When we run our java program then at the run time jvm will create's class class object
inside the heap memory area .The user can use that class class object to get the information about our class like fully qualified name of class ,methods names present inside the class and so on
This class class object is completely different compare to class object. By using the class object we can call only methods present inside our class but by using class class object we can get any type of information about class like methods names are present inside the class,data types etc.
Example: Let's discuss the example ,how many methods present inside the String class by using class class object generated by jvm inside the heap area.
import java.lang.reflect.*;
class Most
{
public static void main(String[] args)throws Exception
{
int count=0;
Class c=Class.forName("java.lang.String");
Method[] m=c.getDeclaredMethods();
for(Method m1:m)
{
count++;
System.out.println(m1.getName());
}
System.out.println("Total methods are:"+count);
}
}
output:
equals
toString
hashCode
compareTo
compareTo
indexOf
indexOf
indexOf
indexOf
indexOf
indexOf
valueOf
valueOf
valueOf
valueOf
valueOf
valueOf
valueOf
valueOf
valueOf
charAt
checkBounds
codePointAt
codePointBefore
codePointCount
compareToIgnoreCase
concat
contains
contentEquals
contentEquals
copyValueOf
copyValueOf
endsWith
equalsIgnoreCase
format
format
getBytes
getBytes
getBytes
getBytes
getChars
getChars
indexOfSupplementary
intern
isEmpty
join
join
lastIndexOf
lastIndexOf
lastIndexOf
lastIndexOf
lastIndexOf
lastIndexOf
lastIndexOfSupplementary
length
matches
nonSyncContentEquals
offsetByCodePoints
regionMatches
regionMatches
replace
replace
replaceAll
replaceFirst
split
split
startsWith
startsWith
subSequence
substring
substring
toCharArray
toLowerCase
toLowerCase
toUpperCase
toUpperCase
trim
Total methods are:77
In the Above example we can see, there are 77 methods present inside String class ,but based our requirement we can pass our class name inside the forName() method and get all present methods our own class.