Skip to main content

Java CLI App

Zero-Dependency Command-Line Applications with Modern Java

Overview

Java CLI App applies the BCE pattern to multi-file command-line applications built with Java 25. Applications are packaged as executable JARs using zb (Zero Dependencies Builder), requiring no Maven or Gradle. The approach favors unnamed classes with top-level methods, records, enums, and sealed types over traditional class hierarchies.

A well-crafted CLI application consists solely of business logic expressed through modern Java features, with zero external dependencies. The code is as simple, elegant, and understandable as possible, choosing the approach with the fewest lines of code when multiple options exist.

Business Components

In a CLI application, business components are source files organized by domain responsibility. Each file uses unnamed classes with top-level methods, avoiding traditional class or interface declarations. The boundary is the main entry point (App.java), controls contain business logic as top-level methods, and entities are modeled as records, enums, and sealed types.

Boundary

The boundary is the application's entry point, typically an App.java file with an instance void main() or void main(String... args) method. It handles argument parsing, delegates to control logic, and formats output for the terminal.

Control

Controls are top-level methods in unnamed classes that contain business logic. Complex boolean conditions are extracted into named predicate methods. Non-trivial calculations become named methods. Inline lambda predicates are extracted into explaining methods and used as method references.

Entity

Entities are modeled using records, enums, and sealed types — never traditional classes or interfaces. They represent domain data with behavior bound directly to the data structures through functional fields and pattern matching.

Principles

Zero Dependencies

No Maven, no Gradle, no external libraries. Built with zb (Zero Dependencies Builder) and the Java platform alone. You know when you need a dependency.

Unnamed Classes

No class or interface declarations. Use top-level methods, records, enums, and sealed types. No package declarations, no static methods.

Simplest Possible Code

Always choose the simplest API. When multiple approaches exist, use the one with the fewest lines. Inline single-use variables. Extract repeated literals into constants.

Modern Java 25

Records, sealed types, pattern matching, module imports, IO.println(), var declarations, and character literals used naturally throughout.

Code Style

Resources

Tools & References