About Question enthuware.ocpjp.v8.2.1362 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

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 »

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: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

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

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

Post by rvt1234 »

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 »

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: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

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

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

Post 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!

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 »

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: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

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 »

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: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

dvc1190
Posts: 15
Joined: Tue Feb 25, 2014 3:14 am
Contact:

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

Post 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.

Post Reply

Who is online

Users browsing this forum: No registered users and 31 guests