First of all you need to create a Java project in Eclipse IDE. In the created Java project, you will see some default items that are displayed. You must know these items before creating and running Java programs.
- In the ‘Eclipse IDE’, see the Package Explorer tab. You will see the created Java project name.
- Expand the Java project folder and ensure that the ‘src’ folder and JRE System Library are displayed.
- ‘src’ folder contains the project source code. Here, you can find all the created Java programs as Java Class files.
- You can find all the predefined libraries under ‘JRE System Library’. These are required to run all the Java programs.
Creating a Package
- From the ‘Package Explorer’, right-click the created project and select New->Package.
- This will display the ‘New Java Package’ dialog box. Type the package name in the Name field. Click Finish.
- Right-click on the created package and select New->Class.
- This will display the ‘New Java Class’ dialog box. Ensure that the following things are reflected, as shown in the image.
- In the Eclipse IDE, ‘Sum.java’ file is displayed.
- Write the code for adding two numbers in the ‘main’ method.
- Save the ‘Sum.java’ file, as shown below.
- Right-click ‘Sum.java’ class and select Run As->Java Application.
- Output will be displayed in the Eclipse IDE->Console.