Make Sense of abstract, transient, and volatile in Java Once and For All

Victor MwendwaVictor Mwendwa
2 min read

Java has many powerful features that help make code clean, efficient, and easy to manage. Three keywords that often come up in Java programming are abstract, transient, and volatile. Let’s break them down in simple terms:


1. abstract – The Blueprint Keyword

Imagine building a house. You don’t start by constructing everything at once. You first create a blueprint, which shows how things should be built, but doesn’t actually build anything.

In Java, an abstract class is like that blueprint. You can define methods in it, but you don’t implement them. You leave the implementation to other classes that extend the abstract class.

abstract class Animal {
    abstract void makeSound(); // No implementation here
}

Why use it?
It allows you to define a template while leaving the details for other classes.


2. transient – Don’t Save This Data

Let’s say you have a User class with username and password. You wouldn’t want to save the password when storing the user data, right? That’s where transient comes in.

When you mark a variable as transient, it won’t be saved during object serialization (the process of saving an object to a file or transferring it).

class User {
    String username;
    transient String password; // Won't be saved
}

Why use it?
It ensures sensitive data like passwords don’t get saved unintentionally.


3. volatile – Always Get the Latest Value

When multiple threads are working together, sometimes they might not see the same value for a variable. To make sure all threads see the updated value, you can mark the variable as volatile.

class Counter {
    volatile int count; // Always gets the latest value
}

Why use it?
It helps avoid issues where threads might see outdated or inconsistent data.


0
Subscribe to my newsletter

Read articles from Victor Mwendwa directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Victor Mwendwa
Victor Mwendwa

I'm Victor Mwendwa — a passionate Product Engineer who loves turning ideas into real, user-focused solutions. Whether I’m building web apps, mobile tools, or smart systems, I care about products that make life easier. I also share what I learn through blogging and mentoring. For me, great engineering isn’t just about code — it’s about creating value, solving problems, and helping others grow.