Java Interview Questions

Master Java with these comprehensive interview questions and expert answers.

Here are the top Java interview questions to prepare for your next role.

1️⃣ Which keyword is used in Java to prevent a variable from being modified after it has been initialized?

  • A) const
  • B) immutable
  • C) static
  • D) final

2️⃣ What is the maximum number of public classes allowed in a single Java source file?

  • A) Two
  • B) One
  • C) Unlimited
  • D) It depends on the JVM

3️⃣ Can you override a static method in Java?

  • A) Only if the class is declared as final
  • B) Yes, static methods support full overriding
  • C) No, static methods cannot be overridden
  • D) Yes, but only when using interfaces

4️⃣ What is the main difference between StringBuilder and StringBuffer in Java?

  • A) StringBuffer is immutable while StringBuilder is mutable
  • B) StringBuilder stores characters in Unicode while StringBuffer does not
  • C) StringBuffer is synchronized while StringBuilder is not
  • D) StringBuilder can only be used in single-threaded applications

5️⃣ Can a HashMap contain null keys in Java?

  • A) Only when using Java 17 or later
  • B) Only if using LinkedHashMap
  • C) Yes, it allows one null key
  • D) No, null keys are never allowed

We use cookies

Some cookies are needed to run this site. With your consent we also measure how it is used, so that we can improve it.

Cookie policy

Choose what we may measure. You can change this at any time.

Strictly necessary

Essential for the proper functioning of the website. These cannot be disabled.

Performance and analytics

Help us understand how Squizzu is used, diagnose technical issues and improve the service.

Java Interview Questions | Squizzu