Intro to Algorithms, Programming and Compilers

Algorithms

An algorithm is just a set of ordered steps to solve a problem — a recipe, directions to a house, and a Java program are all algorithms. Steps run in order, one at a time — this is called sequencing.

Before writing real code, it helps to plan the steps first: in plain English, a diagram, or pseudocode (simplified fake-code written on paper, not run by anything). Getting the steps straight on paper first is what turns a half-formed idea into code that actually works.

Your First Java Program

Every Java program lives inside a class, and every class you run needs a main method — that's where the program starts running.

public class MyClass
{
    public static void main(String[] args)
    {
        System.out.println("Hi there!");
    }
}

Every open curly brace { needs a matching close }. Each word in public static void main(String[] args) gets its own full explanation later — String[] args in Ch.4, public/static more fully in Ch.7, where void fits among method return types in Ch.9 — for now, treat the whole line as fixed boilerplate every program starts with.

When you compile normally (javac, or most IDEs), the file has to be named the same as its public class — MyClass.java for public class MyClass. Running a single file directly with java MyClass.java doesn't enforce this, but matching the names is still the habit to build.

On Java 25: you may also see an even shorter void main() { ... } with no class and no public static — a newer shortcut for quick scripts (JEP 512). This course always uses the full form shown above, since it works unchanged on Java 17 too.

Every Statement Ends With a Semicolon

Each individual instruction is a statement, and every statement ends with ; — think of it like a period ending a sentence.

System.out.println("Hi there!");

Miss it, and the program won't compile. This is one of the most common mistakes when you're starting out — expect it, don't stress about it.

Not everything ends in ;. A line that opens a block, like the class or main line above, has no semicolon before its {.

Compiling: How Your Code Actually Runs

Computers don't understand Java directly. A compiler checks your code for mistakes and translates it into something the computer can run. If it finds a mistake, it stops and tells you — that's a syntax error.

For this course, you have two ways to write and run your code:

  • Use your own IDE, like VS Code with the Java extension — genuinely how most FRC teams write real robot code, so it's good practice either way.
  • Use an online IDE, like Replit, if you don't want to install anything yet.

Write and run your code in one of those to see it actually work. This lesson's own exercises are multiple-choice and reorder (Micro-Parsons) puzzles, so you don't need to submit code anywhere to complete them — a text-submit coding checker, for later chapters, is still being built.

Keywords and Naming

Words like public, class, and void are keywords — reserved words with a fixed meaning in Java. Keywords are always lowercase.

Everything else — every name you pick yourself — follows one of three styles:

  • lowerCamelCase — variables and methods start lowercase, then capitalize each new word: motorSpeed, calculateTotal().
  • PascalCase (also called UpperCamelCase) — classes and interfaces capitalize every word, including the first: System, String, or a class you write yourself like Drivetrain.
  • SCREAMING_SNAKE_CASE — constants (values that never change) are all uppercase with underscores between words: MAX_SPEED, PI. You'll meet real constants starting in Ch.7.4; final, what actually makes a value a constant, gets full treatment in Ch.23.

That's why System.out.println(...) looks the way it does: System is a class, so it's PascalCase. println is a method — here it's just one word, so there's no second word to capitalize, but it still starts lowercase like every method name does.

Syntax Errors vs. Run-Time Errors

  • A syntax error is caught by the compiler, before your program ever runs — a missing ;, an unmatched { or ".
  • A run-time error happens while the program is running, after it already compiled — like dividing a whole number by zero.

Both are normal. Finding and fixing errors is called debugging — informally, an error is a "bug." If you're stuck, explaining your code line-by-line out loud — even to an inanimate object, a real technique called "rubber duck debugging" — often reveals the problem before you finish explaining it.

Comments

// starts a comment that runs to the end of the line; /* ... */ comments out everything in between, even across multiple lines. The compiler ignores comments completely — they exist to explain your code to yourself and your teammates.

// this line is ignored by the compiler
System.out.println("Hi there!"); // so is this part, after the //

Common Pitfalls

  • Missing a semicolon. The single most common first error — check the end of the line the compiler points at, and the line just before it.
  • Mismatched capitalization. System is capitalized (it's a class); public, class, void are not (they're keywords). Java is case-sensitive everywhere.
  • Trusting the error's line number completely. The compiler tells you where it noticed the problem, which is sometimes a line or two after where the actual mistake is.

Key Takeaways

  • An algorithm is an ordered set of steps, run one at a time (sequencing) — you already use these outside of code.
  • Planning steps in plain English or pseudocode before coding turns a half-formed idea into working code.
  • Every Java program has a class, and a main method where it starts running.
  • Every statement ends with ;.
  • Three naming styles: lowerCamelCase (variables/methods), PascalCase (classes/interfaces), SCREAMING_SNAKE_CASE (constants).
  • A compiler checks your code and translates it to run; a syntax error is a mistake it catches before your program ever runs.
  • Write and run code in a real IDE (like VS Code) or an online one; this lesson's exercises are multiple-choice and reorder puzzles, not a code checker.
  • // and /* */ are comments — the compiler ignores them completely.

Derived from csawesome-2026: unit-1-using-objects-and-methods/1.01-introduction-to-algorithms-programming-and-compilers.md (CSA 1.1)