Card 03/ 06

ExampleDifficulty: Beginner1 min

Java Portability Example: One Jar on a Mac and on a Linux Server

Built on a laptop, copied to a server with no compiler and no source, and it runs.

Compiled Java runs on any operating system that has a JVM (the Java Virtual Machine, the program that runs compiled Java), without being compiled again. A jar is a zip file of compiled .class files, and the same jar runs unchanged on different machines.

A colleague builds reports.jar on a Mac and puts it on a shared drive. You copy it to a Linux server that has never seen the source code, and run it:

bash
uname -s
Linux

ls
reports.jar

java -jar reports.jar
Wrote 412 rows to reports/2026-09.csv

There is no compiler on that server and no .java file anywhere on it. The .class files inside the jar hold the same bytecode, the compiled instructions, that your colleague's machine produced, byte for byte.

What is different between the two machines is the Java Virtual Machine, the JVM. The Mac has one built for macOS on an ARM processor; the server has one built for Linux on x86. Each was written by someone else, for that machine, and each reads the same instruction set.

The two runs share more than they look like they do. In both, compiling the source to bytecode had already happened on the Mac before anything ran, and turning bytecode into processor instructions happened on each machine as it ran. That is why neither machine needed the source, and why they did not need to agree about processors.