Java is a programming language, like C++ and Fortran, but with a twist: code written in Java is portable, meaning it can be executed on any machince.
There is a catch: the computer running the Java code must have the Java Virtual Machine (JVM) installed in order to run the code.
This is why, when running an app that uses Java, you’ll be asked to install Java SE (which is the Virtual Machine for desktop computers) if it’s not already installed.
When Java code is compiled, it isn’t turned into machine language. It’s turned into something called bytecode, which is a sort of intermediary between Java code and machine language. This bytecode can be executed by just about anyone (so long as they’ve got the Java Virtual Machine).
But What About .jar Files?
If you’ve ever executed a Java app, you’ve probably seen a .jar file. They’re nothing more than a bunch of bytecode files and their resouces (like audio and image files) compressed into a single file.
Kind of like an interpreter, the JVM takes the bytecode it’s given and turns it into machine language.
What makes the JVM special is the fact that it uses bytecode. Other interpreters, like the Python interpreter, take the source code and turn it straight into machine language. The JVM’s use of bytecode makes it much more effecient than other interpreters.
So Why (or Why Not) Java?
Java made the programmer’s job easier than ever before, which is why so many apps use Java to this day. That’s the main reason for anyone to use Java. But there are a good number of drawbacks, mainly:
- insecure (the JVM is supposed to keep the program separate from the system, but hackers have found that it’s not very good at it)
- slow (it’s still an interpreted language, which are always slower than compiled)
- not as easy to use as other languages that are still portable (e.g. Python)
In other words, you should consider alternatives before jumping on the Java bandwagon.