This tutorial is for you to setup Java tools and text editor so you can do Java programming on Ubuntu. The tools are OpenJDK and the editor is Geany, a lightweight & user-friendly IDE. The platform used here is Java Standard Edition (Java SE). This tutorial is intended for students especially those switching from Windows and those who avoiding resource-hungry editor like Netbeans/Eclipse. Enjoy!

Subscribe to UbuntuBuzz Telegram Channel to get article updates directly.
This setup is for Java. For other languages, go to C setup and C++ setup.

Install OpenJDK


Do it:
sudo apt-get install default-jdk

This needs +/-40MB on Ubuntu MATE 17.10.

Install Editor


Do it:
sudo apt-get install geany

Write


Type source code below and save it as Program.java. Important: the filename must matches the class name in the source.
// file name should be class name (Program.java -> Program)
public class Program{
    public static void main(String[] args){
        System.out.println("hello, java Program!");
    }
}


Compile


Press Compile button, and no need to press Build button. If your code has no error, then this should produces a file named Program.class. Pressing Compile button is the same as  $ javac Program.java .


Run


Press Run button. This shows a new Terminal saying  "hello, java Program!" . Pressing Run button is the same as  $ java Program .



Where to find Java Source Code Examples?


Go to https://www.cs.utexas.edu/~scottm/cs307/codingSamples.htm and run each source there one by one. This page is very simple and easy to understand so it will be good as your learning source. Thanks to Mike Scott (scottm) for the source codes there!


, , , , ,