Java 7 for Absolute Beginners
CHAPTER 4 ■ OPERATORS Listing 4-21. Chaining logical AND operators if (3 > 2 && 2 > 1 && 1 > 0) { Syste ...
CHAPTER 4 ■ OPERATORS Assignment Operators The assignment operators set values and assign object references. The basic assignmen ...
CHAPTER 4 ■ OPERATORS Table 4-3. The assignment operators Operator Description = This is the basic assignment operator. += Add t ...
CHAPTER 4 ■ OPERATORS Implementing the equals Method The first comparison is to see whether one object is equal to another. As w ...
CHAPTER 4 ■ OPERATORS if (!(p instanceof Person)) { return false; } if (p.lastName.equals(this.lastName) && p.firstName. ...
CHAPTER 4 ■ OPERATORS The hashCode and equals methods are closely related because they rely on the same premise. They add togeth ...
CHAPTER 4 ■ OPERATORS Implementing java.lang.Comparable Another best practice acknowledged by the Java community is to use java. ...
CHAPTER 4 ■ OPERATORS return 1; } if (thisTotal < pTotal) { return -1; } // must be equal return 0; } } The contract that the ...
CHAPTER 4 ■ OPERATORS this.lastName = lastName; this.favoriteBook = favoriteBook; } public boolean equals(Person p) { if (p == n ...
CHAPTER 4 ■ OPERATORS Listing 4-32. Book comparator class package com.apress.javaforabsolutebeginners .examples.comparing; impor ...
CHAPTER 4 ■ OPERATORS characters.add(drWatson); // sort by the natural values (uses compareTo()) Collections.sort(characters); f ...
CHAPTER 4 ■ OPERATORS The details of each of the operators. When and how to use the equals and hashCode methods. How to compare ...
C H A P T E R 5 77 Control Flow, Looping, and Branching Control flow, looping, and branching are fundamental concepts in all pro ...
CHAPTER 5 ■ CONTROL FLOW, LOOPING, AND BRANCHING Listing 5-1. A simple if statement if (a > 0) { b = 1; } Let's examine a lit ...
CHAPTER 5 ■ CONTROL FLOW, LOOPING, AND BRANCHING } else { greeting += "evening"; } System.out.println(greeting); You probably kn ...
CHAPTER 5 ■ CONTROL FLOW, LOOPING, AND BRANCHING but many developers prefer switch statements. Also, a switch statement can be e ...
CHAPTER 5 ■ CONTROL FLOW, LOOPING, AND BRANCHING Note the default case at the end. That's a switch block's way of letting you do ...
CHAPTER 5 ■ CONTROL FLOW, LOOPING, AND BRANCHING case 5: { greeting += "Thursday"; } case 6: { greeting += "Friday"; } case 7: { ...
CHAPTER 5 ■ CONTROL FLOW, LOOPING, AND BRANCHING Listing 5-7. Loop that finds directions int[] compassPoints = {22, 77, 144, 288 ...
CHAPTER 5 ■ CONTROL FLOW, LOOPING, AND BRANCHING Listing 5-9. Modifying the initialization variable in the loop body int[] compa ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf