APCS-A Unit 1: Primitive Types

Master the fundamentals of Java primitive types and ace your AP Computer Science A exam. This comprehensive review covers all essential concepts with interactive examples and practice problems.

Curious what some Java source code might look like that does the work of the review? Check out the code example that Copilot created to enhance this review! In addition, you can view the markdown file and the associated text file reviews that Copilot created in response to our prompts (which are listed in the header comments of the Java file).

May 2026 Exam Prep 2.5-5% of Exam Foundation Concepts

Study Progress

Complete the checklist to track your progress!

Quick Navigation
Overview Checklist Data Types Operations Type Casting Common Pitfalls Practice Exam Tips

Study Checklist

Check off each topic as you master it:

Primitive Data Types

int (Integer)

  • Range: -2,147,483,648 to 2,147,483,647
  • Use for: Counting, indexing, whole number calculations
int age = 16; int score = 95; int temperature = -10;

double (Floating-point)

  • Range: Approximately ±1.7 × 10308
  • Use for: Decimal calculations, measurements, averages
double gpa = 3.85; double temperature = 98.6; double pi = 3.14159;

boolean (Boolean)

  • Values: true or false only
  • Use for: Flags, conditions, yes/no situations
boolean isRaining = true; boolean passed = false; boolean ready = true;

char (Character)

  • Range: 0 to 65,535 (Unicode values)
  • Use for: Single characters
char grade = 'A'; char symbol = '$'; char initial = 'K';
Common Mistake

Using double quotes for char: char letter = "A";
Correct: char letter = 'A';

Arithmetic Operations & Operator Precedence

Operator Precedence (Order of Operations)

  1. Parentheses ()
  2. Unary operators ++, --, +, -
  3. Multiplication, Division, Modulus *, /, %
  4. Addition, Subtraction +, -

CRITICAL PROBLEM AREA: Integer Division

int result1 = 7 / 2; // Result: 3 (NOT 3.5!) double result2 = 7 / 2; // Result: 3.0 (still integer division) double result3 = 7.0 / 2; // Result: 3.5 (floating-point division) double result4 = 7 / 2.0; // Result: 3.5 (floating-point division)
Interactive Calculator Demo

Try different operations and see the results:

Enter an expression and click Calculate

Type Casting

Implicit Casting (Widening)

Java automatically converts from smaller to larger data types:

int i = 100; double d = i; // int → double (automatic) char c = 'A'; int ascii = c; // char → int (automatic)

Widening Order:
byteshortintlongfloatdouble

Explicit Casting (Narrowing)

Must use cast operator when converting from larger to smaller:

double d = 3.14159; int i = (int) d; // Result: 3 (decimal part truncated!) int large = 300; byte small = (byte) large; // Possible overflow!
⚠️ Data Loss Warning: Casting truncates, doesn't round!

MAJOR PITFALL: Casting in Expressions

int a = 7, b = 2; double result1 = (double) a / b; // 7.0 / 2 = 3.5 ✅ double result2 = (double) (a / b); // (double) 3 = 3.0 ❌

The placement of the cast operator matters!

Common Pitfalls & Problem Areas

int average = (80 + 90 + 70) / 3; // Result: 80, not 80.0!

Solution: Use double or cast:

double average = (80 + 90 + 70) / 3.0; // Result: 80.0

int result = 2 + 3 * 4; // Many think: (2+3) * 4 = 20 // Actual: 2 + (3*4) = 14

Remember: Multiplication/division before addition/subtraction!

(int) 3.9 // Result: 3 (not 4!)

Remember: Casting truncates, doesn't round!

double result = 0.1 + 0.2; // Result: 0.30000000000000004

Warning: Not exactly 0.3 due to floating-point representation!

Interactive Practice Problems

Click "Start Practice" to begin!
Practice Stats
Questions Answered:
0
Correct Answers:
0
Accuracy:
0%

Exam Strategy Tips

Multiple Choice Tips

  • Trace carefully: Work through each step methodically
  • Watch for traps: Look for integer division and precedence issues
  • Check data types: Pay attention to int vs double
  • Test edge cases: Consider negative numbers, zero, and overflow

Free Response Tips

  • Initialize variables: Always give variables initial values
  • Use meaningful names: Make your code readable
  • Comment tricky parts: Explain complex calculations
  • Test your logic: Mentally trace through your code
Time Management
  • Multiple Choice: ~1 minute per question
  • Don't get stuck: Mark difficult questions and return later
  • Double-check: Verify operator precedence and type casting

Pre-Test Checklist

The day before your test, ensure you can: