All featured quizzes

Java - Basics

Packages, equals method, exception handling, platform independence, and array bounds in Java.

Sample Questions

A preview of what's in this quiz. Answer them interactively for instant scoring and full explanations.

What is the difference between JDK and JRE?

1. What is the difference between JDK and JRE?

  • A.JRE contains JDK and JVM.
  • B.JDK is for development and contains JRE; JRE is only for running compiled Java programs.
  • C.JDK compiles code into machine code; JRE compiles it to bytecode.
  • D.There is no difference; they are aliases.
What does the Java Virtual Machine (JVM) do?

2. What does the Java Virtual Machine (JVM) do?

  • A.Compiles source code .java files into .class files
  • B.Loads, verifies, and executes Java bytecode on host platforms
  • C.Defines the syntax and syntax validation rules of the Java language
  • D.Deletes temporary files in database repositories
What is the default value of an uninitialized local variable inside a Java method?

3. What is the default value of an uninitialized local variable inside a Java method?

  • A.null
  • B.It has no default value and causes a compilation error if read before initialization.
  • C.0
  • D.false
What is the exact entry point signature of a standard Java application?

4. What is the exact entry point signature of a standard Java application?

  • A.public void main(String[] args)
  • B.public static void main(String[] args)
  • C.static void main(String args)
  • D.public static int main(String[] args)
What is the size of an `int` variable in Java?

5. What is the size of an `int` variable in Java?

  • A.16 bits (2 bytes)
  • B.32 bits (4 bytes)
  • C.64 bits (8 bytes)
  • D.8 bits (1 byte)
Which of the following is NOT a primitive data type in Java?

6. Which of the following is NOT a primitive data type in Java?

  • A.int
  • B.String
  • C.char
  • D.boolean
Which of the following is correct regarding platform independence in Java?

7. Which of the following is correct regarding platform independence in Java?

  • A.Java source code runs directly on browser hardware.
  • B.Java bytecode is platform-independent; the JVM is platform-specific.
  • C.Both Java bytecode and the JVM are platform-independent.
  • D.Java requires recompiling source files for every target platform.
What is Unboxing in Java?

8. What is Unboxing in Java?

  • A.Unpacking JAR file archives into directories
  • B.Automatic conversion of wrapper class objects to their corresponding primitive values
  • C.Removing deprecated annotations from source code
  • D.Releasing objects from garbage collection sweeps
Which keyword is used to establish inheritance between classes in Java?

9. Which keyword is used to establish inheritance between classes in Java?

  • A.implements (used for interfaces)
  • B.extends
  • C.inherits
  • D.extends_class
What is Encapsulation?

10. What is Encapsulation?

  • A.Creating child classes inheriting parent properties
  • B.Restricting direct access to object state and exposing it through public methods
  • C.Defining multiple methods with identical names but different signatures
  • D.Converting source files to compiled bytecode archives
What is the size of a `char` variable in Java, and what encoding does it support?

11. What is the size of a `char` variable in Java, and what encoding does it support?

  • A.8 bits (1 byte), supporting ASCII encoding only
  • B.16 bits (2 bytes), supporting Unicode characters
  • C.32 bits (4 bytes), supporting full UTF-32 symbols
  • D.Dynamic size depending on active browser font sizes
What is the difference between StringBuilder and StringBuffer?

12. What is the difference between StringBuilder and StringBuffer?

  • A.StringBuilder is thread-safe; StringBuffer is not.
  • B.StringBuffer is thread-safe; StringBuilder is not thread-safe but performs faster.
  • C.StringBuffer is immutable; StringBuilder is mutable.
  • D.StringBuilder is only for web apps; StringBuffer is for desktop apps.
What is Method Overloading?

13. What is Method Overloading?

  • A.Redefining a parent class method inside a subclass with matching signature
  • B.Defining multiple methods with the same name but different parameters in a class
  • C.Overloading server threads with excessive requests
  • D.Specifying default values inside constructors
What are the four core principles of Object-Oriented Programming (OOP)?

14. What are the four core principles of Object-Oriented Programming (OOP)?

  • A.Classes, Objects, Methods, Fields
  • B.Encapsulation, Inheritance, Polymorphism, Abstraction
  • C.JVM, compiler, interpreter, classloader
  • D.Compilation, Execution, Testing, Deployment
Which operator is used to check if two reference variables point to the exact same object in memory?

15. Which operator is used to check if two reference variables point to the exact same object in memory?

  • A..equals()
  • B.==
  • C.instanceof
  • D.=
What is the difference between String and StringBuilder in Java?

16. What is the difference between String and StringBuilder in Java?

  • A.StringBuilder is immutable; String is mutable.
  • B.String is immutable; StringBuilder is mutable.
  • C.String is thread-safe; StringBuilder is also thread-safe (StringBuffer is thread-safe, StringBuilder is not).
  • D.There is no performance difference between them.
How do you compare the actual text value of two String objects for logical equality?

17. How do you compare the actual text value of two String objects for logical equality?

  • A.str1 == str2
  • B.str1.equals(str2)
  • C.str1 === str2
  • D.str1.compare(str2)
Which keyword is used to instanciate and allocate memory for a new object in Java?

18. Which keyword is used to instanciate and allocate memory for a new object in Java?

  • A.create
  • B.new
  • C.alloc
  • D.instanciate
What is Autoboxing in Java?

19. What is Autoboxing in Java?

  • A.Converting class files into compressed JAR archives
  • B.Automatic conversion of primitive types to their corresponding wrapper classes
  • C.Casting parent class instances to child class references
  • D.Generating constructors automatically at compilation time
Where are literal String values (e.g. `String s = "hello"`) stored in memory?

20. Where are literal String values (e.g. `String s = "hello"`) stored in memory?

  • A.Stack memory
  • B.String Constant Pool (inside the Heap)
  • C.Metaspace (Method Area)
  • D.CPU register memory

Looking for a different topic? Browse all subjects