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

What's New in Java 21 to 25: Compact Source Files and Sequenced Collections

A whole Java 25 program with no class, no static and no String[] args: void main and IO.println greet Jack, Liam and Kate. Then sequenced collections: addFirst puts Lucy at the front, getLast reads Paul, and a LinkedHashMap answers firstEntry Kate=88.

Chaand Sheikh

·27 November 2026·Updated 28 November 2026Basics

What you will learn

  • Write a compact source file with void main, no class and no static
  • Print with IO.println and explain what the compiler adds behind the scenes
  • Use addFirst, getFirst, getLast and reversed on an ordered list
  • Use putFirst, firstEntry and lastEntry on a SequencedMap, and know which collections have an order

Before you start

  • Java Hello World with Maven and the JDK
  • Java maps: HashMap, LinkedHashMap and TreeMap

Think of a car's new model: the same car, but the dashboard got a little nicer. Java 21 to 25 added a few changes like that. This tour covers two you'll meet early: compact source files and sequenced collections.

No class, no static

// A compact source file: no class, no static, no String[] args
String school = "StudyEasy";

void main() {
    // java.base is imported for you, so List needs no import
    List<String> students = List.of("Jack", "Liam", "Kate");
    IO.println("Welcome to " + school);
    for (String s : students) {
        IO.println(greet(s));
    }
}

String greet(String name) {
    return "Hi " + name + ", your first class starts at 9";
}
Welcome to StudyEasy
Hi Jack, your first class starts at 9
Hi Liam, your first class starts at 9
Hi Kate, your first class starts at 9

This is the whole file, Ex01_CompactHello.java. A String field sits at the top with no class around it. main has no public, no static and no String[] args: just void main(). List needs no import, because the common packages of java.base come in for free. And IO.println replaces System.out.println. Compare the classic Hello World: the import, the class line, the closing brace and every static are gone, and the output is the same.

A compact source file can't have a package line: adding package org.studyeasy.s05l11; gives "compact source file should not have package declaration".

What the compiler writes for you

You write a field school and two methods, main and greet, in Ex01_CompactHello.java. The compiler wraps them in a final class named Ex01_CompactHello, then Java creates an object of that class and calls main on it. you write String school = ...; void main() { ... } String greet(...) { ... } final class Ex01_CompactHello { your field and methods go inside new Ex01_CompactHello().main()
Same Java underneath: a class, an object, and a call to main.

Java still needs an object to call a method on. When the file compiles, Java creates a final class with the file's name and puts your field and methods inside. Then it creates an object of that class and calls main on it. That's why main doesn't need static.

First, last and reversed

List<String> line = new ArrayList<>(List.of("Ben", "Paul"));
line.addFirst("Lucy");                // goes in position zero

System.out.println("First: " + line.getFirst());
System.out.println("Last:  " + line.getLast());
System.out.println("Line:  " + line);
System.out.println("Back:  " + line.reversed());
First: Lucy
Last:  Paul
Line:  [Lucy, Ben, Paul]
Back:  [Paul, Ben, Lucy]

Since Java 21, collections that keep an order are sequenced. addFirst drops Lucy into position zero, and Ben and Paul slide over. getFirst and getLast read the two ends, and reversed gives the same list back to front. (They also work on a fixed List.of list for reading; see choosing a collection.)

A map has a first and a last too

SequencedMap<String, Integer> marks = new LinkedHashMap<>();
marks.put("Jack", 91);
marks.put("David", 78);
System.out.println("Marks: " + marks);

marks.putFirst("Kate", 88);            // a map can do it too
System.out.println("Marks: " + marks);
System.out.println("First: " + marks.firstEntry());
System.out.println("Last:  " + marks.lastEntry());
System.out.println("Back:  " + marks.reversed());
Marks: {Jack=91, David=78}
Marks: {Kate=88, Jack=91, David=78}
First: Kate=88
Last:  David=78
Back:  {David=78, Jack=91, Kate=88}

A LinkedHashMap remembers the order you put things in, so first and last make sense for pairs. putFirst puts Kate at the front, firstEntry and lastEntry return the end pairs, and reversed flips the map.

Only collections with an order

CollectionHas an order?First and last
ArrayList, LinkedHashSet, TreeSetyesgetFirst(), getLast()
LinkedHashMapyesfirstEntry(), lastEntry()
HashSet, HashMapnonone: cannot find symbol

Same Java, less ceremony. These are small, handy additions, nothing fancy.

Keep going in Java · 14 of 79

Previous
Java break, continue and Nested Loops
Next post
Java Arrays: Indexes, Default Values, Loops and 2D Grids
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.

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.

On this page

  • No class, no static
  • What the compiler writes for you
  • First, last and reversed
  • A map has a first and a last too
  • Only collections with an order
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.