Return to site

☕🖥️ SCRIPTING in JAVA 25: 🔟 SH/BAT jobs done in Java

Your next sysadmin script can be a single .java file.

September 26, 2026

🔸 TLDR

Java 25 makes Java surprisingly practical for scripting.

▪️ No explicit class required

▪️ void main() is enough

▪️ Run directly with java Script.java

▪️ Compact source files automatically import the public APIs exported by java.base

Here are 🔟 everyday SH/BAT-style scripts written as minimal Java 25 files.

📃 1️⃣ LIST A DIRECTORY

Java 25 snippet: List.java

Equivalent to a basic ls / dir.

Run:

🔎 2️⃣ FIND FILES RECURSIVELY

Java 25 snippet: Find.java

Find matching files through a directory tree.

Run:

👓 3️⃣ GREP A TEXT FILE

Java 25 snippet: Grep.java

A minimal Java equivalent of grep.

Run:

©️ 4️⃣ COPY A FILE

Java 25 snippet: Copy.java

Copy a file and replace the destination if it already exists.

Run:

🚚 5️⃣ MOVE OR RENAME A FILE

Java 25 snippet: Move.java

The scripting equivalent of mv or move.

Run:

🗑️ 6️⃣ DELETE OLD LOGS

Java 25 snippet: CleanLogs.java

Recursively remove .log files older than seven days.

Run:

📊 7️⃣ CHECK FREE DISK SPACE

Java 25 snippet: Disk.java

Quick disk-space check without invoking an OS command.

Run:

🌐 8️⃣ CHECK AN HTTP ENDPOINT

Java 25 snippet: HttpCheck.java

Call an HTTP endpoint and print its response status.

Run:

🔌 9️⃣ CHECK A TCP PORT

Java 25 snippet: PortCheck.java

Test whether a host/port can be reached.

Run:

▶️ 🔟 RUN AN OS COMMAND

Java 25 snippet: Run.java

Execute another program while forwarding its console and exit code.

Linux:

Windows:

🔸 TAKEAWAYS

▪️ Java 25 can now feel much closer to a scripting language for small utilities.

▪️ java MyScript.java means no explicit javac step is required.

▪️ Compact source files remove the class boilerplate and allow void main().

▪️ You still get Java APIs for files, networking, processes, dates and streams.

▪️ SH/BAT remains perfect for tiny OS-specific commands. Java becomes interesting when the script starts growing into actual logic.

Maybe the boundary between "script" and "Java program" just became much thinner. ☕

#Java #Java25 #JDK25 #OpenJDK #Scripting #Automation #DevOps #SysAdmin

Go further with Java certification:

Java👇

Spring👇

SpringBook👇

JavaFullstackBook👇