Navigation

Hello World For Eclipse IDE.

Hello World For Eclipse IDE

1. Prerequisite

To write your first program, you'll need:

  • The Java SE Development Kit.

  • The Eclipse IDE.

If you have not set the above prerequisite refer Introduction to Java to set your environment.

2. Create JAVA Project

Open your Eclipse and select your Workspace (Folder where your projects will be saved).

Image selects workspace location.

You will be greeted with welcome screen, close the welcome screen and your screen looks similarly like one below,

Image shows Eclipse home screen.

We can create our First Java Project,

Choose File -> New -> Other -> Java Project

Click Next

Image selects Java Project from New Wizard Dialog.

Enter Project name as “Hello World” and keep rest of the settings as it is.

Click Finish

Enter Project Name in New Java Projet Wizard.

Our Project will be successfully created in Eclipse.

Image shows Project structor of our Hello World application.

3. Create Java Package

A package is a namespace that organizes a set of related classes and interfaces.

To create Package,Right click on 'src' folder and select from context menu New -> Package.

Image shows how to create new java package.

Enter Package Name.

Click Finish

Image shows how to create new java package.

Our package will be successfully created.

Image shows newly create package in project directory.

4. Create Java Class

Java Class is the file (.java) where we will write all our Java source code.

Right click on our package 'com.helloworld.example’ and select from context menu New -> Class.

Image shows how to create new java class

Write "HelloWorld" in the 'Name' field and select the check-box for 'public static void main(String[] args)'.

public static void main(String[] args) – Is a Main method from where our program execution starts.

Image shows how to create new java class

Click "Finish" button. Eclipse will generate a java class and open the same in the java editor as shown below.

Image shows newly java class

5. Write Java Code

Edit the generated 'HelloWord' java class to simple print “Hello World” to Console.

                package com.hellowworld.example;
                /**
                 * My First Java Class.
                 * 
                 * @author vasanth
                 *
                 */
                public class HelloWorld {
                    /**
                     * A Main method from which program exection starts.
                     * 
                     * @param args
                     */
                    public static void main(String[] args) {
                        // Simply print 'Hello World' to Console.
                        System.out.println("Hello World");
                    }
                }
            

6. Run Our Code

To Run our Code, Right click on 'HelloWorld.java' and select from context menu 'Run As' --> 'Java Application'.

Image shows how to run java application

7. Console Output

Our code will print 'Hello World' in the eclipse console.

Image shows 'hello world' printed in eclipse console

We have successfully created our first Java Project.


No comments:

Post a Comment