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

Each action is listed in clear order.
2

Finite

The procedure always reaches an end.
3

Precise

No guessing โ€” every step is unambiguous.
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

Java source is checked before it becomes .class bytecode.

๐Ÿ”

Checks Before Running

A compiler checks source code for some errors before the program runs.

๐Ÿ›‘

Fix Before Running

Fix every compiler-detected error before the program can run.

.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

Breaks Java's grammar, so the code will not compile.

๐ŸŽฏ

Logic Error

Runs normally, but produces the wrong result.

๐Ÿ’ฅ

Runtime Error

Starts successfully, then fails while running.

๐Ÿ” Error Detective (1/3)

Identify the error family from the scenario.

๐Ÿ“

Question

You're filling out an online registration form. You type your email as "studentgmail.com" without the "@" symbol and click Submit. The form immediately highlights the email field in red, displays "Invalid format," and refuses to proceed โ€” nothing gets saved or processed.

Which error family does this describe?

๐Ÿ” Error Detective (2/3)

Identify the error family from the scenario.

๐Ÿ“

Question

You're playing a mobile game. Halfway through the third level boss fight, the game suddenly crashes to the home screen with no warning.

Which error family does this describe?

๐Ÿ” Error Detective (3/3)

Identify the error family from the scenario.

๐Ÿ“

Question

Your friend follows a pancake recipe step by step โ€” mix, pour, flip โ€” and the pancakes come out looking perfect. But after the first bite you realize they used salt instead of sugar. Every instruction was followed correctly, and nothing burned or broke.

Which error family does this describe?

๐Ÿงฑ Standard Framework

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

HelloWorld.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
Console Output
Hello World
Comparison.java
Console Output
Hello World

๐Ÿ” Output Quiz

What exactly is printed?

Quiz.java

โœจ Escape Sequences

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

Escape.java
Console Output
Line 1 Line 2 She said "Hi!" Path: C:\temp
\n

New Line

Moves the cursor to the next line

\"

Double Quote

Prints a quote inside a string

\\

Backslash

Prints a single backslash character

๐Ÿ” Escape Quiz (1/2)

What exactly is printed?

EscapeQuiz.java

๐Ÿ” Escape Quiz (2/2)

Which Java statement produces this output?

EscapeQuiz.java

๐Ÿฟ 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

Java evaluates grouped and higher-priority operations before lower-priority ones.

1

Grouping

() are always evaluatedย first.
2

Powerhouse

*, /, and % have higherย priority.
3

Standard

+ and - are performedย last.
7 - (6 + 5) % 4

Press Next to evaluate one rule at a time.

0 / 3

โœ‚๏ธ Truncation Trap

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

/
2

Integer Division

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

๐Ÿ” Arithmetic Quiz (1/5)

What is the value of this expression?

ArithmeticQuiz.java

๐Ÿ” Arithmetic Quiz (2/5)

What is the value of this expression?

ArithmeticQuiz.java

๐Ÿ” Arithmetic Quiz (3/5)

What is the value of this expression?

ArithmeticQuiz.java

๐Ÿ” Arithmetic Quiz (4/5)

What is the value of this expression?

ArithmeticQuiz.java

๐Ÿ” Arithmetic Quiz (5/5)

What is the value of this expression?

ArithmeticQuiz.java

๐Ÿ“ Documentation

The machine simply skips them entirely.

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

๐Ÿ“ Homework

Complete it on time and submit it before the deadline.

๐Ÿงญ Next Class

Check what comes next and arrive ready.

๐Ÿ”– Summary

Key takeaways from this lesson.

๐Ÿ›

Error Types

Syntax stops compilation, logic gives a wrong result, and runtime crashes 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 whole-number values truncates the decimal: 5 / 2 = 2.

๐Ÿ“

Comments

Use // or /* */ for people; the compiler ignores both.

01 / 30