This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

How to practice catching typo-style errors?  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I'm currently studying for the Java OCA and OCP exams. In doing practice exams and questions, I think I'm losing 5-15% worth of points by not catching errors like the one in the following question, and I want to figure out how to fix that.

(From Selikoff et al. OCA/OCP Java SE 8 Programmer Practice Tests, Chapter 3)
20. What is the output of the following application?



A. Too few B. Too many C. The code does not compile. D. The code compiles but throws a division by zero error at runtime.

The correct answer is that it doesn't compile because "int leaders = 10 * (2+(1+2/5);" is missing a closing paren.

As soon as I see the problem it is obvious, so this isn't a knowledge problem. But when I read code normally, my brain just assumes it's right and sees the necessary paren until its pointed out that its not there (i.e. by a compiler error or IDE warning).

What I've done to try to train this:

- write code in notepad instead of IDE, and try to catch errors before hitting compile (I think I've gotten a bit better by doing this, but not a lot).
- be paranoid when answering practice questions (not sure this helps at all)

Does anyone have any other strategies for catching these types of errors? Any study exercises for getting better at spotting them?

I appreciate your time for reading/answering.

- J
 
Marshal
Posts: 61753
193
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I am afraid that errors with mismatched brackets of any sort are all too frequent; we see them all the time on our beginning forum You are going to have to become paranoid and assume there are such errors. Count the ( and the ) and similarly for {}. The latter can be confused by poor indentation, but I am not sure whether the actual exam will have misleading indentation. The fact that an answer about failure to compile is included should make you suspicious.
Another counting thing. If you use the ?: operator, you must have the same number of ? and : You may do well to format an expression with multiple ?: on paper to be able better to understand it.
 
author & internet detective
Posts: 38911
686
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:The fact that an answer about failure to compile is included should make you suspicious.


More than half of the exam questions have "does not compile" as a choice. So you should be suspicious always!

Jimmy: Missing parens aren't common on the OCA, but they aren't unheard of either. (Missing squigglies are rare though). On the OCP, missing parens are really rare.
 
Jimmy Robov
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a bunch for your replies. I really appreciate it. Practice makes perfect it is then...
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!