PROGRAMMING LANGUAGES · EPISODE 11 OF 15 · 12 MIN ·

What does 'write once, run anywhere' actually mean?

Write once, run anywhere. That was the promise Sun Microsystems made for its new language, Java, in the nineteen-nineties. In episode two, we saw that compiled code is a list of numbers that only one family of chips understands. So how can one program run on any computer? And what's the catch?

▶ Watch on YouTubePlay the whole Programming Languages series ▶

The full story

The episode's narration, word for word. Numbers link to the sources below; timestamps play that moment.

The question 0:00

Write once, run anywhere. That was the promise Sun Microsystems made for its new language, Java, in the nineteen-nineties 1,2,3. In episode two, we saw that compiled code is a list of numbers that only one family of chips understands 4. So how can one program run on any computer? And what's the catch?

A remote nobody bought 0:24

In 1991, Patrick Naughton, Mike Sheridan and James Gosling started a secret project at Sun, called Green 5. Writing a new language wasn't even the point 5. They were trying to guess computing's next wave, and bet on gadgets merging with computers 5. By the summer of 1992 they had a handheld controller for home entertainment, running on a new language Gosling had written that didn't depend on any one processor 5. He called it Oak, after the tree outside his window 5.

Rescued by the web 0:59

The cable TV companies didn't want to give up that much control, so the team asked a new question: why not the internet 5? By 1994 they had built a web browser in their own language 5. Early in 1995, at the TED conference, Gosling moved his mouse over a 3D molecule on a web page, and it turned 5. On the twenty-third of May 1995, Sun announced Java, with Netscape agreeing to put it in its browser 5.

One build per chip 1:30

A program inside a web page could land on any computer, with any chip and any operating system 6. Machine code built for one family of chips won't run on the others 4. Java's designers had already set themselves three rules, back when the target was gadgets on a network, and the web made them matter far more 6. Compiled code had to survive the trip across the network, run on any machine, and assure that machine it was safe to run 6.

An imaginary chip 2:01

Their answer was the trick we met with Python in episode two: compile for a chip that doesn't exist 4. A compiler called javac turns your Java into a class file 4. It holds no machine code for your processor, just bytecode, the machine language of the Java Virtual Machine, or JVM 4. The JVM is a whole imaginary computer, with its own instruction set, built in software 6. Every class file even starts with the same four bytes, which spell CAFEBABE in hexadecimal 7.

Four bytes 2:37

Here's a tiny Java method that adds two whole numbers, straight from Oracle's specification for the JVM 8. There's no Java on the computer that made this video, so the compiled version on screen is the one the specification prints 8,9. Four instructions: load the first number, load the second, add, and return 8. Each instruction is a single byte, so the method's code is just four bytes long 10,9. And not one of them names a register on a real chip 10,6.

A spike of dockets 3:10

Instead, the JVM works with a stack 10. Picture order dockets on a spike: new ones go on top, and you can only take from the top. Load i puts a two on the spike, and load j puts a three on top of it 10,9. The add instruction takes both off, adds them, and puts a five back 10. Return hands back the top one 10. Where the picture breaks: a fast JVM can skip the dockets entirely, and translate these instructions into the real chip's own code 6.

Write once, port many 3:45

So who does the hard part? The JVM is an ordinary program, and someone has to write one for every kind of computer 1. Java 1.0 shipped in January 1996 for just a handful: Windows 95 and NT on Intel chips, and Sun's own Solaris on SPARC chips, with the Mac promised by the end of March 1. Write once, for you, meant port many times, for someone else 1.

Checked at the door 4:16

The JVM also checks each class file before running it, enforcing strict rules on its structure 6. Sun promised that a web page's programs couldn't damage your machine 6,11. In the browser, that promise didn't fully hold 12. Old Java versions have known security problems, and in 2016, as browsers dropped plugins, Oracle announced its browser plugin would go 13,14.

Debug everywhere 4:43

Different JVMs didn't always behave the same way, and programmers joked that the slogan really meant write once, debug everywhere 2,15. Running bytecode through an interpreter, a program that reads each instruction and carries it out, was slower than running machine code directly 13. Java earned a reputation for being slow and hungry for memory 13.

Finding the hot spots 5:08

The fix was the just-in-time compiler, the trick we saw JavaScript use in episode two 13. On the twenty-seventh of April 1999, Sun released the HotSpot engine, and claimed it doubled performance 16. HotSpot watches for the parts of a program that run most often, the hot spots, and recompiles them into the chip's own machine code while the program is running 4. It became Sun's standard JVM with Java 1.3 17.

Who takes out the rubbish? 5:38

Java made one more big promise: the runtime hands memory back for you, which is called garbage collection 13. In a language like C, you free memory by hand 18. Free something too early, and the program can use memory that's already been reused, and freeing it twice is a bug too 18. Starting from what the program can see directly, the collector follows every reference; anything it can't reach is rubbish 19. The idea is old: John McCarthy came up with it for the language Lisp, around 1959 18,20.

Most objects die young 6:14

