Julia Programming

High-performance scientific computing and numerical analysis.

1. Hello, World!

println("Hello, World!")

2. Variables and Basic Types

# Basic Types in Julia
string_var = "Rau ma" # String
int_var = 36 # Integer
float_var = 3.6 # Float
bool_var = true # Boolean
char_var = 'A' # Character

println(typeof(string_var)) # String
println(typeof(int_var))    # Int64

3. Control Flow

If-Else

if 36 < 92
    println("36 is less than 92")
elseif 36 == 92
    println("36 equals 92")
else
    println("36 is greater than 92")
end

Loops

# For loop
for i in 1:10
    println("Number: $i")
end

# While loop
n = 3
while n > 0
    println("Countdown: $n")
    global n = n - 1
end

4. Multiple Dispatch

Julia calls different function implementations based on the types of the arguments.

function add(a::Int, b::Int)
    println("Adding Integers")
    a + b
end

function add(a::Float64, b::Float64)
    println("Adding Floats")
    a + b + 0.5
end

add(10, 20)      # Calls Int version
add(10.0, 20.0)  # Calls Float version

5. Data Structures

Arrays

arr = [18, 36, 92]
push!(arr, 43)
println(sum(arr))

Dictionaries

dict = Dict("name" => "Alice", "age" => 30)
println(dict["name"])

6. Plotting

using Plots
x = 1:10
y = rand(10)
plot(x, y, title="Random Plot")
savefig("plot.png")