In this part I will show how to define the repository and controller Java classes for our Pet class. This part assumes you have completed Part 3 of this series of articles. In the previous part we defined a Pet class and made it suitable to become a database table. We now need a repository class that forms the data access mechanism....
In this part I will show how to define the Java classes to model our pets and get them stored within a relational database table. This part assumes you have completed both Part 1 and Part 2 of this series of articles. We firstly need to define a Java class that will model each pet, and will therefore create a new Pet class. This class will be...
In the previous lesson we looked at recommended overrides from the Object class, Previous lesson: 9.3 Recommended overrides from the Object classCourse contents Documentation, testing, and debugging Java provides a built-in tool to help you document your classes. NetBeans incorporates the JUnit testing tool and a debugging tool. In this section you...
While Java doesn't support default values for parameters, we can use chaining to achieve this within constructors. Let's define a simple Java class called Animal that has two instance variables, the first for the animal's name and the other its date of birth: import java.time.LocalDate;public class Animal { private String name; private LocalDate da...
In the previous lesson you saw how to use the Java APIs. Previous lesson: 2.4 The Java APIsCourse contents Using classes and methods Methods provide the means of telling an object what it can do. In this series of lessons you will learn: Methods which change an object's stateOverloading and inheritanceAbstract classes and methods Methods that ...
In this part I will show how to create a new Spring Boot 3 project and create a Java entity class to model a pet. This part assumes you have completed Part 1 of this series of articles, where we verified that when creating a new Maven project in NetBeans we could see the option to create a new Spring Boot Initializr project: Ensure Spring Boot...
This series of articles will demonstrate how to get started with Spring Boot 3. I will do this by creating a very simple application to manage the pets we might have in our household. For the purposes of this article I will use Apache NetBeans 17, but you should easily be able to adapt this to instead use IntelliJ or Spring Tool Suit...
This is Lesson 1.6 of the Java programming course. Previous lesson: 1.5 Java syntax and naming conventionsCourse contents How Java programs are entered While it is possible to use a simple text editor to enter Java source code, and to use command line instructions to invoke the compiler, it is generally beneficial to use an Integrated Developm...
In the previous lesson you learnt about using classes and methods. Previous lesson: 3.1 Using classes and methodsCourse contents Method overloading The Animal class currently defines a constructor which requires three argument values to be supplied (for the name, gender and age), and if when you invoke this constructor you supply the wrong number o...
Method delegation in Java In this article I will show how you can delegate a method call from one Java object to another. Let's start with a simple Employee class that contains a method to perform some work: public class Employee { public void performSomeWork() { System.out.println("I am performing some work); }} Now suppose we have a Business clas...
Using the static keyword in Java to increment an object index number In this article I will show how to use Java's static keyword to increment a unique index number for object instances. We will start by creating a simple class called Employee comprising fields only for name and address. These fields will be normal instance variables: public class ...
Previous lesson: 20.1 Other Java featuresCourse contents Graphics There are facilities to draw graphics by overriding the paint() method of the component classes. Create a new class in virtualzoo.ui called PenguinPicture: package virtualzoo.ui;import java.awt.*;import javax.swing.*;public class PenguinPicture extends JPanel { @Override public void ...
Previous lesson: 14.13 JTreeCourse contents JSplitPane The JSplitPane class displays two components next to each other with a user moveable dividing bar between them. Usually, the components on either side of the divider will be panels, each containing one of more other components: // Panel to go on the left or the topJPanel panelOne = new JP...
Previous lesson: 14.12 JTableCourse contents JTree The JTree class displays items which are structured in a hierarchy. Each item is known as a node, and each node can contain other nodes as its "children". Like JList and JTable, the JTree uses an associated model object (a TreeModel) to provide its data. However, in many cases it is easier to...
Previous lesson: 14.11 JListCourse contents JTable Whereas the JList class displayed a list of items in a single column, the JTable class is capable of showing items that each have several columns. You need to attach a TableModel object (which references the item data) to the JTable. The most common way of doing this is to subclass the Abstra...
Previous lesson: 14.10 JSpinnerCourse contents JList The JList class displays a selection of a number of items, from which one or more may be selected. It is possible to pass an array of objects into the JList constructor, and it is usual to nest the list inside a JScrollPane: String[] options = {"Red", "Green", "Blue"};JList list = ne...
In the previous lesson we looked at immutable classes. Previous lesson: 9.1 Immutable classesCourse contents Preventing the compromisation of immutable classes Whenever you decide to create an immutable class, you need to take steps to ensure the immutability is not compromised, since you may have coded the rest of the application on the stri...
Previous lesson: 20.3 JavaBeansCourse contents Networking Two of the main ways of programming networking applications in Java is through sockets and Remote Method Invocation (RMI): Sockets Java supports connection to other hosts through the use of sockets. You can use the Socket class (in package java.net) to connect to a remote host b...
Previous lesson: 20.2 GraphicsCourse contents JavaBeans A JavaBean is a reusable component that is written to conform to certain conventions. Although they don't have to be, JavaBeans are often graphical in nature and in fact all the Swing graphical components are JavaBeans. This enables them to be used within builder tools such as NetBeans. ...
Previous lesson: 19.2 Other types of persistenceCourse contents Other Java features The desktop application developed in this course used many, but not all, of the major facilities of the Java language. This final section provides a brief look at some of the other useful features. In this section you will learn: How you can distribute your ap...