Java Development - What to install & why?

Install Java SE Development Kit (JDK)

Install Eclipse SDK

Hello World - Building Simple Java Program

How to run your Java Application outside of eclipse

Tutorial

Java, Beginner Guide, Install Java JDK, IDE & Build your first Java Program - Hello World


This tutorial help reader setup their working environment into a Java Application development machine. Begin with installing Java SE Development kit (JDK), Eclipse SDK and finally write a simple program.


Java Development - What to install & why?


To create a Java Application, you need the following tools to be install on your computer:

  • Java SE Development Kit (JDK) - This is the backbone of Java Technology. It allow developer turn plain Java source code into fully functional Java Application. It also include Java Runtime Environment (JRE), which is a program for computer execute Java Application.
  • Install Eclipse SDK - This is one of the best tool where you manage your Java project, write your Java source code and build source code into Java program.

There is a more tradisional command line way of developing Java Applicaiton without using any IDE tools such as Eclipse SDK. Since this tutorial aim at setting up the best development environment for beginners without overwhelming them with huge amount of information, I will skip that in this tutorial.

Install Java SE Development Kit (JDK)


Download latest JDK from http://java.sun.com/javase/downloads/index.jsp. The site has already provided comprehensive installation instruction on how to install JDK on various platforms. Follow the instruction and complete the installation.

Install Eclipse SDK


Download latest Eclipse SDK from http://www.eclipse.org/downloads/ . Installing Eclipse is very easy. In most cases, unpack the downloaded zip on a disk drive with sufficient free space will do. The following list shows what is required:

  • JDK. Which you already installed on the step above.
  • Sufficient disk space. 300MB.
  • Sufficient RAM. Recommanded at least 512RAM for Developer computer. Best if you got 1024RAM or more.

Unpack downloaded eclipse into anywhere in your disk drive. e.g. C:\eclipse. Browse into the unpacked folder and double-click on eclipse.exe icon to launch eclipse. For the first time eclipse run. It will prompt you with the Workspace Launcher.

Workspace is a folder where you store all your Java development work. We recommand you to create a folder call 'workspace' in the eclipse folder. For example, if you unpacked your eclipse in D:\eclipse\, then create a folder D:\eclipse\workspace, then browse the Workspace Launcher to use the created workspace folder.

Although you may create your workspace folder outside of eclipse folder, there are good reason we recommand creating workspace inside eclipse folder. For example if you want to move your development environment into another computer, all you need to do is simply copy entire eclipse folder into target machine without worry about where you store your other Java project files.

Now you got your computer setup for Java Development. Read the next section for building a simple Java Application - Hello World.

Hello World - Building Simple Java Program


During this tutorials, don't bother yourself to understand what is Java Package, source code and Project etc, it will be explain in detail in other tutorial. This tutorial is just for you to get the feel of overall process to make a simple Java program - write a simple Java program that display some text on computer screen "Hello World!". Run eclipse by double-click on eclipse.exe in root folder of eclipse. If eclipse show you a welcome screen as follow:

Eclipse Welcome Screen

Click on the Go to the workbench icon

Eclipse WorkBench

Eclipse WorkBench is where you create Java Project, write source code, browse project files, debug and build Java Application.

First create a Java Project from the menu File-> New-> Project...

Select Java Project and click Next

For this tutorial purpose, enter "Hello World" as the project name and set the Project layout as Create separate source and output folders. Click Finish button.

The resulting Project will be display in Package Explorer(default location would be on the left of the Eclipse workbench). The default content of the project in Package Explorer will be consist of src folder and JRE System Library.

src folder is where you manage your Java package and source code. JRE System Library is the default Java library provided by Sun Microsystems for software development.

Right click on the src folder, select New-> Class

For this example, enter HelloWorld (case sensitive) for the Name and make sure checkbox public static void main(String[] args) is checked. Click Finish button.

It will create a Java source file HelloWorld.java in the src folder with the similar source code as follow (double-click the HelloWorld.java if the editor do not showing the source code):


public class HelloWorld {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

}

}


This is the basic skeleton of every Java program. The goal of this example is to make the program display a text on computer screen "Hello World!". So add the following code into the editor (shown in bold).



public class HelloWorld {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

System.out.println("Hello World!");
}

}

Save your source file by pressing ctrl+s.

Before we test run the HelloWorld program, make sure you have the console view opened. Go to menu Window->Show view->Console. Console is where you see the output generated by Java Application during test run.

Run the HelloWorld program by right click on the HelloWorld.java -> Run As-> Java Application. Eclipse will auto compile your HelloWorld.java and run the program. You will see the message "Hello World!" display on the Console View as follow:

How to run your Java Application outside of eclipse


The final product of the Java Development is Class file. If your project are created in workspace D:\eclipse\workspace\HelloWorld, then your class file will be compile into D:\eclipse\workspace\HelloWorld\bin directory.

Locate and copy HelloWorld.class into any other folder(can be on different computer) where you want this Java Application to be place. e.g. C:\HelloWorld.class

Before execute the program, make sure your target computer at least has Java Runtime Environment (JRE) installed (If you follow this tutorial from beginning and have JDK installed, JRE is already included in the installation as well). To execute the HelloWorld.class, bring up a command line tool from Window Start menu->All Programs->Accessories->Command Prompt.

Enter cd\ to go to the root of drive C. Then enter java HelloWorld to execute the program. Result as shown below: