Friday, October 06, 2006

Java magic

Today a collegue of me was having problem in running a Hello.java program which prints plain hello on the console.

It was complaining time and again "NoSuchMethodError:main"...

we thought its problem with the JDK in that machine.

But actual culprit is my collegue only, what she did is that she wrote a Hello.java program with invalid main method (with no arguments) and placed it in JDK\bin directory. she compiled in that location itself so JDK\bin has the Hello.class file too.

Now she is trying to create Hello.java in a different directory and with proper main method. but she is getting the error.

When i gave java -verbose Hello
it is showing me that the class is loaded from JDK\bin, that was the mistake.

i removed the Hello.class file from JDK\bin and it is now referring the class file that is created in the current directory.

Summary

JVM gives preference to the JDK\bin directory for locating class files.

No comments: