How To Create Your First Java Program

Ok so you have heard all about Java, read various tutorials and articles but now you are ready to actually get your hands dirty. So lets get started and write a really simple java program to show you guys some basic Java.

Hello World

There is 1 thing you need to create your first java program and that is some java code. The code we are going to start off with is a little favourite called “Hello World”. “Hello World” tends to be the first code that everyone looks for when starting a new language.

Its one of the most simple ways to start, is pretty easy to understand in most languages, and the fact that you are creating some output gives you some feedback that your first program has actually worked.


class HelloWorld {

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

So that is your first Java class, which is a simple bit of code that will print hello world to the console output.

Compiling your Java source code

So how do you we go about creating and running our code. Well that bit of text above at the moment is just that. A bit of text. So what we need to do is get a suite of programs that will turn that text into something that will actually do something useful. What we need is something thats known in programming circles as a compiler.

The compiler takes source code, which is what the HelloWorld class above is, and turns it into some code that can run and do something.

To compile you Java source code you need the Java compiler. The Java compiler is essentially part of what is called the JDK (Java Development Kit). We need to download this from Oracle, who own Java, so that we have to tools to be able to create executable java code.

The latest Java JDK is available here Java JDK Download. If you are an absolute beginner that page may seem a bit confusing at first but you will soon come to understand what most of that means. For now just click on the JDK download and that will start the process of saving that to your computer.

Leave a Comment

Your email address will not be published.