Is java.lang.Class the same as the actual .class file? i.e. is the content equivalent?
I want to send the .class over socket, and was wondering if instead of trying to find and load the actual .class file, if I could just transmit the java.lang.Class instead?
Elaboration (read if you want more info)
Suppose I have a Java class called SomeObj. When this file is compiled, a file called SomeObj.class will be generated.
We also know that if I have SomeObj as a type, we could get its java.lang.Class type by doing:
Class someObjClss = SomeObj.class;
We know java.lang.Class implements Serializable, thus it can be transmitted.
So is java.lang.Class basically the object representation of the actual .class file?
UPDATE:
Assuming I have transmitted the .class file over to another host, do I just use the defineClass() method to construct the class back?
Link here
UPDATE2:
This code does returns null InputStream. How is that possible?
Class clazz = String.class;
String className = clazz.getName(); System.out.println(className);
URL url = clazz.getResource(className);
if( url != null )
{
String pathName = url.getPath(); System.out.println(className);
}
InputStream inputStream = clazz.getResourceAsStream(className);
if(inputStream != null )
{
System.out.println(inputStream.available());
}