mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
1.9 KiB
1.9 KiB
| layout | title | description | group |
|---|---|---|---|
| page | Java interpreter in Apache Zeppelin | Run Java code and any distributed java computation library by importing the dependencies in the interpreter configuration. | interpreter |
{% include JB/setup %}
Java interpreter for Apache Zeppelin
How to use
Basically, you can write normal java code. You should write the main method inside a class because the interpreter invoke this main to execute the code. Unlike Zeppelin normal pattern, each paragraph is considered as a separate job, there isn't any relation to any other paragraph. For example, a variable defined in one paragraph cannot be used in another one as each paragraph is a self contained java main class that is executed and the output returned to Zeppelin.
The following is a demonstration of a word count example with data represented as a java Map and displayed leveraging Zeppelin's built in visualization using the utility method JavaInterpreterUtils.displayTableFromSimpleMap.
%java
import java.util.HashMap;
import java.util.Map;
import org.apache.zeppelin.java.JavaInterpreterUtils;
public class HelloWorld {
public static void main(String[] args) {
Map<String, Long> counts = new HashMap<>();
counts.put("hello",4L);
counts.put("world",5L);
System.out.println(JavaInterpreterUtils.displayTableFromSimpleMap("Word","Count", counts));
}
}