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...