Lesson 2 - NetBeans IDE and your first console application

Java Basic constructs NetBeans IDE and your first console application

In the previous lesson, Introduction to the Java language, we talked about the language itself and went over how Java works. In today's lesson, we're going to focus on the NetBeans IDE. We'll show you how to use it and program a simple console application.

IDE stands for Integrated Development Environment. In a nutshell, it's an application in which we'll write a source code, and then use it to run, test and debug our application.


As first we need to download JDK (Java Development Kit) which is a set of tools needed for Java development. We'll find it at http://www.oracle.com/…s/index.html. We'll select that we agree with a license and select JDK for our operating system (for you, it'll be probably Windows 64 or 32, depending on your PC). The installation is trivial, just keep clicking on the Next button. It's possible that the installation will run the installation of some other components, just install them as well.

Now, let's download the IDE. It's a abbrev. of Integrated Development Environment and, simply speaking, it's an application in which we'll write our source code, run it and debug it. We'll use NetBeans since it's probably the most popular Java IDE and it's developed by the same company as the Java language is. Another alternative could be e.g. Eclipse IDE.

Visit http://netbeans.org/…s/index.html and download the NetBeans version for Java SE development. Install it (just keep clicking Next) and run it.

Backup and version control

Programmers usually need a tool that will provide version control and backup of his work. We can't rely on the fact that we could just save the program because we're humans and humans make mistakes. When you lose a few days' or even a few weeks' work, it can be really demotivating. It's good to think about such situations right from the start. I highly recommend Dropbox, which is extremely simple, and automatically stores multiple versions of your files, which makes it possible to revert to previous versions of the project, and also synchronizes with a web repository. Even if you've accidentally deleted your project, overwrote it, somebody stole your laptop or your hard drive accidentally collapsed, your data will remain safe. Dropbox also allows you to share projects with several developers.

You can also use a tool called GIT for the same purposes, but its configuration would require the "while" article. Dropbox is perfect for our current intents and purposes.

Creating a project

Run NetBeans and select File -> New Project in the application menu.

Creating a new project in NetBeans

In the New Project window, select the Java - Java Application template. In the next menu, name this project "FirstApplication". Create a folder for your projects in your Dropbox folder, for example, "java". Use the Browse button and select a folder C:\Users\your_na­me\Dropbox\ja­va. We will stick with console applications, command line interface, for a while because it needs minimal knowledge of the object-oriented world, and they are ideal for learning the basics of the language. The window should look like this:

Creating a new console application in Java

Confirm the form.

NetBeans Tutorial

The window now looks like this (I have resized it to fit :) ):

NetBeans Java window

We're interested mainly in the middle window in which NetBeans will generate some source code. It may be a surprise to some of you that we are not starting out with an empty window, but then again that is exactly what a template is (easily modifiable preset code)! We'll keep it simple for now, everything will be explained throughout the courses. Some parts are quite advanced, so we'll just accept the fact they're there and go into detail later.

We won't pay any attention to the package and class, just keep in mind that Java uses them to structure programs. The key will be the main() method for us, we'll write our code between the curly brackets below it, i.e. the body. Main is a reserved word, and Java knows that this method must be executed as first after the application starts (there are more methods, but more on that later). Actually, we'll ignore everything except for the main() method.

The second important element in the window is a green "Play" button in the upper bar, which compiles and runs our program. You can try it, but our program will not do anything, just turn terminate right away. You can also run the program with the F6 keyboard shortcut.

Hello world

As tradition instructs, we'll make the first program most people make when they learn a new language -Hello World. This is a program that displays "Hello world" or some similar text. Again, let me remind you that we'll write commands in the body of the main() method.

To write text we use the following bit of code:


System is a class. For now, we'll see classes as sets of available commands. In Java, commands are called methods. So System includes methods for console operations. We call the println() method, which displays a text, on the out (as output) object. You can see that we use a dot operator to call the method in the class. Methods can receive input parameters, which are entered in parentheses and separated by commas. In the case of the println() method, the parameter is the text to be printed. In programming, texts are called strings, like a string of characters, and written it in quotation marks. Java sees the quotation marks and interprets it as text so it's not confused with other commands. We should write the commands on separate lines, and after every line, we should put a semicolon. Our main() method will now look like this:

public static void main(String[] args)
        System.out.println("Hello ICT.social!");

You can run the program by pressing F6 if your system hasn't assigned a different command for the key. You can also run code snippets from our articles by pressing the "Play" button above, you can edit the code as well, just click on it. Try that :) This makes you able to study from anywhere, even without your IDE.

Hello ICT.social!

Congratulations, you have just become a programmer :) That will be all for today, in the next lesson, Variables, type system and parsing in Java, we'll look at the basic data types and create a simple calculator.

Today's project is attached as a file at the end of the article. You could always download the result below each lesson. I suggest that you create a project using the tutorial, and if something in your project doesn't work, then download it to find a mistake. If you download the lesson code before even trying to make it yourself, you won't learn anything :)



Downloaded 173x (15.01 kB)
Application includes source codes in language Java



Article has been written for you by David Capka
Do you like this article?
8 votes
The author is a programmer, who likes web technologies and being the lead/chief article writer at ICT.social. He shares his knowledge with the community and is always looking to improve. He believes that anyone can do what they set their mind to.
Unicorn College The author learned IT at the Unicorn College - a prestigious college providing education on IT and economics.
Activities (7)



Display older comments (10)

stanley kariuki:19. May 12:49

where can i download the setup file

Reply 19. May 12:49
David Capka
ICT.social team
Replies to stanley kariuki
David Capka:19. May 17:29

The links are in the lesson :)

Reply 19. May 17:29
You can walk through a storm and feel the wind but you know you are not the wind.
stanley kariuki:20. May 6:24

hallo Dave?should i delet the wors written in fedded ink,mine doest run,shows errors

Reply 20. May 6:24
stanley kariuki:20. May 6:49

hey,what area did you put the codes

Reply 20. May 6:49
Arthur Kateeba Ssekikubo:21. May 11:24

Well i have installed the netbeans and jdk 8 and also done with the first lesson. I did notice though that the class first letter has to be in uppercase.

Reply 21. May 11:24
Akintunde Richard:5. June 11:00

David thanks so much for this lesson. It's so exciting.

Reply 5. June 11:00
Shecy:14. June 6:30

Please state that the commands/class "System" is case sensitive! i spent a lot of time figuring that out! thanks.. nice work

Reply 14. June 6:30
Georges Maina Brown:20. June 16:37

nice one. thanks guys

Reply 20. June 16:37
Dorkky Olalekan Paul:2. July 15:39

I really need your help about the first assignment the program fail to run because of "printIn". I don't know how to type the "In" or it it 1 please I don't know how to write it

Reply 2. July 15:39
David Capka
ICT.social team
Replies to Dorkky Olalekan Paul
David Capka:2. July 18:40

It's not In, it's Ln like Line :)

Edited 2. July 18:40
Reply 2. July 18:40
You can walk through a storm and feel the wind but you know you are not the wind.
To maintain the quality of discussion, we only allow registered members to comment. Sign in. If you're new, Sign up, it's free.

10 messages from 20 displayed. Show all