the CustomMessage.class from com.scjp5.classes package is used both in complie time and run time if you set CLASSPATH like this : $JAVA_HOME/jre/lib/ext/My_Custom_Classes.jar;.....;.; In the complie time the CustomMessage.class from My_Custom_Classes.jar is used In run time the CustomMessage.class from com.scjp5.classes package is used
Which version of CustomMessage.class file will be used when run the code :
I think the a is corret(maybe in the run time )
if l mistake plz correct me!
[ March 18, 2006: Message edited by: Changchun Wang ] [ March 18, 2006: Message edited by: Changchun Wang ]
the class in My_Custom_Classes.jar will be used both at compile time and at runtime.
The java compiler and the java runtime will look for CustomMessage.class in the directories listed in CLASSPATH chronologically. In both the cases, $JAVA_HOME/source/com/scjp5/classes does not fall under the CLASSPATH. If the CLASSPATH was, say,
I think the CustomMessage class in /source/com/scjp5/classes packageis used both in compile time and run time
Joined: Feb 15, 2006
Edisandro could you supply your classpath to us? thanks!
Joined: Jan 19, 2006
First of all. The correct answer is B.
So let me explain why.
1st -> In order to find all .class files they need, both java and javac commands use the same search mechanism, so, in this question, both commands will use the same .class version. (At compile and run times)
2nd (Most Important) -> Inside your Java installation directory (which I called as $JAVA_HOME, maybe you can find questions on the real exam that refers to java instalation directory as $JAVA_HOME), there's a subdirectory named jre/lib/ext. If you put any custom .jar files into the ext subdirectory, java and javac can find the classes they contain even you don't mention these .jar files in your classpath.
3rd -> Actually, there's a core function into Java that performs the search in .jar files located in jre/lib/ext directory BEFORE look at any classpath provided at command line or system variable. So, in the same way the java and javac commands look from left to right at directories provided in classpath and stop searching when the first occurrence of file is found, java and javac commands also ignore any classpath if the .class files they need is found at .jar files existing in jre/lib/ext subdirectory.
4th -> I got surprised when I first saw the main declaration public static void main (String ... args) as a valid signature for main method. So, I decided to put this kind of main declaration just to confuse some guys who don't know this issue.
Note that String ... args as command line parameter is valid only as of Java 5.
5th -> In javac -source 5 com/scjp5/CustomMessageMain.java command, there's no need to put the argument -source 5. I put -source here just to explicitly tell that I want compile my code for Java 5 because of using a different main method signature.
6th -> In java -classpath . com.scjp5.CustomMessageMain command, the custom classpath provided tells Java to searching inside source/ subdirectories for any .class file it need. However, DON'T forget that Java first looks at jre/lib/ext subdirectory in order to find the .jar files and classes it needs. So, if Java is able to find the file inside jre/lib/ext subdiretory, it simply ignores any entries provided in classpath.
Bottom line, DON'T forget that regardless of entries provided in classpath, java and javac command will ignore them if they're able to find the .class file they need inside some .jar file existing right into $JAVA_HOME/jre/lib/ext.
Just for your information, ext means external. I would say, external classes.
Please let me know if you need some more explanations about this question.
Joined: Nov 11, 2005
Thanks Edisandro for interesting question, it's always good to try myself especially that exam is coming closer. Sorry, I told you I'd let you know in the evening, but I cannot send you another private mesage until you reply, so I please send a short reply.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com