1. Reference Guide

Key Topics


Term Definition Example
Variable Named storage location in memory for data. int age = 16;
Declaration Creating a variable with a type. double price;
Initialization Giving the variable a value at creation. double price = 4.99;
Assignment Giving a value later (after declaration). price = 5.99;
Primitive type Basic data types built into Java. int, double, boolean, char
Reference type Points to objects (more complex). String, Scanner
  • Primitive types don’t have methods
  • Reference types are objects and have methods associated with them

Java Data Types

Type Meaning Example Notes
int Whole numbers int year = 2025; Range: about -2 billion → 2 billion
double Decimal numbers double price = 4.99; More precise than float
boolean True/False boolean done = false; Used for conditions
char Single character char grade = 'A'; Always single quotes
String Text (sequence of chars) String name = "Paul"; Not primitive (it’s a class)

Picking a Type

  • Counting things → int
  • Money, measurements → double
  • Yes/No questions → boolean
  • One letter → char
  • Names, sentences → String

2. LxD Cycle Process

Empathize: Students pick a type by how the data looks, not by what they will do with it, so phone numbers become ints and averages lose their decimals. Interviews with first-year students found misconceptions about memory and about what happens when a primitive is declared (Kaczmarczyk et al., 2010).

Define:

  • POV: CSA students need to choose a type from what the data means, because the type decides what values fit and what you can do with them, and a wrong choice spreads through the whole program.
  • Learning Goal: Students will declare variables with int, double, boolean, and String, use final for values that never change, and say why String is a reference type.

Ideate:

  • HMW Question: How might we get students to ask “what will I do with this value?” before they pick a type?
  • HMW Question: How might we show that an int or boolean can never be null, but a String can?
  • Activity: Make variables for your own favorite things, choose types for everyday data in the MCQ, then build a small grade calculator.

Prototype:

  • A reference guide, runnable Java examples, personalized variable practice, an MCQ knowledge check, and a scaffolded grade rubric.
  • Students revise variable declarations after seeing compiler output or feedback.
  • Excellence means explaining why each type fits the data, using final appropriately, and improving the first attempt rather than only producing working code.

Test:

  • Ask peers in peer review to complete the practice without additional explanation.
  • Observe whether peers choose types based on meaning and intended operations.
  • Compare your lesson with another that is posted.
  • Use the findings to revise any instruction or rubric criterion that did not guide students clearly.
  • On submission, collect evidence from runner output, MCQ results, AI grading and student explanations.
  • After teaching, grading and analysis, come back and revise lesson to complete teaching cycle for continuous improvement.

3. College Board Requirements

AP CSA Unit 1, Topic 1.2 Variables and Data Types. Quoted from the course and exam description (College Board, 2025, p. 32):

  • 1.2.A.1 “A data type is a set of values and a corresponding set of operations on those values. Data types can be categorized as either primitive or reference.”
  • 1.2.B.1 “The three primitive data types used in this course are int, double, and boolean. An int value is an integer. A double value is a real number. A boolean value is either true or false.”
  • 1.2.B.2 “A variable is a storage location that holds a value, which can change while the program is running. Every variable has a name and an associated data type.”

The College Board also says char is “outside the scope of the AP Computer Science A course and exam” (College Board, 2025, p. 32). This lesson still uses it because it is handy in real code, but it will not be on the exam.


4. Lesson Plan

Learning Objective: Pick the best data type for a piece of information and declare, initialize, and assign variables correctly.

Success Criteria: You can choose a type from what the data means, use final for values that never change, and explain the difference between primitive and reference types.

Tech Talk (5 minutes)

A variable is a labeled box that holds a value. Every variable has a name and a type.

Pick the type by asking two things: what values go in, and what will I do with them?

Code Runner Challenge

Run it, then change a value and predict the new output

View IPYNB Source
int siblings = 2;              // whole numbers you count
double gpa = 3.75;             // decimals you average
boolean isHungry = true;       // only true or false
String name = "Alex";          // text you display
final int DAYS_IN_YEAR = 365;  // never changes
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

5. Code Examples

