Getting Started With Java Programming

13 February 2012 By Nithya Vasudevan 6,898 views One Comment
0 Flares Twitter 0 Facebook 0 Google+ 0 0 Flares ×

Environment Used

  • Windows 7
  • Java 6
  • Notepad
  • Eclipse Helios


Installing JDK

JDK should be installed with proper environment set up. Read this page for installing the JDK and setting up the environment.

Installing Eclipse IDE

We use Eclipse IDE through out this tutorial. If you need to install Eclipse, you can read this page.

Your First Java Program Using Notepad

  • Open Notepad and type the following code.
    public class Hello {
    	/* My first Java program */
    	public static void main(String[] args) {
    		System.out.println("Hello World!");
  • Save the file as “” in some folder. In my case the location is “C:\Users\iByteCode\java-pgms\HelloWorld”.

Compile and Run

In Windows open Command Prompt (Windows button + R and type cmd) or Terminal in Linux and go to the folder (use cd command) where your java code exists.

  • To compile a Java program, type the command:
    • javac [filename]
    • So in this case, type: javac
  • During compilation, javac adds a file to the disk called [filename].class, or in this case, Hello.class, which is the actual bytecode.
  • To run your Java program, type in the command:
    • java [.class file without the extension]
    • In the case of our example, type: java Hello
  • You can see on the screen after running the program: “Hello world”

Using Eclipse IDE

Integrated Development Environment (IDE) allows developers to quickly develop Java projects by all the needed features like, GUI builder, text or code editor, compiler and/or interpreter and a debugger in a single application.
In this section we will create the same Java project using Eclipse IDE.

  • Open Eclipse IDE.
  • Make sure you are in “Java Perspective”. If not go to Window -> Open Perspective -> Other, select Java and click on OK. Or Use the icon present near top right corner to change perspective.

Creating Java Project

New Project can be created in many ways,

  1. Inside Eclipse select the menu item File -> New -> Project…. to open the New Project wizard.

    • Select Java Project then click Next to start the New Java Project wizard:
    • Type “HelloWorld” in the Project name field, and make sure Java SE 1.6 is selected as execution environment
  2. Right click on Package Explorer -> New -> Java Project
  3. File -> New -> Other and Select Java Project.

Creating Java Class

  • After creating Java Project, right click on ‘src’ folder in package explorer -> New -> Class or go to File -> Class or click on the “New Java Class” icon on the toolbar.
  • Type the class name as “Hello” and make sure to check the “public static void main(String[] args)” check box and click on Finish
  • Type the following code in the editor and save your class (Ctrl + s).
    public class Hello {
    	/* My first Java program */
    	public static void main(String[] args) {
    		System.out.println("Hello World!");
  • Compiling and running java code in Eclipse IDE is easy. Eclipse automatically compiles the code and displays error messages in editor. You can also compile manually by going to Project -> Build Project. By default “Build Automatically” option is enabled in Eclipse.
  • The code can be run in many ways.
    1. Press Ctrl + F11 and the output will be displayed in the “Console” tab.
    2. (or) Click on the “Run” icon in toolbar.
    3. (or) Right click on editor and select “Run As” option.
    4. You should run it as Java application in all the options.

Code Explanation

  1. public class Hello
    • Indicates the name of the class which is Hello
    • In Java, all code should be placed inside a class declaration
    • The class uses an access specifier public, which indicates that our class in accessible to other classes from other packages (packages are a collection of classes).
  2. {
    • curly brace { indicates the start of a block.
  3. /* My first Java program */
    • Indicates a Java comment which is used to document a part of a code.
    • It is not part of the program itself, but used for documentation purposes.
    • It is good programming practice to add comments to your code.
    • Comments are ignored by the compiler but are useful to other programmers
  4. public static void main( String[] args ){
    • Method declaration
    • The main method is the starting point of a Java program.
    • All programs except Applets written in Java start with the main method.
    • Make sure to follow the exact signature.
  5. System.out.println(“Hello world”);
    • The command System.out.println(), prints the text enclosed by quotation on the screen.
  6. }
  7. }
    • The last two lines which contain the two curly braces are used to close the main method and class blocks respectively.

Coding Guidelines

  • Java programs should always end with the .java extension.
  • Filenames should match the name of your public class. So for example, if the name of your public class is Hello, you should save it in a file called
  • Write some comments in your code explaining what a certain class does, or what a certain method does.

Tags: , , , , ,

  • Jabir KH

    Thanks alot..:)
    it’s very much informative..