Programming Basics &
Algorithmic Thinking

Master the core of Java, from logical steps to machine execution.

What is an Algorithm?

A precise, step-by-step procedure for solving a specific task.

1
Step-by-step
2
Finite
3
Precise
6:00 AM
01
Alarm Rings
02
Snooze?
03
Get Out of Bed
04
Start Your Day
05

The Compiler

The Compiler translates human Java code into machine instructions.

High Strictness

Unlike humans, a compiler cannot "guess" your meaning. Every semicolon, bracket, and quote counts.
.javaHUMAN READABLE
Compiler

01101001

11001110

10101011

00000001

11110000

10101010

01010101

11001100

10001000

01110111

.classBYTECODE

Standard Framework

Every Java journey starts with a class and a main method.

HelloWorld.java
java

"Think of it as the mandatory doorway to your code."

String Literals

The 'Containers' of Messages

"Hello World"
String Container
This is the Data (Text)

The Container Rule

Quotes tell the compiler: "Everything inside is just text, don't try to run it!"

Literals

Directly typed text in code. What you see inside the quotes is what gets printed.

Output Mechanics

Communicating with the Machine Console

print = Stay on line

println = Message + Enter

Comparison.java
java
Console Output
Hello World
Comparison.java
java
Console Output
Hello World

Quick Challenge

Predict the Output

Quiz.java
java

Escape Sequences

A backslash changes the meaning of special characters in a string.

\n
New Line
\"
Double Quote
\\
Backslash
Escape.java
java
Console Output
He said "Hi!"

Escaping Quiz

Predict the Visual Result

Quiz.java
java

Arithmetic Operators

The Building Blocks of Java Calculation

+
Addition
5 + 2 = 7
-
Subtraction
5 - 2 = 3
*
Multiplication
5 * 2 = 10
/
Division
5 / 2 = 2
Integer Division!
%
Modulo
5 % 2 = 1
Remainder

Precedence

1

Grouping

() are always evaluated first.
2

Powerhouse

*, /, and % have higher priority.
3

Standard

+ and - are performed last.
Precedence Rule
7 - (6 + 5) % 4
1→ 7 - 11 % 4
2→ 7 - 3
3→ 4
Result4
/
2

Integer Division Playground

Truncation Trap

In Java, dividing two integers always results in an integer.

Integer Division

Java intentionally truncates (throws away) the decimal part. It never rounds up, even if the result is 2.99!

Calculation Quiz

Apply precedence and truncation

What is the result of:
10 / 4 + 7 % 3 * 5

Documentation

The machine simply skips them entirely.

//Single-line
/*...*/Multi-line
/**...*/Doc Comment
CommentDemo.java
java

After-Class
Assignment

Character Challenge

Write a Java program to print your favorite quote wrapped in literal double quotes.
Solve all 5:
(8 + 2) / 3 * 2
9 / 2 - 5 % 3
(7 + 4) / 3 + 1
6 * 3 / 5 + 1
(9 - 1) % 5 / 2

Math Lab

Manually calculate these 5 mixed expressions on paper using Java's precedence and truncation.