Semioptimist's Java Tutorials

Teaching you how to program, I promise.

Your First Program

Posted by semioptimist on June 19, 2009

Traditionally, every programmer’s first creation is a simple program entitled Hello World, and all it does is display the words ‘Hello World’ on the console window.

Yeah, I know it’s stupid – but it’s always a nice way to start things.

So lets write our Hello World program now!

First, open up Notepad, then save a file called “HelloWorld.java”. Make sure you capitalize things accordingly and please leave out those quotes.

Next, type what you see below into your newly created file:

helloWorld

Once you’ve done that, save the file.

Now at the present moment, you can read the code you’ve written, but unfortunately, your computer can’t.

To make this possible, you have to transform your code into a language your machine can understand.

Fortunately, there’s a program that can do this for you.

That program is known as a Java compiler, and it was the program that you configured in the first tutorial.

All you have to do is open up a console window and type in:

javac HelloWorld.java

Just make sure that the console window is pointing to the same directory that you saved the HelloWorld.java file in.

If nothing happened after that step, then you’ve successfully compiled your program.

If it gave you an error message, go back and make sure you typed in everything correctly.

The Java compiler is a very picky thing, and it won’t compile your code unless you’ve written it 100% correctly.

Once your program has been compiled, just type in:

java HelloWorld

Did your console window display the words ‘Hello, World!’ ?

Congratulations, you just ran your first program.

Now that wasn’t so hard, was it?

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>