• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Guram's reported errata for Sybex OCA chapter 1  RSS feed

 
Greenhorn
Posts: 24
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Try this to compile, this is a compilation error: unreported exception java.lang.Throwable; must be caught or declared to be thrown

https://docs.oracle.com/javase/specs/jls/se8/html/jls-11.html#jls-11.1.1

The unchecked exception classes are the run-time exception classes and the error classes.
The checked exception classes are all exception classes other than the unchecked exception classes. That is, the checked exception classes are Throwable and all its subclasses other than RuntimeException and its subclasses and Error and its subclasses.

 
author & internet detective
Marshal
Posts: 38687
677
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not saying that you don't need declare a Throwable. I'm saying you shouldn't be throwing or catching it.
 
Guram Savinov
Greenhorn
Posts: 24
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you wish, but for me this is a misconception.
Maybe we should ask some other people about the explanation.
 
Guram Savinov
Greenhorn
Posts: 24
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page 21
Java Primitive Types
Example of long '123' should be '123L' like the float example '123.45f'
 
Guram Savinov
Greenhorn
Posts: 24
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same page 21
2^8 is 2 × 2 = 4 × 2 = 8 × 2 = 16 × 2 = 32 × 2 = 64 × 2 = 128 × 2 = 256
Should be 2^8 is 2 × 2^7 = 4 × 2^6 = 8 × 2^5 = 16 × 2^4 = 32 × 2^3 = 64 × 2^2 = 128 × 2^1 = 256
 
Guram Savinov
Greenhorn
Posts: 24
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page 22
hexadecimal (digits 0–9 and letters A–F)
lowercase 'a-f' is correct characters for hex literals as well
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 38687
677
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Guram Savinov wrote:Page 21
Java Primitive Types
Example of long '123' should be '123L' like the float example '123.45f'


No, the L is only required if you have a number that is larder than an int. As is the case of l3 below. 123 is a small number so you can write it as an int and have the compiler cast it for you. That's what you will see on the OCA.


Whereas a float requires the "f" to write even the simplest code such as:


Which means you have to know about "f" in order to write basic code.

ps - I split this into a new thread of your comments on chapter 1. Easier to keep track of than in one giant thread. Especially if any of them require a discussion rather than being "simple typos".
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 38687
677
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Guram Savinov wrote:Same page 21
2^8 is 2 × 2 = 4 × 2 = 8 × 2 = 16 × 2 = 32 × 2 = 64 × 2 = 128 × 2 = 256
Should be 2^8 is 2 × 2^7 = 4 × 2^6 = 8 × 2^5 = 16 × 2^4 = 32 × 2^3 = 64 × 2^2 = 128 × 2^1 = 256


That's another way of thinking of it. Either way you get 256. Both ways show that you multiple by 2 until you get the answer.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 38687
677
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Guram Savinov wrote:Page 22
hexadecimal (digits 0–9 and letters A–F)
lowercase 'a-f' is correct characters for hex literals as well


I actually didn't know that. (because convention is uppercase). It's not an errata per se. On the exam you'll see capital letters if you see hex at all.

Scott and I keep a private list of things that aren't quite errata but are misleading/could be clearer/would be useful to include. I've added this comment to that list. It wouldn't take much space for us to mention that lowercase is ok.
 
Guram Savinov
Greenhorn
Posts: 24
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chapter1 review question 12, answer F and explanation.

float primitive defaults to 0.0


0.0 is a double literal (same as 0.0d), so even if would be instance variable it's still not correct.
It would be corect if answer is 0.0F or 0.0f and it's an instance variable.
 
Guram Savinov
Greenhorn
Posts: 24
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chapter1 review question 11 explanation isnt clear about 0.0 literal too:

float and double primitives defaults to 0.0

 
Guram Savinov
Greenhorn
Posts: 24
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question 14 is not enough described: you didn't mention about runnning class in JVM, just about comiling.
Actually javac compiles any package declaration without any problem, but after that you should put .class file to appropriate directory to run bytecode.
And the Bird class must have main method if we going to run it in JVM.

For example:
1. you are in /my/directory
2. declare package: package my.directory.named.A
3. make subdirectories my/directory/named/A
4. put Bird.class from named/A to my/directory/named/A
5. run with: java my.directory.named.A.Bird
 
Guram Savinov
Greenhorn
Posts: 24
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should correct question 14 by:
1. replacing

if we compile from /my/directory

to

