Java-Specific Question -- CORRECTION
Don Park
donpark at quake.net
Sat Apr 4 06:31:05 BST 1998
This is a correction of my answer to David's question which is:
>>Here's a Java question. Let's say that I have a class with a method
>>
>> public void parse (String publicId, String systemId, Reader reader)
>> throws java.lang.Exception;
>>
>>What will happen if the "java.io.Reader" class is not available on my
>>system (perhaps because I'm using a 1.0.2 browser), but I never invoke
>>this method (I'm assuming that I compiled my code under JDK 1.1 or JDK
>>1.2)?
I answered:
>ClassNotFoundException will be thrown when the class is loaded. What you
This is wrong. David reported test results to the contrary so I went back
to the VM spec and found that my understanding is either obsolete or wrong
to begin with. Since the last thing I want to do is misinform, here is the
correct answer:
When a Java class is loaded, only the superclass and interfaces it
implements are 'resolved', meaning that they are loaded as well. The class
is then 'verified'. Verification of a class does not include checking
whether referenced classes, methods, fields actually exists. After
verification, the class and its superclasses are 'initialized' and executed.
During execution, referenced classes are 'loaded' upon 'use'. This means
that uninvoked methods can reference any class they want to as long as they
are available during compilation process. Same is true for classes
referenced in unexecuted code path.
Therefore, following code could be used to write Reader aware SAX-client
which can run under Java 1.0:
try
{
// if the exception is not thrown, the class is available so use the
// Reader based method to parse.
parser.parseReader(new java.io.InputStreamReader(in));
}
catch (ClassNotFoundException ex)
{
// InputStreamReader is missing so use the stream-based method.
parser.parseStream(in);
}
What I just described might not be true under just-in-time compilers and
server-side Java compilers depending on the compilation strategy involved.
I hope this corrects any misunderstanding due to my evil-twin's activities
;-p
Regards,
Don Park
http://www.docuverse.com/personal/index.html
xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/
To (un)subscribe, mailto:majordomo at ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)
More information about the Xml-dev
mailing list