Machine learning with Java & Kotlin

While Python dominates the machine learning landscape, the JVM ecosystem offers compelling advantages for building production-grade AI systems. Java and Kotlin provide strong typing, mature tooling, excellent performance, and seamless integration with enterprise infrastructure, making them viable choices for machine learning workloads, especially in organizations already invested in JVM technology.

Deeplearning4j (DL4J) is the most prominent deep learning framework for the JVM. It is an open-source, distributed deep learning library written in Java and Kotlin that supports neural network architectures including convolutional networks (CNNs), recurrent networks (RNNs and LSTMs), transformers, and autoencoders. DL4J integrates with Apache Spark for distributed training and uses ND4J as its numerical computing backend, which leverages native libraries like OpenBLAS and CUDA for GPU acceleration. This means JVM developers can build and train sophisticated models without leaving their ecosystem.

Kotlin, as a modern JVM language, brings significant advantages to ML development. Its concise syntax, null safety, coroutines for asynchronous processing, and excellent Java interoperability make it particularly appealing. KotlinDL, a high-level deep learning API developed by JetBrains, provides a Keras-like experience for Kotlin developers, making it straightforward to define, train, and deploy neural networks. KotlinDL supports TensorFlow and ONNX model formats, enabling developers to import models trained in Python frameworks and run inference on the JVM.

Weka (Waikato Environment for Knowledge Analysis) remains one of the most established ML toolkits in the Java ecosystem. Originally developed at the University of Waikato in New Zealand, Weka provides implementations of hundreds of classification, regression, clustering, and feature selection algorithms. Its graphical interface makes it accessible for exploratory data analysis, while its Java API allows programmatic access for integration into larger applications. Weka excels at traditional machine learning tasks and is widely used in academic research and teaching.

Apache Spark MLlib brings distributed machine learning to the JVM at scale. Built on top of Spark's distributed computing engine, MLlib provides scalable implementations of common algorithms including linear regression, decision trees, random forests, gradient-boosted trees, k-means clustering, and collaborative filtering. Spark's DataFrame API, accessible from both Java and Kotlin, provides a clean interface for building ML pipelines that can process datasets far too large for a single machine.

Smile (Statistical Machine Intelligence and Learning Engine) is a modern, high-performance ML library for Java and Kotlin. It provides a comprehensive set of algorithms for classification, regression, clustering, feature selection, and natural language processing. Smile is notable for its speed, often matching or exceeding the performance of equivalent Python libraries, and its clean API design that feels natural to JVM developers.

Tribuo, Oracle's open-source ML library for Java, offers a typed, modular approach to machine learning. Each model carries metadata about its training data and parameters, enabling reproducibility and auditability. Tribuo supports a wide range of algorithms natively and can also interface with TensorFlow, XGBoost, and ONNX Runtime for additional model types. Its emphasis on provenance tracking makes it well-suited for regulated industries where model governance matters.

For natural language processing specifically, Stanford CoreNLP provides a mature Java toolkit for tokenization, part-of-speech tagging, named entity recognition, sentiment analysis, and dependency parsing. Apache OpenNLP offers similar capabilities with a focus on maximum entropy and perceptron-based models. Both libraries integrate smoothly with Java and Kotlin applications.

The integration story is perhaps the strongest argument for ML on the JVM. Enterprise applications built with Spring Boot, Micronaut, or Ktor can embed ML inference directly without the overhead of calling out to Python services via REST APIs or gRPC. ONNX Runtime for Java allows running models trained in PyTorch or TensorFlow natively on the JVM with near-native performance, bridging the gap between Python-centric training workflows and JVM-based production systems.

Kotlin Multiplatform adds another dimension, enabling ML code to be shared across JVM, native, and JavaScript targets. This means a model trained and validated on the JVM can potentially be deployed to edge devices, mobile apps, or browser-based applications without rewriting the inference logic.

The rise of large language models (LLMs) and generative AI since 2023 has further expanded the JVM's role in AI systems. While model training remains predominantly Python-based, JVM applications increasingly serve as the orchestration layer for LLM-powered features, using libraries like LangChain4j and Spring AI to integrate with models from OpenAI, Anthropic, and open-source alternatives. The growing availability of open-weight models that can be self-hosted means organizations are no longer forced to route all their data through a handful of dominant AI providers, preserving both data sovereignty and flexibility. This pattern of Python for training and JVM for production serving plays to each ecosystem's strengths.

In summary, while Python remains the language of choice for ML research and experimentation, Java and Kotlin offer a mature, performant, and well-integrated alternative for production ML systems. Organizations already building on the JVM can leverage their existing expertise, infrastructure, and tooling to develop and deploy machine learning solutions without adopting an entirely separate technology stack.

Deeplearning4j, CoreNLP, ND4J, Smile, Mahout, Weka