Intro to Algorithms, Programming & 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 }. The file itself has to be named the same as the class — MyClass.java for public class MyClass.
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. Write and run it there, then copy your finished code into this course's checker when an exercise asks for it.
- Use this course's built-in checker directly — no copying needed. This part of the course is still being built, so it's not ready yet.
For now, the first option is what actually works: write and run your code in a real IDE (or an online one, like Replit), then paste the result in when an exercise asks for it. (This section will get an update once the built-in checker exists.)
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 likeDrivetrain. - SCREAMING_SNAKE_CASE — constants (values that never change) are all uppercase with underscores between words:
MAX_SPEED,PI. You'll see this style starting 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 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
int score = 10; // 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.
Systemis capitalized (it's a class);public,class,voidare 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 amainmethod 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, then paste it in when an exercise asks for it.
//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)