1Z0-811 What is Java Practice Question
A junior developer writes a simple 'Hello World' program and saves it as HelloWorld.java. He compiles it successfully with 'javac HelloWorld.java', confirming that HelloWorld.class is created in the current directory. When he tries to run it with the command 'java HelloWorld', the system returns 'Error: Could not find or load main class HelloWorld'. The current directory is indeed the one containing HelloWorld.class. He has JAVA_HOME set to the JDK installation directory and has verified that java is in the PATH. What is the most likely cause?
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
The classpath does not include the current directory
By default, the java command does not include the current directory in the classpath, so even though HelloWorld.class exists in the current directory, the JVM cannot find it. The developer must explicitly add the current directory using -cp . or set the CLASSPATH environment variable. Option A is incorrect because a corrupt class file would typically cause a ClassFormatError, not 'Could not find or load main class'. Option C is incorrect because a missing or incorrect main method would yield 'Main method not found in class HelloWorld' error. Option D is incorrect because the error message indicates that the java command executed (it found the java executable), so it is in the PATH.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The class file is corrupt
Why it's wrong here
A corrupt class file would cause ClassFormatError, not 'Could not find or load main class'.
- ✓
The classpath does not include the current directory
Why this is correct
Java does not automatically search the current directory; use '-cp .' to include it.
- ✗
The main method is missing or incorrectly declared
Why it's wrong here
That would produce 'Main method not found' error.
- ✗
The java command is not in the PATH
Why it's wrong here
The command ran, so java is in PATH; otherwise, a different error would occur.
Go deeper
Related to this question
About these practice questions
One of 481 original 1Z0-811 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
Same concept, more angles
1 more way this is tested on 1Z0-811
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. A developer compiles a Java program successfully but gets 'ClassNotFoundException' when running it. What is the most likely cause?
medium- A.The Java version is incompatible
- B.The main method signature is incorrect
- C.The program has multiple classes
- ✓ D.The classpath does not include the directory containing the .class file
Why D: ClassNotFoundException occurs when the JVM cannot find the class definition, typically due to the classpath not including the location of the .class file. Option A is wrong because Java version incompatibility leads to UnsupportedClassVersionError, not ClassNotFoundException. Option B is wrong because an incorrect main method signature causes NoSuchMethodError. Option C is wrong because having multiple classes does not cause ClassNotFoundException unless one of them is missing from the classpath.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.