Will the code even compile? | Preparing for Java Oracle Associate Certification (OCA) / Java basic technical tests

I’ve always been pretty fast at everything. Same goes for the exams I passed at school. When I was training for my Java Certification, my first certification ever (OCA Oracle Certified Associate Java SE 8 Programmer 1Z0-808), at ease, with no pressure, I was wrapping the test in way less time than allowed. However, I totally used up all the available time when I was at the test center for my certification.

Lucky enough I had prepared myself a mental checklist of a few things to check before diving into the code. If you’ve never taken a programming certification, things are like this very often: most questions are code snippets and you’re being asked to tick correct answer(s), either saying what will be the input, or how to fix the code. But guessing the output is a very very very common type of question in the OCA. If you don’t do a pre-check, you could easily waste precious minutes resolving the code for nothing, just adding up to your stress.

Note this kind of question is also very common in job interviews for developer or software engineer positions, you might use those tips to pass technical questionnaire tests when applying for a programming job!


This article is the first of a whole series on how to prepare for the OCA certification, make sure to register to get future posts in your mailbox. Next articles will break each theme of the certification with main attention points, pitfalls, and some advice.


This article was mentioned in JetBrains’ Java Annotated Monthly (October 2020)


Does it even compile?

One major thing to master (yes, master) when passing a test in Java (or any compiled programming language) is knowing either the code will compile or not. Thus also knowing what compiling means and knowing that compiling and running are two different things. If you take the OCA, you’ll get ask what’s the input of a code snippet a lot. Very often, you will find these two options in the multiple choice list: “It doesn’t compile” and “It doesn’t run“. Just knowing that it won’t work is not enough. You have to know why and at which stage it will fail. This kind of “subtlety” can also make you fail a job interview, especially when applying for a job where at least a little experience is required (maybe as a total beginner you’d be safe from them, but that’s not even sure).

In Java, we talk about “compile-time” and “runtime” problems/errors/issues… The compiling part has become quite abstract for most programmers now because the IDE (Eclipse, IntelliJ, NetBeans…) does it for us, in real time. You might want to make some research about it to know your subject, but here’s a really short guide to compiling and running a Java application manually.

The short and fast way to understand the difference is so: when using an IDE, which compiles in real time, any error appearing on the screen is a compile-time error. It would usually be underlined in red. Anyway, compile-time problems won’t allow you to run the application (running is what you do when you press the “play” or “run” button ▶️ in the IDE).

So, first thing to do when you have a code snippet to solve is to check for compile-time issues. That’s the fastest case because if the code can’t be compiled, there will be no output, no result whatsoever, and no error or exception thrown! So as soon as you find a compile-time problem, you can leave the rest of the code and answer the question, and next!

Some common compile-time problems include:

  • unreachable code (code that’s after a return/break/continue statement),
  • missing return statement or returning the wrong type,
  • trying to instantiate an abstract class or interface,
  • initialized variable,
  • no type match (but be careful with inheritance!),
  • missing ; or { }, wrong code organization in general,
  • missing imports or package declaration,
  • incomplete method signature or class declaration, or wrong word order,
  • wrong or redundant identifier, or reserved word used as identifier,
  • variables out of scope…

We will see a lot more cases in the other OCA series posts!

Supa dupa important: you can’t run the application if compilation fails. Just remember this and keep it in mind during the exam (and during your whole career as a developer!). Also, compile-time errors don’t throw actual errors or exceptions. They can’t, because the program has to run to throw an error…

If compilation can’t fail…

You also want to check the answers before reading the question, because if there is no option “Compilation fails”, it means you don’t have to look for compilation errors at all! In that case, the code has to be solved, either to find out the output and/or find out the errors or exceptions occurring.

What about errors and exceptions?

Remember that an error or exception can only be thrown if the code runs, and that having exceptions thrown does not mean that there will be no other output, because an exception can happen later in the execution of the code! And they can be caught, which we will also see in a later post. Also remember that runtime issues in Java always happen with an error or exception thrown.

Studying for the certification

When I took the exam for the OCA certification, I already passed Introduction to algorithms and programming and Object Oriented Programming classes at school (Computer Science bachelor degree), both in Java. Still, I learnt a lot while studying for my certification and had to practice again and again to ensure I would pass. The certification makes sure that you know Java very well, not just that you’re able to program. You can already program (badly), even for years, and not master what’s under the covers of the Java APIs.

I used the very well known “OCA: Oracle Certified Associate Java SE 8 Programmer I Study Guide: Exam 1Z0-808” book which covers all the topics of the certification, with a lot of exercises. They might even be a bit harder than the actual exam questions, but that’s what makes it an excellent study material.

I also took a license at Enthuware (OCA pack costs around $10 which is very low price to ensure you’ll pass and to thank them for the collection work they performed). Enthuware software allows you to train on exam-alike questions with a timer (mock exams). There is a really large bank of questions and you might choose to train on particular topics or choose only the toughest questions to challenge yourself.

Both will help you master the compiling vs running understanding and have you prepared to answer such questions!

Since then I’ve passed a few other IT certifications and I experienced both in center and at home exams (all with Pearson Vue), please feel free to drop any question you might have!

Skip to content