CompSci Blogs

August 2023 to June 2024

Unit 1

While this is not a significant portion of the exam, the topics covered in this unit are ESSENTIAL to succeeding in this course. AP Computer Science A (or AP CSA for short) is a course that builds on previous topics covered, so make sure you know this unit inside and out, and come back to review it frequently. You will use these foundations in every subsequent unit.

1.1

Programming is the process of writing that code. With programming, you can build websites, mobile apps, Chrome extensions, and many other types of software. This software can make your life more convenient and can be used to help others as well.

public class Main {
    public static void main(String[] args) {
        System.out.prinln("Hello World!");
    }
}
public: command not found
bash: syntax error near unexpected token `('
bash: syntax error near unexpected token `"Hello World!"'
bash: syntax error near unexpected token `}'
bash: syntax error near unexpected token `}'

1.2

int age;
age = 15;

int age = 15;

// Inputs
import java.util.Scanner;
Scanner input = new Scanner(System.in);

1.3

int ab = 5 + 2;
int bc = 5 - 2;
int cd = 5 * 2;
int de = 5 / 2;
int ef = 5 % 2;

double ab2 = 5 / 2.0;
Command 'int' not found, but there are 19 similar ones.
Command 'int' not found, but there are 19 similar ones.
Command 'int' not found, but there are 19 similar ones.
Command 'int' not found, but there are 19 similar ones.
Command 'int' not found, but there are 19 similar ones.
Command 'double' not found, but can be installed with:
sudo apt install plotutils

1.4

int age = 5

// Compound Operators
age = age + 1;
age += 3;
age++;

1.5

Printing and Comments

The System.out.print and System.out.println methods are used to send output for display on the console. The only difference between them is that the println method moves the cursor to a new line after displaying the given data, while the print method does not. A comment is any text in a source code file that is marked to not be executed by the computer. In Java, single line comments are denoted by //, and multiline comments are demarcated by /* and /, as in the following examples: // this is a single line comment / This is a multiline comment. All of this will be ignored by the computer.

Data Types

Every value in a program is of a certain type, and that type determines what operations can be performed on the value. Every type is categorized as being either a primitive type or a reference type.

Though Java has eight primitive types, only the three shown in the table below are used in AP Computer Science A. All primitive data can be represented using literals, which are representations in code of exact values.

DataTypes