In the previous lesson you learnt how to debug a class. Previous lesson: 10.3 How to debug a classCourse Contents Collections and maps The Java Collections Framework provides a set of classes and interfaces that let you manage groups of related objects in a more powerful way than arrays. In this section you will learn: How the collections fra...
In the previous lesson you saw how to test a class. Previous lesson: 10.2 How to test a class using JUnitCourse contents How to debug a class Finding where you have a bug in your classes can sometimes be a time-consuming process. To help you, NetBeans incorporates a debugging tool that lets you set one or more breakpoints at any point in your code....
In the previous lesson we saw how to document your classes using the Javadoc tool. Previous lesson: 10.1 How to document your classesCourse contents How to test a class using JUnit Testing that your classes do what they are supposed to is an essential part of software development. In practical terms, it is impossible to ensure that software is tota...
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...
In the previous lesson we looked at preventing the compromisation of immutable classes. Previous lesson: 9.2 Preventing the compromisation of immutable classesCourse contents Recommended overrides from the Object class You will recall that every class (both those supplied by Java and those you write yourself) inherits from the Java supplied class c...
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...
In the previous lesson we built the Person utility class. Previous lesson: 8.3 Person utility classCourse contents Immutable classes and the Object class Immutable classes are those which don't enable their state to change after they have been constructed. The Object class provides a core set of functionalities inherited by every Java c...
In the previous lesson we discussed what utility classes are. Previous lesson: 8.2 Utility classCourse contents Person utility class Now that you have a separate Utilities project containing the Gender enum, you can create the class called Person in the com.example.util package of Utilities: package com.example.util;public class Person { // I...
In the previous lesson we looked at refactoring. Previous lesson: 8.1 RefactoringCourse contents Utility classes When developing any application, it makes sense to reuse classes which have already been developed, assuming you can find something suitable, of course. This will save you the time of having to specify, code and test something from scrat...
In the previous lesson we created our own Exception class. Previous lesson: 7.3 Creating an Exception classCourse contents Refactoring and utility classes Refactoring refers to the process of improving how you application is internally structured. Utility classes can be defined to provide commonly used services for multiple applications. In this se...
In the previous lesson we saw how to throw exceptions. Previous lesson: 7.2 Throwing exceptionsCourse contents Creating your own exception class It is possible to create an exception class of your own, if you can't find an appropriate Java supplied one to use. As an example, in a later section you will develop a user interface where the user can ma...
In the previous lesson we introduced exceptions. Previous lesson: 7.1 ExceptionsCourse contents Throwing exceptions Instead of catching an exception and handling it in the current method, you could choose to throw it back to the client object. You would do this if different clients might need to handle the situation in different ways. I...
In the previous lesson we looked at sorting in alternative sequences. Previous lesson: 6.5 Sorting in alternative sequencesCourse contents Exceptions Exceptions are Java's way of controlling unexpected occurrences, and which allows you can gain control over what to do in these circumstances. In this section you will learn: What exceptions are...
In the previous lesson you saw how to sort arrays and objects in their "natural" sequence. Previous lesson: 6.4 Sorting arraysCourse contents Sorting in alternative sequences You have seen that making your class implement the Comparable interface and implementing its compareTo() method lets you define a class's natural (or default) ordering. ...
In the previous lesson we showed how to loop over an array. Previous lesson: 6.3 Looping over an arrayCourse contents Sorting arrays The Arrays class (which exists in package java.util) contains a number of static utility methods to facilitate the sorting of arrays. Sorting primitive arrays If you need to iterate over an array ensuring that t...
In the previous lesson we defined a class that utilises an array. Previous lesson: 6.3 Example class using an arrayCourse contents Looping over arrays Java allows four different mechanisms for looping over the elements of an array. Looping is sometimes referred to as iteration. The standard "for" loop The standard for loop is in the following forma...
In the previous lesson we looked at what arrays are. Previous lesson: 61. ArraysCourse contents Example class using an array You will now develop a simple class that uses a single-dimensional array to model a pen that contains a group of animals. Create a new class in virtualzoo.core called Pen as follows that declares a constant and three in...
In the previous lesson we looked at arithmetic operations on primitives. Previous lesson: 5.11 Arithmetic operations on primitivesCourse contents Arrays, loops, and sorts Arrays provide a simple means of grouping like objects that they can be processed as a whole. Loops enable you to repeat parts of your code a certain number of times, while ...
In the previous lesson you learnt about casting. Previous lesson: 5.10 CastingCourse contents Arithmetic operations on primitives Enter your text here ... The arithmetic operators are: + for addition: e.g., a + b- for subtraction: e.g., a - b* for multiplication: e.g., a * b/ for division: e.g., a / b% for modulus (i.e., the remainder after divisio...
In the previous lesson you learnt about conditionals using the switch...case... block. Previous lesson: 5.9 Conditionals using switch caseCourse contents Casting Enter your text here ... You previously learned about the different capacities of the numeric primitive types, i.e., byte (8 bits), short (16 bits), int (32 bits), long (64 bits), ch...