All times are UTC - 5 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: About Question enthuware.ocpjp.v8.2.1362 :
PostPosted: Tue Mar 15, 2016 2:08 pm 
Offline

Joined: Mon Aug 18, 2014 5:25 am
Posts: 10
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?


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v8.2.1362 :
PostPosted: Tue Mar 15, 2016 9:33 pm 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6863
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.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v8.2.1362 :
PostPosted: Thu Mar 24, 2016 10:02 am 
Offline

Joined: Mon Aug 18, 2014 5:25 am
Posts: 10
all clear, thanks!


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v8.2.1362 :
PostPosted: Mon Jun 20, 2016 4:03 am 
Offline

Joined: Sat Jun 18, 2016 12:44 am
Posts: 9
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?
}


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v8.2.1362 :
PostPosted: Mon Jun 20, 2016 5:39 am 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6863
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.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v8.2.1362 :
PostPosted: Mon Jun 20, 2016 10:57 pm 
Offline

Joined: Sat Jun 18, 2016 12:44 am
Posts: 9
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!


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v8.2.1362 :
PostPosted: Thu Jan 12, 2017 3:30 am 
Offline

Joined: Thu Dec 29, 2016 5:57 am
Posts: 6
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


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v8.2.1362 :
PostPosted: Thu Jan 12, 2017 4:39 am 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6863
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.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v8.2.1362 :
PostPosted: Fri Jan 13, 2017 5:56 am 
Offline

Joined: Thu Dec 29, 2016 5:57 am
Posts: 6
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


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v8.2.1362 :
PostPosted: Fri Jan 13, 2017 11:51 am 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6863
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.


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Template made by DEVPPL/ThatBigForum