Java(principles)

Kay(Geun Woo)
4 min readJan 19, 2024

--

What is Java? How does Java work?

Java is one of the most famous high-lelvel programming languages. It allows the developers to write programs in a language like human language. The programs written in high-level languages are called the source codes. Before we start to talk about how Java works, we have to know some logics behind the programming.

Compliers

The most computer languages use the “compile-link-execute” format. When a developer writes a source code, and runs, the compiler converts it into a low-level program language, which is the language that the computers can understand. Most of the compiled programs form a file and the file containing the converted low-level code is called an object file. A collection of object files are linked together to form an executable file, which that the operating systems like Windows, macOS and Linux can load into RAM to run the content that the developers wrote. Sometime the “executable files” are referred as “relocatable machine codes”. As I mentioned, executable files are written in low-level language, which the computers can understand. However, even though the executable files are in low-level languages, they may not be runnable on a computer if there are dependencies in the source codes. For example, if you want to execute square root, which is not a simple mathematical operation that the computer can deliver without the mathematical programs. In this kind of cases, the object files do not explain how the computation works, but they refer to the square root from the mathematical program that can compute it.

Interpreters

Other than the compilers, we have to know what interpretation is. The interpreted language takes each high-level statement, determines its low-level version and executes the result. This is done for each statement in succession.

The compilers and the interpreters are two different concepts. In metaphor, if you want to read a poem written in a language you don’t know, reading a compiled(translated) version of the poem is faster than doing so everytime you want to read it. Then, why do we need interpreted languages, which are relatively slow? The interpreted languages take advantage when programming applications like artificial intelligence because the artificial intelligence programs may have to adapt new stimuli.

So, How does Java work???

Java is the first language which is neither truly interpreted nor compiled because it actually uses both. This characteristic takes advantageous role in programming. Let’s take a look how it made Java to become one of the most preferred programming languages of the developers.

Platform-Independence

There has been a huge problem for the developers programming with the traditional languages like C and C++. It’s the platform. If a program is targetted to be ran on an operating system, the program only could be ran on the machines with the targetted operating system. For example, if I develope a C++ program that can be ran on Windows, it only can be ran on the devices with Windows operating system(OS), not MacOS or Linux. In order to let the program to be ran on the different OS, I have to change the source code a bit. It was tedious and stressful for the high-level language developers since they had to make 3 versions of source codes with same functions. However, Java resolved the issue by reorganizing the compile-link-execute process at a lower level of the compiler. The Java compilers compile the source code to create bytecode files instead of object files. The bytecode files are the object file for the virtual machines. This type of compiler is often called as JVM(Java Virtual Machine) compiler.

It’s not done yet. Although JVM compilers allowed to bypass the platform dependency by creating bytecode files that can be used on any platform that has Java installed, the bytecodes cannot be executed since they are not executable files. To execute the bytecode files, a Java interpreter, called java, is required to be invoked.

In short, Java bypassed the platform depenency by creating a bytecode with JVM compiler, and let Java interpreter to recognize the local device’s operating system and link the bytecode files in the appropriate way for the OS to be able to execute the program. This method is often referred as compile and link-execute, while the traditional platform dependent languages use compile-link and execute method.

Applet

Resolving of the platform independence leads to another advantage of Java, applet. Applet is a special Java programs that are designed to run on the World Wide Web. Writing a Java applet and putting the bytcode on a webpage allows the Java-enabled web browsers to be able to download and execute it within them. Again, this could not be possible without resolving the platform independence problem.

Library-based

It is very common to create applications by importing modules from the predefined modules, but it wasn’t so before the invention of Java. Java is the first library-based language. Java includes a large number of pre-existing programs and allows the developers to connect their source codes with these useful libraries as needed and save their times.

Other than the above advantages, Java has the features of the languages existed before it was released(distributed programming, multi-threading, security, etc).

Fun Fact : C#

C# is the first major language after Java that followed compile and link-execute method. However, it’s half platform independent. Windows and MacOS can run C# programs written in the same manner, but Linux can’t.

--

--