A java program can be created using simple text editors such as the ubiquitous Notepad in Windows or TextEdit in Macs. Such programs are called editors. Editors cannot execute the programming code written on them. They are simply means of storing the program for future execution. There are other computer software that can be used to specifically aid a java developer to create and edit and manage complex and elaborate codes and algorithms. These programs offer a variety of features, to help a Java programmer organize their codes and files. A java program is a file with the “.java” extension (i.e. myJavaProgram.java). A Java program requires compilation using a program called a Java compiler. What a Java compiler does is to interpret the human-readable code written in the .java file and covert it to a file in bytecode. Basically, the human-readable instructions typed in a .java file are called a source code.
By using a java compiler, these instructions are converted and stored in bytes. Each of the class included in a java source code are separately encoded to a corresponding class file. For example, a .java file defining two classes- myClass and myOtherClass will compile into two files in bytecode, with the names myClass.class and myOtherClass.class, respectively. Files saved as .class lose their human readability, but are more compact and easier to distribute. However, there are ways to reverse engineer .class files back to a human-readable source code. Reverting bytecoded files back to its source code can be done by using decompilers. Decompilers themselves are not meant to steal the original codes of a program. As such, care and ethical concerns should always be considered when attempting to reverse engineer and extract information from someone else’s hard work.
It is also during compilation that the program is checked for errors. Syntax errors can occur when the compiler encounters parts of the code that it cannot recognize. Compilers will not produce a class file for as long as it has these syntax errors. Source codes can only be allowed to compile without these syntax errors. A successfully compiled .class file is no t guaranteed error free. A logical error can occur but the compiler will ignore it simply because it can understand the code. Common logical errors include mistakes in string values or mathematical expressions. These are human errors does not interfere with the ability of the program to execute, but they generally make the program provide an unexpected behaviour or output. Debuggers are applications that help developers to watch and trace a program as it traverses its designed algorithm. Debugging is not integrated in the steps needed to run a java program. However, debuggers are one of the most important tools used by programmers to ensure that their programs would run the way they are designed to be, and not just run simply for the sake of it.
After obtaining the compiled .class files from the source code, the program is one step closer to becoming machine readable. The personal computer used by people everyday is collectively a machine. In order for the machine to perform tasks, it must receive information in bitwise machine code or machine language (i.e. sequences of ones and zeroes). As a final step, .class files are relayed to the actual machine by another program called a virtual machine. A virtual machine will verify, interpret and the java byte code file as though it is an actual machine receiving instructions in machine language. The Java Virtual Machine (JVM) is also known as the Java Runtime Environment (JRE). This software allows Java programs to be executed on an actual machine, such as the personal computer or a mobile phone. Being a virtual machine, it bridges the program to the actual machine’s environment and resources. It also ensures that the program is contained in its environment and prevents the program from directly interacting with the actual machine’s operating system or hardware through malicious codes or erroneous instructions. At this stage, the program is now finally “running” and is now able to give instructions to the virtual machine.