Hello World example in Java

Category: fundamental, viewed: 16466 time(s).

Hello World is a classic sample to start when we learn a new programming language. Below is the Java version of Hello World program, it simple enough to start.

public class HelloWorld
{
    public static void main(String[] args)
    {
        // say hello to the world
        System.out.println("Hello World!");
    }
}

The code contains one class called HelloWorld, a main(String[] args) method which is the execution entry point of every Java application and a single line of code that write a Hello World string to the console. That's all, we are done!

To run the application we need to compile it first. I assume that you have your Java in your path. To compile it type

% javac HelloWorld.java

The compilation process will result a file called HelloWorld.class, this is the binary version of our program. As you can see that the file ends with .class extension because Java is everyting about class.

To run it type the command bellow, class name is written without it extension.

% java HelloWorld
Click here to lend your support to: Kode Java Org and make a donation at www.pledgie.com !

 

Can't find what you are looking for? Join our FORUMS and ask some questions!
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Sponsored Links

Our Friends

Statistics

Locations of visitors to this page
visitor stats