Java MCQs (Multiple Choice Questions) with Answers - Set I

Java MCQs ( Multiple Choice Questions ) with Answers - Set I - CodingHumans

This is the first of our three Java MCQ sets. It sticks to the basics most students meet in their first semester of Java: where the language came from, why it runs on any machine, the JDK tools, and a few tricky output questions that show up in campus tests and placement rounds.

We rewrote this set in October 2026. Every answer now comes with a short reason, and we fixed two questions from the old version: the expression question in Q14 had the wrong answer marked, and the program in Q15 had no main method, so it could not actually print anything.

How to use this set: pick an option for each question. You will see straight away whether it is right, with a short note on why. There are 15 questions.

What this set covers

  • History of Java and the Oak project
  • Bytecode, the JVM and platform independence
  • JDK tools: javac, jdb and friends
  • Servlets, filters and JDBC driver types
  • OOP basics and the break statement
  • Pre and post increment, and the order of static and instance blocks

Java MCQs with answers and explanations

Q1. Java has its origin in which language?

a) Oak

b) COBOL

c) C

d) Perl

Q2. Java programs are best described as:

a) Faster than programs in every other language

b) Not scalable

c) Not reusable

d) Platform independent

Q3. Which one of the following is true for Java?

a) Java is always faster than C

b) Java is object-oriented and interpreted

c) Java has no garbage collection

d) Java is not robust

Q4. Java servlets are an efficient and powerful way to create ________ for the web.

a) Dynamic content

b) Hardware drivers

c) Static content

d) Desktop user interfaces

Q5. The command javac is used to:

a) Create a JAR file

b) Run a Java program

c) Compile a Java program

d) Debug a Java program

Q6. Which of the following is NOT a Java feature?

a) Architecture neutral

b) Object-oriented

c) Dynamic

d) Use of pointers

Q7. Which of these gives Java its portability and security?

a) Dynamic binding between objects

b) Bytecode is executed by the JVM

c) Exception handling

d) Applets make the code secure

Q8. A native-protocol pure Java (Type 4) JDBC driver converts ________ into the ________ used by the DBMS directly.

a) JDBC calls, network protocol

b) ODBC calls, user calls

c) ODBC calls, network protocol

d) JDBC calls, user calls

Q9. Which is the root class of all AWT events?

a) java.awt.AWTEvent

b) java.awt.ActionEvent

c) java.awt.event.Event

d) java.awt.event.AWTEvent

Q10. Which of these are benefits of object-oriented programming? i) Higher productivity ii) Reusability iii) Lower maintenance cost iv) High vulnerability

a) ii, iii and iv

b) All four

c) i, ii and iv

d) i, ii and iii

Q11. Which tool is used to find and fix bugs in Java programs?

a) JRE

b) jdb

c) JDK

d) JVM

Q12. Filters were officially introduced in which Servlet specification?

a) 2.1

b) 2.2

c) 2.3

d) 2.4

Q13. The break statement is used to: i) get out of a method ii) end a program iii) get out of a loop iv) get out of the system

a) i and ii

b) iii only

c) i, ii and iv

d) i and iii

Q14. If x = 3, y = 5 and z = 10, what is the value of this expression?

++z + y - y + z + x++

a) 23

b) 25

c) 20

d) 24

Q15. What does this program print?

public class CodingHumans {
    static int a = 10;
    static int n;
    int b = 5;
    int c;

    public CodingHumans(int m) {
        System.out.println(a + ", " + b + ", " + c + ", " + n + ", " + m);
    }

    { b = 30; n = 20; }

    static { a = 60; }

    public static void main(String[] args) {
        new CodingHumans(7);
    }
}

a) 60, 5, 0, 0, 7

b) 10, 5, 0, 20, 7

c) Compilation error

d) 60, 30, 0, 20, 7

Quick revision notes

  • Java started as Oak at Sun Microsystems (1991) and was renamed in 1995.
  • javac compiles, java runs, jdb debugs, javadoc builds documentation, jar packages files.
  • Bytecode plus the JVM is what makes Java portable.
  • ++x changes the value before it is used; x++ uses the old value and changes it afterwards.
  • Order when you create an object: static blocks (once per class), then field initialisers and instance blocks in the order written, then the constructor body.

Frequently asked questions

Are these Java MCQs useful for placement tests?

Yes for the basics. Aptitude rounds at service companies often ask exactly this kind of output and theory question. For product companies you will also need data structures and coding practice.

Why was the answer to Q14 changed?

The earlier version marked 24 as correct. If you run the expression in Java with x = 3, y = 5 and z = 10, it prints 25, so we corrected it and added the working.

Which Java version should I learn in 2026?

Learn on a current long-term support release such as Java 21 or 25. The questions here cover basics that have not changed between versions.

Comments

Answered 0/0Correct 0