There are three flavors of Java: ME for mobile, SE for desktops, and EE for enterprise.
"Java is portable" refers to the SE version. It means that you can run Java bytecode on any hardware that has a compliant JVM.
It doesn't mean that ME is the same as SE is the same as EE. EE has EJBs, but SE and ME don't. That does not make them less portable.
C++ language doesn't change in all platforms.
This statement is not strictly correct. Microsoft adds extensions to their C++ that won't run elsewhere.
ANSI C++ might mean portable source code, as long as you stay away from platform-specific extensions. It does not mean portable bytecode; you may have to recompile and relink.
You want to run genetic algorithms on phones? I know that mobile devices have become pretty powerful, but I'm educated to think that GA would be a server-side functionality. Mobile devices feel more like view to me.
Answer from duffymo on Stack OverflowThere are three flavors of Java: ME for mobile, SE for desktops, and EE for enterprise.
"Java is portable" refers to the SE version. It means that you can run Java bytecode on any hardware that has a compliant JVM.
It doesn't mean that ME is the same as SE is the same as EE. EE has EJBs, but SE and ME don't. That does not make them less portable.
C++ language doesn't change in all platforms.
This statement is not strictly correct. Microsoft adds extensions to their C++ that won't run elsewhere.
ANSI C++ might mean portable source code, as long as you stay away from platform-specific extensions. It does not mean portable bytecode; you may have to recompile and relink.
You want to run genetic algorithms on phones? I know that mobile devices have become pretty powerful, but I'm educated to think that GA would be a server-side functionality. Mobile devices feel more like view to me.
Every hardware architecture has its own somewhat unique instruction set (add ax, bx...) when you build a C++ code, the compiler turns it into a machine code specific to the system/architecture you are working on. So you have to customize and build your code for different architectures for it to work on them.
But What happens in java is, When you build it, it is compiled into a Byte code (as opposed to machine code). And the java virtual machine(JVM) interprets the Byte Code into an instruction that is understandable by the specific architecture you the program is running on. There is JVM for every major architecture and operating system so the code you write on windows will be interpreted and run on MAC-OS or linux without any source level modification by you. That is why Java is portable and that is where the Write Once Run Everywhere motto comes from
java - What is exactly the meaning of "portability"? - Software Engineering Stack Exchange
Why is C (or other similar programming languages) called portable if we need to code compilers for all platforms?
Why is Java considered more portable than other languages like C++? - Software Engineering Stack Exchange
Appreciation for Java portability
Videos
Java is object-compatible. You compile it on one patform and the resultant class files can run on any JVM.
C is source-portable. You can take your C source code and compile it on any ISO C compiler, provided you follow the rules - that means no using undefined or implementation defined behaviour or any non-standard features.
In C only the source code is portable, you have to recompile it on every target platform, given that a suitable C compiler exist. Also, if you access any library or operating system function it must exist on any platform where you want to run your program on.
The big deal in java is, that the language itself brings a lot of standard libarary functions with it, so you rarely need access to the operating systems api.
For C to be portable on system X, we need to write a compiler for that system X. Does that makes C unportable on system X. What exactly is definition for portability of a programming language?
Java is compile once run anywhere. C++ is write once compile anywhere.
"writing a specific JRE for each platform" is not something you do everytime. Porting the JRE to a new platform is something you need doing only once. This task is generally done by the core maintainer/developers of the program and/or the platform. A lot of factors may come into play when deciding who and how the JRE would be ported. Among other things, it depends on the licensed it's published under (I hear Java is Open Source, so I guess anyone could do it). Funny anecdote, Steve Jobs made a big deal about not wanting to take care of the porting of Java on Mac, around a year ago.
The point is not how or who ports the JRE, but the fact that once it is ported, every Java application should now theoretically run easily on the new machine. In that sense, the JRE forms an abstraction layer, completely hiding the machine, allowing easy porting.
However, reality is not always pretty like this. I won't go as far as calling portability a "myth", but it's true that it's not so perfect. For instance, Java has a package called JNI that allows sending native calls, bypassing the JRE, thus preventing the perfect seamless portability, what Java fans like to call "Write once run everywhere".
As mentioned in the comments, C++'s approach to portability is different. On the one hand, it's a compiled language, and those binaries are almost always platform specific. So c++ executables will never be portable (unlike Java). On the other hand, porting the compiler can sometimes be enough. The community has found that by porting the compiler as well as some core libraries of the language, source codes (and not binaries) could be portable.
However, C++ is widely used in critical systems like compilers, kernels, real-time systems,embedded systems, ... There's a "low level" aspect of C++ that cannot be overlooked, when talking about portability.
Just wanted to post on here to say I was actually shocked a couple of days ago when I finished my application, built the jar, and could run it seamlessly across OSs without any issues.
I wrote a patient record system using swing for the gui and a custom file type and encryption for data storage. Took me a few months of work but finally got it all working, held my breath waiting for the jar to build, expecting errors and compatibility issues but to my surprise - nothing. Seamless.
JVM is damn good! Didn’t appreciate it as a student but I really do now.
TL,DR: JVM is great.