-
Chapter 1, Page 23
The line at the top of the page:
If you define a public class or an interface in a class, its name should match the name of the Java source code file.
should be:
If you define a public class or an interface in a Java source code file, the name of the class/ interface and Java source code must match.
-
Chapter 1, Page 24
Twist in the Tale 1.2 should indicate the possibility of existence of multiple correct options:
Question: Examine the content of the following Java source code file, Multiple2.java, and select the correct option(s).
-
Chapter 1, Page 24
Option (e) for Twist in the Tale 1.2:
Changing class Multiple2 to a non-public class will compile the code.
should be:
Changing interface Multiple2 to a non-public interface will compile the code.
-
Chapter 1, Page 41
The highlighted code in figure 1.23:
protected string author;
should be:
protected String author;
-
Chapter 1, Page 46
In figure 1.29, the access modifier symbol for the private method 'countPages()' should be '-'.
-
Chapter 1, Page 57
The bulleted point:
The OCA Java SE 7 Programmer I exam covers only two nonaccess modifiers:
abstract and static.
should be:
The nonaccess modifiers covered by the OCA Java SE 7 Programmer I exam are abstract, final and static.
- Chapter 2, Page 86
In figure 2.14:
char - /u0000
should be:
char - \u0000
- Chapter 2, Page 88
The comment for example code 'b -= a;':
OK; b is assigned a value of 10. b = 20 - 10.
should be:
OK; b is assigned a value of 0. b = 10 - 10.
- Chapter 2, Page 91
In the middle of the page, below the text 'The same logic applies to the unary operator...', two occurences of the comment:
Assign 20.0 * (--10), that is, 20.0 * 9.0, or 180.0 to c
should be:
Assign 20.0 * (--10), that is, 20.0 * 9.0, or 180.0 to f
- Chapter 2, Page 108
The explanation should be:
Option (a) is incorrect because the code prints true.
Option (d) is incorrect because the code prints false.
The code in option (c) uses parenthesis to indicate which expression should evaluate prior to the rest. Steps of execution:
boolean returnVal = (num1 >= 12 && num2 < 4.567) || eJavaResult == true;
returnVal = false || eJavaResult == true;
returnVal = true;
The original code in the question doesn't use parenthesis to group the expressions. In this case, because the operator && has a higher operator precedence than ||, the expression 'num1 >= 12 && num2 < 4.567' will be the first expression to execute. Steps of execution:
boolean returnVal = num1 >= 12 && num2 < 4.567 || eJavaResult == true;
returnVal = false || eJavaResult == true;
returnVal = true;
- Chapter 3, Pages 162 & 167
Text for question 3.3:
Which of the following methods correctly accepts three whole numbers as method arguments and returns their sum as a decimal number?
should be:
Which of the following methods correctly accepts three non-decimal numbers as method arguments and returns their sum as a decimal number?
- Chapter 4, Page 185
Code:
day = day.replace('D', 'Z').substring(3);
System.out.println(day);
should print:
Zday
- Chapter 4, Page 201 and 230
/u0000 for char data
should be:
\u0000 for char data
- Chapter 4, Page 206
Section 4.3.8, first bullet point:
lengthThe variable length contains the number of components of the array.
should be:
lengthThe variable length stores the number of elements of the array.
- Chapter 4, Page 233
Question 4-4, answer option (c):
Calling clear() and remove() on an ArrayList will remove all its elements.
should be:
Calling clear() or remove() on an ArrayList will remove all its elements.
- Chapter 4, Page 238
Explanation for Question 4-4, option (c):
Option (c) is incorrect. Only remove() will remove all elements of an ArrayList.
should be:
Option (c) is incorrect. Only clear() will remove all elements of an ArrayList.
- Chapter 5, Page 253
The first line of code, that is, 'else',
should be indented by 4 spaces to align it to the code 'if (score < 400)'.
- Chapter 5, Page 279
The bullet:
should be:
- Chapter 5, Page 283
The bulleted point:
- The continue statement is used to skip the remaining steps in the current iteration
and start with the next loop iteration. The continue statement works with
the for, for-each, do, and do-while loops and the switch construct.
should be:
- The continue statement is used to skip the remaining steps in the current iteration
and start with the next loop iteration. The continue statement works with
the for, for-each, do, and do-while loops.
- Chapter 6, Page 307
Code:
interface MyInterface {
int age = 10;
}
should be:
interface MyInterface {
int AGE = 10;
}
- Chapter 6, Page 339
Option b in Q6-9:
Modify code on line 3 to: publicStringprint();
should be:
Modify code on line 3 to: public String print();
- Chapter 6, Pages 339 and 345
Code in Q6-8:
class TestEJava {
Programmer a = new Programmer();
// INSERT CODE HERE
a.print();
b.print();
}
should be:
class TestEJava {
public static void main(String[] args){
Programmer a = new Programmer();
// INSERT CODE HERE
a.print();
b.print();
}
}
- Chapter 7, Page 350
Text in bullet point starting with 'Class OpenFile':
-
The constructor of the class FileInputStream throws a checked exception FileNotFoundException (as shown in figure 7.3). If you try to compile this code without enclosing it within a try block or catching this exception, your code will fail to compile.
should be:
-
The constructor of the class FileInputStream throws a checked exception FileNotFoundException (as shown in figure 7.3). If you try to compile this code without enclosing it within a try block and catching it, or marking it to be thrown by method main (by using the throws statement), your code will fail to compile.
- Chapter 7, Page 351
Side bar titled 'File I/O in Java' - First line in the last paragraph:
Creating an object of class File can throw the checked exception java.io.FileNotFoundException.
should be:
Creating an object of class FileInputStream or FileOutputStream can throw the checked exception java.io.FileNotFoundException.
- Chapter 7, Page 372
Code:
public class InvalidArrayAccess {
public static void main(String args[]){
String students[] = new String[]{"Shreya","Joseph"};
int pos = 1;
if(pos > 0 && pos < students.length)
System.out.println(students[pos]);
}
}
should be (the variable pos is assigned value 10):
public class InvalidArrayAccess {
public static void main(String args[]){
String students[] = new String[]{"Shreya","Joseph"};
int pos = 10;
if(pos > 0 && pos < students.length)
System.out.println(students[pos]);
}
}
- Chapter 7, Page 389
In Review notes, the heading:
An exception is thrown
should read:
What happens when an exception is thrown
- Chapter 7, Page 390
Review note:
None of the try, catch, and finally blocks can exist independently.
should read:
None of the (regular) try, catch, and finally blocks can exist independently.
- Chapter 7, Page 390
Review note:
Subclasses of the class java.lang.Exception are categorized as checked exceptions
if they are not subclasses of class java.lang.Runtime.
should read:
Subclasses of the class java.lang.Exception are categorized as checked exceptions
if they are not subclasses of class java.lang.RuntimeException.
- Chapter 7, Page 391
Bullet point in review notes for Errors:
Though you can handle the errors syntactically, there is little that you can do when these errors occur. For example, when the JVM throws OutOfMemory- Error, your code execution will halt, even if you define an exception handler for it.
should read:
Though you can handle the errors syntactically, there is little that you can do when these errors occur. Usually, ordinary programs are not expected to recover from errors.
- Chapter 8, Page 421 and 468
Options a and b for question ME-Q42:
a 1 GB
b 2 GB
should read:
a 1GB
b 2GB
- Chapter 8, Page 431 and 485
Options a and b for question ME-Q68:
a 1 GB
b 2 GB
should read:
a 1GB
b 2GB
- Chapter 8, Page 466
Explanation for answer to question ME-Q39:
Options (c) and (d) are correct. Exception handlers execute when the corresponding
checked or runtime exceptions are thrown.
should read:
Option(c) is correct. Exception handlers execute when the corresponding runtime exception is thrown.
Option(d) is incorrect. If StackOverflowError were a checked exception, the code wouldn't compile.
- appendix, Page 510
In explanation to Twist in the Tale 4.2, the code:
StringBuilder name = StringBuilder();
should read:
StringBuilder name = new StringBuilder();
- appendix, Page 514
In explanation to Twist in the Tale 6.2, the text:
As you can see in figure A.5, the classes Manager and HRExecutive implement the interface Interviewer. The class Employee doesnt implement the interface Interviewer; hence, an object of the class Manager cant be added to an array of type Interviewer.
should read:
As you can see in figure A.5, the classes Manager and HRExecutive implement the interface Interviewer. The class Employee doesnt implement the interface Interviewer; hence, an object of the class Employee cant be added to an array of type Interviewer.