General Java Questions III
_istream = new BufferedReader( new
InputStreamReader(fileURL.openStream()) );
  
j o h n e w e b e r
Or, simpler
getClass().getResourcesAsStream("file.txt"), but you must be sure that
file is in the same directory ( package ) as your class, otherwise you
need play with getClassLoader().getResourceAsStream( "/file.txt" );
  
Oleg
Q: Difference between loading and instantiating a class???
Well, the subject says it all. What is the difference between loading and instantiating
a class in a JVM.
Second question: What would happen if at runtime I update a class file? Will the JVM
know to use that instead?
Answer: The difference is that when a class is loaded by a ClassLoader it is read in
as a stream of bytes, presumably from a file, but it could just as easily be from over
the network, and then processed or "cooked" into a representation that the VM can
use to make instances of Objects of that classes type. This last part is the
instantiation. You can load a class at runtime with:
Class.forName( "MyClass" );
and instantiate one with:
MyClass mc = Class.forName( "MyClass" ).newInstance();
Cool, ehh. You don t have to know the name of a class at compile time.
>Second question: What would happen if at runtime I update a class file?
>Will the JVM know to use that instead?
Loaded classes are cached because it s quite costly to do the "cooking" I mentioned
above. So it will not be loaded. You may create a separate ClassLoader with new
SecureClassLoader but that will cause all classes _it_ loads to be loaded from this
new ClassLoader but that s not what
you want.
I don t know if you can specify that a class should be loaded from disk again using
the normal ClassLoader. You could very easily make your own ClassLoader in which
case you would have explicit control over such things. Look at java.lang.ClassLoader
and java.lang.Class.
  
Michael B. Allen
file:///F|/a_jsite/350_tips/general_java III.htm (4 of 9) [2001 07 08 11:24:53]






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java web hosting

 

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved