In this lesson, we learn how to compile and run a simple Java program which just prints "Hello World!" to the console. (Lesson 01 is the introduction lesson with no examples, so we start here at 02 :-)
- open console
- type
sudo apt-get update
and press enter - type in your passoword if asked to
- type
sudo apt-get install openjdk-8-jdk
and press enter - type in your passoword if asked to
- open browser
- go to http://www.oracle.com/technetwork/java/javase/downloads/index.html
- download the latest JDK (not the JRE!)
- after download, install
-
open console
-
type
java -version
-
the output should be something like:
$ java -version openjdk version "1.8.0_121" OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-0ubuntu1.16.04.2-b13) OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
We use a very simple example program here, a typical Hello World! program.
Compile:
javac HelloWorld.java
you get a file HelloWorld.class
which can be executed in the Java VM.
Execute (after compiling):
java HelloWorld