Overclock.net › Articles › An Introduction To Java Programming

An Introduction To Java Programming

As we approach the future, computers are becoming increasingly necessary. Hardware is cool, but software is just as important. Java is a popular programming language used to write software and today I’ll show you how to write your first java program.

The first thing you need is a java compiler. I recommend using JCreator LE, which is free. You can download it from their homepage here: http://www.jcreator.com/index.htm

Once you download and install this, you will also need to install the JDK (java development kit) which can be found here: http://www.oracle.com/technetwork/java/javase/downloads/jdk-7u1-download-513651.html

Now that you have both installed on your machine, you are ready to get started. Open JCreator and click File->New->File. In the next window, click on “File Path”, and then you will be able to choose the name of your program as well as the location to save it. For now I recommend saving it to your desktop and naming it HelloWorld. Click “Finish” and you will now see HelloWorld.java on your desktop. All of your java programs will have a .java extension.

Now that your program is open, it should look like this:

public class HelloWorld {
public HelloWorld() {
}
}

Ignore the green text at the top of the screen; these are comments which are not used by the program. The class will have the same name as your program. Now on the line above the bottom curly brace, type: public static void main(String[] args). This is the heading for your main method (the part of the program that runs your code). On the line below that, put an open curly brace, then insert two blank lines and put a closed curly brace. Between these two braces, your code will be executed. On one of the two blank lines, type: System.out.println("Hello World");. In java, every statement must end with a semicolon. The text in the quotes is what will be printed to the output. Your program should now look like this:

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

Now you’re ready to run your first java program. At the top of the screen, click Build->Build File. This will compile your program (you shouldn’t get any errors). Next, click Run->Run File. At the bottom of the screen you will see your output, which is "Hello World" printed to the screen.

Congratulations, you’ve just written your first java program!

Comments (1)

useful information thanks, please tell me about learning c language.
Overclock.net › Articles › An Introduction To Java Programming