How to create Java class in Eclipse

blog img

Create a new class

First you create a new Java project.

To create a Java class in Eclipse you need to use the new Java Class Wizard. The Java Class Wizard can be invoked in different ways. Any of the methods described below can be used.

>> By clicking the File menu.

Click File > New > Class

>> By clicking on the class drop down button on ribbon.

>> By right clicking in the anywhere on package explorer.

Using the new Java Class Wizard

  • The source folder automatically captures.
  • Package – keep it blank (Takes the default package)
  • Enter the name of the class
  • Select class modifier. Now select public
  • Select method – we choose public void main method.

You can click the Finish button to create a new class of Java. 

Package Explorer window

A class named Newly Generated Tutorials can be viewed in Package Explorer. The same appears in the editor area.

Auto generated Java Code

    public class Tutorials {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
	
	  }
     }

Example Java Code

Sample Java Code

public class Tutorials {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("WELCOME to techsiter.com");
	   }
     }

Run the code

To run the code you have to press the play button which appears on the ribbon bar.

Result

Once the code is run, the result of the code can be viewed in the console window.

Share your thoughts

Your email address will not be published. All fields are required.