print and println@printftry-catch for Exception HandlingfinallySolidifying your Julia setup and practicing the initial steps of writing and running Julia code are the focus. This includes verifying your installation, organizing your workspace, and executing a simple script that goes a bit further than the traditional 'Hello, World!' example. This practical experience is foundational for the topics that follow.
Before writing more code, it's a good practice to confirm that Julia is correctly installed and accessible from your system's command line interface (like Terminal on macOS/Linux or Command Prompt/PowerShell on Windows).
Open your terminal and type the following command:
julia --version
Press Enter. You should see output similar to this, indicating your installed Julia version:
julia version 1.x.y
(Where 1.x.y is the specific version number you installed, for example, 1.9.3.)
If you see an error message like 'julia: command not found' or similar, it means that the Julia executable is not in your system's PATH. You might need to revisit the installation instructions for your operating system (covered in "Installing Julia on Your System") to ensure the 'Add Julia to PATH' option was selected, or manually add it. Being able to run julia from any directory in your terminal is important for a smooth development experience.
Good organization habits start early. Let's create a dedicated space for your Julia projects and write a small script.
Create a Project Directory:
Navigate to a place on your computer where you like to keep your projects (e.g., your Documents folder). Create a new directory. For this course, you might name it julia_course_work or something similar.
# In your terminal, navigate to your preferred location
# For example, if you are in your home directory:
cd Documents # Or your preferred directory
mkdir julia_course_work
cd julia_course_work
This new directory will be your primary workspace for the exercises in this course.
Revisit the REPL for Quick Tests: Open your terminal (if not already open and in your new project directory) and start the Julia REPL:
julia
You'll see the julia> prompt. Let's try a quick calculation:
julia> 25 * 4 + 15
115
julia> exit() # or press Ctrl+D (Cmd+D on macOS)
The REPL is excellent for these kinds of quick experiments and calculations.
Create Your First Calculation Script:
Now, let's create a script file. Using your chosen text editor (whether it's VS Code with the Julia extension, Atom with Juno, or a simple editor like Notepad++, Sublime Text, or Gedit), create a new file named simple_calc.jl inside your julia_course_work directory.
Enter the following code into simple_calc.jl:
# simple_calc.jl
# A script to perform and display a few calculations
# Define a couple of variables
principal_amount = 1000 # Initial amount
annual_interest_rate = 0.05 # 5% interest rate
# Calculate simple interest for one year
interest_earned = principal_amount * annual_interest_rate
# Calculate the total amount after one year
total_amount = principal_amount + interest_earned
# Display the results
println("Initial Principal: \$$principal_amount") # Using string interpolation with a literal $
println("Annual Interest Rate: $(annual_interest_rate * 100)%") # Interpolation with an expression
println("Interest Earned in One Year: \$$interest_earned")
println("Total Amount after One Year: \$$total_amount")
A few things to note in this script:
# are comments, ignored by Julia. They are for human readers.principal_amount and annual_interest_rate.println() is used to display output to the console. Notice the use of $ before a variable name (e.g., $principal_amount) or $(...) around an expression (e.g., $(annual_interest_rate * 100)) directly within the text strings. This is called string interpolation, a convenient way to embed values into strings. To print a literal dollar sign, we "escape" it with a backslash, like \$.Run Your Script:
Save the simple_calc.jl file. Go back to your terminal, ensuring you are still in the julia_course_work directory (where you saved the file). Execute the script by typing:
julia simple_calc.jl
You should see the following output:
Initial Principal: $1000
Annual Interest Rate: 5.0%
Interest Earned in One Year: $50.0
Total Amount after One Year: $1050.0
Congratulations! You've configured a basic workspace and run a Julia script that performs some actions.
You've now used both the Julia REPL and script files.
As you progress, you'll find yourself moving between these two modes. Often, you might prototype an idea in the REPL and then transfer the refined code into a script.
If things didn't go as smoothly as expected, here are a couple of common initial hurdles:
julia: command not found (or similar): This usually means Julia's installation directory isn't in your system's PATH. Recheck your installation steps, specifically any options related to adding Julia to PATH. You might need to restart your terminal or even your computer after installation or PATH modification for changes to take effect.ERROR: could not open file simple_calc.jl: This typically means your terminal is not in the same directory where you saved simple_calc.jl. Use commands like cd (change directory) to navigate to the correct folder (julia_course_work in our example) before running julia simple_calc.jl. You can use pwd (print working directory) in Linux/macOS or cd (without arguments) in Windows Command Prompt to see your current directory.Don't be discouraged by initial errors. They are a normal part of programming, and learning to interpret and fix them is a valuable skill.
The REPL has a very useful built-in help mode. You encountered it briefly in "Accessing Julia Documentation and Support". Let's try it again. Start the Julia REPL:
julia
At the julia> prompt, type ? and press Enter. The prompt will change to help?>. Now, you can type the name of a function or concept to get documentation. For example, to learn about the sqrt function (for square roots):
help?> sqrt
Press Enter. You'll see documentation for sqrt.
search: sqrt CbrtIEuclidean Isqrt
sqrt(x)
Return $\sqrt{x}$. Throws DomainError for negative Real arguments. Use complex(x) to obtain a complex result.
If x is a matrix, computes matrix square root.
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Examples
≡≡≡≡≡≡≡≡≡≡
julia> sqrt(4.0)
2.0
julia> sqrt(big(81))
9.0
julia> sqrt(-1)
ERROR: DomainError with -1.0:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
Stacktrace:
[...]
Press Backspace or q to exit the help pager if it takes over the screen, returning you to the help?> prompt. Press Backspace again (or Ctrl+C) to get back to the julia> prompt. Now you can use the function:
julia> sqrt(16)
4.0
julia> sqrt(2)
1.4142135623730951
This interactive help is a powerful tool for learning about Julia's capabilities directly within your working environment.
With your environment configured and these initial scripting steps completed, you're well-prepared for the subsequent chapters. We encourage you to create subdirectories within your julia_course_work folder for each chapter or topic as you progress. Experimentation is what will build your fluency in Julia, so don't hesitate to modify the scripts, try new things in the REPL, and consult the documentation when you're curious or stuck. This hands-on practice is what will build your proficiency.
Was this section helpful?
© 2026 ApX Machine LearningEngineered with