How to Open a New Project in Eclipse

This recipe describes how to open a new project in Eclipse™. The goal is to create a new project with a name containing the word “My”. This recipe illustrates basic Eclipse operations that are useful when working with any Eclipse-based workbench.

Have you been meaning to start a new Eclipse project, but aren’t sure what to do? The simple process of creating a project is outlined in this tutorial, with screenshots of each step. By the end, you’ll know the steps for creating a new Project in Eclipse.

Creating and Running Your First Java Project

To create a simple first Java project follow the steps:

Click on File -> New -> Java project.

Click on file-new-Java project

The following window will open:

Name your project

Give a name to your project in the highlighted text field. While creating a formal project the name should have a logical sense, however as we are in the learning process, for now, you can name your project as “MyFirstProject” and leave the rest of the fields as default and click next.

The following screen opens up:

Define Build Settings

Leave all the options as it is and click on finish.

You will see the following structure created in your project explorer.

Structure created in your project explorer

Here you can see two sub-items under your project name. The JRE system library is the default Java library that Eclipse adds to your project. This library provides Java support and without this, you cannot proceed with creating a Java project. The other folder is the “src” folder or the source folder. Your project structure will get created inside this.

You now have your base project structure, let’s add more to this. In Java, we have packages and classes. Packages provide logical separation for classes. Packages are just folders, whereas classes are where you write your actual code.

Recommended Reading =>> NetBeans Vs Eclipse: Which IDE Is Better For Java Application

To create a package right-click on your project name as shown below.

Create a Package

Click on the package:

Name the new java Package and click finish

Java says package names should be in a small case, so give any name such as “myfirstpackage” and click on finish.

Check your Project Structure.

Check your project structure

 Next, you need to create a class, and this is where your actual code will go. Right-click on the package name as shown below.

Create New class

Click on the class:

Name the class and keep the modifier selected as public.

Give a name to your class and keep the modifier selected as public. While creating a simple Java project, ensure to check the checkbox for creating the method “public static void main(String[] args)”.

Click on finish, and now your project will look as shown below.

Tick the checkbox for creating the method

You can see that the class is created and as we selected the main method to be added, the method signature is added to the class. Similar to a class you can also create an interface by following the same steps and by selecting “New Interface”.

 As we have successfully created a project and class, let’s put a simple print statement in it and run the same to check the output.

Write the below code and save:

Simple program

Code:

Code generated:

package myfirstpackage; public class MyFirstClass { public static void main(String[] args) {       // TODO Auto-generated method stub        System.out.println("This is my first code");       }}

Once you have saved the file there are multiple places from where you can run it as a Java application.

a) Keep your cursor on the class that you want to run and click on this icon: 

b) Right-click on the class name in the project explorer and select Run as and click as shown below.

Select Run as

c) Select the class name in the project explorer and then select the Run option from the top menu -> select Run As and then click on Java application.

select run as and then click on Java application

As soon as you run your class from any of the above places, a console window opens up in the bottom pane of your workbench and displays the output of your program.

Output

The console in Eclipse displays the runtime logs while your application is running. In a simple application like ours, it is simply the output of the print statement, however, in complex projects, there may be a lot more information displayed.

The console also displays error information if your program encounters any exceptions while running. So in this section, we have created a simple project and seen how we can run it and see the output generated by your code.

Apart from classes, there are many other types of files that you can create in Eclipse which can be used in a Java project such as XML files, interfaces, or even simple files.

You can explore the types of files or types of projects that you can create by clicking on File-> New-> Others, and the following wizard will open up.

Exploring the projects and files

However, as a beginner, you may leave these for a while and work with the simple Java project by adding more packages and classes as you need.

Build Your Java Project

A Java builder is the tool that will compile your code and create class files for your classes.

Usually, in Eclipse IDE, the default setting is to have your code build automatically.

Build your Java Project

However, if you want to build manually, you can uncheck this option and then the Build Project option will be enabled for you. You can also control the build configuration for your project and add or remove builders by doing a right-click on the project name in the project explorer and open properties.

Build configuration for your project

You can add or remove builders from the above section.

However, as a beginner, you may leave these for a while and work with the simple Java project by adding more packages and classes as you need.

Close and Reopen Your Java Project

If you are done working on your project, then it is always a good option to close the project. A closed project will still be available for you in the project explorer section. However, it will not be available in the editor section.

To close a project, simply click on the closed sign on all the open files of that project. To reopen any file, simply navigate to that file from the project explorer and double click on the file name.

Install the Eclipse IDE for Java Developers. 

When you install Eclipse for the first time, you’re given the option to choose your IDE (integrated development environment). Choose “Eclipse IDE for Java Developers”. This will install the necessary files and tools to create Java projects.If you installed Eclipse for a different programming language, you can add Java support from within Eclipse. Click the “Help” menu and select “Install New Software”. Select “All Available Sites” from the top drop-down menu, and then type “java” into the Filter field. Check the “Eclipse Java Development Tools” box and click “Next”. Follow the prompts to download and install the Java tools. Eclipse will restart once the installation is complete.

Conclusion

The first step in creating a new project is to create the directory structure for the source files that your project needs. Eclipse organizes source code into a directory tree, where each directory and subdirectory represents a different source file or set of source files.

1 Comments
Flattrade December 17, 2021
|
Hi,I have been trading in stocks using Flattrade and I am really happy with the experience. They charge a flat free of ₹10 for trading and Zero brokerage on all equity delivery. More importantly, Flattrade gives you a stable trading experience on its advanced Mobile, web and windows platforms. Use the below link to open FREE demat account.flattrade.in/ and investing in IPO is totally free https://flattrade.in/kosh/upcoming-ipos-2021