Software and platforms

Machine learning for Java developers

Java developers use machine learning to add predictions to the services they already run: scoring transactions, filtering spam and ranking search results. You can train classical models directly in Java with Tribuo or Smile, or train in Python and serve the exported model through ONNX Runtime or DJL.

Where to start

Learn supervised learning on tabular data first: features, labels, a held-out test set and a baseline to beat. Then practise exporting one model and checking that Java inference returns the same predictions as the training code.

How Java developers use machine learning

Ranking search results

A search engine first retrieves documents that match a query, then a trained model re-orders the top results using features such as text match scores, freshness and popularity. Gradient-boosted trees and linear models are common choices, and the model runs inside the JVM search server.

Real example: Apache Solr Learning to Rank module. Solr's Learning to Rank module re-ranks the top N retrieved documents using trained machine learning models.

Running deep learning models inside Java services

Teams often train neural networks in Python but serve them from existing Java or Scala systems, so predictions sit next to the data stream with no extra service hop. Libraries such as DJL and ONNX Runtime load the trained model and run inference from Java code.

Real example: Netflix log clustering with DJL. Netflix's observability team uses Deep Java Library to run pre-trained deep learning models that cluster application log lines in real time.

Training classical models with a record of how they were made

Classification and regression models for fraud, risk or spam can be trained directly in Java. Recording the data, transformations and hyperparameters behind each model makes it possible to trace and audit predictions later.

Real example: Tribuo (Oracle Labs). The Tribuo paper describes a Java ML library that records the full processing pipeline, training algorithm and hyperparameters for every model automatically.

Machine learning on large data in the JVM

When training data is spread across a cluster, distributed libraries fit models such as logistic regression, decision trees and recommenders over the whole dataset. Spark's API is available in Java and Scala as well as Python.

Real example: MLlib: Machine Learning in Apache Spark. The JMLR paper presents MLlib, Spark's open-source distributed machine learning library.

Can Java developers learn machine learning?

Yes. Java developers already have the hardest engineering habits: types, testing and running services in production. Add enough Python to read and run ML code, the statistics behind evaluation, then supervised learning on tables, and finally how to export a model and serve it from Java.

  1. Python for reading ML code. Most tutorials, papers and training scripts are written in Python, so learn enough to run a notebook and follow a training script, even if you serve models from Java. Taught in the Python track of Foundations of AI
  2. Data handling with NumPy and pandas. Learn to load a table, inspect missing values and build a feature matrix, which is the same work Tribuo or Smile expect you to do in Java. Taught in the Data Tools track of Foundations of AI
  3. Statistics for evaluation. Precision, recall, confidence intervals and class imbalance decide whether a fraud or spam model is better than a simple rule. Taught in the Statistics track of Foundations of AI
  4. Supervised learning on tabular data. Train and compare logistic regression, trees and gradient boosting against a baseline with a held-out test set. Taught in the Machine Learning track of Foundations of AI
  5. Exporting and serving a model from Java. Export a trained model to ONNX, load it with ONNX Runtime or DJL, and check that Java returns the same predictions as the training code.

Moving from Java development into machine learning

If you already work in the field

As a Java developer you already know how to ship and monitor services, which is where many ML projects struggle. Add the modelling side: evaluation, feature preparation and how models fail on new data. A realistic first move is to take a model your data team trained in Python and own its serving and monitoring in your Java stack.

If you come from data science or ML

If you come from Python data science, learn enough Java to read the service your model will run in, plus ONNX export and the JVM inference libraries. Pair with a backend engineer on one deployment to learn latency budgets, threading and logging in production.

Roles that do this work: Machine learning engineerBackend engineer, ML platformSearch relevance engineerMLOps engineer

Tools you will use

ToolWhat you use it for
TribuoTrain, evaluate and track classification, regression and clustering models in plain Java with typed outputs.
SmileFit classical models such as random forests, gradient boosting and SVMs inside a JVM application.
ONNX Runtime (Java)Load a model exported from scikit-learn or PyTorch and run fast inference from a Java service.
Deep Java Library (DJL)Run and fine-tune PyTorch, TensorFlow or ONNX deep-learning models through one Java API.
WekaExplore datasets and compare many classic algorithms in a GUI before writing Java code against its API.

Public data to practise on

  • Spambase (UCI): Word and character frequency features for emails labelled spam or not spam; a clean first binary classifier.
  • Bank Marketing (UCI): Client and campaign records from a bank's phone marketing; predict whether a client subscribes to a term deposit.

Your first project

Download Spambase, train a logistic regression classifier in Tribuo to predict whether an email is spam, and compare it with a majority-class baseline using F1 on a held-out test split.

Keep the result, your code and a short note on what didn't work. That record is worth more than the score.

Common questions

Can you do machine learning in Java?
Yes. Tribuo, Smile and Weka train classical models in Java, Spark MLlib trains on clusters, and DJL and ONNX Runtime run deep learning models. Training new deep learning models is still far more common in Python.
Should a Java developer learn Python for machine learning?
Learning enough Python to read and run training code is worth it, because most examples, papers and model releases use it. You can keep serving models from Java once they are exported.
Is Java fast enough for running ML models?
For inference, yes. ONNX Runtime and DJL run models through native engines, the same ones Python code calls, so a Java service can serve predictions without running Python.
Which Java ML library should I start with?
Start with Tribuo or Smile for classical models on tables, and ONNX Runtime when you need to serve a model trained elsewhere. Weka is useful for comparing algorithms in a GUI before writing code.

First Principles, the SchoolWhool newsletter

One machine learning idea, explained properly, every week.

The intuition, the common mistake, and a five-minute way to try it yourself. Written by Gaurav.

Learn the machine learning behind it, from first principles.

Start with Python from zero, free. Every stage after that builds on the last, and a person answers your doubts.