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?

Posted in Java Tutorials | Tagged: , , , , , | Leave a Comment »

Installing Java (In 5 minutes or less(Depending on how fast you read))

Posted by semioptimist on June 18, 2009

Activities carried out on the computer usually begin with the installation of something, and programming is no exception.

But before we delve into that, let me start with some general facts.

All programming is done via some programming language. There are literally thousands of programming languages in existence. Some are designed to fulfill a specific niche, while others are created for programming in general.

The language we’ll be using here is Java, initially known as Oak.  It was invented circa 1995 by a guy named James Gosling, and it was originally intended to be used in set top boxes, but it ultimately became popular for general purpose programming, especially programming on the internet.

Java is a popular language, and it’s easier to learn than the languages that preceded it, so I thought it would be a great language to teach the concepts of programming in general.

But before we can start programming in Java, it’s necessary that we install and configure it. And before we can install it, it’s necessary that we download it.

Therefore, it’s necessary you go here: http://java.sun.com/javase/downloads/index.jsp

We’re going to be downloading the JDK, which as you’ll see stands for Java Standard Edition Development Kit. As of today the most recent JDK is # 6, update 14. Get that one.

You’re going to be a developer now, isn’t that exciting?

But don’t get excited yet, we still have a bit more tutorial to get through.

So once the JDK is finished moving to your computer, install it.

This is a ridiculously simple process, so I won’t say much about it. Just keep clicking ‘next’ until the installation wizard says it’s finished.

By the way, I’m assuming that you’re using Windows XP. If not, now would be the time to find another installation tutorial.

So once it’s installed, it’s time to configure it. Get ready.

  1. First, click the Start button.

  2. Then, click Control Panel.

  3. Next click the System icon.

  4. Click the Advanced tab.

  5. Click Environment Variables.

  6. Under System variables, edit your path variable to begin with:   .;

  7. Then, directly after the semicolon from step 6, add the directory path to where Java was installed.

  8. #8 is just an example for step 7, don’t worry. Ex: C:\Program Files\Java\jdk1.6.0_14\bin;

  9. Make sure the path ends in a semicolon, like with the example provided in the previous step.

  10. You’re done! Keep clicking ‘Ok’ until there are no more windows left.

What you just did enables you to access the Java compiler (And other programs located within the Java folder) from the command line, no matter what directory you’re in.

That may not make much sense to you at the moment, but it will soon. Maybe.

We’re actually almost finished, we just need to check that you did everything properly.

Click Start again, and then click Run and type in ‘cmd’ and press enter on the keyboard.

That black window that just popped up is called a console window, and we’re going to be making good friends with it.

In the window, type javac -version and press enter.

Then, type java -version and press enter again.

If you did that correctly, then the version information for Java should be displayed. If not, scroll back up and find your mistake, or find mine.

If you’ve made it this far then congratulations, you just successfully installed and configured Java.

You can get excited now.

Posted in Java Tutorials | Tagged: , , , , , , | 1 Comment »

First post!

Posted by semioptimist on June 18, 2009

Hello, everybody!

As you might have guessed from the title, this humble blog is going to feature a series of tutorials on the Java programming language, and the act of computer programming in general.

I’ll try my best to keep it interesting, but lets face it- we’re talking about programming here: things are going to get geeky real fast.

I’ll start the series off by assuming you have no knowledge of programming whatsoever, and then as you start to learn more, I’ll turn things up a notch.

I suppose we’ll get started by installing Java…

Posted in Uncategorized | Leave a Comment »