Create First Java console Project in NetBeans

 

Watch this Tutorial on YouTube

Java Console Project in NetBeans

For Java Development normally people use NetBeans or Eclipse. And JDK (java development kit) I use NetBeans 8.1 and JDK of the same type.So first of all for my very first project I just install both NetBeans and JDK from Oracle official website. And after installation complete, we are going to create our first Java project.

Now run NetBeans which possible on desktop or start menu

start NetBeans
start NetBeans

Step 1:

It may take a couple of minutes to load. After loading probably, the start page will open which is something like

NetBeans StartPage
NetBeans StartPage

Now Choose File or Alt+F and the File menu will open on the top-right of the screen and from there select New Project or crt+shf+N Because this time; we will create a new project.

NetBeans New Project
NetBeans New Project

Step 2:

After Selecting New Project, a new popup window will open.

NetBeans choose project type
NetBeans choose project type

In this window, there are two fields one is Project Category, and other is projects type. We are developing Java Project so select Java from categories and from project select Java Application, which contains main function of the project and then click next.

Step 3:

Name and Location of new project
Name and Location of new project

Then next window will open where you have to put the name and location of your project by default was set to the location where you install NetBeans if you want to change it, change the location manually or browse it using the button next to project location option.

The project name is any name you want to give to the project and then click Finish.

This will create a new folder in your workspace and show you the text area to write your code.

Step 4:

Now it’s time to start the main part of the project which is coding.

Here is the tab name same as you gave in the project name, option in the previous panel, like in this case it’s Myfirstproject.java. As it’s a Java project, so it has extension of .java and this file contain the package name main function by default

NetBeans text area window
NetBeans text area window

 

If you just want to run this just press F6 or press Run Button (green button on upper bar) and as we have nothing to show or print so our project will run successfully but show nothing.

Understanding Code:

Now Consider the above default code and try to understand it the first line is Package myfirstProject; else all the thing written between /*  */ is comment area in Java and they have no effect on the output or execution of the project.

The package name is same which we gave while project setup and the package is the technique to organize and manage Java classes because one project may have many classes, so the classes under same package name are categorized by their type.

The next Line Public class MYFirstProject{ } is the first class of our java program as the Java is Object Oriented Language, so it uses classes.

First, we Use Access Specifiers to tell the program the scope of the class, in that case, its public mean’s it’s visible everywhere in the program.

Next, We use the class keyword to show that it’s class.

And at the last select some name for the class. Here it’s same which we add while project setup.

Inside the MyFirstProject class, there is the main function of our program.

Function:

Function have following syntax:

[Access Specifier] [ Return Type][ Function name] ([ Arguments]){ –Body–}

As its the main function we name it main and void return type means its returning us nothing.

Now See after

 

Step 5:

To write our first simple Java Program we select that place and start writing here.

This time, I only write a simple program like how to say outside world that I am alive :p

To print a simple line in output System.out.Println(); is used and the line or string that we want to show in output is written in ( ) inside small braces like

Remember Java is case sensitive language and after every single line of code semicolon is mandatory and as I am writing a string, so I use ” ” double quotation marks and put my statement inside them.

Now out overall code is like:

NetBeans Hello World project
NetBeans Hello World project

Step 6:

Now Run the Project by pressing F9 or click on the run button. It will show the output in the Output console.

output of hello world on console
Output of hello world on console

See this Tutorial on YouTube

Leave a Reply

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