Alternate Hello World

From CompSciWiki
Jump to: navigation, search

Back to the Program-A-Day homepage

Problem

The Hello World problem has been around almost as long as modern programming has. Traditionally, when trying a new programming language or technology, developers and students like to make their new medium say hello. Because of this, the Hello World problem will be your first Java application.

When executed, this application will display "Hello World!" on the console.

 

Getting Started

Wiki start01.jpg

Solution

The solution is in two steps:

  • Create the HelloWorld class and main method
  • Use System.out.println to print the message

Next, create a Hello World java class. In your .java file under the import statement, create a public class called "HelloWorld" and a standard main method within the class.

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

Now you are ready to create the body of your program. This will use System.out.println to print the message to the console.

 System.out.println("Hello World!"); 

Finally, compile and run your application. Congratulations! You've written your first Java application. It doesn't do much for now but don't worry, you'll learn much more later. Also note that it's a good idea to keep your HelloWorld.java file around since it's a convenient template for future Java applications you may write.

Code

Solution Code

Back to the Program-A-Day homepage