• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OCAJP OCPJP Java 7 Mock Certification Exam Question: Use parentheses to override operator precedence

 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just posted a question and answer describing a tricking mock exam question that you'll run into on the OCAJP exam. You might even find it on the OCPJP exam as well.

The question itself walks through a discussion of the following code snippet:



A mock Java exam question would ask what the output would be, and provide a few sample answers, although I personally think an aspiring Java Professional should be able to figure out the answer without being given a few multiple choice answers to sort through.

OCAJP Mock Exam Question: Unary Operatrors, Math Shortcuts and Overriding Operator Precedence

TheServerSide article contains a crosslink to this page for discussion. Let the discussions begin!
 
Greenhorn
Posts: 11
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Cameron,
I'm not sure whether the discussion was to be here or in the Q&A thread, but I don't want to look at the Q&A first and see the answer (even though I know it ;-)

The thing to remember is that, in any expression involving a post-fix operation, the value of the variable x before the "++" operation is used in evaluating the expression each time it appears. Further, the entire expression on the right will be evaluated before the "+=" operator is applied.

Since evaluation proceeds left-to-right:
     x += x++ * x++ * x++;
by substitution, this is equivalent to:
     x += (x) * (x+1) * (x+2)
or:
     x += (x^2 + x) * (x+2)
or:
     x += (x^3 + 2x^2 + x^2 + 2x)
or:
     x += (x^3 + 3x^2 + 2x)
or:
     x = x^3 + 3x^2 + 3x
so if x=2:
     x = 2^3 + 3 (2^2) + 3(2)
or:
     x = 8 + 12 + 6
     x = 26

If you think that's a toughie, try figuring out the cost of upgrading from the original "Java Platform 2" certification to the array of certifications available now that cover the same technical territory, and whether there is any "upgrade" discount!

JeffInTampa
 
Cameron Wallace McKenzie
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very sweet.

I ran a conversation on this question over at TheServerSide: Interesting OCAJP/OCPJP Mock Exam Question

The general consensus was that they hated the fact certification exams too often test people based on riddles. They didn't like it.

 
Jeff Hill
Greenhorn
Posts: 11
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The sad fact is one is likely to see such code in the wild, and have to maintain it, so IMHO such questions are valid. If nothing else they make you pay attention during the test. I'll bet those who complained also wanted a "participation" certificate if they didn't pass!

Besides, anything that makes you think can help stave off dementia.

JeffInTampa
 
Enthuware Software Support
Posts: 4803
52
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is entirely possible that one might have to maintain such a cryptic code base. However, one might have to do several other things as well while maintaining a code base. Does that mean they should all be on the test?

I feel that in the limited time and number of questions that a candidate has to be tested within, it believe it is better to focus on basic programming and language skills than on deciphering cryptic code.

A recruiter can always have a specialized evaluation if they have a special need for the candidate to be able to decipher cryptic code. After all, one test cannot fit all
 
reply
    Bookmark Topic Watch Topic
  • New Topic