dcsimg
LinkedIn
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Jun 15, 2021

How to Create the Hello World Program in Java

Hello World apps serve as introductions to new programmers - or developers that are new to a language but have experience coding in other languages - to creating software with a given technology. It's akin to learning Smoke on the Water when you first play guitar or bass. So when you create your first "Hello World" application, you are basically introducing yourself to the world. At least, in theory!

Creating a Java Hello World app is fairly simple, as you might imagine. The goal: create a program that prints - or outputs - the text "Hello, World!" to the user's computer screen. Pretty easy, right? To achieve this in Java, we first have to create a class. When we develop programs in Java, we always have to start every application by creating a class definition. The topic of what a class and class definition is are too advanced for this article, but we will cover both in great detail in a later article, so keep your eyes peeled!

To create a class definition, we use the following Java code:

class HelloWorld {
 
}

Next we have to add our main method. Main methods are the place where the compiler begins executing your Java code. Therefore, all Java apps need a main method. In this case, our main method will look like the following:

public static void main(String[] args) {
 
}

This main method will be added to our class definition; we will put all of our code together at the end of this article.

Finally, we need to actually have our program do something. To print text to the screen, we use the Java print statement and assign it some text to print. Here is how we write our print statement in Java:

System.out.printIn("Hello, World!");

To put the entire program together, we write the following code:

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

When we run this program, we get the following output:

Hello, World!
James Payne
 
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date