×
☰ See All Chapters

Using Eclipse IDE for Java programming - Java Code in Eclipse

In our previous chapter we have learnt to execute java simple program from command prompt. We used notepad for coding or as editor. In real time you will not use notepad or simple editors for coding. We use sophisticated integrated development environments like Eclipse, Intellij. Eclipse is an open source, most popular development environments for Java, as it contains everything you need to develop a java project from scratch. Follow below steps to run java code in eclipse.

Step 1:  Download Eclipse IDE for java from Eclipse Website. You will get it in zip file format. Unzip it to get the executable files. This software is not required to install in OS, it is like portable software.

Launch eclipse by clicking on "eclipse.exe" which will be available inside the unzipped folder.

Step 2:  When eclipse is opened, it asks for a workspace folder. Give your preferred location and press "ok". This workspace folder will be used by eclipse to save all our project work.

java-code-in-eclipse-0
 

After eclipse is launched

java-code-in-eclipse-1
 

Step 3:  When eclipse is opened, it asks for a workspace folder. Give your preferred location and press "ok". This workspace folder will be used by eclipse to save all our project work.

java-code-in-eclipse-2
 

After eclipse is launched

java-code-in-eclipse-3
 

Step 4:  Close welcome window, it is better to un select “Always show Welcome at start up” option at right bottom corner. Click on Open Perspective button and select Java option.

java-code-in-eclipse-4
 
java-code-in-eclipse-5
 

Step 5: Select File -> New -> Project -> Java Project -> Next

Enter the project name; our project name is “com.java4coding”, then click Finish button.

java-code-in-eclipse-6
 

Click on Create to create module descriptor (module-info.java)

java-code-in-eclipse-7
 

Step 6: Right click on the project select New -> Class

java-code-in-eclipse-8
 

Enter the Class Name. Our class name is "HelloWorld".

Check the checkbox "public static void main(String args)"

Click on "Finish"

java-code-in-eclipse-9
 

Step 7:  Write your program, we are adding a simple statement to write a message “Hello World” on console. After changes, save the file (Press Ctrl+S)

 java-code-in-eclipse-10
 

package com.java4coding;

 

public class HelloWorld {

        public static void main(String[] args) {

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

        }

}

Step 8:  To run program, Right Click on your java file (HelloWorld.java in our case), select -> "Run As" -> "Java Application"

 

Check the output on console

 

All Chapters
Author