A. Variable basics. The VariableBasics class is defined to Declare, Assign, Print sample variables

Three steps get mixed up a lot:

<code class=\"language-java\">
int number;      // declaration: makes the box
number = 10;     // assignment: puts a value in
int age = 16;    // a declaration with initialization: both at once
</code>

Terminalogy:

int, double, and boolean are primitive: they hold the value itself and can never be null. String is a reference type: it points at an object, so it can be null.


Code Runner Challenge

Run it, then try int emptyNumber = null; and see what the compiler says

View IPYNB Source
// CODE_RUNNER: Run it, then change a value and predict the new output
// Simple Variable Examples
public class VariableBasics {
    // Step 1: Declare variables (create empty boxes)
    String name;
    int age;
    double gpa;
    boolean isStudent;

    // Step 2: Make a method to print the values of the variables
    void printVariables() {
        System.out.println("Name: " + name);
        System.out.println("Age: " + age);
        System.out.println("GPA: " + gpa);
        System.out.println("Is student: " + isStudent);
    }

    public static void main(String[] args) {
        // Step 3: Create an instance of the class to access instance variables
        VariableBasics basics = new VariableBasics();

        // Step 4: Print initial values of the variables
        System.out.println("Initial values:");
        basics.printVariables();

        System.out.println("-------------------");

        // Step 5: Put values in the declared variable boxes
        basics.name = "Alex";
        basics.age = 16;
        basics.gpa = 3.77;
        basics.isStudent = true;

        // Step 6: Print the values
        System.out.println("Updated values:");
        basics.printVariables();
    }
}
VariableBasics.main(null);

Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

B. Variable comparison. The TypeComparison class shows the differenct between Primitive and Reference

Common cmparison mistake:


number1 == number2         // primatives use ==
string1.equals(string2)    // string uses .equals

Terminology:

Primitives hold the value. References point at an object, so they either contain an address, or they default to null.


Code Runner Challenge

Replace the sample values with your own, then run it

View IPYNB Source
// CODE_RUNNER: Run it, then try int emptyNumber = null; and see what the compiler says
// Simple vs Fancy Variable Types
public class TypeComparison {
    // Simple types (primitives) - store the actual value
    int number1 = 5;
    int number2 = 5;

    // Fancy types (reference) - more complex
    String word1 = "Hello";
    String word2 = "Hello";

    // String can be empty (null), but int cannot
    String emptyText = null;

    // This would cause an error:
    // int emptyNumber = null; // NOT ALLOWED!

    public static void main(String[] args) {
        TypeComparison types = new TypeComparison();
        System.out.println("Same number? " + (types.number1 == types.number2)); // true
        System.out.println("Same word? " + types.word1.equals(types.word2)); // true
        System.out.println("Empty text: " + types.emptyText);
    }
}

TypeComparison.main(null);
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

6. Hacks & Practice Tasks

Prepare your submission IPYNB

  1. Create a new notebook in your portfolio homework area: _notebooks/homework.
  2. Add one raw cell at the top with the frontmatter:

Code Runner Challenge

Fill in the blanks, then run it

View IPYNB Source
---
layout: post
codemirror: true
title: Variables and Data Types HW
categories: [Java]
lesson_language: Java
lesson_topic: Variables-and-Data-Types HW
lesson_part: interactive
lesson_type: lesson
permalink: /csa/unit_01/1_2-hw
author: yourGithubID
---
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...
  1. Add code cells for the Popcorn Hack and the Homework Hack. Make sure every cell runs with visible output.
  2. Submit the link to your published page at the bottom of this page, and paste this in the description box:
Lesson: CSA 1.2 Variables and Data Types
MCQ 1.2: <paste the copied result line, such as 5/6 | answers: A,C,B,A>
Popcorn: six variables declared (String, int, double, boolean, char, final int), runs and prints
Homework: final student name and final class name used (yes/no)
Homework: three int scores = <s1>, <s2>, <s3>
Homework: average printed = <value>, letter grade = <letter>

Submission Safety Rules (Read First)

  • One class per cell, ending with ClassName.main(null);.
  • Run each cell and leave the output showing.
  • Use your own values, not the sample answer.
  • Include your MCQ score.
  • Use ## headings or smaller.

