Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 40 ยท Getting Started

What Is Julia?

Learn what the Julia programming language is, why it was created, how its JIT compiler removes the two-language problem and where Julia is used today.

Julia is a programming language built for numerical and scientific computing. It reads almost like Python or MATLAB, yet it runs at speeds close to C and Fortran. You write short, high-level code, and the compiler turns it into fast machine code behind the scenes. That combination is the reason Julia exists.

Julia was first released in 2012 by four researchers who were tired of a familiar trade-off: easy languages were slow, and fast languages were hard to write. Today Julia is used for climate models, drug discovery, finance, robotics and machine learning. In this lesson you will learn the idea behind the language, how it runs your code, and how this tutorial teaches it on a site that cannot execute Julia itself.

This site has no Julia installed. All Julia code is read-only, and any output is shown in comments. The runnable examples are Python stand-ins that demonstrate the same ideas, and each one says what is real Julia and what is only an analogy.

The two-language problem

Scientists and engineers often prototype in a friendly language such as Python, R or MATLAB. The prototype works, but it is too slow on real data. So someone rewrites the heavy parts in C, C++ or Fortran. Now the project has two languages, two build systems, a fragile bridge between them, and a team where only some people can touch the fast code. This is called the two-language problem.

Python libraries such as NumPy hide the problem by moving loops into compiled C code. That works well as long as your problem fits into the operations the library already provides. The moment you need a custom loop, a new data structure or an unusual algorithm, you are back to slow interpreted code.

Julia's answer is to be one language for both jobs. A plain for loop in Julia is fast. A user-defined type can be as fast as a built-in one. You do not need to leave the language to make code quick.

The next example runs a Python version of the problem. The loop and the library call compute the same result, but only the library call avoids the interpreter. In Julia, you would not need the second version to be fast.

Python Same answer, two styles

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

In real Julia the first style is the fast one. The equivalent code is a plain loop, and Julia compiles it to a tight machine-code loop:

JULIA
total = 0
for x in 1:100_000
    total += x * x
end
total   # 333338333350000

(This snippet is meant to live inside a function when you care about speed. Performance Tips explains why.)

How Julia runs your code

Julia is not interpreted line by line, and it is not compiled ahead of time like C. It uses just-in-time (JIT) compilation built on LLVM, the same compiler infrastructure used by Clang and Rust. The steps are roughly these:

  1. You call a function, for example area(2.0).
  2. Julia looks at the types of the actual arguments (Float64).
  3. It compiles a specialized version of area for exactly those types.
  4. It runs that machine code, and caches it for later calls with the same types.

Calling area(2) with an integer triggers a second, separate compilation for Int64. Each specialization is as tight as hand-written code for that type.

From source to speed

You write Short, readable code.
Types inferred Julia works out argument types.
LLVM compiles One fast version per type combination.
Cached Later calls reuse the machine code.

The first call pays the compile cost. The rest are fast.

1 / 2

A consequence is first-call latency: the very first call of a function in a fresh session includes compile time, which can be noticeable for large libraries. Later calls are fast. You will see how to measure this in How Julia Compiles Code.

The following stand-in imitates the idea. It keeps a cache keyed by argument types and "compiles" a version only the first time a new type combination appears. Python does not generate machine code here; this only shows the caching behavior.

Python A specialization cache (analogy)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Real Julia does this with actual machine code and with far more type information than a name, but the rhythm is the same: compile on first use per type combination, then reuse.

What makes Julia different

A few design choices define the language, and later lessons cover each in depth:

  • Multiple dispatch. A function can have many methods, and Julia picks one using the types of all its arguments, not only the first. This is the organizing principle of the whole ecosystem. See Multiple Dispatch.
  • A rich type system with optional annotations. You can write code with no types at all, or add them where they help dispatch and documentation. See The Type System.
  • Composability. Packages written by different people work together because they share generic interfaces. A differential equation solver can run on numbers with units or on automatic-differentiation types it has never heard of.
  • Metaprogramming. Code is data, and macros can rewrite it. Metaprogramming gets its own chapter later in this tutorial.
  • Built-in package manager and reproducible environments. See Packages and Environments.

Julia is also free and open source (MIT license), and it has first-class support for arrays, linear algebra, parallel programming and Unicode math symbols such as ฮฑ and โˆ‘.

Where Julia is used

Julia shines wherever heavy numerical work meets the need for readable, flexible code:

  • Scientific simulation: climate and weather models, astrophysics, computational biology.
  • Optimization and modeling: planning, scheduling and energy systems with libraries such as JuMP.
  • Data science and machine learning: tabular data with DataFrames.jl, neural networks with Flux.jl.
  • Finance and pharma: risk models, pharmacometrics, quantitative research.
  • High-performance computing: Julia runs on clusters and GPUs.

It is a weaker fit for small scripts where startup time dominates, for projects that need a huge web or mobile ecosystem, and for teams that already have a mature Python codebase and no performance problem.

A first taste

Here is a complete Julia function and its calls. It is read-only here; you will run code like this on your own machine after the next lesson.

JULIA
function area(r)
    return ฯ€ * r^2
end

area(2.0)   # 12.566370614359172
area(1)     # 3.141592653589793

Notice there are no type declarations, and the same function works for an integer and a float. Julia compiled two specialized versions for you.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the "two-language problem"?

    Teams often prototype in a high-level language and then port performance-critical parts to C or Fortran. Julia aims to let one language cover both stages.
  2. 2. How does Julia run your code?

    Julia uses just-in-time compilation with LLVM. Each function is compiled per combination of concrete argument types and the result is cached.
  3. 3. Why is the first call of a Julia function often slower than later calls?

    Compilation happens on first use for each type combination. That first-call latency does not repeat for the same types.
  4. 4. Which feature picks a method based on the types of all arguments?

    Multiple dispatch selects among a function's methods using every argument's type, which is central to how Julia code is organized.

Summary

  • Julia is a high-level language for numerical computing that aims to run at close to C speed.
  • It targets the two-language problem: prototype and production code can be the same code.
  • JIT compilation with LLVM builds a specialized version of a function for each combination of argument types, and caches it.
  • The first call includes compile time; later calls are fast.
  • Multiple dispatch, a strong type system and composable packages are the defining ideas.
  • On this site Julia code is read-only, and runnable examples are honest Python stand-ins.

Next, set up your own machine in Installing Julia and Using the REPL.