zeppelin/java
eunhwa99 f45587db39
[ZEPPELIN-6299] Refactor StaticRepl for readability, correctness, and modern Java usage
### What is this PR for?
This PR refactors the `StaticRepl` class to improve readability, maintainability, and align with modern Java best practices.  
There are no functional changes.  

- Generic type refinement with diamond operator in loop:  Adds type safety by explicitly specifying the generic type. Prevents unchecked warnings and makes the code clearer to readers and tools.
- Replace `Arrays.asList` to `List.of` :  List.of (Java 9+) produces an immutable list, which is safer and better communicates the intent that the list will not be modified. It avoids side effects of Arrays.asList, which is fixed-size and backed by the original array.
- Minor typos fixed: Corrected spelling mistakes and adjusted comments.
-  Removes redundant boolean comparison to follow standard Java coding conventions.
- Replace index-based loop with enhanced for-each to eliminate boilerplate index management, improves readability, and reduces chances of off-by-one errors. It makes the intent ("iterate all elements") clearer.
- Variable declaration moved closer to usage to improve code locality and readability by reducing variable scope. This makes the code easier to maintain and follow.

### What type of PR is it?
Refactoring

### Todos
* [ ] - Task

### What is the Jira issue?
* [ZEPPELIN-6299](https://issues.apache.org/jira/browse/ZEPPELIN-6299)  

### How should this be tested?
* Run existing unit tests to confirm behavior remains unchanged.  

### Screenshots (if appropriate)

### Questions:
* Does the license files need to update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No


Closes #5048 from eunhwa99/ZEPPELIN-6299.

Signed-off-by: ParkGyeongTae <gyeongtae@apache.org>
2025-09-05 14:40:13 +09:00
..
src [ZEPPELIN-6299] Refactor StaticRepl for readability, correctness, and modern Java usage 2025-09-05 14:40:13 +09:00
pom.xml [MINOR] Bump up version to 0.13.0-SNAPSHOT 2025-08-02 22:05:06 +09:00
README.md [ZEPPELIN-3653] - New Java interpreter 2018-08-03 09:15:19 +08:00

Overview

Java interpreter for Apache Zeppelin

Architecture

Current interpreter implementation supports the static REPL. It compiles the code in memory, execute it and redirect the output to Zeppelin.

Technical overview

  • Upon starting an interpreter, an instance of JavaCompiler is created.

  • When the user runs commands with java, the JavaParser go through the code to get a class that contains the main method.

  • Then it replaces the class name with random class name to avoid overriding while compilation. It creates new out & err stream to get the data in new stream instead of the console, to redirect output to Zeppelin.

  • If there is any error during compilation, it can catch and redirect to Zeppelin.

  • JavaInterpreterUtils contains useful methods to print out Java collections and leverage Zeppelin's built in visualization.