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
- JVM, JDK and JRE
- Classes, objects and constructors
- Inheritance and interfaces
- Exceptions and collections
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?
- Dennis Ritchie
- James Gosling
- Guido van Rossum
- Bjarne Stroustrup
Answer: James Gosling
Java was developed by James Gosling at Sun Microsystems in 1995.
2. Java is a ____ programming language.
- Compiled and Interpreted
- Machine Language
- Assembly Language
- 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?
- Microsoft
- Oracle
- IBM
Answer: Oracle
Oracle Corporation acquired Java when it purchased Sun Microsystems.
4. Which keyword is used to define a class in Java?
- class
- Class
- define
- object
Answer: class
The class keyword is used to create classes in Java.
5. Which method is the entry point of every Java program?
- start()
- main()
- run()
- 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?
- .
- :
- ;
- ,
Answer: ;
Every Java statement ends with a semicolon.
7. Which keyword is used to create an object?
- new
- create
- object
- make
Answer: new
The new keyword creates an object from a class.
8. Which package is automatically imported in every Java program?
- java.util
- java.lang
- java.io
- java.net
Answer: java.lang
The java.lang package is automatically imported.
9. Which data type stores whole numbers?
- int
- float
- double
- boolean
Answer: int
The int data type stores integer values.
10. Which loop is best when the number of iterations is known?
- for
- while
- do...while
- 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?
- extends
- implements
- inherits
- super
Answer: extends
The extends keyword is used to inherit a class.
12. Which keyword is used to implement an interface?
- implements
- extends
- interface
- inherit
Answer: implements
A class uses the implements keyword to implement an interface.
13. Which access modifier makes a member accessible from anywhere?
- public
- private
- protected
- default
Answer: public
Public members can be accessed from any class.
14. Which keyword is used to prevent method overriding?
- final
- static
- const
- sealed
Answer: final
A final method cannot be overridden.
15. Which keyword refers to the current object?
- this
- self
- current
- super
Answer: this
The this keyword refers to the current object.
16. Which keyword refers to the parent class?
- super
- parent
- base
- this
Answer: super
The super keyword is used to access parent class members.
17. Which exception occurs when dividing by zero?
- ArithmeticException
- IOException
- NullPointerException
- RuntimeException
Answer: ArithmeticException
Division by zero throws an ArithmeticException.
18. Which collection stores unique elements only?
- Set
- List
- Array
- Vector
Answer: Set
A Set does not allow duplicate values.
19. Which package contains the ArrayList class?
- java.util
- java.lang
- java.io
- java.net
Answer: java.util
ArrayList belongs to the java.util package.
20. Which of the following is a major advantage of Java?
- Platform Independent
- Object-Oriented
- Secure
- All of the above
Answer: All of the above
Java is platform-independent, object-oriented, secure, and robust.