A Standard Search Pattern for SCJP Questions
Noodle Food is a blog that I have been reading on and off for a few years now and recently there has been a post that got me thinking of strategies for dealing with SCJP questions. The post by Paul Hsieh talks about developing a standard "search pattern" for studying x-rays and I think the idea of a standard "search pattern" for java questions should be developed. So I'm going to list some things to look for in SCJP questions. Note: This is for questions that have very general answers (Compiler error, checked exception, runtime exception). Obviously if it's a question that doesn't have these general answers you don't have to worry about it, but, from what I understand, SCJP has these answers on most questions. So, it's important to look for these things in your search pattern.
The Search Pattern
Sometimes you may look at a question and have a gut feeling that something is wrong. When this happens you should immediately look at the provided answers and see if it is in there. If it is make sure that it does not conflict with other answers and use that answer. This guide is not a complete strategy to taking the exam it is only for questions that are too complicated for the answer to just pop out. It is a systematic way of looking for problems in code.
First check the order as if it were in a java source file. First package, second imports, and then classes. Only one class can be public and of course the file must have that classes name. Next, check for correct blocks of code. All code must be in a set of curly brackets with semicolons after each statement.
Next, check for valid identifiers and assignments. Don't for get to check assignments in for loops. If polymorphism is used make sure the assignment is correct. If and assignment is made with a return from a method check the access to that method along with the return type. If the method throws an exception make sure that it is handled during the assignment. You do not have to go through the method line by line at this point.
The next thing to look at are conditional statements. if, for, while, assert all have conditions that may not make sense. Look for assignments (=) instead of equality checks (==). Look for method calls that do not return boolean.
Line by Line Search
The idea of a line by line search is to start from the beginning of a program and figure out exactly what each line does. If the question does not have a main method the question will usually tell you where to start. Once you find an error don't lose your place. It may not be the answer the question is looking for.
Well this is all I'm going to write on this for now. I'm sure as I go through the book I will find things to add.