General Java Questions I
   ...
}
it is not working for me. Is there any workaround?
Answer: If the source and the text file are in the jar file, then you access the file by:
URL fileURL = getClass().getResource("file.txt");
You can then read the file by using a reader (or whatever you choose),
e.g.:
_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.
file:///F|/a_jsite/350_tips/general_java I.htm (19 of 33) [2001 07 08 11:24:51]






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