Java programming course: 5.9 Conditionals using switch case

In the previous lesson you leant about the ternary operator. Previous lesson: 5.8 The ternary operatorCourse contents Conditionals using switch case An alternative structure to if…else… is the switch…case… block. You can only use this when testing for equality and for the integer primitives (byte, short, int, long and char) and their wrapper classe...

Java programming course: 5.8 The ternary operator

In the previous lesson you learnt about the if...else... block. Previous lesson: 5.7 The if else blockCourse contents The ternary operator There is a short-cut technique you can sometimes use in place of simple if...else... blocks. Consider the following code: int temperature = 27;String weather = "?";if (temperature > 25) { weather = "hot";} el...

Java programming course: 5.7 The if else block

In the previous lesson you learnt about compound operators. Previous lesson: 5.6 Compound operatorsCourse contents  The if else block You can use the else statement when you need to specify what should happen if the condition is not met. For example, you could modify the weatherCheck() method from the previous lesson: public void weatherC...

Java programming course: 5.6 Compound operators

In the previous lesson you learnt about logical operators and the if condition: Previous lesson: 5.5 Logical operators and the if conditionCourse contents  Compound operators If you need to test more than one condition at the same time you can use the logical and operator && or the logical or operator ||: // Compound operatorsint i = 3...

Java programming course: 5.5 Logical operators and the if statement

In the previous lesson you learnt about using enum for constants. Previous lesson: 5.4 Using enum for constantsCourse contents  Logical operators and the if statement Frequently in programming you need to check whether a certain condition is true and perform different processing if the condition holds to when the condition does not hold. Java ...

Java programming course: 5.4 Using enum for constants

In the previous lesson you learnt about constants.  Previous lesson: 5.3 ConstantsCourse contents Using enum for constants You will commonly see the above technique of static final variables to define constants, including in the Java APIs. However, since Java version 5, a new and more powerful way of defining constants has been available, know...

Java programming course: 5.1 Static members, constants, and conditionals

In the previous lesson we started to manage the zoo using class ZooAdministrator. Previous lesson: 4.7 Manage zoo using ZooAdministratorCourse contents Static members, constants, and conditionals The static keyword enables you to define a variable or method that is not dependent upon any object. A constant is a variable whose value cannot be change...

Java programming course: 5.2 Understanding System.out.println

In the previous lesson we looked at static members. Previous lesson: 5.1 Static membersCourse contents Understanding System.out.println() You have several times used the System.out.println() statement to send text to the Output window, and its syntax looks slightly unusual in that there are two dots. If you look at the API for the System class, you...

Java programming course: 5.3 Constants

In the previous lesson we looked System.out.println(). Previous lesson: 5.2 Understanding System.out.printlnCourse contents Java Constants Another common use of class level (i.e., static) variables is for the definition of constants. These are values which once set, cannot be changed. In the Animal class there exists the instance variable gender wh...

Java programming course: 4.7 Managing the zoo using ZooAdminstrator

In the previous lesson you learnt about Java interfaces. Previous lesson: 4.6 InterfacesCourse contents  Managing the zoo using ZooAdminstrator From this point in the course, you will start to make more use of the ZooAdministrator class by using it to store example animals, zookeepers, visitors, etc. The VirtualZoo class, which is the entry po...