How to Java programming- Creating first Java project

This tutorial will explain to you how to create a new java project in Eclipse IDE. To install Eclipse IDE, check our previous tutorial how to install Eclipse IDE. This guide includes 4 main steps.

1.Create new Java project.
2.Create a package inside the project.
3. Create a class.
4.Run the project.

 

1.Create new Java project.

On Eclipse IDE, locate File >> New >> Java project. Create new Java project.

Add Project Name on Create a Java Project tab. Click on finish button.

Create new java project

Create Java project

 

Now you’ve got project folder with 2 subfolders, src and JRE system library. We are going to code inside src ( source) folder.

2.Create a package inside the project.

A java package is a group of similar types of classes, interfaces, and sub-packages. Java package is used to categorize the classes and interfaces so that they can be easily maintained.

To create a package, Right click on src folder and select New >> Package from the drop down menu.Enter a name to package folder and click finish to create the package.

Create a package

Create java project

 

You can see the package folder at your workspace which resides in the windows user folder. a Java package removes naming collision.

 

3. Create a class.

To understand the class, you’ve to know what is an object.An Object is an entity that has state and behavior is known as an object e.g. chair, pen, table, car etc. It can be physical or logical. The example of a logical object is banking system.

A class is a group of objects that has common properties. It is a template or blueprint from which objects are created.

To create a class inside your package, Right click on the package “FirstPackage” and navigate New >> Class on the drop down list.

On New Java Class window, Add a Class name and check “Public static void main” to create a method. A method is like function used to expose the behavior of an object.

Here class name is MyFirstClass. Once you were done, click Finish to create the class.

Create a class

Create java project

 

You will see the package, class inside the package, and a method inside the class on java editor that we created. The main method in Java is a standard method which is used by JVM( Java Virtual Machine) to start execution of any Java program. So this method will compile at the beginning of the run.

MyFirstClass.java

Create Java project

 

Here, we are going to print Hello World on screen.  The eighth line system.out.println() will print you the string inside the parenthesis. The compiler ignores everything from /* to */ and it ignores everything from // to the end of the line.

The compiler ignores everything from /* to */ and it ignores everything from // to the end of the line.

 

MyFirstClass.java
	package FirstPackage; 
	public class MyFirstClass { 
		public static void main(String[] args) { 
			// TODO Auto-generated method stub 
			// Here output "Hello World" 
			System.out.println("Hello World"); 
		} 
	}

 

4.Run the project.

Now our first project is ready. Let’s run it by clicking run button on top menu bar of Eclipse IDE. The compiler will tell you to save and launch. Click OK to continue.

Create java project

 

The output will show on console window at the bottom of the utility. Here it will print “Hello World”.

Sample code
     Hello World

 

Anwar Yakkiparamban

Anwar Yakkiparamban is the founder of Lauyou Learning. Prior to Lauyou learning, Anwar worked at ARD Engineering & Development, Qatar. He holds bachelor degree in Electronics and Communication Engineering from Govt. Engineering College Idukki.

You may also like...