Hi friends,
I hope everybody is fine and doing well. I had a previous thread quering about system calls. Unfortunately, you got the impression that I was discussing some kind of homework with you guys, and you got the thread closed. Infact, there was no homework involved there, it was just an idea that came to mind, when I was writting a c program using the read() system call. I hope this question of mine is not mistaken for a homework.
I am in the process of learning Java, with the help of a very good book titiled, "Java The complete Reference". There it is mentioned that java is a platform-independant language, and it can be interpreted anywhere regardless of the underlying hardware or operating system. About Java they say, "Write once, run anywhere" unlike in C/C++ which says, "Write once, compile anywhere". Java programs are compiled into an intermediary form, "the byte code" with .class extension, which can be interpreted by the Java Virtual Machine.
Here is my query, and a small java program which I want to run on a different platform.
// File name Java_Port.java
// Compiled on x64 architecture running Windows 7
// To be run on Solaris 10 , SPARC architecture running in 32-bit mode
public class Java_Port
{
public static void main(String args[])
{
System.out.println("Java is portable!");
}
}
I compiled it by
javac Java_Port.java
I got the the file Java_Port.class
Interpreting it on the same computer where it has been compiled, it runs successfully.
But when I transfer this class file to a SPARC machine, with the latest version of JDK, it doesn't run there.
It says,
$ java Java_Port
Exception in thread "main" java.lang.UnsupportedClassVersionError: Java_Port : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: Java_Port. Program will exit.
The same problem persists whenever I run the same .class file on different versions of Microsoft Windows.
I am a novice as far as java is concerned, so if I have stated any thing silly, I beg your pardon for that.
Looking forward to your wonderful and helpful replies!
Thanks in advance!