Page 1 of 1

About Question enthuware.ocpjp.v8.2.1362 :

Posted: Tue Mar 15, 2016 2:08 pm
by rvt1234
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?

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

Posted: Tue Mar 15, 2016 9:33 pm
by admin
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.

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

Posted: Thu Mar 24, 2016 10:02 am
by rvt1234
all clear, thanks!

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

Posted: Mon Jun 20, 2016 4:03 am
by sahoo007tm
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?
}

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

Posted: Mon Jun 20, 2016 5:39 am
by admin
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.

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

Posted: Mon Jun 20, 2016 10:57 pm
by sahoo007tm
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!

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

Posted: Thu Jan 12, 2017 3:30 am
by dr_astico
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

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

Posted: Thu Jan 12, 2017 4:39 am
by admin
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.

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

Posted: Fri Jan 13, 2017 5:56 am
by dr_astico
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

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

Posted: Fri Jan 13, 2017 11:51 am
by admin
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.

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

Posted: Thu Oct 10, 2019 6:19 pm
by dvc1190
dr_astico wrote:
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
Actually, I'd argue that the exam is very much about taste - Oracle's exam designers' tastes. Questions like this are designed to help us to learn the tastes of the Oracle exam designer so that we can get these subjective questions correct.

In this case, my takeaway is that the exam will consider user input (or a passed argument in a public method) as something that should not be tested with assertions. In contrast, variables that are not passed into a public method or otherwise stated to be user input are things that can be tested using assertions.