#2 How to create and run first java program or java class in Eclipse?

Yosuva ArulanthuUncategorizedLeave a Comment

This post will explain How to create and run first java program or java class in Eclipse IDE software.

To create class in eclipse, first you should to know how to create project in eclipse.

If you have already created project in eclipse, then expand the project folder and right click on the src folder and click on New -> Class

This will open New Java Class window.

Enter package name as com.test.example and class name as Test and click Finish to add class to into your project

package com.test.example;

public class Test {

}

We have created Java class successfully. In order to run your java program, your class should have main method in it. You can’t run you java class without the Main Method.

//Main method 
public static void main(String[] args) {

 }

Example class with Main method with print statement in it.

package com.test.example;

public class Test {

	public static void main(String[] args) {
		System.out.println("Hello World");
	}

}

Now it is time to run our first java program. To run your program right click on the code and Select Run As -> Java Application

If you run the above code, it will print the Hello World in the eclipse console

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.