Beginner

Hello World in Julia

Your first Julia program - the classic Hello World example with Docker setup

Every programming journey starts with Hello World. Let’s write our first Julia program.

The Code

Create a file named hello.jl:

1
println("Hello, World!")

Simple and clean—one line to print to the console.

Understanding the Code

  • println() - Prints a string to standard output with a newline. print() omits the newline.
  • .jl extension - Julia source files use this extension.
  • No imports needed - println is available by default (from Base).

Running with Docker

The easiest way to run this without installing Julia locally:

1
2
3
4
5
# Pull the Julia image
docker pull julia:1.11-alpine

# Run your script
docker run --rm -v $(pwd):/app -w /app julia:1.11-alpine julia hello.jl

Running Locally

If you have Julia installed:

1
2
# Run the script
julia hello.jl

Or use the interactive REPL:

1
2
3
4
5
6
# Start Julia REPL
julia

# Then type:
julia> println("Hello, World!")
Hello, World!

Expected Output

Hello, World!

Key Concepts

  1. Dynamic language - No compilation step needed for scripts
  2. JIT compiled - Code is compiled on first run for performance
  3. 1-indexed arrays - Unlike most languages, Julia arrays start at 1
  4. Mathematical syntax - Designed for scientific computing
  5. Unicode support - Variable names can use Greek letters and math symbols

String Interpolation

Julia uses $ for string interpolation:

1
2
name = "World"
println("Hello, $name!")

For expressions, use parentheses:

1
2
3
x = 6
y = 7
println("$x × $y = $(x * y)")  # 6 × 7 = 42

A Function Example

1
2
3
4
5
function greet(name)
    return "Hello, $name!"
end

println(greet("World"))

Or use the compact form:

1
2
3
greet(name) = "Hello, $name!"

println(greet("World"))

Multiple Dispatch Preview

Julia’s defining feature—functions behave differently based on argument types:

1
2
3
4
5
greet(name::String) = "Hello, $name!"
greet(n::Int) = "Hello, person #$n!"

println(greet("World"))  # Hello, World!
println(greet(42))       # Hello, person #42!

The compiler picks the right method based on the argument type.

Unicode in Julia

Julia embraces mathematical notation:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# You can use Greek letters (type \alpha + Tab in REPL)
α = 0.5
β = 0.3
γ = α + β

# Mathematical operators work too
println("α + β = ")

# Even emoji work as variable names!
🎉 = "Hello, World!"
println(🎉)

The Julia REPL

The REPL (Read-Eval-Print Loop) is powerful:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
$ julia
julia> 2 + 2
4

julia> "Hello" * ", " * "World!"  # String concatenation uses *
"Hello, World!"

julia> ?println  # Help mode - press ? first
search: println printstyled print sprint isprint

julia> ]  # Package mode - press ] first
pkg> status

Special modes:

  • ? - Help mode (documentation)
  • ] - Package mode (install/manage packages)
  • ; - Shell mode (run shell commands)

Type Annotations (Optional)

Julia is dynamically typed, but you can add annotations:

1
2
3
function greet(name::String)::String
    return "Hello, $name!"
end

Types are optional but help with:

  • Documentation
  • Multiple dispatch
  • Performance hints
  • Error catching

Next Steps

Continue to Variables and Types to learn about Julia’s type system and multiple dispatch.

Running Today

All examples can be run using Docker:

docker pull julia:1.11-alpine
Last updated: