CEIT

Java

Software

  1. Download Java Development Kit (JDK)

Check Java installation

Type the blow commands in a terminal (or Command Prompt in Windows):

java --version

and

javac --version

The above commands should show the version numbers if the installation was successful.

Example:

kamal@sky:~$ java --version
openjdk 25.0.2 2026-01-20 LTS
OpenJDK Runtime Environment Temurin-25.0.2+10 (build 25.0.2+10-LTS)
OpenJDK 64-Bit Server VM Temurin-25.0.2+10 (build 25.0.2+10-LTS, mixed mode, sharing)
kamal@sky:~$ javac --version
javac 25.0.2
kamal@sky:~$ 

Simple Java program

  1. Save below content in a file named HelloWorld.java:

    public class HelloWorld {
        public static void main(String[] args) {
            System.out.println("Hello World!");
        }
    }
    

    A common mistake while using Notepad in Windows is saving the file as "HelloWorld.java.txt" which will not work. You will have to rename the file to the correct name HelloWorld.java in that case.

  2. Use a terminal (Command Prompt in Windows), change to the directory where HelloWorld.java was saved.

    For example, if you saved the file inside directory C:\fullstack\java\01-helloworld in Windows, use below command:

    cd C:\fullstack\java\01-helloworld
    
  3. To compile, run below command:

    javac HelloWorld.java
    

    If no errors found, the above command will create a file called HelloWorld.class in the same directory. Check availability with 'dir' command.

  4. To run the program, run below command:

    java HelloWorld
    
  5. Below you see how the above steps are done on a Linux computer:

    kamal@sky:~$ cd ceit/fullstack/java/01-helloworld/
    kamal@sky:~/ceit/fullstack/java/01-helloworld$ ls -l
    total 4
    -rw-rw-r-- 1 kamal kamal 127 Feb  1 15:47 HelloWorld.java
    kamal@sky:~/ceit/fullstack/java/01-helloworld$ cat HelloWorld.java 
    public class HelloWorld {
        public static void main(String[] args) {
            System.out.println("Hello World!");
        }
    }    
    kamal@sky:~/ceit/fullstack/java/01-helloworld$ javac HelloWorld.java
    kamal@sky:~/ceit/fullstack/java/01-helloworld$ ls -l
    total 8
    -rw-rw-r-- 1 kamal kamal 426 Feb  5 16:38 HelloWorld.class
    -rw-rw-r-- 1 kamal kamal 127 Feb  1 15:47 HelloWorld.java
    kamal@sky:~/ceit/fullstack/java/01-helloworld$ java HelloWorld
    Hello World!
    kamal@sky:~/ceit/fullstack/java/01-helloworld$
    
  6. Can you change the program to print "Hello yourname!" where yourname will be your own name?