Popcorn Hack (In-Class)

2-minute challenge: make variables for your favorite things, then run the cell.

  1. Favorite food (text)
  2. Your age (whole number)
  3. Your height in feet (decimal)
  4. Do you like pizza? (true or false)
  5. First letter of your favorite color
  6. Your birth year (this never changes, so which keyword do you add?)

Replace the sample values with your own.

// CODE_RUNNER: Replace the sample values with your own, then run it
// Practice #1 - Try it yourself first!
public class MyFavoriteThings {
    // Try writing your own code here first!

    // Sample answer:
    String favoriteFood = "Pizza";
    int myAge = 16;
    double heightInFeet = 5.5;
    boolean likesPizza = true;
    char colorFirstLetter = 'B';  // Blue
    final int BIRTH_YEAR = 2008;  // Never changes

    public static void main(String[] args) {
        MyFavoriteThings me = new MyFavoriteThings();
        System.out.println("Favorite food: " + me.favoriteFood);
        System.out.println("Age: " + me.myAge);
        System.out.println("Height: " + me.heightInFeet + " feet");
        System.out.println("Likes pizza: " + me.likesPizza);
        System.out.println("Favorite color starts with: " + me.colorFirstLetter);
        System.out.println("Born in: " + me.BIRTH_YEAR);
    }
}

MyFavoriteThings.main(null);

MCQ Check

4 questions, one at a time. Answer, check, then go to the next one. At the end, copy the score line into your submission notes.

Homework Hack

Task: Build a grade calculator. Store the student’s name and the class name in final variables, store three test scores as int, then print the average and the letter grade.

Solution Skeleton:

// CODE_RUNNER: Fill in the blanks, then run it
public class GradeCalculator {
    final String STUDENT_NAME = "Your Name";
    final String CLASS_NAME = "AP CSA";

    // 1. Three test scores as whole numbers
    int test1 = 0;
    int test2 = 0;
    int test3 = 0;

    // 2. Add them up and find the average
    double average = 0.0;

    // 3. Pick the letter grade (90 = A, 80 = B, 70 = C, 60 = D, else F)
    String grade = "?";

    public static void main(String[] args) {
        GradeCalculator calculator = new GradeCalculator();
        System.out.println(calculator.STUDENT_NAME + " in " + calculator.CLASS_NAME);
        System.out.println("Average: " + calculator.average);
        System.out.println("Grade: " + calculator.grade);
    }
}

GradeCalculator.main(null);

Grading Plan (1 Point Total)

Part Points What earns the points
Popcorn 0.2 Six variables with fitting types, including a final birth year, and the cell runs.
MCQ 0.2 5 or 6 correct. 0.15 for 3 or 4, 0.1 if every question was answered.
Homework: final values 0.15 Student name and class name stored in final variables.
Homework: scores 0.15 Three test scores stored as int.
Homework: average 0.15 Average of the three scores calculated and printed.
Homework: letter grade 0.15 Letter grade printed.
Total 1.0  

Quick Validation Checklist

  • Each cell ends with ClassName.main(null); and shows output.
  • MCQ score in the notes.
  • final on the birth year and on both names.
  • Three int scores, a printed average, and a letter grade.

7. Lesson Revisions

Revision Made: Lesson authors: what you changed because of it.


8. Feedback Evidence

Feedback Received: Lesson authors: what your peers said in the practice run.


9. References

College Board. (2025). AP Computer Science A course and exam description [Effective fall 2025]. https://apcentral.collegeboard.org/media/pdf/ap-computer-science-a-course-and-exam-description-effective-fall-2025.pdf

Kaczmarczyk, L. C., Petrick, E. R., East, J. P., & Herman, G. L. (2010). Identifying student misconceptions of programming. In Proceedings of the 41st ACM Technical Symposium on Computer Science Education (pp. 107–111). Association for Computing Machinery.

Submit Assignment

Your code will be saved as a Gist and reviewed automatically. You must be logged in to submit.

Need to update a submission later? Open the submissions dashboard.