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:
| |
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..jlextension - Julia source files use this extension.- No imports needed -
printlnis available by default (from Base).
Running with Docker
The easiest way to run this without installing Julia locally:
| |
Running Locally
If you have Julia installed:
| |
Or use the interactive REPL:
| |
Expected Output
Hello, World!
Key Concepts
- Dynamic language - No compilation step needed for scripts
- JIT compiled - Code is compiled on first run for performance
- 1-indexed arrays - Unlike most languages, Julia arrays start at 1
- Mathematical syntax - Designed for scientific computing
- Unicode support - Variable names can use Greek letters and math symbols
String Interpolation
Julia uses $ for string interpolation:
| |
For expressions, use parentheses:
| |
A Function Example
| |
Or use the compact form:
| |
Multiple Dispatch Preview
Julia’s defining feature—functions behave differently based on argument types:
| |
The compiler picks the right method based on the argument type.
Unicode in Julia
Julia embraces mathematical notation:
| |
The Julia REPL
The REPL (Read-Eval-Print Loop) is powerful:
| |
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:
| |
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.