Oracle's guide says most objects only live for a short time 21: think of the scratch numbers in a sum. So new objects go into a small young area that's cleaned often, and the few survivors move to an older area that's checked less 21. Microsoft's runtime does much the same, with three generations 19. When memory runs short, the collector must run, and the program can stall 13. And here's where the cleaner idea breaks: keep a reference to something you'll never use, and it's never binned 13.

Microsoft's Java 6:48

Then Microsoft joined in. It built its own JVM for Internet Explorer 22,23. In October 1997, Sun sued, saying Microsoft's version broke Java's compatibility rules 23. In January 2001 they settled, and Microsoft paid Sun twenty million dollars 24,25. By then, Anders Hejlsberg, the Turbo Pascal designer we met in episode six, was leading a team at Microsoft building a new language 26,27.

C sharp 7:20

In June 2000, Microsoft unveiled its new .NET platform, and a few days later, the language to go with it: C sharp 28,26. It was standardised by an international standards body in December 2001, and launched with the .NET Framework early in 2002 29,30. Microsoft's own documentation says C sharp 1.0 looked a lot like Java 31. In 2002, James Gosling quipped that imitation is the sincerest form of flattery 32. Microsoft's docs put it plainly: a viable alternative to Java on Windows 31.

The same machine, again 8:00

Underneath, it's the same design 33,4. The C sharp compiler produces common intermediate language, or CIL, instructions for no particular processor 33. The first time a method is called, the runtime's just-in-time compiler turns it into the chip's own code, and keeps it for next time 33. Here's an example from the official standard, written by hand in CIL 34. Load the argument, push ten, add, return 34. It's a stack machine again, the same shape as the JVM's 34,10. Feed it five, and out comes fifteen 9.

.NET leaves home 8:39

But in November 2014, Microsoft made the server side of .NET open source, and announced it would run on Linux and the Mac 35. Today, .NET is free, open source and cross-platform 36. Microsoft's own .NET had finally left home.

Java, without the JVM 8:58

Google bought Android in 2005, and wanted the millions of Java programmers to write apps for it 37. So Android apps are compiled to Java bytecode, but then a tool converts that into a different bytecode, called DEX 38. DEX runs on a different virtual machine, one that uses registers instead of a stack 39. From Android 5, phones compiled apps into real machine code when they were installed 40,41. Since Android 7, they mix that with just-in-time compiling, and spend the effort on the parts of an app that actually get used 42.

Fair use, and Kotlin 9:35

Oracle, which had bought Sun, sued Google, partly over about eleven and a half thousand lines of Java's library declarations that Google had copied 37. In April 2021, the US Supreme Court ruled that copying was fair use 37. Meanwhile, Google made Kotlin, a language from the company JetBrains, official for Android in 2017, and Kotlin-first in 2019 43,44,45. Kotlin also compiles to Java bytecode, and works with Java code in both directions 45.

Where they run today 10:12

Where do they run today? In Stack Overflow's 2025 survey, of the thirty-one thousand-odd developers who answered the question, about twenty-nine per cent had done serious work in Java in the past year, and nearly twenty-eight per cent in C sharp 46. Among professional developers, the two were almost level 46. In games, the Unity engine runs C sharp scripts, and where just-in-time compiling isn't supported, it converts them to C plus plus ahead of time 47. And in 2011, Oracle claimed one point four billion Java Cards were made every year: a tiny Java, for the chips in SIM cards and bank cards 48,49,50.

What it actually means 10:56

So what does write once, run anywhere actually mean? You compile once, for an imaginary machine 4. Someone else builds that machine for every real one 6,1. As your program runs, that machine checks it, compiles the busy parts, and cleans up memory 6,4,13. The price is some speed, some extra memory, and the odd pause 4,13. Garbage collection is one way to prevent some memory bugs, but it isn't the only one 19. So why are people still inventing new languages?

Sources

