Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

Java
  • Install Java 25 (JDK) and IntelliJ IDEA, Then Run Your First Program
  • Use Claude Agent, Copilot or Junie Inside IntelliJ IDEA
  • Java Hello World with Maven: What the JDK Does and What Maven Adds
  • Java Variables, Keywords and Naming Rules
  • Maven in IntelliJ: pom.xml, Dependencies and the Build Lifecycle
  • Java Primitive Types and Memory: What int x = 5 Really Does
  • Java Strings and Text Blocks: Quotes, Concatenation and parseInt
  • Java Operators: Arithmetic, a++ vs ++a, Precedence, && || and the Ternary
  • Java Type Casting: Widening, Narrowing and Converting Text to Numbers
  • Java Practice Lab: A Cafe Bill with Variables, Operators and Casting
  • Java if, else and switch: Braces, Else-If Ladders and the Modern Switch
  • Java Loops: for, while, do-while and for-each
  • Java break, continue and Nested Loops
  • What's New in Java 21 to 25: Compact Source Files and Sequenced Collections
  • Java Arrays: Indexes, Default Values, Loops and 2D Grids
  • Java Methods and Overloading: Parameters, return and Pass-by-Value
  • Java Scope, Code Blocks and the Call Stack
  • Read User Input in Java with Scanner (and the Leftover Enter Trap)
  • Java Practice Lab: A Gym Weekly Tracker with Loops, Arrays and Methods
  • Debugging Java in IntelliJ: Stack Traces, Breakpoints and a Better AI Prompt
  • Java var: Let Java Infer the Type
  • Push and Pull in IntelliJ: Two Developers, One GitHub Repository, a Rejected Push and a Conflict
  • Java Classes and Objects: One Blueprint, Many Cars
  • Java Constructors and the this Keyword
  • Java Instance Methods, Getters, Setters and toString
  • Java static: Fields, Methods and Blocks Shared by the Whole Class
  • Java Packages and Imports: Every Class Has an Address
  • Java Access Modifiers and Encapsulation: Private Data, Public Methods
  • Java final and Immutable Objects: Assign Once, Share Safely
  • Java Strings as Objects: The String Pool, == vs equals, StringBuilder and printf
  • Java Practice Lab: A Library Book Catalogue with final Fields and StringBuilder
  • Java Inheritance: extends, super and the Order Objects Are Built
  • Java Method Overriding, @Override and the Object Class
  • Java Polymorphism: Upcasting, Dynamic Dispatch and Downcasting
  • Java Composition: Has-A vs Is-A
  • Java Abstract Classes: A Parent That Leaves One Blank
  • Java Interfaces: Contracts and Multiple Inheritance
  • Java Nested, Inner and Anonymous Classes
  • Java Enums with Fields, Methods and switch
  • Java Practice Lab: Payment Processing with an Interface, an Abstract Class and an Enum
  • Java Records: A Whole Data Class in One Line
  • Java Sealed Classes and Interfaces
  • Java Pattern Matching with instanceof and switch
  • Java Record Patterns: Unpacking a Record
  • Java equals and hashCode: Why a HashSet Needs Both
  • From Arrays to Collections: The Java Collections Framework Map
  • Java Wrapper Classes and Autoboxing
  • Java ArrayList: The Stretchy Array
  • Java LinkedList vs ArrayList: Nodes or an Array
  • Java Sets: HashSet, LinkedHashSet and TreeSet
  • Java Sorting with Comparable and Comparator
  • Java Maps: HashMap, LinkedHashMap and TreeMap
  • Java Stacks, Queues and Deques: ArrayDeque and PriorityQueue
  • Choosing a Java Collection: Immutable and Sequenced Collections
  • Java Exception Handling: try, catch and finally
  • Java throw, throws, Checked vs Unchecked and Custom Exceptions
  • Java try-with-resources and Clean Error Handling
  • Java Generics: Type-Safe Containers
  • Java Generic Methods, Bounded Types and Wildcards
  • Java Lambdas and Functional Interfaces
  • Java Built-in Functional Interfaces: Predicate, Function, Consumer, Supplier
  • Java Optional: Saying Maybe Without null
  • Java Streams I: filter, map and reduce
  • Java Streams II: Collectors, groupingBy and flatMap
  • Why Concurrency: Processes, Threads and the Main Thread in Java
  • Creating Threads in Java: Thread, Runnable and Lambdas
  • Java Thread Lifecycle: sleep, join and interrupt
  • Java Race Conditions and synchronized
  • Java volatile and Atomic Variables
  • Java ExecutorService and Thread Pools
  • Java Callable, Future and CompletableFuture
  • Java Locks, Deadlock and tryLock
  • Java Concurrent Collections and Virtual Threads
  • Why Slow Work Belongs off the Request Thread: 202 Accepted and a Job Id in Spring Boot
  • Virtual Threads in Spring Boot: One Property, and the Connection Pool Trap
  • @Async, Named TaskExecutors and Structured Concurrency in Spring Boot
  • Java Files and Directories with NIO.2: Path and Files
  • Reading and Writing Text Files in Java
  • Java Structured Data: Reading and Writing JSON and CSV
  1. Blog
  2. /
  3. Java
  4. /
  5. Basics

Java Variables, Keywords and Naming Rules

A variable is a labelled jar that holds one value at a time. Four small programs show declaring, reassigning, the names Java accepts, the keywords it reserves, and why daysUntilLaunch beats d.

Chaand Sheikh

·27 November 2026·Updated 28 November 2026Basics

What you will learn

  • Declare a variable with a type, a name and a value
  • Reassign a variable without repeating its type
  • Apply Java's naming rules: camelCase, _ and $, no leading digits or spaces, case sensitivity
  • Recognise reserved keywords and choose names that explain themselves

