Java Quiz

Java is a widely used object-oriented language for enterprise software and Android. This quiz covers the JVM, syntax, classes and objects, inheritance, exceptions and the standard library.

What this quiz covers

Study tip: Pay attention to the difference between the JDK, JRE and JVM; it is one of the most common interview questions.

Questions, answers and explanations

1. Who developed Java?

  1. Dennis Ritchie
  2. James Gosling
  3. Guido van Rossum
  4. Bjarne Stroustrup

Answer: James Gosling

Java was developed by James Gosling at Sun Microsystems in 1995.

2. Java is a ____ programming language.

  1. Compiled and Interpreted
  2. Machine Language
  3. Assembly Language
  4. Scripting Language

Answer: Compiled and Interpreted

Java source code is compiled into bytecode and then interpreted by the JVM.

3. Which company currently owns Java?

  1. Microsoft
  2. Google
  3. Oracle
  4. IBM

Answer: Oracle

Oracle Corporation acquired Java when it purchased Sun Microsystems.

4. Which keyword is used to define a class in Java?

  1. class
  2. Class
  3. define
  4. object

Answer: class

The class keyword is used to create classes in Java.

5. Which method is the entry point of every Java program?

  1. start()
  2. main()
  3. run()
  4. execute()

Answer: main()

Execution begins from the public static void main(String[] args) method.

6. Which symbol is used to end a statement in Java?

  1. .
  2. :
  3. ;
  4. ,

Answer: ;

Every Java statement ends with a semicolon.

7. Which keyword is used to create an object?

  1. new
  2. create
  3. object
  4. make

Answer: new

The new keyword creates an object from a class.

8. Which package is automatically imported in every Java program?

  1. java.util
  2. java.lang
  3. java.io
  4. java.net

Answer: java.lang

The java.lang package is automatically imported.

9. Which data type stores whole numbers?

  1. int
  2. float
  3. double
  4. boolean

Answer: int

The int data type stores integer values.

10. Which loop is best when the number of iterations is known?

  1. for
  2. while
  3. do...while
  4. foreach only

Answer: for

The for loop is commonly used when the number of iterations is known.

11. Which keyword is used for inheritance in Java?

  1. extends
  2. implements
  3. inherits
  4. super

Answer: extends

The extends keyword is used to inherit a class.

12. Which keyword is used to implement an interface?

  1. implements
  2. extends
  3. interface
  4. inherit

Answer: implements

A class uses the implements keyword to implement an interface.

13. Which access modifier makes a member accessible from anywhere?

  1. public
  2. private
  3. protected
  4. default

Answer: public

Public members can be accessed from any class.

14. Which keyword is used to prevent method overriding?

  1. final
  2. static
  3. const
  4. sealed

Answer: final

A final method cannot be overridden.

15. Which keyword refers to the current object?

  1. this
  2. self
  3. current
  4. super

Answer: this

The this keyword refers to the current object.

16. Which keyword refers to the parent class?

  1. super
  2. parent
  3. base
  4. this

Answer: super

The super keyword is used to access parent class members.

17. Which exception occurs when dividing by zero?

  1. ArithmeticException
  2. IOException
  3. NullPointerException
  4. RuntimeException

Answer: ArithmeticException

Division by zero throws an ArithmeticException.

18. Which collection stores unique elements only?

  1. Set
  2. List
  3. Array
  4. Vector

Answer: Set

A Set does not allow duplicate values.

19. Which package contains the ArrayList class?

  1. java.util
  2. java.lang
  3. java.io
  4. java.net

Answer: java.util

ArrayList belongs to the java.util package.

20. Which of the following is a major advantage of Java?

  1. Platform Independent
  2. Object-Oriented
  3. Secure
  4. All of the above

Answer: All of the above

Java is platform-independent, object-oriented, secure, and robust.

Take the timed quiz