aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Operator Precedence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Operator Precedence" Watch "Operator Precedence" New topic
Author

Operator Precedence

venkatesh rajmendram
Ranch Hand

Joined: Dec 05, 2000
Posts: 130
Hi All,
I have been working in java for some time, and was planning to take this exam from long time...I am using K&B ...there is not much mentioned about operator precedence...here is my question on

int x = 2;
int y = 5;
boolean f =true;

if ((x>3) && (y<2) | f )
System.out.println("print true");
it will not print anything
But if we add paranthesis in if for short circuit operator , it prints
int x = 2;
int y = 5;
boolean f =true;

if (((x>3) && (y<2)) | f )
System.out.println("which if1");
Well I thought seeing bitwise operator having more precedence than short circuit then it must be printing in the first case also,
can anyone clarify....
THanks
Venkatesh


SCJP 1.4, SCWCD<p>Ours is a world where people don't know what they want and are willing to go through hell to get it.<br /> - Don Marquis
Amir Kamran
Ranch Hand

Joined: Apr 21, 2002
Posts: 48
hello!
the precedence of bitwise operators is more than short circuit logical operators
so
(x>3) && (y<2) | f
means
(x>3) && ((y<2) | f )
for complete list of operator precedence check out this linkhttp://mindprod.com/jgloss/precedence.html
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
Howdy,
Just wanted to say that the real 1.4 exam has very little that tests you on anything but the basics, common-sense stuff on operator precedence. I've seen a lot of mock exams that have extremely elaborate and tricky questions on precedence, but there's nothing in the real exam that does that. Gosh knows there are ENOUGH tricky questions on the exam, but that's one are we just didn't go down. Perhaps the only areas that might get you on the exam involve casting:
return (int) 5.4 * 2.4; for example...
But that's about it. You could use common sense to work out virtually everything else where precedence is an issue on the current exam.
Now, you might get a question that *appears* to be an involved precendence/associativity question, but look again... the code might not compile. Like maybe it's a top level class marked private. Don't go too far down a convoluted code snippet until you step back and look at something more basic in the class. You might see, for example, a question with an elaborate bit of thread code and start working furiously on following the behavior. When the thread code has nothing whatsoever to do with the question... because the question was about import statements!! Always look FIRST at whether the code will even compile and run, before you start working out what the code does.
Remember, the real exam does not tell you the objective a particular question is trying to test. So what LOOKS like a thread question might really be an inner class question. And what LOOKS like a precedence question might really be about access mofidiers. You get the idea...
But you're not the first person to mention that our book is light on precedence. We probably should put more in for the next edition (on the Tiger exam), and in fact, there might *be* questions about it on the next exam, in which case we would regardless. But again, we generally go light in the book on areas that are not really tested much in the exam. We figure you have *enough* to worry about. But I've seen plenty of mock exams floating around on the web that would scare the heck out of me if I saw them on the real exam.
And yes, there will be a massive, 100% new SCJP exam coming for Tiger. No dates set as of yet, but you've got a while. I say 100% because every single question will be written from scratch, and in our new performance-based (rather than knowledge-based) style (which involves things like drag and drop questions where you have to construct code refrigerator-magnet style).
The 1.4 exam was considered a "refresh", where we did not revise the complete exam. We reused some of the questions from the 1.2 exam on the 1.4 exam. But that will not be the case with Tiger. And I can tell you that the exam for Tiger will be more difficult than the current exam, but in a different way. Where the current exam relies sometimes on *tricky* questions, the new exam will be much more about code and scenarios. There will be graphical and drag and drop questions on the new exam. The new SCWCD (beta in January) will be the first full look at the new style, although the SCBCD has some of this as well.
cheers,
Kathy
Hey, better hurry and get your SCJP if you want to take the two new beta tests coming soon... the 100% new SCWCD and the brand new Mobile Application Developer exam. Both require SCJP as a prerequisit. Stay tuned to javaranch for more info about the beta, including how to sign up. And remember, a beta test is FREE, grueling (instead of 70 questions you might have 180, but with more time), and gives you a full/real certification. If you pass a beta, you are certified exactly as if you had taken the real exam. It IS a real exam. Just more of it. The purpose of the beta is to attach a difficulty weight to each question, and to decide if any questions are simply way too easy or way too difficult to keep. No new questions can be added after a beta, and in fact only minor typos can be fixed. If a question is not clear and needs to be rewritten, we must throw it out completely. Otherwise, the beta would not be a true validation for the final release of the exam. The reason for the difficulty weighting is to ensure that each candidate taking a real exam gets an equally-difficult exam, even if they have different questions from the other people taking the exam.
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by Kathy Sierra:
And remember, a beta test is FREE, grueling (instead of 70 questions you might have 180, but with more time), and gives you a full/real certification. If you pass a beta, you are certified exactly as if you had taken the real exam. It IS a real exam. Just more of it. The purpose of the beta is to attach a difficulty weight to each question, and to decide if any questions are simply way too easy or way too difficult to keep. No new questions can be added after a beta, and in fact only minor typos can be fixed. If a question is not clear and needs to be rewritten, we must throw it out completely. Otherwise, the beta would not be a true validation for the final release of the exam. The reason for the difficulty weighting is to ensure that each candidate taking a real exam gets an equally-difficult exam, even if they have different questions from the other people taking the exam.

