JBang vs JShell vs Kotlin Scripting

JBang vs JShell vs Kotlin Scripting

Java developers have long wished for scripting capabilities that are as fast and flexible as Python or Bash. With modern tooling, that dream is closer than ever. In this post, we’ll explore and compare three powerful tools that bring scripting to the JVM world:

  • JBang: Full-powered Java scripting with dependency support
  • JShell: REPL-based exploration tool built into the JDK
  • Kotlin Scripting: Flexible scripting with Kotlin’s concise syntax

🎯 Use Case Overview

Before diving into the details, let’s briefly define where each tool shines:

  • JBang: Great for quick scripts, CLI tools, and automation with real dependencies
  • JShell: Ideal for quick experimentation and learning Java interactively
  • Kotlin Scripting: Perfect for concise scripts, DSLs, and integration into build tools

🔍 Feature Comparison

Feature JBang JShell Kotlin Scripting
Requires Java knowledge ⚠️ Familiarity with Kotlin
Scriptable with top-level code
Dependency support //DEPS ⚠️ Limited (via startup script) ✅ (via gradle.kts or annotations)
Runs from CLI ✅ (REPL)
Compilation required
External library usage ✅ (via Maven Central) ⚠️ Workaround needed ✅ (with script config)
CLI App Development ✅ (with Picocli) ⚠️ DSL-friendly, not CLI focused

📜 Syntax Examples

1. JBang Example

//DEPS org.apache.commons:commons-lang3:3.12.0
import org.apache.commons.lang3.StringUtils;

public class Hello {
    public static void main(String[] args) {
        System.out.println(StringUtils.capitalize("hello jbang!"));
    }
}

2. JShell Example

jshell
jshell> int a = 5;
jshell> System.out.println(a * 2);

3. Kotlin Script

// File: hello.kts
val name = "Kotlin"
println("Hello, $name Scripting!")

To run: kotlinc -script hello.kts

🔧 Installation Overview

  • JBang: Install via brew, sdkman, or script from jbang.dev
  • JShell: Comes with Java 9+ (jshell command)
  • Kotlin Scripting: Install Kotlin CLI tools

✅ When to Use What?

  • 👨‍💻 Use JBang if you’re building quick scripts, tools, or want dependency management.
  • 📚 Use JShell for learning Java, testing ideas, or debugging APIs quickly.
  • Use Kotlin scripting when you prefer Kotlin’s syntax and want to write concise, expressive scripts.

🔚 Final Thoughts

The JVM ecosystem now offers some amazing scripting tools. JBang makes Java scripting modern and powerful. JShell is excellent for interactive experimentation. And Kotlin scripting brings elegance and expressiveness to JVM scripting.

Choose the tool that fits your workflow — or combine them!

👉 Want a guide on creating CLI tools with JBang + Picocli or scripting APIs with Kotlin? Let me know!

Comments

Popular posts from this blog

Sentiment Analysis Using Hugging Face API in Spring Boot

Building a Recommendation System in Spring Boot

Voice & Chatbots – AI-Assisted Conversational Apps