Algorithms, Programming, Compilers
| English | Chinese | Pinyin |
|---|---|---|
| algorithm | 算法 | suàn fǎ |
| high-level language | 高级语言 | gāo jí yǔ yán |
| compiler | 编译器 | biān yì qì |
| syntax error | 语法错误 | yǔ fǎ cuò wù |
| logic error | 逻辑错误 | luó jí cuò wù |
What is an algorithm?
- An algorithm 算法 is a finite, ordered set of steps that solves a problem.
- A recipe is an algorithm: precise steps, in order, that finish.
- Programming is the craft of turning an algorithm into code a computer runs.
- Good algorithms are clear, correct, and finite — they always stop.
Programming languages
- Computers run machine code (raw 0s and 1s) — hard for humans to write.
- We write in a high-level language 高级语言 like Java: readable, English-like.
- Java code says what to do; a translator turns it into machine instructions.
- This course teaches problem-solving through Java.
Compilers
- A compiler 编译器 translates your whole Java program into an intermediate form at once.
- Java compiles to bytecode, which the Java Virtual Machine (JVM) then runs.
- "Write once, run anywhere": the same bytecode runs on any machine with a JVM.
- Compile errors (caught before running) differ from run-time errors (caught while running).
Kinds of errors
- A syntax error 语法错误 breaks Java's grammar — the compiler refuses to build.
- A run-time error crashes the program while it runs (e.g. dividing by zero).
- A logic error 逻辑错误 runs fine but gives the wrong answer.
- Debugging is finding and fixing all three.
From source code to running program
See how Java source becomes a running program.
A program that compiles is not automatically correct. The compiler only catches syntax errors (broken grammar). A logic error — wrong formula, wrong condition — compiles cleanly and runs, but produces the wrong result. Always test your algorithm's output, not just whether it builds.
An algorithm to find the larger of two numbers a and b:
- Step 1: if
a > b, the answer isa. - Step 2: otherwise, the answer is
b. - Finite, ordered, and always finishes — a valid algorithm, ready to code in Java.
An algorithm is a finite, ordered set of steps that solves a problem; programming turns it into code. Java is a high-level language that a compiler translates to bytecode for the JVM. Watch for syntax, run-time, and logic errors — a clean compile does not guarantee a correct result.
An algorithm is best described as...
Finite, ordered steps that finish — that's an algorithm.
A Java compiler translates your source code into...
Java compiles to bytecode, which the JVM executes.
A program that compiles and runs but gives the wrong answer has a...
Wrong result despite clean compile = logic error.
A syntax error prevents a Java program from compiling.
Broken grammar → the compiler refuses to build.
If a program compiles with no errors, it is guaranteed to be correct.
The compiler catches syntax, not logic — always test the output.