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.
I compiled it by
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,
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!
Any program COMPILED on one architecture becomes architecture specific, the resulting binary will only be able to run on that platform...
Do not mix a language with result of compilation, Java is portable because you can get java for almost any architecture and so you can then use your code... and compile again
So what is the difference between Java and C/C++ then? You can also get C/C++ compilers for any plaform you want. I don't figure how Java is more protable or "Write once, run any where". According to you Java should also say, "Write once, compile and run any where". So what's the different. And where does the bytecode thing fit in the equation, I don't really get it dear!
Thanks for your wonderful reply anyway!
So what is the difference between Java and C/C++ then?
The ease at reading the code you did not write in a language you dont know but have to debug...
Quote:
According to you Java should also say, "Write once, compile and run any where". So what's the different.
Yes, You just have to "copy" your code (no rewrite then! )... true compiling is generating a machine language and so is processor dependant...(plus libraries... etc...)
I believe the error you're seeing is related to JDK version mismatch.
I suppose that the latest version on the SPARC machine is older than the one used for the compilation on Win 7.
So:
1. Check the version on the Solaris machine: java -version.
2. Use the same version to compile on Windows
(I have very limited experience with Java, but I believe you need to use at least the same major version:
if you compile the code with JDK 7, it won't work with 6,
if you use 6 for compilation, it will work with both 6 and 7).
3. Try to execute the .class file that you've compiled on Windows on the SPARC machine again.
The JVM will hide the specific platform dependencies.
Yes true but the java virtual machine is still architecture dependant... you will have difficulties running a 64 bit binary on a 32 bit JVM... and java is very "version dependant" ... have you checked?
Why if it were so miraculous that big vendors (e.g. oracle) when giving installation software using java distribute their version in it?