if we compile from /my/directory and run it with java named.A.Bird


2. adding main method to the Bird class
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 38687
677
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Guram Savinov wrote:Chapter1 review question 12, answer F and explanation.

float primitive defaults to 0.0


0.0 is a double literal (same as 0.0d), so even if would be instance variable it's still not correct.
It would be corect if answer is 0.0F or 0.0f and it's an instance variable.


Agreed. Good catch. I've added this to the errata.

Guram Savinov wrote:Chapter1 review question 11 explanation isnt clear about 0.0 literal too:

float and double primitives defaults to 0.0


There it is the logical 0 so I'm not worried about it.

Guram Savinov wrote:Question 14 is not enough described: you didn't mention about runnning class in JVM, just about comiling.
Actually javac compiles any package declaration without any problem, but after that you should put .class file to appropriate directory to run bytecode.
And the Bird class must have main method if we going to run it in JVM.


It doesn't need a main method. It could be part of a larger program. The question is clearly about understanding package names. This question is a perfect example of what you could see on the exam. Things aren't specified to the point of a lawyer. They use common, colloquial English. This is sometimes tricky for people who have more experience (as you sound like you do.) Because you have to put aside those details and answer the question with the best answer.
 
Guram Savinov
Greenhorn
Posts: 24
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:

Guram Savinov wrote:Chapter1 review question 12, answer F and explanation.

float primitive defaults to 0.0


0.0 is a double literal (same as 0.0d), so even if would be instance variable it's still not correct.
It would be corect if answer is 0.0F or 0.0f and it's an instance variable.


Agreed. Good catch. I've added this to the errata.

Maybe answer F for question 12 on page 46 should be 0.0f too.

 
Guram Savinov
Greenhorn
Posts: 24
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page 71

There is no requirement that second and third expressions in ternary operations have
the same data types, although it may come into play when combined with the assignment
operator.


That's not actually the truth, in the examle ternary operator result is of common type java.lang.Object which is passed to the System.out.println() method.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 38687
677
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sentence is referring to more specific types than Objects. It is correct as written.
 
Guram Savinov
Greenhorn
Posts: 24
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page 73
Figure 2.4
default branch of switch statement can have optional break as well as case branches
 
Guram Savinov
Greenhorn
Posts: 24
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page 82
Example at the top:


Prints: 0 1 2 3 4 5
Instead of: 0 1 2 3 4

because of last output of x value
 
Guram Savinov
Greenhorn
Posts: 24
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Errata has note about x output on page 82 and says: it can be removed, but it can't, because of this:

This code demonstrates three variations of the for loop you may not have seen. First, you
can declare a variable, such as x in this example, before the loop begins and use it after it
completes.


 
Guram Savinov
Greenhorn
Posts: 24
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page 85, Real World Scenario:

Should be:


because List<Integer> may contain null values
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 38687
677
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Guram Savinov wrote:Page 73
Figure 2.4
default branch of switch statement can have optional break as well as case branches


I dont' undersatnd what the errata is. We do point out that case and branch are both option.

Guram Savinov wrote:Page 82
Example at the top:


Prints: 0 1 2 3 4 5
Instead of: 0 1 2 3 4

because of last output of x value


Yes. We already have an errata that the extra println should be removed

Guram Savinov wrote:Errata has note about x output on page 82 and says: it can be removed, but it can't, because of this:

This code demonstrates three variations of the for loop you may not have seen. First, you
can declare a variable, such as x in this example, before the loop begins and use it after it
completes.



You can still use x after the loop completes. We just didn't show it

Guram Savinov wrote:Page 85, Real World Scenario:

Should be:


because List<Integer> may contain null values


They are equivalent. Because both versions in the book through an exception if there is a null in the list.
 
Guram Savinov
Greenhorn
Posts: 24
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page 135
Table 3.3

In real coding, you won’t be so concerned which is returned from each method due to autoboxing.


Actually, parseXxx(String s) and valueOf(String s) are not used during autoboxing.
Autoboxing can be done with help of methods like these (for Integer wrapper):
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 38687
677
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Guram Savinov wrote:Page 135
Table 3.3

In real coding, you won’t be so concerned which is returned from each method due to autoboxing.


Actually, parseXxx(String s) and valueOf(String s) are not used during autoboxing.
Autoboxing can be done with help of methods like these (for Integer wrapper):


The comment still holds. For example, in real life, it is less critical whether you know if parseInt() returns an int or an Integer:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!