Why does only java have a VM?
Everyone knows about classic languages such as C++, Assembly and C. What's weirdly specific about Java is the java virtual machine, why does it need a VM to run when other languages don't need to, even python.
It checks, reads and verify the java bytecode and the intepreter/core of java. It's basically used in JRE and JDK.
JRE is obviously, for being able to run java code & apps. It also uses heap space for dynamic memory allocation for java objects.
JDK is for developing & building applications for java.
It says C++ directly compiles code to machine code, but apparently java uses an entire separate interpreter, like some other apps I used before that emulate.
Python also has a bytecode checker but it's not a virtual machine, so why does java need an entire virtual machine just to run code?
It checks, reads and verify the java bytecode and the intepreter/core of java. It's basically used in JRE and JDK.
JRE is obviously, for being able to run java code & apps. It also uses heap space for dynamic memory allocation for java objects.
JDK is for developing & building applications for java.
It says C++ directly compiles code to machine code, but apparently java uses an entire separate interpreter, like some other apps I used before that emulate.
Python also has a bytecode checker but it's not a virtual machine, so why does java need an entire virtual machine just to run code?
Comments
JAVA is a "write once, run anywhere" environment.
IOW, you build some code on an Intel based windows machine, and in theory, it would run on a PowerPC Mac.
So basically your telling me that if I wrote Java code on PC-DOS if possible, it could run on a m68k Mac, ARM Mac, Windows 10, Linux Debian and even FreeBSD if it was all supported
https://www.ibm.com/docs/hu/aix/7.2?topic=monitoring-advantages-java
Advantages of Java
2024-08-29
Java™ has significant advantages over other languages and environments that make it suitable for just about any programming task.
The advantages of Java are as follows:
Java is easy to learn.
Java was designed to be easy to use and is therefore easy to write, compile, debug, and learn than other programming languages.
Java is object-oriented.
This allows you to create modular programs and reusable code.
Java is platform-independent.
One of the most significant advantages of Java is its ability to move easily from one computer system to another. The ability to run the same program on many different systems is crucial to World Wide Web software, and Java succeeds at this by being platform-independent at both the source and binary levels.
Because of Java's robustness, ease of use, cross-platform capabilities and security features, it has become a language of choice for providing worldwide Internet solutions.
https://www.google.com/search?q=why+use+java&oq=why+use+java&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIGCAEQLhhA0gEINTc1MWowajGoAgCwAgA&sourceid=chrome&ie=UTF-8
The entire idea of interpreted or virtual machines was around on early personal computers because nobody was sure what CPU the next machine would have.
The UCSD P-System is one example. One could write and compile a program for the UCSD P-System and in theory it would run on any machine.
There were also Smaltalk type VMs, and that includes VisiCorp Visi On. Had that been successful, it could have been easily ported to other systems.
Even the TI-99/4A's Graphics Programing Language was the result of uncertainty during the design phase about what CPU would ship in it. They could have gone with a Z-80, or TI's 8-bit CPU, but instead they shoehorned their 16-bit CPU in there.
Microsoft .NET was created at a time when Intel was threatening to pull x86 compatibility from their CPUs, and Microsoft wanted a way to keep some kind of binary application compatibility across these platforms.
P-Code virtual machines had a second advantage beyond portability. P-Code can use considerably less memory. Java was intended for tiny embedded systems at first. The memory savings come at the cost of performance.
Microprocessors and micro-controllers usually have a distinct instruction set that's incompatible with others, so your code for micro-controller X wouldn't necessarily work on micro-controller Y. e.g. The instruction set for the Zilog Z80 is different to the instruction sets of the MOS 6502 and Motorola 68010. The instruction set on the Zilog Z80 is similar to that of an Intel 8080 (with a few changes), but is totally alien to that of an Intel 960.
There were options, of course:
- Paying a source license for access to a high-level language compiler and re-targeting it,
- Writing your own language compiler for the instruction sets you use,
- Paying the micro-controller manufacturer for their development stuff, if they have any,
- Writing code for either a single micro-controller or family of controllers and never using anything else.
The thinking with Java was "well, rather than do any of that, why not just either obtain a language runtime for your micro-controller or write one yourself." Writing a bytecode interpreter is a lot simpler than writing a compiler.This allows someone to write code for, say, a Zilog Z80 using Java, then move it to any micro-controller for which the Java virtual machine existed with minimal effort.
Modern Java still has that design goal, but it's pretty non-obvious now. In the 90s and 00s, you could write your code on Sun's Solaris Unix (SPARC architecture), and have it run on Microsoft Windows (Intel architecture).
Java becoming dominant in various areas is down to Sun Microsystems and is quite a story in its own right, with lots of players -- including Steve Jobs.