What is the Java Virtual Machine?

The JVM is like a virtual computer that runs on your machine. You may think of it as a computer running inside of your computer that is used for executing Java programs. The way this works is that a Java program is compiled into Java byte code. If you have been programming in Java already, you'll notice that when you compile a program, a .class file is created that has the same name as the .java file. This file contains the byte code used by the virtual machine.

It is this JVM that allows a Java program to be written from a single computer and run perfectly anywhere, as long as that computer has Java installed (meaning, the JVM exists on that computer). The JVM also protects a programmer from doing any accidental harm or leaving security holes in his or her program. Let me give an example. In C++, you can actually manipulate the memory on your computer, without any safeguards. If you alter a piece of memory that another program running on your computer is using, C++ will allow you to do so. The results of performing such an act are undefined and could cause your computer to crash! Java has no such thing. Java handles all the memory and nitty-gritty stuff for you, which can be both good and bad.

One criticism of the Java Virtual Machine is that it is slow. Sun Microsystems has been optimizing the JVM to be faster and better, especially when sorting out the memory. As Java improves its memory management, programs written in Java will continue to get faster and faster. For the beginner programmer this is no big deal, but for those who are serious about performance, you absolutely should make sure you're doing everything in your power to optimize the code you write for maximum efficiency.

The JVM simplifies the lives of programmers by letting the programmer worry about the actual code and not every underlying detail. It also acts as protection from writing dangerous code with undefined results. On top of all this, Java programs can be written for any type of computer, be it Mac or Windows, without having to change the code at all! This is the beauty of Java, and with continued improvements to the JVM it will continue to be an excellent language for both beginners to learn and experts to master.

Custom Search