Unit 1: Primitive Types Flashcards Preview

AP CS-Applications > Unit 1: Primitive Types > Flashcards

Flashcards in Unit 1: Primitive Types Deck (13)
Loading flashcards...
1

What is the correct way to initialize a primitive?

a) [type] [name] = new [type]();
b) [name] [type] = [value];
c) [type] [name] = [value];
d) [type] [name] == [value];

c) [type] [name] = [value];

ex: int num = 10;

2

What are primitives?

Primitives are the simplest elements available in a programming language. Ex. int, double, char, boolean

3

int

The int data type stores whole numbers from -2,147,483,648 to 2,147,483,647.

4

double

The double data type stores decimal numbers up to 15 decimal digits

5

char

The char data type stores a single character/letter or ASCII values.

6

Casting

Type casting is when you assign a value of one primitive data type to another type.
Ex.
public class Casting
{
public static void main(String[] args)
{
int total = 100;
int numPeople = 40;
double average = total / (double) numPeople;
}
}

7

What is a compound assignment operator?

A simpler way to assign an arithmetic value to a pre-existing value.

ex: += , /=

8

What is the correct way to create a Scanner object?

a) Scanner = new Scanner(System.in);
b) scanner object = new scanner;
c) Scanner objectName = new Scanner(System.in);
d) Scanner objectName = System.in;

c) Scanner objectName = new Scanner(System.in);

9

What does "final" do when used while initializing a primitive?

"final" makes it such that you cannot modify the variable after its initialization.

10

How do you swap the data stored in two variables of the same type?

Through the use of a temp variable that stores the data of one of the variables so that it is not lost.

For example, if you have variables a and b, and you want to switch their values:

temp c;
c = a;
a = b;
b = c;

11

modulus (%)

returns the remainder of a division operation.

Ex. 25%7 = 4

12

What is the correct way to name a variable?

Variables names must start with a letter, $, or _ and be lowerCamelCase
examples include:
- numApples
- $numApples
- _numApples

13

What is a reference type?

An example of a reference value would be a string.
Reference variables store the address of the value.