Java Program 1 – Compile and Run a Hello-world Java Program

Step 1
Open "Folder" and create a new directory called "myproject" under your home directory to keep all your works.

Step 2
Open "Text Editor" (gedit). Enter the following source code and save as "" under the "~/myproject" directory created eariler.
    public class Hello {   // To save as "" under "~/myproject"
       public static void main(String[] args) {
          System.out.println("Hello, world from Ubuntu!");


Step 3
To compile the Hello-world Java program, launch a Terminal and issue these commands:
// Change directory to where the source code resides
cd ~/myproject
// List the contents of current directory. Check for ""
    …… ….
// Compile "" into "Hello.class"
// Check for "Hello.class"
    …… Hello.class ….

Step 4
Run the Hello-world Java program:
// Run "Hello.class"
java Hello

    Hello, world from Ubuntu!

Compile and Run a Hello-world Java Program


You can leave a response, or trackback from your own site.

Leave a Reply