Caveat Academic Services
Every course and price · Practice course
Practice course · Grades 10 to 12 · Follows the AP Computer Science A (Java) course and exam

AP Computer Science A Practice Course

A six-unit practice course that follows AP Computer Science A: Java basics, selection and iteration, classes and objects, arrays and ArrayLists, inheritance, polymorphism and recursion, and a final unit on exam strategy for multiple-choice tracing and the four free-response question types. Plan on about 8 to 10 weeks at three lessons a week, with each lesson taking about 40 minutes including practice, and keep a free Java compiler or a free online Java runner open while you work.

Read lesson 1 belowSelf-pacedIncluded with Caveat Plus
Cover of AP Computer Science A Practice Course

6 modules · 18 lessons · about 14 hours · practice after every lesson and an exam for every module

Module 1 · Lesson 1 of 3

Programs, variables and primitive types

Java is the programming language used in AP Computer Science A. A Java program is organized into classes, and a program starts running in a special method named main. To follow this course you need a way to compile and run Java: a free Java Development Kit (JDK) installed on your computer, or a free online Java runner in your browser. Either is enough. Type every example yourself, run it, and compare the output with what you predicted.

Worked example: a complete program

  1. public class Hello {
  2. public static void main(String[] args) {
  3. System.out.println("Hello from Java.");
  4. }
  5. }
  6. The class name Hello must match the file name Hello.java.
  7. main is where the program begins. The braces group the statements that belong to the class and to the method.
  8. Output: Hello from Java.

Statements and output

Each statement ends with a semicolon. System.out.println prints its argument and then moves to the next line. System.out.print prints without moving to a new line, so the next output continues on the same line. Java is case-sensitive: println works, but Println does not compile. Comments start with two slashes and are ignored by the compiler.

Variables and primitive types

Variable
a named place in memory that holds one value of a fixed type
Declaration
a statement that creates a variable and gives it a type, such as int count;
Assignment
storing a value in a variable with the = sign
int
a primitive type for whole numbers from about negative 2.1 billion to about positive 2.1 billion
double
a primitive type for numbers with a decimal part, such as 3.5 or 2.0
boolean
a primitive type with exactly two values, true and false
Literal
a value written directly in code, such as 42, 3.14, true or "hi"

A variable is declared once with a type and a name, and its type never changes. You may assign a new value as often as you like. Names may use letters, digits and underscores but cannot begin with a digit, and by convention they start with a lowercase letter and capitalize later words, as in totalScore. An int literal has no decimal point; a double literal has one. You may store an int in a double variable because nothing is lost, but storing a double in an int variable is a compile-time error unless you cast, which the next lesson covers.

Worked example: tracing assignments

  1. int a = 4;
  2. int b = a + 2;
  3. a = 10;
  4. System.out.println(a + " " + b);
  5. Line 2 computes b from the value a holds at that moment, which is 4, so b is 6.
  6. Line 3 changes a to 10. It does not go back and recompute b.
  7. Output: 10 6

Constants

Adding the word final to a declaration makes it a constant: final int MAX_PLAYERS = 4; Any later attempt to assign to MAX_PLAYERS is a compile-time error. Constants are usually written in all capitals with underscores.

The rest of the course comes after checkout

This is the real start of lesson 1.

What you will be able to do

  • Compute the result of Java expressions involving primitive types, integer division, casting and String methods.
  • Analyze code with conditionals, loops and nested loops by building a trace table.
  • Design classes with private instance variables, constructors, accessors and mutators, and explain references and aliasing.
  • Apply standard traversal, search and sort algorithms to arrays, ArrayLists and 2D arrays.
  • Explain inheritance, overriding and polymorphism, and trace recursive methods and binary search.
  • Evaluate free-response code against the common deductions and fix the errors it contains.
  • Compare a compile-time error with a runtime error and predict which one a given line causes.

What is in the course

  1. Module 1: Java basicsPrograms, variables and primitive types · Arithmetic, casting and the Math class · Strings, compile-time errors and runtime errors · about 2.3 hours
  2. Module 2: Selection and iterationBoolean expressions and if statements · while and for loops · Nested loops, string algorithms and tracing · about 2.6 hours
  3. Module 3: Classes and objectsWriting a class: instance variables and constructors · Methods, static versus instance, scope and this · References, null, and wrapper classes · about 2.2 hours
  4. Module 4: Arrays and ArrayListsArrays and standard traversal algorithms · ArrayLists and searching · 2D arrays, selection sort and insertion sort · about 2.3 hours
  5. Module 5: Inheritance, polymorphism and recursionInheritance: superclasses, subclasses and super · Polymorphism and interfaces · Recursion, binary search and merge sort · about 2.3 hours
  6. Module 6: Exam strategyThe exam format and multiple-choice tracing · Free-response: methods and control structures, and classes · Free-response: arrays, ArrayLists and 2D arrays, and common deductions · about 2.4 hours

For families

A practice course; it does not replace the AP class or award credit. AP is a registered trademark of the College Board, which does not endorse this course. Your student needs only a computer with a free Java compiler installed or a free online Java runner in a browser, with nothing to buy. Plan on about 8 to 10 weeks of 40 minute sessions, and you can help by asking your student to explain one short program out loud each week; being able to trace code aloud is the single most useful exam skill.

See every course

Secure checkout by StripeYour card details go to Stripe, not to us.
Ready right after checkoutNothing to wait for. It stays in your account.
For your familyIncluded with Caveat Plus. Questions: team@caveatacademic.com.

For use by the purchasing family; please do not resell or post it. Questions or a problem with an order: team@caveatacademic.com. Caveat Academic Services is independent and not affiliated with any school district or curriculum publisher.

Written with AI, then checked before it is published. How we checkFound a mistake? Report it and we fix it, or refund you.Cancel anytime.