Unit 1: Primitive Types Flashcards

1
Q

What are primitives?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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);

A

c) (Type) (Name) = (Value);

ex: int num = 10;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What values can int hold?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What values does double hold?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What values does char hold?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is casting?

A

Type casting is when you assign a value of one primitive data type to another type.
Ex.

int total = 100;
int numPeople = 40;  
double average = total / (double) numPeople;
//Average will equal 2.5 as a double
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a compound assignment operator?

A

A simpler way to assign an arithmetic value to a pre-existing value. (+= , /=, *=, -=)

Ex:

int num = 8;
num += 7;
//Now num will equal 15
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the correct way to create a Scanner object?

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does “final” do when used while initializing a primitive?

A
The word "final" makes it such that you cannot modify the variable after its initialization. 
Ex. final String name = "Chad";
//This String will always be Chad.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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

A

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:

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does modulus (%) do?

A

It returns the remainder of a division operation.

Ex. 25%7 = 4
Ex. 25%5 =0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a reference type?

A

An example of a reference value would be a string.

Reference variables store the address of the value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the correct way to name a variable?

A
Variables names must start with a letter, $, or _ and be lowerCamelCase
examples include:
- numApples
- $numApples
- _numApples
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does a String hold?

A

A String holds a list of ASCII characters or numbers. For example any word in the English language.

Ex. String numbers = “123456789101123456789011223344556677”;
String words = “Cat dog mice cows horses !@#$%^&&* more things”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Is a string a Primitive

A

It is not because it has chars in it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

int thing = 2*2.2;

A

4

17
Q

double thing = 2.2 *2;

A

4.4

18
Q

How do you print things out

A

System.out.print(“THing”); or

System.out.println(“THings”);

19
Q
What is the Answer of this expression?
4 + 8 * 3 / 4 + 5 % 2 = ?
A.) 5 
B.) 6
C.) 12
D.) 11
A

D.) 11
PEMDAS don’t forget that modulus is treated as multiplication or division so don’t forget to follow the order of operations.

20
Q

What is the result of the following expression when x is 125?
x % 6

A

5

Don’t forget that modulus returns the remainder.

21
Q
Which of the following values can correctly be saved in a boolean?
A.)False
B.)Yes
C.)no
D.)true
A

D.) true

Boolean values in java save true/false values without a capitalized letter