Hello World For Eclipse IDE
Table of Contents
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).
You will be greeted with welcome screen, close the welcome screen and your screen looks similarly like one below,
We can create our First Java Project,
Choose File -> New -> Other -> Java Project
Click Next
Enter Project name as “Hello World” and keep rest of the settings as it is.
Click Finish
Our Project will be successfully created in Eclipse.
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.
Enter Package Name.
Click Finish
Our package will be successfully created.
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.
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.
Click "Finish" button. Eclipse will generate a java class and open the same in the java editor as shown below.
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'.
7. Console Output
Our code will print 'Hello World' in the eclipse console.
We have successfully created our first Java Project.
No comments:
Post a Comment