+ 2

Write Once. Run Anywhere

java

22nd Nov 2016, 2:34 AM
AVATAR
AVATAR - avatar
6 Antworten
+ 2
I understand what Daniels says and he is partially correct. it is true that it needs modification on Java program sometimes to run on other platform. it needs jre for adjustment of platform independent and there is JVM and program and os. these are facts we have to keep in mind but the Java bytecode generated is never a platform specific it is in machine code that is same for every platform. so you need not a single step unlike other programs to convert a program made for an os to other what does a window with Java feature install run .jar and a Mac .jar a Linux distr. .jar and it is not only same extension but exactly same file. he was absolutely wrong in saying c++ a platform independent lang with write once run anywhere because all articles coin this as example of being strictly platform dependent starting from variable creation memory via controlling screen values till mode to execution it is all different. they use it in opposite example that's why instead of having such a useful lang Java came. what write once run anywhere means is compile and make your program once package it and the same file made will run on every platform that supports Java program feature ...
23rd Nov 2016, 5:45 AM
Sandeep Chatterjee
+ 1
my understanding of this is that the Java virtual machine translate Java Instructions into binary code, which every machine can understand
22nd Nov 2016, 2:41 AM
Ricardo Coleman
Ricardo Coleman - avatar
+ 1
what it means is other platform dependent lang needs a source code and then compile to for the platform the compiled file runs only on that platform but in Java it is platform independent and the same .class file runs anywhere you do not need the source code to modify and compile it for that platform .jar once created runs almost anywhere. traditional program : code-complwindows (Intel) - machine code-complserver(Linux).- machine code-compiledforit-. machine Java : / JVM windws soucecode----jbtcode. ~JVM amd \ JVM mac
22nd Nov 2016, 4:13 AM
Sandeep Chatterjee
+ 1
it's platform dependant only if you use platform dependant things like OS calls. it IS possible to write independant code, say for example simple C++ "hello world" program is platform independant, you can compile it for every platform and distribute it. Java bytecode runs on only ONE platform - the JVM. that platform is a layer between your program and the OS. that platform is the analogue of C++ compiler, instead it does the platform-specific compiling for you. C++ doesn't have that layer so you instead cross-compile code for all target plaforms.
23rd Nov 2016, 7:30 AM
asdadasdsaczxc
0
actually its a bit different than Sandeep and Ricardo claim. the JRE does not translate the code further, instead it executes the bytecode directly, using itself as the middleman between the Operating System and the program you are executing. this in no way gives it power to run absolutely anywhere though. this does not mean the code can't be compiled to native executable to eliminate the need for a JRE. another write-once-run-anywhere language is C++, but you need to either cross compile or compile directly on the target machine. even though same goes for Java - it needs a JRE implementation on the target machine to function properly. so Java isn't unique in what it does.
22nd Nov 2016, 5:33 AM
asdadasdsaczxc
- 1
java just adds a layer between source code and native executable. basically the JVM was once code that has been cross-compiled to run on various machines. it is a machine in itself, interpreting your bytecode in the appropriate way for any system it is built to work on. well written c++ code, for example, can be cross-compiled for every platform, or compiled by the user with absolutely no changes. the difference from Java is that there is no middle-man platform or bytecode. the Java coder has one less step to distributing the program, but the end user needs to take one extra step installing the JRE. the C++ coder has to take one extra step, cross-compiling code for every platform it wants to run it on. the end user doesn't need to do anything extra. and neither of them can 100% work "anywhere"
22nd Nov 2016, 4:44 PM
asdadasdsaczxc