☕ Getting Started with Java

AP Computer Science A • Unit 1 • Activity 1.1.1 • Mr. Babb

Warm-up

Why learn Java?

Java is a widely used, platform-independent programming language. Thanks to the Java Virtual Machine (JVM), the same Java program can run on websites, phones, and video game consoles. People use Java to build mobile apps, music-mixing software, money management systems, and games.

Your first Java program

public class Welcome { public static void main(String[] args) { System.out.println("Welcome to PLTW Computer Science A."); System.out.println("Hope you have fun learning Java!"); } }

The lines beginning with public define the structure of the program. The two lines beginning with System are the sequence of steps the program completes — one at a time, in order. That's called sequencing.

(click Run to see the output)

🧠 Quick check

Before a Java program can run, a compiler translates the code into machine code and checks it for errors. What do you think happens if the compiler finds a mistake?

Learn the words

Vocabulary flashcards

Click a card to flip it. Use the arrows to move through the deck — say the definition out loud before you flip!

Prove it

Matching challenge

0 / 8 matched

Click a term, then click its definition. Match all 8 to unlock the next section.

Explore

Anatomy of a Java program

This program has 5 important parts. Click each highlighted line or symbol in the code to reveal what it does. Find all 5!

0 / 5 discovered

🔑 The rules you just discovered

  • The class name must match the file name: public class WelcomeWelcome.java
  • public static void main(String[] args) is the main method — the entry point. The JVM finds it and starts there.
  • Curly braces { } mark a block of code. Every open brace needs a matching close brace.
  • Every statement ends with a semicolon ;
  • A method is a named block of code that only runs when it is called.
Detective mode

Debug your first Java program

Bug 1 of 4

Errors in programs are called bugs, and fixing them is called debugging. This program HelloPLTW.java has 4 bugs. Read the compiler error, then click the line that contains the bug.

Experiment

print vs. println

System.out.println moves the cursor to a new line after printing. System.out.print stays on the same line. And inside quotes, escape sequences \n (new line), \" (double quote), and \\ (backslash) have special meanings.

🔬 Predict the output

System.out.print("Java "); System.out.println("is"); System.out.println("fun!");

How many lines of output will this print?

Build a program

Print Lab: make the smiley

Build a program line-by-line to produce exactly this output (this is the real Activity 1.1.1 challenge!):

Rules: use print at least twice, println at least twice, and all three escape sequences (\n, \", \\).

(your program is empty — add a statement above)
(output console)
Exit ticket

Show what you know

Answer all 8 questions, then click Grade my exit ticket. You can retry once to improve your score.

📝 Computer Science Notebook

Before you leave, add these to your notebook — you'll use them all year:

  • Sequencing defines an order for when steps in a process are completed — one at a time.
  • A compiler checks code for some errors; those errors must be fixed before the program can run.
  • A syntax error breaks the rules of the language and is detected by the compiler.
  • A method is a named block of code that only runs when it is called; a block of code is any code in braces.
  • A string literal is characters in double quotes; a literal is the code representation of a fixed value.
  • Escape sequences \", \\, and \n start with \ and have special meaning in Java.