About Question enthuware.ocpjp.v8.2.1362 :

Moderator: admin

Post Reply
rvt1234
Posts: 10
Joined: Mon Aug 18, 2014 5:25 am
Contact:

About Question enthuware.ocpjp.v8.2.1362 :

Post by rvt1234 » Tue Mar 15, 2016 2:08 pm

Hey,

during a exam. How would one differentiate between this quesiton and let's say enthuware.ocpjp.v8.2.1399 (question 9 in Test Exceptions and Assertions).
In both cases the assert is in a public method and while 9 says it's appropriate and in question says that it doesn't work in all situations.

How would I know what knowledge the question is after? Because in Question 9 I would assume none of the snippets are appropriate?

admin
Site Admin
Posts: 7143
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1362 :

Post by admin » Tue Mar 15, 2016 9:33 pm

Both the question are testing you on two entirely different usages of assertions.
1. 2.1399: Here, the caller of the method can send any value as input and an assertion is being used to make sure the value is not illegal (from a business logic point of view). This is not good because assertions can (and usually are) be disabled in production and therefore you will lose the validation.
2. 2.1362: Here, it is not validating any user input. It is validating a given condition that the getCode method returns what it claims (0 or 1). If the getCode method returns something else then there is a coding issue which should be resolved during development (when assertions are enabled.). That is why, here, the usage of assertion is appropriate.

HTH,
Paul.

rvt1234
Posts: 10
Joined: Mon Aug 18, 2014 5:25 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1362 :

Post by rvt1234 » Thu Mar 24, 2016 10:02 am

all clear, thanks!

sahoo007tm
Posts: 9
Joined: Sat Jun 18, 2016 12:44 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1362 :

Post by sahoo007tm » Mon Jun 20, 2016 4:03 am

In choice #2, else block will never get "code == 0" due to the if , then what does it mean to do an assert like this
assert == 0 ?

its like

if(a ! = 0){
assert a == 0: "blah.."; //isn't this is somewhat a dead code?
}

admin
Site Admin
Posts: 7143
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1362 :

Post by admin » Mon Jun 20, 2016 5:39 am

Think about what will happen if getCode returns a non-zero value. The control will go to the else part and the assert will fail thereby triggering an AssertionError.

sahoo007tm
Posts: 9
Joined: Sat Jun 18, 2016 12:44 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1362 :

Post by sahoo007tm » Mon Jun 20, 2016 10:57 pm

admin wrote:Think about what will happen if getCode returns a non-zero value. The control will go to the else part and the assert will fail thereby triggering an AssertionError.
Thank you:)
my bad!

dr_astico
Posts: 6
Joined: Thu Dec 29, 2016 5:57 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1362 :

Post by dr_astico » Thu Jan 12, 2017 3:30 am

Hello,

excuse me, but what does mean "appropriate"?
I don't feel like putting an assertion alone, inside a else block or a switch default option is appropriate use of assertions.
is valid because the compiler will admit it, but there's no need to do it this way.
disabling assertions (in production environment), the result would be an empty else block or a useless switch option, which i believe is not appropriate especially if you are pointing efficiency optimization.

i think it would be more appropriate put the assertions out of such blocks/options.

and the answer, for this reason should be:
"none of the code snippets given in above options is appropriate."

Am I wrong?

Best regards

admin
Site Admin
Posts: 7143
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1362 :

Post by admin » Thu Jan 12, 2017 4:39 am

What you are saying is not wrong. This is all a bit subjective. But you need to think about the exam and in the exam, you in the exam you have to select the best option. In this question, we feel that is the best option because of the reason mentioned earlier.

HTH,
Paul.

dr_astico
Posts: 6
Joined: Thu Dec 29, 2016 5:57 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1362 :

Post by dr_astico » Fri Jan 13, 2017 5:56 am

Thank you.
You are right, is a bit subjective, but after all the question doesn't put the problem in such terms like optimization.
It looked a little painful to me, because of the traduction of that word in italian, wich depict it as "the best of solutions" either formally and in elegance.
but this is a matter of taste and is not about the exam at all.
and the exam is not about taste.

Best of all

Marco

admin
Site Admin
Posts: 7143
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1362 :

Post by admin » Fri Jan 13, 2017 11:51 am

Unfortunately, you may find a few questions in the exam that have a fair bit of subjectivity. We try to provide answers that will satisfy the exam so that you don't lose marks.

HTH,
Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests