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.

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 exampleApache Solr Learning to Rank moduleSolr'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 exampleNetflix log clustering with DJLNetflix'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 exampleTribuo (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 exampleMLlib: Machine Learning in Apache SparkThe 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 codeMost 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.Learn it in Python
  2. Data handling with NumPy and pandasLearn 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.Learn it in Data Tools
  3. Statistics for evaluationPrecision, recall, confidence intervals and class imbalance decide whether a fraud or spam model is better than a simple rule.Learn it in Statistics
  4. Supervised learning on tabular dataTrain and compare logistic regression, trees and gradient boosting against a baseline with a held-out test set.Learn it in Machine Learning
  5. Exporting and serving a model from JavaExport 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 workMachine 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.

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.

Courses for these skills

New to programming or maths? Start with Python, or follow the machine learning path in order. Published lessons are free to read; compare Free and Pro.