Page 1 of 2
Here we tell you how to get started with modern Java development in the shortest possible time. The approach uses NetBeans and Swing and all of the resources used are free to download and use.
Modern Java Contents
- Getting started with Java
- Introducing Java - Swing Objects
- Writing Java Code - Methods
- Command Line Programs
- The Java User Interface - More Swing
- Working With Class
- Class Inheritance
- Building a Java GUI - Containers
This tutorial is aimed at the Java beginner and the complete beginner to programming.
If you can already program in another language and are wanting to learn Java then there are some very introductory sections that you can skip.
If you want to know more about why NetBeans and Swing were selected then read the next section. If you simply want to get started then skip this too.
Where to start
Getting started with Java is difficult - more difficult than it needs to be. The reason is that there are so many different ways of writing a Java program.
This is confusing for the beginner.
One solution is to strip the process down to its bare essentials. This is why many introductions to Java start with programs written using NotePad or some other simple text editor and compiled using the command line.
This is at least a common baseline but it is very basic indeed. Modern Java programming isn't done from the command line and the typical Java application doesn't target the console.
To be reasonably up-to-date we have to start as we mean to go on - using an IDE (Integrated Development Environment) and creating GUI (Graphical User Interface) applications.
Now we hit the first snag - which IDE and which GUI Framework?
Most Java programmer have their preferred way of creating a Java program. Eclipse and NetBeans are two very popular IDEs that Java programmers tend to swear by. I'm not going to spend time considering the merits of the two for the simple reason that one of these IDEs is much more suited to the beginner. No matter what IDE you end up using in the future NetBeans is much easier to use to get started. A simplified configuration can be downloaded and installed in one operation and it supports a drag-and-drop GUI designer without the need to find and install anything extra. In other words, it provides a modern approach to Java development in one download.
Selecting NetBeans also solves the problem of which UI framework to use. It supports the Swing library out of the box and, as this is currently the most popular way of building a user interface, it makes sense to accept the situation. There are more modern UI Frameworks that you can use with Java - SWT, Pivot and JavaFX for example - but these have their drawbacks for the beginner. Once you have seen Swing in action then transferring your skills to another UI framework is comparatively easy.
So starting with the most direct and easy-to-use route to modern Java application development brings us to NetBeans and Swing.
You first task is to set up a development environment. This is remarkably easy. First you need to install the JDK and then a suitable copy of NetBeans.
To download and install the JDK go to:
You need to select, download and run the latest JDK - JDK 8 update 77 a the time of writing. Select the platform of your choice and run the download. It is simplest to accept the defaults.
To download and install NetBeans go to:
and click the download button. You will next be presented with a selection of different NetBeans. You can make use of any that include Java support but for getting started all you really need is Java SE support which is the first of the opitons.
If you don't have the JDK installed then you will see an error message and an instruction to install it.
Again accept the default installation options.
If anything goes wrong your first attempt to make it work should be to uninstall and try again.
Starting A Project
Now that you have Java installed it is time to write a first program.
As with all first programs this will be as simple as possible just to make sure everything is installed and working. However, instead of creating a console based application, which is arguably the simplest possible Java program, we are going to start with the simplest Swing application.
So start NetBeans running.
To get started we first have to create a project. A project consists of all of the files and resources needed to create an application.NetBeans can create a number of different types of projects to help get you started - we need the simplest project supported.
To create a new project we use the menu command
File, New Project
You will see the New Project dialog box listing all of the possible initial project types - select
and click the Next button.
In the next dialog box give the project the name Hello Swing and uncheck the Create Main Class selection box.
In most cases we need a Main class and most of the projects you will create in the future will start from a Main class but in this case things its simpler to do without and just click Finish.