Every factual claim in the episode is tied to one of these. Spotted an error? Tell us.

  1. Sun Microsystems press release, "JavaSoft Ships Java 1.0", Palo Alto, 23 January 1996… — web.archive.org
  2. Wikipedia, "Write once, run anywhere" (WORA; "Write once, debug everywhere", citing W.… — en.wikipedia.org
  3. Sun Microsystems, java.sun.com home page, archived 10 December 1997 ("Write Once, Run… — web.archive.org
  4. Oracle, The Java Tutorials, "About the Java Technology" (javac, .class files,… — docs.oracle.com
  5. J. Byous, "Java Technology: The Early Years", Sun Developer Network, 1998 (archived 20… — web.archive.org
  6. Oracle, The Java Virtual Machine Specification, Java SE 21 Edition, Chapter 1… — docs.oracle.com
  7. Oracle, JVM Specification, Java SE 21, Chapter 4 "The class File Format" (4.1: magic… — docs.oracle.com
  8. Oracle, JVM Specification, Java SE 21, Chapter 3 "Compiling for the Java Virtual… — docs.oracle.com
  9. This episode's own check, calc.py (2026-10-07, Apple silicon Mac, CPython 3.13.7; no…
  10. Oracle, JVM Specification, Java SE 21, Chapter 6 "The Java Virtual Machine… — docs.oracle.com
  11. Sun Microsystems, The Java Virtual Machine Specification, 2nd edition, section 1.1… — web.archive.org
  12. CERT/CC Vulnerability Note VU#625617, "Java 7 fails to restrict access to privileged… — kb.cert.org
  13. Wikipedia, "Java (programming language)" (history; performance reputation; JIT… — en.wikipedia.org
  14. D. Topic, "Moving to a Plugin-Free Web", Oracle Java Platform Group blog, 27 January… — web.archive.org
  15. W. Wong, "Write Once, Debug Everywhere", Electronic Design, 26 May 2002 (archived) — web.archive.org
  16. Sun Microsystems press release, "Sun announces availability of the Java HotSpot… — web.archive.org
  17. Sun Microsystems, J2SE 1.3 documentation, "The Java HotSpot Client and Server Virtual… — web.archive.org
  18. Wikipedia, "Garbage collection (computer science)" (McCarthy, Lisp, c. 1959; dangling… — en.wikipedia.org
  19. Microsoft Learn, "Fundamentals of garbage collection" (.NET: benefits, roots,… — learn.microsoft.com
  20. J. McCarthy, "Recursive Functions of Symbolic Expressions and Their Computation by… — www-formal.stanford.edu
  21. Oracle, Java SE 17 HotSpot Virtual Machine Garbage Collection Tuning Guide, "Garbage… — docs.oracle.com
  22. Wikipedia, "Microsoft Java Virtual Machine" (Sun lawsuit October 1997; January 2001… — en.wikipedia.org
  23. Sun Microsystems press release, "Sun Sues Microsoft for Breach of Java Contract", 7… — web.archive.org
  24. Sun Microsystems press release, "Sun and Microsoft Settle Lawsuit; Settlement Protects… — web.archive.org
  25. Microsoft PressPass, "Microsoft Reaches Agreement to Settle Contract Dispute With Sun… — web.archive.org
  26. Microsoft News, "Microsoft Introduces Highly Productive .NET Programming Language:… — news.microsoft.com
  27. N. Hamilton, "The A-Z of Programming Languages: C#" (interview with Anders Hejlsberg),… — web.archive.org
  28. Microsoft News, "Microsoft Unveils Vision for Next Generation Internet", Redmond, 22… — news.microsoft.com
  29. Ecma International, "ECMA-334" and "ECMA-335" standard pages (1st editions, December 2001) — ecma-international.org
  30. Microsoft News, "Microsoft Launches XML Web Services Revolution With Visual Studio… — news.microsoft.com
  31. Microsoft Learn, "The history of C#" (C# 1.0, January 2002, "looked a lot like Java") — learn.microsoft.com
  32. CNET News.com, "Why Microsoft's C# isn't", 18 January 2002 (archived; Gosling:… — web.archive.org
  33. Microsoft Learn, "Managed execution process" (CIL; JIT per CPU architecture; compiled… — learn.microsoft.com
  34. Ecma International, ECMA-335: Common Language Infrastructure (CLI), 6th edition,… — ecma-international.org
  35. Microsoft News, "Microsoft takes .NET open source and cross-platform…", New York, 12… — news.microsoft.com
  36. Microsoft Learn, "Introduction to .NET" (free, cross-platform, open source; MIT… — learn.microsoft.com
  37. Supreme Court of the United States, Google LLC v. Oracle America, Inc., No. 18–956,… — supremecourt.gov
  38. Android Developers, "d8" (compiles Java bytecode into DEX bytecode) — developer.android.com
  39. Android Open Source Project, "Dalvik bytecode format" ("The machine is register-based") — source.android.com
  40. Android Open Source Project, "Android runtime and Dalvik" (ART executes DEX; AOT with… — source.android.com
  41. Android Developers, "Verifying app behavior on the Android runtime (ART)" (ART the… — developer.android.com
  42. Android Open Source Project, "Configure ART" (How ART works: AOT, and from Android 7 a… — source.android.com
  43. M. Cleron, "Android Announces Support for Kotlin", Android Developers Blog, 17 May 2017 — android-developers.googleblog.com
  44. Android Developers, "Android's Kotlin-first approach" (Google I/O 2019; 100%… — developer.android.com
  45. JetBrains, Kotlin documentation, "FAQ" (JetBrains; started 2010; 1.0 February 2016;… — kotlinlang.org
  46. Stack Overflow, 2025 Developer Survey, "Technology: Programming, scripting, and… — survey.stackoverflow.co
  47. Unity Manual (Unity 6.6), "Scripting back ends" (Mono JIT; IL2CPP AOT, IL to C++,… — docs.unity3d.com
  48. Oracle, java.com "Learn About Java Technology", archived 24 November 2011 (1.1 billion… — web.archive.org
  49. Wikipedia, "Java Card" (smart cards; SIM, eSIM and banking cards) — en.wikipedia.org
  50. Oracle, "Oracle Java Card technology" (SIM and embedded SIM, NFC mobile payment;… — web.archive.org

Researched and scripted with AI assistance, fact-checked claim by claim, with synthetic narration and diagrams drawn in code. How we make episodes.

More from Programming Languages