Hi Kathy,
I guess all the questions appeared in the beta exam are all located in the exam pool of Prometric... If a beta-test taker fails the exam and he/she goes for the officially released exam, I guess he/she will get the same questions out of all the questions he/she has done in the beta exam...
Is it the way how the beta exam works? I'm sorry, if I dig very deep into such things...


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
venkatesh rajmendram
Ranch Hand

Joined: Dec 05, 2000
Posts: 130
Hi Kathy,
I put this question on precedence in hurry...I think my question is not very clear. But first of all let me tell you I love your book. It's greatly presented. I enjoy reading every bit of it. Its entertaining and knowledgable...I have been in Javaranch for long time (at least more compared to others) you can see my registered date. ..my schedule is very busy and I have not got a chance to give SCJP.(even I got sometimes I was lazy )...I have been also working with java since version 1.1...planned to give exam during that time also...I had bought book by Robert and Philip... But was never able to give....Then after sometime I thought I will move on to SCEA which suits me more...But well I came back to SCJP to finish it....As long as I have been here on ranch...Your's was one of the best books I have ever seen, read and heard back from people...It makes comfortable for begginner as well experienced to read. Yes, we cannot get everything in one place...But you have tried best to put everything in one place prefect for this exam......
As far as precedence is concerned on page 216..the example shows the implications of putting bracket and removing it. you have literally naratted the scenario which is very good ..you have put more effort than any other author I have seen. but it kind of left me little unclear weather as bit wise operator still executes even short circuit operator (&&) takes over and doesnot evalute further, all that I felt was missing punch line saying what happens in prespective of precedence...
int x = 2;
int y = 5;
boolean f =true;
if ((x>3) && (y<2) | f )
I also agree the precedence is common sense. But as a matter of fact I have not used bit wise operator a whole lot...so it leaves some doubt in mind.
Well as you said, you might have it as a chapter or page in your next release.That will be great. Also personally I feel when you(Bert also ) have done splended job in putting together this book, why don't you just give an additional boost by putting some stuff on precedence and other things if at all you think are necessary on your web site, why give chance to point.That's just IMHO. ,But again that's not the only thing for whole exam..There's much "bigger fish to be fried"...which you already have done it or atleast marinated
Also thanks for your tips, I really appreciate that...maybe you can post more specific dates about SCWCD and Mobile...as they will be in vicinity.
Cheers
Venkatesh
[ December 18, 2003: Message edited by: venkatesh rajmendram ]
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8883
    
    5
Hi Venkatesh,
Thanks for your ideas for the book. Our general philosophy for the SCJP book is to focus our topics on the exam. There have been a few good ideas for additions to the book, but we're very careful to add only those topics that relate to the exam. We might beef up the precedence discussion a little bit, but my sense is that most of the mock exams are "out of whack" when it comes to precedence. I think this has led to a general feeling in the SCJP world that precedence is a big deal on the exam... IT'S NOT ! It's relatively easy to write tricky mock questions using obscure precedence rules, and a lot of mock creators do that. In my opinion, no production software should EVER include code that does not make precedence explicit. (Translation: USE PARANTHESES ! .) The good news is that in terms of the SCJP exam, Sun implicitly agrees with this philosophy. (The "use parantheses" philosophy.) In fact, several months ago I talked to one of the engineers at Sun who was a lead in the SCJP exam creation team. He said that he was of the "use parantheses" school, and that he made every effort to remove precedcence related questions from the exam.
Kathy indicated the areas in which you might need to know a bit about precedence, and I think her summary is right on. So, given that this forum is, after all, about the SCJP exam , my advice is, focus your studies on topics like threads, inner classes, and GC, that everyone agrees are really tricky, and also play a big part on the exam. I guess if you feel that you have absolutely everything else "down cold", you could study precedence, but for me, life is too short


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
 
wood burning stoves
 
subject: Operator Precedence