Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passed Mock Exam with 75% --> Some questions about wrong answers...

 
Kai Wähner
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I just made the first mock exam from the SCJP book. Some questions occurred, where I am a little bit unsure:


1) If I use , do I still access the Strings with agrs[0], agrs[1] and so on?




2) Method: --> if z has the value 3, the method call returns 3, not 4, right?




3) --> the go method has "void" as return value, so that is not possible (because it does not return anything. But what else is not allowed? I do not understand this?
Does String s; or String s = "test"; return anything? Can someone please explain me this rule?




4) I thought that an interface declaration MUST be declared public? (I know that methods are declared public abstract implicitly, and constants are declared static final implicitly)




5) Why does USUALLY the developer throw the NumberFormatException? I never did :-) Isn't this thrown USUALLY by the JVM (e.g. when I divide 10 through 0), just like NullPointerException, ClassCastException, and so on?




6) Can you please explain me the "switch and final" rule?
final int x = 3 may be used as switch expression, but short = 3 must not? Why?





I think with 75% in this mock exam (although I have seen some of the questions before), I am on a good way - with some more learning I am ready to try the exam :-)

I just downloaded the "ExamLab for SCJP 6.0" - do you think this is the best way now to improve my knowledge at this point?


Best regards,
Kai
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) yes
2) yes
3) The second part of assert statement after : cannot have a call to a method returning void. See this
4) Interfaces are not required to be declared public
5) ArithmeticException is thrown when 10 is divided by 0 not NumberFormatException. NumberFormatException is generally thrown by parseXXX methods like parseInt to indicate that the parsed String cannot be parsed into a number.
6) I cannot understand this question of yours. You've written short = 3 which is not even a legal java syntax...
 
Kai Wähner
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your quick reply.

Assert:
Expression2 is an expression that has a value. (It cannot be an invocation of a method that is declared void.)

Ok, so the second expression can be anything else, but not a call to a method that is declared void?




Question 6 again, sorry for my mistake:
Can you please explain me the "switch and final" rule?
final int x = 3 may be used as switch expression, but short y = 3 must not? Why? e.g:



Why fails the second example and what is the specific rule to remember? Does a switch expression always have to be declared final or be an Enum?


 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kai Wähner wrote:
.........



Why fails the second example and what is the specific rule to remember? Does a switch expression always have to be declared final or be an Enum?



Does this fail? switch expression need not be a final, but the case!
 
Kai Wähner
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this fail? switch expression need not be a final, but the case!


Oh, ok. You are right. So only the case expression must be final or a Enum...
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kai Wähner wrote:
Does this fail? switch expression need not be a final, but the case!


Oh, ok. You are right. So only the case expression must be final or a Enum...


If you've enough time, and knowledge hungry, have a look on this
 
Kai Wähner
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, I am knowledge hungry :-) Thanks...
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As for assert statement, you cannot put "anything" after : in assert statement. It should be an expression which returns a value. Check the documentation of AssertionError class, it has a number of constructors which take primitive types and Object as argument. So the part after : can be anything which returns a primitive or Object as a value...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic