if you are getting the following error:
java.lang.UnsupportedClassVersionError: test_hello_world :
Unsupported major.minor version 51.0
the you must follow the following thing written below:
The reported major numbers are:
J2SE 8 = 52,
J2SE 7 = 51,
J2SE 6.0 = 50,
J2SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45
To fix the actual problem you should try to either run the Java code with a newer version of Java JRE or specify the target parameter to the Java compiler to instruct the compiler to create code compatible with earlier Java versions.
For example, in order to generate class files compatible with Java 1.4, use the following command line:
javac -target 1.4 HelloWorld.java
if you really want to install different version the follow:
If you download the linux binary from http://java.com/en/download/help/linux_install.xmlyou can install it in whatever directory you like. Then just reference those libs in your code, and you're good to go.
With the binary installer, it'll create its own named subdirectory (e.g. in your example, /usr/java/jdk1.5.0_), so you can download as many as you want, and they'll line themselves up in appropriately named sub-drectories.
The main java binary lives in /usr/bin, so if you want to replace that to the point where when you type "java" it accesses your java, and not that one, you just move the old one out of /usr/bin, and link your new one in there. Typing which java will tell you what the default java on your system is.