JShell REPL & Launching Single-File Source Code (Java 11+)
1Concept
Java 9 introduced JShell (Interactive REPL) for rapid prototyping without writing full boilerplate classes. Java 11 introduced single-file execution: `java App.java` runs directly without pre-compiling `javac App.java` to disk.
2Architecture Diagram
Source File (App.java) ---> [ Direct `java App.java` Execution ] ---> Memory Compiled & Run (No .class written to disk)
3Code Example
Core Java
public class SingleFileLauncher {
public static void main(String[] args) {
System.out.println("Direct execution without javac step supported in Java 11+");
System.out.println("Arguments Passed: " + String.join(", ", args));
}
}4Expected Output
Direct execution without javac step supported in Java 11+ Arguments Passed:
5Key Takeaways
- ✓Use JShell for testing quick APIs, math expressions, and stream pipelines.
- ✓Single-file launcher `java Script.java` compiles to memory and executes instantly.
- ✓Ideal for shell automation scripts and lightweight application prototypes.