Quick revision
The short answer
I would allow it, but for a clearly limited kind of script and as a pilot first. Compact source files give one language for services and scripts, typed code and the whole JDK with no build step, but they cost JVM startup time, have no built-in dependency manager and are unfamiliar to many operators. The guidelines I would set are: small single-purpose scripts only, a pinned JDK in the runner image, version control and review, and a rule that a script needing dependencies, tests or several files moves into a normal project.
What to remember
In this answer, we looked at Java 25 compact source files as a tool for operational scripts. They bring one language, types, the JDK and the company's shared libraries with no build step, and they cost startup time, a missing dependency manager and some operator familiarity. The guidelines keep them to small single-purpose scripts, move anything with dependencies, tests or several files into a real project, pin the JDK in the runner, and keep scripts reviewed in version control. A one-team pilot with agreed measures decides whether the idea spreads.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would allow it, but for a clearly limited kind of script and as a pilot first. Compact source files give one language for services and scripts, typed code and the whole JDK with no build step, but they cost JVM startup time, have no built-in dependency manager and are unfamiliar to many operators. The guidelines I would set are: small single-purpose scripts only, a pinned JDK in the runner image, version control and review, and a rule that a script needing dependencies, tests or several files moves into a normal project.
Why this question is asked
Operational scripts are the glue of a platform team: rotate keys, check queues, move files, call internal APIs. Most companies write them in Bash and Python, and every team ends up with a second set of skills, libraries and review habits next to its Java services. When Java 25 made compact source files final, many teams asked whether they could write scripts in Java too. Interviewers ask this leadership question to see how we weigh a technology choice: the real benefits, the real costs, the guidelines that keep it healthy and how we would prove it works before rolling it out. In this answer, we will look at what a Java script looks like today, compare it honestly with Bash and Python, set guidelines, and plan a pilot.
1What a Java Script Looks Like Now
With JEP 512, a script can be a single file with a main method and no class declaration. It imports the whole java.base module automatically, so files, HTTP, dates and collections are available without imports, and the source launcher runs it straight from source with java check_queue.java. On Linux and macOS a file without the .java extension can even start with a shebang line, the #! line that tells the shell which program runs the file.
Notice that java.net.http is in its own module, so we write the full names or add import module java.net.http;. Notice also System.exit: in a script the exit code is the contract with whatever runs it, so calling it at the end of main is right here, unlike in library code.
2Weighing the Benefits Against the Costs
The benefits are real. Teams already know Java, so one language covers services and scripts and code review standards apply to both. The code is typed, so a typo in a field name fails at compile time instead of halfway through a production run. The JDK brings a solid HTTP client, JSON is one small library away, and scripts can call the same internal client libraries the services use, so a script that talks to the billing API uses the same request models as the billing service.
The costs are also real. Startup is the first: the source launcher compiles the file in memory on every run, so a small script typically takes a few hundred milliseconds or more before doing any work, against a few milliseconds for Bash. For a cron job that runs every five minutes this does not matter; for a command called thousands of times in a loop it does. Dependencies are the second: the launcher accepts a class path, but there is nothing like pip or a lock file, so someone must decide where library jars come from. The third is people: on-call operators who read Bash fluently may not want to debug Java at 3 a.m.
| Concern | Bash | Python | Java 25 compact file |
|---|---|---|---|
| Startup per run | milliseconds | tens of ms | a few hundred ms, measure |
| Type checking | none | optional | compiler, before running |
| Dependencies | system tools | pip, venv, lock files | class path only, no manager |
| Shared company libraries | rarely | separate ports | same jars as services |
| Operator familiarity | high | high | varies by team |
3The Guidelines I Would Set
The central rule is about size. Compact source files are for small, single-purpose scripts: one file, one job, readable in one sitting. As soon as a script needs third-party dependencies beyond a pinned shared jar, needs unit tests, or grows into several files, it moves into a normal project with a build, where Maven or Gradle handle dependencies and tests run in CI. This keeps the convenience where it helps and stops a folder of scripts from becoming an unbuildable application.
The second rule is about reproducibility. The JDK version is pinned where the script runs, in the container image for jobs or with a toolchain file for developers, so a script written for Java 25 never meets a Java 21 runtime that cannot parse it. The third rule is the same discipline we apply to services: scripts live in version control, changes go through review, and each one says at the top what it does, who owns it and what its exit codes mean. Finally, Bash stays allowed for what it does best, short pipelines of Unix tools, and Python stays where the team's existing tooling is strong. The goal is a better default, not a ban.
- Single file, single job?YesCheck dependenciesNoNormal project with a build
- Needs libraries beyond the shared jar?YesNormal project with a buildNoCheck tests
- Needs unit tests in CI?YesNormal project with a buildNoCompact source file
- Compact source filepinned JDK image, reviewed, owner and exit codes documented
4 steps in order. Play them, or step through them one at a time.
4Running a Pilot Before a Wide Rollout
I would not announce a company-wide change. I would pick one team that owns, say, 20 operational scripts and is keen to try, and let them write new scripts and rewrite five painful old ones as compact files for one quarter. Before starting, we agree what we will measure: incidents caused by scripts, time to change a script, review comments, run time including startup, and a short survey of the on-call engineers who had to read them.
At the end we compare those numbers with the team's Bash and Python scripts over the same period. If the Java scripts break less often and are easier to change, and startup is acceptable for how they are run, we publish the guidelines with real examples from the pilot and offer them to other teams. If startup or operator comfort turned out to be a problem, we keep Java scripts for the cases where shared libraries are a big win and stop there. Either way the decision rests on evidence from our own systems.
5Follow-up questions
How would you distribute shared helper code to scripts?
I would put the helpers, such as authentication to internal APIs, logging setup and common clients, into a small versioned library built and tested like any other jar and published to the internal artifact repository. The script runner image then contains a pinned version of that jar, and scripts run with it on the class path, for example java --class-path /opt/scripts/lib/ops-helpers-1.4.jar rotate_keys.java. Scripts never download code at run time. Upgrading the helpers means building a new image, which goes through the same review and rollout as anything else, and teams that need a newer helper upgrade together.
Is JVM startup a deal breaker for scripts?
Usually not, but it should be measured instead of guessed. For scheduled jobs and on-demand operator commands, a few hundred milliseconds is invisible next to the network calls they make. It matters for scripts called in tight loops or from shell completion. For those, Bash remains the better tool, or the script can be compiled once and run with an ahead-of-time cache on recent JDKs; check your version for the options available.
What would make you stop the pilot early?
A production incident caused by a runtime mismatch, such as a script running on an older JDK, or clear pushback from on-call engineers who cannot debug the scripts. Both would mean the guidelines or the training are not ready, and fixing those comes before more adoption.
6Conclusion
In this answer, we looked at Java 25 compact source files as a tool for operational scripts. They bring one language, types, the JDK and the company's shared libraries with no build step, and they cost startup time, a missing dependency manager and some operator familiarity. The guidelines keep them to small single-purpose scripts, move anything with dependencies, tests or several files into a real project, pin the JDK in the runner, and keep scripts reviewed in version control. A one-team pilot with agreed measures decides whether the idea spreads.
Open with
I would allow it, but in a limited and measured way. The benefits are real: our engineers already write Java, so services and scripts share one language and one review standard, the code is typed so many mistakes fail before running, and scripts can use the JDK's HTTP client and our own shared client libraries instead of re-implementing them in Bash or Python.
Then, if they want more
With compact source files and the source launcher, there is no build step for a small script. The costs are real too. The source launcher compiles on every run, so startup is a few hundred milliseconds, there is no built-in dependency manager, only a class path, and some on-call operators are more comfortable with Bash.
So my guidelines would be: compact source files for small, single-purpose scripts; once a script needs extra dependencies, tests or several files, it moves into a normal project with a build and CI. The JDK version is pinned in the runner image or toolchain, and scripts live in version control with review, an owner and documented exit codes.
Shared helpers go into a versioned jar baked into that image. Before any wide rollout, I would pilot with one team for a quarter, measure incidents, change effort and run time against their existing scripts, and decide from that.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 25, Java 21
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Your company wants to use Java 25 compact source files for operational scripts that are...": https://scrivio-interview-library.netlify.app/java/classes-and-objects/c2228a1754/