Comment on page
1.2 Java Workflow
Taking a program from a
.javafile into an executable has two main steps in Java: compilation and interpretation.
To run the code in
Hello.java, we would first compile the code into a
.classfile using the command
javac HelloWorld.java. Then, to run the code, we would use the command
In your terminal, the result would look like the following:
$ javac HelloWorld.java
$ java HelloWorld
There are several reasons for the usage of
.classfiles, which we will only cover briefly here. First of all,
.classfiles are guaranteed to have been type-checked, making the distributed code safer. They are also more efficient to execute, and protect the actual source code in cases of intellectual property. We will not go into the details of
.classfiles in this textbook beyond knowing that they are created after compilation.