Java
Ah, the second computer language. One thing is guaranteed: it's going to be different. Here is one difference right up front.
Python programs run until they complete execution or until some error or exception triggers program death and a traceback prints out.
In python you edit code then run it.
Java has an additional step, compilation.
Just as with Python, you will edit source code. Once
you edit and save, you run the compiler,
javac
. This can have two results.
- Your program makes grammatical sense and compiles.
You will know this because there will be no error
message and, when you list your files, you will see
a
.class
file. You will see that the Java compiler makes Miss Wormwood look pretty slack. - Your program fails to make grammatical sense.
Java aborts compilation and spews forth with error
messages. You go back to your source, fix the indicated
errors, and try again. Errors at this stage are
called
compile time errors
- Once your program compiles, if it has a
main
method, you can run it withjava
.
Both languages can have errors when programs written in them run. These errors are called runtime errors.
What is the JVM? A virtual machine is a computer implemented in software. Java source code compiles to Java byte code, which is the machine language of the JVM.
This is why a given Java program can run on different platforms. The Mac JVM translates Java byte code to Mac machine code, which then runs. Thw Windoze JVM translates Java byte code into machine language for the Windoze system. This layer of abstraction is happily concealed from you.
Does Python have a virtual machine? Yes. Read about it here.
We will begin to learn about Java's type system using
its REPL jshell
.