AP Computer Science A

Advanced Placement Computer Science A focusing on Java programming and object-oriented design.

Basic Concepts

Variables, Data Types, and Operators

Storing and Manipulating Data

Computers need to store information and perform calculations. In Java, we use variables to store data, data types to define the kind of data, and operators to manipulate it.

Common Data Types

  • int: Whole numbers (e.g., 10, -3)
  • double: Decimal numbers (e.g., 3.14, -0.001)
  • boolean: True or false
  • char: Single characters, like 'A' or 'z'
  • String: Text, like "Hello!"

Operators

  • Arithmetic: +, -, *, /, %
  • Assignment: =, +=, -=
  • Comparison: ==, !=, <, >, <=, >=
  • Logical: &&, ||, !

Example Code

int age = 16;
double price = 4.99;
boolean isStudent = true;
String name = "Taylor";

if (isStudent && age < 18) {
  System.out.println(name + " gets a discount!");
}

Real-World Applications

Variables and operators are everywhere: from banking systems tracking balances to video games calculating health points.

Tips

  • Choose meaningful variable names.
  • Match the data type to the information you want to store.

Examples

  • Using int to count the number of books in a library.

  • Checking if a user is old enough to drive using comparison operators.

In a Nutshell

Variables hold data, data types define the kind of data, and operators let you perform calculations and checks.