In this video, we’ll look
at creating a very simple project using Netbeans.
We’ll begin at the Netbeans start page.
On the file menu, we select new project.
For the project category, we’ll select Java, and then Java Application.
Unless you have a lot of existing files, and are a
more advanced Java programmer,
I’d recommend against using “Java Project with Existing Sources”.
It is very easy to simply drag files into the project,
as we’ll see later.
“Java Desktop Application” creates a graphical user interface,
or GUI, but this also is more complicated than I like,
and it is easy enough to add that later,
so I’ll stick with the “Java Application”.
Now push “next”.
This brings up a screen where you can give the name and
location of the project.
I’ll call this MyFirstProject,
and accept the default location,
which is a “NetBeansProject” folder under my documents.
Below that it asks if you want to create a main class.
If you already have a program, uncheck this,
but I’ll go ahead and create one.
We’ll also let this be the “main project”.
Netbeans allows you to have multiple projects open at the
same time and have one main one that you’re working on.
I find it easier to only have one project open at a time,
and I always want that one to be the main one.
You’ll note that the name of the main class is the name of the
project “dot Main”.
Having a dot in the name uses the Java idea of “packages”,
which are useful for large projects and lets you store files
in multiple folders.
Since we’re starting small, I’m going to get rid of that,
and only put in class name of “HelloWorld”.
Remember to capitalize the name of the class.
Now let’s look at the many folders Netbeans created.
We have “src”, which is where the Java source code will go,
“build”, which will contain the compiled classes, “dist”,
where it creates JAR files you can distribute to others,
“test”, which is for automated testing, and “nbproject”
which has some Netbeans-specific files.
To start, you’re mostly interested in what is in the
“src” folder and can ignore all the rest.
Back in Netbeans, we can see the created project.
There are also tabs for files and services.
I’m going to close these to reduce the amount of clutter.
If you want them back, you can get them from the Window menu.
I’ll pretend to accidentally close the projects window and
then show it again using the menu.
We can right click on the project, close it, and then open it again.
You can see it on the “recent projects” on the start page,
and in File/Open Recent Project, but I’ll open it using
File/Open Project so you can see how. We open HelloWorld.
java by opening source packages and default package and
double-clicking on it.
You can see that Netbeans has added a lot of code for us,
and put a “TO DO” for us to add code. I’ll add a println.
Notice that as soon as I type “System dot”,
Netbeans shows a lot of suggestions.
Also, Netbeans is constantly compiling in the background,
so if I type something wrong, like leaving off the
“n” at the end of println,
a red squiggly appears under the line indicating there is an error.
Hovering over the red exclamation mark, I can see the error message.
To run the program, simply hit the green “run project” button.
We can add more than one file, or even more than program to a project.
By simply dragging a file into the project, it is added.
We can then run the other file by right clicking on it
and selecting “run file”.
Netbeans is an extremely powerful IDE with lots of options
that can be intimidating,
but you can also use only a small subset of it fairly easily.