Skip to main content

Programming concepts

What is a Runtime?

Definition

A runtime is the software environment that executes a program and provides the services it needs while running, such as memory management and I/O.

Also known as: Runtime environment, Runtime system

Runtime in more detail

The word carries three meanings and context has to sort them out. As an environment, the runtime is the thing your code runs inside — Node.js for server-side JavaScript, the JVM for Java and Kotlin, the CLR for .NET, CPython for Python. As a phase, run time is when the program is executing, contrasted with compile time; that is what a 'runtime error' means. As a library, the runtime is the support code linked into a compiled program to handle allocation, exceptions, coroutines and similar.

In the environment sense the runtime provides everything the language assumes but the source never mentions: allocating and reclaiming memory, usually by garbage collection; dispatching method calls; scheduling concurrency, such as JavaScript's event loop or Go's goroutine scheduler; unwinding exceptions; and exposing the platform's capabilities — files, sockets, timers, clocks — through the standard library. Even languages with no virtual machine, such as C, Rust and Go, ship a small runtime that starts the program and provides these services.

The distinction that matters practically is which errors belong where. A compile-time error means the program was never valid; a runtime error means it was valid and something went wrong while executing — a null dereference, a missing file, a division by zero, a failed network call. Static typing moves some of the second group into the first, which is most of the reason people adopt it.

Runtime example

Runtime as an environment
  node server.js       -> V8 + the Node runtime (event loop,
                          fs, net, timers, module loader)
  java -jar app.jar    -> the JVM (GC, JIT, class loading)
  python app.py        -> CPython (bytecode interpreter, GC)

Runtime as a phase
  compile time:  const n: number = "hello";
                 -> Type 'string' is not assignable to 'number'
                    (the program never runs)

  run time:      const rows = await db.query(...);
                 rows[0].name
                 -> TypeError: Cannot read properties of undefined
                    (perfectly valid code; the data was empty)

Same JavaScript, different runtimes, different globals:
  browser -> window, document, fetch
  Node    -> process, fs, Buffer

Runtime — common questions

Is Node.js a language or a runtime?
A runtime. The language is JavaScript; Node.js is an environment that runs it outside the browser using the V8 engine, adding APIs for files, networking, processes and modules that browsers do not provide.
What is the difference between a compile-time error and a runtime error?
A compile-time error is found before the program runs and prevents it from building. A runtime error occurs during execution in a program that was valid, usually because of data, environment or state the compiler could not know about.
What is a runtime environment?
Everything present while your program executes: the virtual machine or interpreter, the garbage collector, the scheduler, the standard library and the operating system interfaces it exposes. Your code depends on all of it without naming any of it.

Keep reading

Every definition in the set is indexed A-Z in the developer glossary, and the cheat sheets cover the syntax once you know what you are looking for.

Browse the A-Z glossary