Java Synchronization Basics

Here are 10 essential multiple-choice questions on Java Synchronization Basics, covering key concepts.

Last Updated :
Discuss
Comments

Question 1

Why is synchronization used in Java multithreading?

  • To improve CPU performance

  • To allow multiple threads to execute at once

  • To prevent data inconsistency and race conditions

  • To increase thread priority

Question 2

Which keyword is used to synchronize a method in Java?

  • lock

  • sync

  • synchronized

  • atomic

Question 3

What is the output of the following code?

Java
public synchronized void print() {
    System.out.println("Start");
    try { Thread.sleep(100); } catch (Exception e) {}
    System.out.println("End");
}
  • Will always print "Start" and "End" together

  • Will print "Start" only

  • Might throw InterruptedException

  • Prints "End" before "Start"

Question 4

Which of the following can be synchronized in Java?

  • Methods only

  • Constructors

  • Blocks and Methods

  • Interfaces

Question 5

Which object does a synchronized instance method lock on?

  • Class object

  • The method itself

  • The this object

  • The parent class

Question 6

How do you synchronize a block of code inside a method?

  • lock(this)

  • synchronize(this)

  • synchronized(this) { /* code */ }

  • Thread.lock(this) {}

Question 7

Which type of lock is acquired when using a static synchronized method?

  • Instance lock

  • Local lock

  • Class-level lock

  • Method-level lock

Question 8

What is a potential problem with improper synchronization?

  • Compilation error

  • Memory leak

  • Faster execution

  • Deadlock

Question 9

Which interface or class in Java provides explicit locking besides synchronized?


  • LockSupport

  • ReentrantLock

  • AtomicBoolean

  • ThreadGroup

Question 10

What happens if two threads access a non-synchronized method of the same object?

  • One thread waits

  • Both can execute concurrently

  • Compilation error

  • JVM throws exception

There are 10 questions to complete.

Take a part in the ongoing discussion