Monday, November 27, 2006

Java Code and Version Dependency

If you are a person who plays with different versions of Java, according to your business need, client need or your interest. Be careful for java version dependency. Ok, let me show you an example, this is the code I was trying in morning:

class StringTest {

public static void main(String[] args)
throws Exception
{
String s[] = new String[10];
String news = s[-1].valueOf('a');
}
}

Nothing great in this code, but will this code give an exception or not ? s[-1] is ofcourse a negative index array value but mind it method "valueOf" is a static method and hence not depending on the instance of the class. The result is quite interesting:

jdk 1.1 - running perfect.
jdk 1.2 - throwing an error.
jdk 1.3 - running perfect.
jdk 1.4 - throwing an error.
jdk 1.5 - throwing an error.

Thanks to my office system , which has all the java versions. Hmm, result is quite interesting.

I start searching the problem in "Google" and I got an awesome article, again on Javaworld.com which practically not solved my problem but at least relaxed me (Click on the main title to go on Javaworld.com page). Lots of things to read off, I can't write whole in blog :)

No comments: