PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Java · Theory

Volatile Keyword in Java

← All stacks

Theory

131/270

Volatile Keyword in Java

Volatile Keyword is part of Java concurrency. A thread is a path of work inside a process. Create with Thread or Runnable, then call start() — not run(). run() only runs on the same thread.

For Volatile Keyword: if two threads share data, synchronize or the result can be wrong. sleep pauses. join waits for another thread to finish. daemon threads die when all user threads finish.

Volatile Keyword deadlock: two threads wait for each other’s lock forever. Avoid by locking in the same order. Don’t guess thread order — it can change every run.

Let's take this on the board with one tiny Main class — no extra files. Volatile Keyword in Java — final, boolean, if, true are keywords used with normal meaning. Start from main, go line by line, and stop at each print. That output is the proof for Volatile Keyword.

Exam tip

Give 5 keywords from different groups: access, type, control, modifier, package.

Example

// Keywords in real code
public class Main {
  public static void main(String[] args) {
    final int MAX = 10; // final is a keyword
    boolean ok = true;   // boolean / true are keywords
    if (ok) {
      System.out.println("MAX = " + MAX);
    }
  }
}

Volatile Keyword in Java — final, boolean, if, true are keywords used with normal meaning.

Short notes

  • DefVolatile Keyword — thread = one path of work. start() schedules it. run() does not.
  • RuleVolatile Keyword — shared data needs synchronization.
  • RememberVolatile Keyword — sleep = pause. join = wait for other thread.
  • TrapVolatile Keyword — calling run() instead of start(). Deadlock = locks in wrong order.

Questions

1

What is Volatile Keyword?

2

Why do we use Volatile Keyword in Java?

3

Write one small example of Volatile Keyword.

4

What mistake do beginners make with Volatile Keyword?

5

Where is Volatile Keyword used in a real program?

Previous← Reentrant MonitorNextJava Input/Output →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.