For example, Oracle makes a JVM for Windows, and one for Linux, and one for Solaris, and other vendors make JVMs for their own operating systems.
Yes, you could implement your own JVM, but that would ofcourse not be a simple project, and probably far too big and too complex for a single person. And if you're officially allowed to call it a Java Virtual Machine depends on Oracle, you'll need a license from Oracle and it will need to pass Oracle's compatibility tests before you can officially call it Java.
Apache tried to make a fully open source, free software implementation of the JVM called Apache Harmony but they gave up, because formerly Sun and now Oracle did not want to cooperate with the licensing.
Mansukhdeep Thind wrote:OK. So these are some sort of op-codes / mnemonic codes which are used to instruct the underlying platform to perform the specific task
Yes. Just like every single program that runs on every single computer ever made.
Some part of the JVM is native code for the underlying processor. It has to be. It could have been written in assembly, or machine language, or by flipping switches on a panel, but mostly it's written in C or C++. That C++ is compiled to native machine language for that platform. Other parts of the JVM can be written in Java. Just like any other Java code, that Java code is turned into bytecode (machine language for the JVM), and then interpreted or compiled (by other parts of the JVM) into native machine language for the underlying platform.
Mansukhdeep Thind wrote:OK. So these are some sort of op-codes / mnemonic codes which are used to instruct the underlying platform to perform the specific task like class format verification, semantics, loading, calculations etc. Correct?
That's why it's called the Java Virtual Machine. Java is normally compiled to bytecode for the JVM. Bytecode consists of machine language instructions (opcodes with operands) for a virtual (as opposed to a real, physical CPU) machine.
The JVM runs the bytecode, just like a CPU does in hardware: it looks at each instruction and then executes it on the underlying operating system and CPU. To make things run faster, Oracle's JVM includes a JIT (Just In Time) compiler, which translates Java bytecode to native machine instructions, which are then executed. Programs run a lot faster because the JIT has to convert the bytecode to native code only once, and the native code can then be run many times.
Oracle's JVM is written in C++.
There are a number of advantages to having a virtual machine instead of compiling source code directly to native machine instructions. It means that your compiled code is CPU-independent, so you can easily run it on different kinds of CPUs without needing to recompile it. Also, the JVM can do certain optimizations for the specific CPU that the program is running on that would be hard to do if you would compile the code to native code ahead of time.
Mansukhdeep Thind wrote:But then there are different jdk installables for different platforms such as for Windows/Linux/Solaris etc.
There are different JDKs for each platform, but these are for developing applications. To run a Java application you only need a JRE (which is a JVM plus associated libraries and resources), but again there is a different JRE for each platform.
Mansukhdeep Thind wrote:What's a system call? As in some commands that are specific to the platform kernels?
I'm not sure what Fred means by "system call," but there are some things that may work on one platform but not the other, or that may "work", but behave in a way you didn't want. This is usually the result of the programmer explicitly writing platform-dependent code. Some examples:
fred rosenberger wrote:you can, using java, explicitly call a command on the underlying OS. So, if i wanted to rename a file, I could call "mv fileA.txt fileB.txt" on my unix machine. This would work fine (although there are some caveats to this), until I moved my class file to a windows box. There, it would not work at all, since Windows doesn't have "mv", but "rename"
@OP: That's the Runtime.exec()/ProcessBuilder bullet point in my post.