OCP exam prep: how Java works¶
☕ Java 17 · 🎓 OCP 1Z0-829 · How Java Works Under the Hood
Optional page
This page is for readers preparing the Oracle Certified Professional Java SE 17 Developer exam (1Z0-829). The concepts are all you need otherwise.
Four traps to watch for¶
Trap 1 — javac compiles, java runs
javac Movie.java takes a file name with its extension and produces Movie.class. java Movie takes a class name, without .class. The exam shows command-line snippets, not IDE buttons.
Trap 2 — Public class name = file name
public class Movie must live in Movie.java. A mismatch, even only in letter case, is a compilation error.
Trap 3 — Case-sensitive everywhere
Movie, movie and MOVIE are three different identifiers: class names, variables and keywords alike.
Trap 4 — The JDK includes everything
Since Java 11 there is no separate JRE download: the JDK brings the JVM, the libraries and javac, java, jar and javadoc.
Practice questions¶
1. A file named StreamingPlatform.java contains public class streamingPlatform { }. What happens when you run javac StreamingPlatform.java?
A. It compiles and produces streamingPlatform.class
B. Compilation error
C. It compiles and produces StreamingPlatform.class
D. It compiles, but java StreamingPlatform fails at runtime
Answer
B. The public class must have exactly the file's name, letter case included. streamingPlatform ≠ StreamingPlatform, so the compiler refuses the file. Running never even starts.
2. Movie.class exists and has a valid main method. What happens with java Movie.class?
A. The program runs
B. Compilation error
C. Error: java expects a class name, without .class
D. The JVM ignores the extension and runs the program
Answer
C. java looks for a class literally named Movie.class, which doesn't exist, so the launcher fails to find or load it. It isn't a compilation error: javac isn't involved. The right command is java Movie.