Java Hello World

by Trevor Page on July 8, 2012

Your first Java Program – The Java Hello World Program

So, what does Java Hello World even mean anyway? Well, in the programming world, the term “Hello World” typically refers to the most basic program that can be written and run in a given language. Think of it like this, if you can write a Java Hello World program, this means that you were able to:

  1. Setup the necessary tools
  2. Write the code
  3. Correctly compile the code
  4. Run your program

 
This isn’t always the easiest task to accomplish when you are new to a programming language. So, as it pertains to Java, if you can accomplish all of these tasks and successfully write your Java Hello World program, then you are off to a good start. Now, we have already covered step 1 above, in a previous post. So let’s move on to step 2, writing the code.

First, Launch your Spring STS tool, you’ll notice that you get stuck on this screen:
Java Hello World - Pic 1
 
You’ll just need to pic a folder that will house your development files. I usually choose C:\DEV\, but it’s your choice. So, pick a folder and click OK.

Now, with Spring STS open, you’ll need to start a new project, so choose File -> New -> Java Project. You’ll be presented with this screen:
Java Hello World
 
Be sure to fill out a program name, I used “helloWorld”, but you can use any name you like for this project. Next, you should have the JRE installed (we covered this in the last post), but if for some reason it didn’t install correctly, just leave a comment and I’ll see what I can do to help you get setup! Now Click Finish.

You may or may not be presented with this window, if you are just click the “Remember my decision” and click Yes:
Java Hello World
 
Now, if all went well, you should see something like the following:
Java Hello World
 
We need to create a new file for this project, so click File -> New -> Class. So now you should see this screen:

Be sure to fill out two fields: Package and Name, for the Package I used “com.helloworld”, for the Name I used “HelloWorld”. You can see this in the screenshot above. Now click Finish.

That should have created a new Class file called “HelloWorld.java” and you should now see something like this on your screen:

Now we are ready to write some code! If you like, you can copy/paste the following code into your HelloWorld.java file:

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

Now, for the final step, you’ll need to run this! If you right click your mouse anywhere in the code area, you’ll get a menu that will have a menu item named “Run As“, hover over it and select “Java Application“. This will run your code and output “Hello World” into your console. If you don’t see the console, just click Window -> Show View -> Console, like so:


 

Voila, you have just setup, coded, and run your first Java program! Welcome to your first accomplishment as a Java developer. If you have any troubles following these steps or need any assistance, please leave a comment below and I’ll try to help you out as best as I can.




{ 44 comments… read them below or add one }

Leave a Comment

Powered by sweet Captcha

Previous post:

Next post: