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.
With NetBeans And Swing
- Getting started with Java
In chapter 1 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.
Introducing Java - Swing Objects
In the second chapter of our beginner's guide to Modern Java we find out more about objects by exploring the Swing framework with a simple hands-on example.
- Writing Code
Using ifs and loops is one of the most difficult parts of learning how to program. Our beginners introduction to Java reaches the part all programmers have know and know well - how to write code.
Command Line Programs
Command line programming means doing things in the simplest possible way. We take a careful look at how data types and code build a program.
User Interface - More Swing
Finding out how to create a User Interface (UI) using the Java Swing library is not only a useful skill, it also is an ideal way to learn about objects and to make sure that the ideas really have sunk in.
Working With Class
The Swing components have provided an easy approach to the idea of objects, but there comes a time when you have to find out how to create your own. In this part of Modern Java, we look at the standard ideas of object-oriented programming.
Java Class Inheritance
Working with classes and objects is a very sophisticated approach to programming. You can't expect to absorb all of its implications in one go. We have already looked at the basics of class and objects. Now we need to look at encapsulation, constructors, overloading and inheritance.
Building a Java GUI - Containers
In this chapter we get to grips with the idea of a container that is used to host components to build a user interface. We also find out how the Swing GUI Builder generates code to make it all much easier.
Java Data Types - Numeric Data
After looking at some of the advanced ideas of classes and objects we need to return to some simpler topics to make our understanding complete. We need to look more closely at data and, to get things moving, numeric data.
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.