Before you start

  • Java Hello World with Maven and the JDK

Code needs to remember things: a score, a name, a price. A variable is how it remembers. Think of a jar with a label: the label is the name, the jar holds the value. You store the value once, then use the name anywhere.

int score = 87: int is the type, score is the label on the jar, 87 is the value inside. After score = 92 the same jar holds 92 and the 87 is gone. int score = 87; score = 92; score 87 type: int (whole number) score 92 87 replaced, not added reassign One variable, one value at a time.
The name is the label, the value sits in the jar, and reassignment swaps what's inside.

Store a value once

package org.studyeasy.s02l02;

public class Ex01_FirstVariable {
    public static void main(String[] args) {
        String player = "Emma";
        int score = 87;
        System.out.println(player + " scored " + score);
    }
}
Emma scored 87

int score = 87; has three parts. int is the type (a whole number), score is the name, 87 is the value. String player works the same way for text. Inside println we only use the name, never 87 again. If the score changes, you change it in one place and every line that uses score sees the new value.

You don't need to memorise the syntax; an AI assistant can type it for you. What matters is knowing what each part means.

Reassign without the type

package org.studyeasy.s02l02;

public class Ex02_Reassign {
    public static void main(String[] args) {
        int score = 87;
        System.out.println("Score: " + score);
        score = 92;
        System.out.println("Score: " + score);
    }
}
Score: 87
Score: 92

Java already knows score is an int, so the second line is just score = 92;. The 87 is replaced, not added to. That's reassignment.

Write int score = 92; on that line instead and the compiler says the variable is already defined: you're trying to make a second jar with the same label.

What Java allows as a name

  • camelCase is the convention: start lowercase, capitalise each new word. "user age" becomes userAge.
  • A name may start with _ or $ (you'll rarely need $).
  • A name can't start with a digit and can't contain spaces.
  • Names are case sensitive: score and Score are two different variables.
package org.studyeasy.s02l02;

public class Ex03_Naming {
    public static void main(String[] args) {
        int userAge = 30;
        int _count = 3;
        int $price = 12;
        int score = 87;
        int Score = 10;
        System.out.println("userAge: " + userAge);
        System.out.println("_count: " + _count + ", $price: " + $price);
        System.out.println("score: " + score + ", Score: " + Score);
    }
}
userAge: 30
_count: 3, $price: 12
score: 87, Score: 10

All five are legal. score and Score hold 87 and 10 separately. Rename userAge to 2fast, or to user age with a space, and the compiler refuses both.

Some words are already taken

Keywords (reserved words) already mean something to Java, so you can't use them as your own names:

KeywordWhat it does
inta whole-number type
classstarts a class
ifmakes a decision
returnhands a value back from a method
forstarts a loop
newcreates an object
voida method that returns nothing
truea boolean value

Name a variable class or new and the compiler stops you straight away. Pick another name.

A name that explains itself

package org.studyeasy.s02l02;

public class Ex04_GoodNames {
    public static void main(String[] args) {
        int d = 14;
        int daysUntilLaunch = 14;
        System.out.println("d = " + d);
        System.out.println("Jack launches in " + daysUntilLaunch + " days");
    }
}
d = 14
Jack launches in 14 days

d is valid, but 14 what? daysUntilLaunch tells you why the variable exists. Java doesn't care about the name; the next person reading your code does.

Common mistakes

  • int score = "87"; with quotes: that's a String, and an int only holds whole numbers, so javac refuses it.
  • Repeating the type when reassigning: "variable is already defined".
  • Starting with a digit or using a space: 2fast, user age.
  • Mixing up case: Score is not score.

Recap

IdeaExample
Declare: type, name, valueint score = 87;
Reassign: no typescore = 92;
camelCase namesuserAge, daysUntilLaunch
Allowed first charactersa letter, _ or $
Not alloweda leading digit, spaces, keywords
Case sensitivescore and Score differ

Next, look at what types like int really store in Java primitive types and memory.

Keep going in Java · 4 of 79

Previous
Java Hello World with Maven: What the JDK Does and What Maven Adds
Next post
Maven in IntelliJ: pom.xml, Dependencies and the Build Lifecycle
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE

Java 25, JSP, Hibernate, Spring Boot 4, REST APIs, React and Spring AI.View on Udemy ↗: FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE (paid course, opens in a new tab)

Related posts

Install Java 25 (JDK) and IntelliJ IDEA, Then Run Your First Program

Install JDK 25 (Microsoft Build of OpenJDK) with JAVA_HOME, install IntelliJ IDEA, then point a run configuration at the JDK and the main class and run Hello World.

Use Claude Agent, Copilot or Junie Inside IntelliJ IDEA

Open IntelliJ's AI Chat, pick Claude Agent (the agent behind Claude Code) or Copilot and a model, ask in plain words for Main.java to print the date and time, review the change, and run it.

Java Hello World with Maven: What the JDK Does and What Maven Adds

javac compiles HelloWorld.java into bytecode and java runs it on the JVM. Maven adds one pom.xml, the same folders in every project and one build command. Then a real Maven Hello World in IntelliJ.

Maven in IntelliJ: pom.xml, Dependencies and the Build Lifecycle

Open a plain project and a Maven project in IntelliJ, read an invoice app's pom.xml, follow jackson-databind from Maven Central into ~/.m2, and see why each lifecycle phase runs the ones before it.

On this page

  • Store a value once
  • Reassign without the type
  • What Java allows as a name
  • Some words are already taken
  • A name that explains itself
  • Common mistakes
  • Recap
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE

Java 25, JSP, Hibernate, Spring Boot 4, REST APIs, React and Spring AI.View on Udemy ↗: FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.