NetBeans Tutorial: Create a New Project
Author: Travis Suel
Create a new project in one of two ways:
- File → New Project
-
Click on the New Project toolbar button.
This will open a new dialog window which will lead you through the steps to
create a new project.
- Select Java in the Categories box (if not already selected).
- Select Java Application in the Projects box (if not already selected).
- Click on the Next button at the bottom of the window.
You will then be presented with the following dialog window:

- Name your project by editing the text in the field labeled Project Name.
- Click on the Finish button at the bottom of the window.
The dialog window will be dismissed and NetBeans will create an empty
project. On the left side of the NetBeans window, there will be a project
hierarchy displaying your new project in the Projects pane. On
the right, there will be a text editor showing the contents, or the source,
of one of the files of your project. This file will be named Main.java.

Main.java will contain the source for what is called the driver. The driver directs the flow of the program but does not actually perform the core functionality. Another file will be created which will be responsible for the core functionality of the program.
Creating a new source file can be done in one of two ways:
- File → New File
-
Click on the New File toolbar button.
This will open a new dialog window which will lead you through the steps to
add a new file to your project.

- Select Java in the Categories box (if not already selected).
- Select Java Class in the File Types box (if not already selected).
- Click on the Next button at the bottom of the window.
You will then be presented with the following dialog window:

- Name the file by editing the text in the field labeled Class Name.
- Click the Finish button at the bottom of the window.
In the NetBeans window, you will now notice the file DayOfWeekCalc.java has
been added to the project hierarchy in the Projects pane and the editor has
opened a new tab displaying this file.

The new file will have the following contents:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dayofweek;
/**
*
* @author travis
*/
public class DayOfWeekCalc {
}
Add the find function:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dayofweek;
/**
*
* @author travis
*/
public class DayOfWeekCalc {
public static String find(int Year, int Month, int Day) {
GregorianCalendar DayCalc = new GregorianCalendar(Year,Month - 1,Day);
int DayOfWeek = DayCalc.get(Calendar.DAY_OF_WEEK);
String DayName = "";
if(DayOfWeek == Calendar.MONDAY) {
DayName = "Monday";
} else if(DayOfWeek == Calendar.TUESDAY) {
DayName = "Tuesday";
} else if(DayOfWeek == Calendar.WEDNESDAY) {
DayName = "Wednesday";
} else if(DayOfWeek == Calendar.THURSDAY) {
DayName = "Thursday";
} else if(DayOfWeek == Calendar.FRIDAY) {
DayName = "Friday";
} else if(DayOfWeek == Calendar.SATURDAY) {
DayName = "Saturday";
} else if(DayOfWeek == Calendar.SUNDAY) {
DayName = "Sunday";
}
return DayName;
}
}
Once you have entered the code above, several words will be underlined in red. This is because NetBeans does not understand what these words mean. To fix this, NetBeans needs to be instructed where it can find the meanings.
- Right click anywhere in the document.
- Click on Fix Imports (approximately a third of the way down the menu).
This will add the following lines near the top of the source file:
import java.util.Calendar;
import java.util.GregorianCalendar;
If, after fixing imports, some code is still underlined in red, you likely have a typo or two.
Now save your work:
- File → Save or
-
Click on the Save All toolbar button.
Now switch to Main.java by clicking on its tab. Main.java will contain the following code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dayofweek;
/**
*
* @author travis
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
Modify the main function as follows:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dayofweek;
/**
*
* @author travis
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
String LineIn;
int Year;
int Month;
int Day;
System.out.print("Year: ");
while(stdin.hasNextLine()) {
LineIn = stdin.nextLine();
Year = Integer.parseInt(LineIn);
System.out.print("Month: ");
LineIn = stdin.nextLine();
Month = Integer.parseInt(LineIn);
System.out.print("Day : ");
LineIn = stdin.nextLine();
Day = Integer.parseInt(LineIn);
System.out.println(Month + "/" + Day + "/" + Year + " is a " +
DayOfWeekCalc.find(Year, Month, Day));
System.out.print("Year: ");
}
}
}
After modifying Main.java, if any of your code is underlined in red, remember to right click anywhere in the document and click on Fix Imports. Once you have fixed imports, remember to save your work.
You now have a complete program and are ready to build (compile), run, and test it:
-
Click on the Build Main Project toolbar button.
-
Click on the Run Main Project toolbar button.
-
NetBeans will display a console at the bottom of the interface. Simply
press the stop button to end the program.