Language
Java
- First appeared
- 1995
- Paradigm
- Object-oriented, imperative, statically typed
- Toolchain
- OpenJDK 21
- Container image
debian:trixie-20261027-slim + openjdk-21-jdk-headless 21.0.12.1
Java came out of Sun Microsystems in 1995 with the promise “write once, run anywhere”: it compiles to bytecode for the Java virtual machine, not for one kind of processor. It’s one of the most-used languages in the world, mostly in business systems and Android apps. Data science reaches it through the big-data tools built on the JVM, such as Hadoop, Spark, and Kafka.
Its standard library is large, with collections, streams, and file and
date handling, but it has no statistics or matrices, so the methods here are
written out by hand. The implementations use no build tool and no
third-party library: each is one file, compiled with javac and run with
java. Libraries such as Apache Commons Math aren’t installed.
Quirks
==compares objects, not their contents.new String("rosa") == "rosa"is false;.equals("rosa")is true.- The same goes for boxed numbers, with a twist: two
Integers holding 127 are==, but two holding 1000 aren’t, because Java reuses the small ones. printffollows the computer’s language settings, so on a German system%.6fprints 29,677500. Every program here passesLocale.ROOT.- A method that can throw a checked exception, such as
IOExceptionwhen reading a file, must saythrows IOExceptionor catch it, or the file won’t compile. intarithmetic wraps without warning:Integer.MAX_VALUE + 1is −2147483648.-7 / 2is −3;Math.floorDiv(-7, 2)is −4.
Concepts in Java
- Cross-validation
- Decision tree
- Descriptive statistics
- k-means clustering
- k-nearest neighbors
- Linear regression
- Logistic regression
- Naive Bayes
- Principal component analysis
Run the examples locally
You need Docker and Python 3. The harness builds the pinned container and runs every Java example:
git clone https://github.com/qnixon/dswithx.git
cd dswithx
python3 harness/run_tests.py --language java