refelction_getClasssName.htm
Refection has the ability to retrieve information about the object during runtime :
  • Determine the class of an object.
  • Get information about a class's modifiers, fields, methods, constructors, and superclasses.
  • Find out what constants and method declarations belong to an interface.
  • Create an instance of a class whose name is not known until runtime.
  • Get and set the value of an object's field, even if the field name is unknown to your program until runtime.
  • Invoke a method on an object, even if the method is not known until runtime.
  • Create a new array, whose size and component type are not known until runtime, and then modify the array's components.

 

reflection getclassname()

import java.io.*;
import java.awt.Color;
import java.lang.reflect.*;
class Test_this {
static public void main( String[] args ) {
Test_this tt = new Test_this();
tt.printName(tt);
}
static void printName(Object o) {
Class c = o.getClass();
String s = c.getName();
System.out.println(s);
}
}

 
import java.io.*;
//import java.awt.Color;
import java.net.*;
//import java.lang.reflect.*;
class Test_this {
static public void main( String[] args ) {
process_this tt = new process_this();
Test_this.printName(tt);
}
static void printName(Object o) {
Class c = o.getClass();
String s = c.getName();
System.out.println(s);

}
}
class process_this
{
//public String str = "manas6";
public static void method_socket_address(String str2)throws IOException
{
InetAddress address2 = InetAddress.getByName(str2);
System.out.println("Remote server is http:// "+ address2);
System.out.println("Remote server name : "+ address2.getHostName());
System.out.println("Remote server IP : "+ address2.getHostAddress());

}
}
 
 

//import java.net.*;
import java.lang.reflect.*;
public class Test_this {
static public void main( String[] args ) {
String st = new String();
printName(st);
System.out.println("----");
Test_this tt = new Test_this();
printName(tt);
}
static void printName(Object o) {
Class c = o.getClass();
String s = c.getName();
System.out.println("class name : " + s);
int m = c.getModifiers();
if (Modifier.isPublic(m))
System.out.println("modifier public");
if (Modifier.isAbstract(m))
System.out.println("modifier abstract");
if (Modifier.isFinal(m))
System.out.println("modifier final");
}
}

 

import java.lang.reflect.*;
import java.awt.*;
import java.net.*;
import java.io.*;

public class Test_this {
static public void main( String[] args )throws IOException
{
Button st = new Button();
printName(st);
System.out.println("----");

Test_this tt = new Test_this();
printName(tt);
System.out.println("----");
InetAddress address = InetAddress.getByName("manas6");
System.out.println("Networking Host is http:// "+ address);
printName(address);

}
static void printName(Object o) {
Class subclass = o.getClass();
Class superclass = subclass.getSuperclass();
while (superclass != null) {
String className = superclass.getName();
System.out.println(className);
subclass = superclass;
superclass = subclass.getSuperclass();

}
}
}