Programming Basics &
Algorithmic Thinking

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

Algorithm Discovery

Can you guide the robot to its morning coffee?

Command Bank

Add steps to your algorithm.

Step-by-Step Sequence0/8

Algorithm is empty.
Select commands to start.

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

When Languages Don't Match

A translator can turn unfamiliar signals into a shared language.

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

When Things Go Wrong

Even the best programmers make mistakes — the key is knowing what kind.

The Three Error Families

Every bug you meet will be one of these three.

Syntax Error

Won't compile
Compiler rejects your code — it cannot even start.

Like writing "Stirr eggs 10 minuts" in a recipe — the grammar is so jumbled that nobody can follow it.

Logic Error

Runs, but wrong result
No error message — the behavior is not what you intended.

Like a grammatically perfect recipe that says "Add 100 spoons of salt" — the program didn't crash, but it's completely wrong.

Runtime Error

Crashes mid-execution
Program starts fine, then hits an impossible operation.

Like trying to find a 6th person in a classroom with only 5 seats — an impossible task that causes a crash.

🔍 Error Detective: Life Edition

Read each scenario — can you spot which error type it is?

Standard Framework

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

HelloWorld.java
java

English Symbols Only

All symbols must be English-mode. Chinese ;() cause errors.

Semicolons Required

Every statement must end with a ;
— it's the period of Java sentences.

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

Output Quiz

Trace 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!"

Escape Quiz

Predict or construct the correct output

Quiz.java
java
Question 1 of 2

One Snack Run

Snacks, discounts, and leftovers can all change the final basket.

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

Press Next to evaluate one rule at a time.

0 / 3
/
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!

Arithmetic Quiz

Precedence, integer division & more

Quiz.java
java
Question 1 of 5

Documentation

The machine simply skips them entirely.

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

Course Summary

Key takeaways from today's session

Error Types

Syntax = compilation fails, Logic = wrong result, Runtime = crash during execution.

Standard Framework

Every program needs a class and a main method to run.

Output Mechanics

print stays on the same line, while println adds a new line after.

Escape Sequences

Use \n for new lines and \" to print double quotes inside strings.

Integer Division

Dividing two ints always truncates (drops the decimal). example: 5 / 2 = 2.

Comments

Use // for single-line and /* */ for multi-line notes — ignored by the compiler, essential for humans.

01 / 21