AP Computer Science A - Primitive Types (Unit 1) Test Review

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/153

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

154 Terms

1
New cards

it is a javadoc comment

What does */ mean?

2
New cards

-it is an inline comment

-for example, it could be something like: double sum; // we defined the double variable sum

-in the example above, everything after // was the inline comment

What does // mean?

3
New cards

Class

where the program lives in memory

4
New cards

public class ______________________;

What is the class header in Java?

5
New cards

the class body

What is below the class header?

6
New cards

methods

What goes inside the class body?

7
New cards

public static void main(String[] args);

What is the main method header?

8
New cards

they tell something to happen

What do methods do inside classes?

9
New cards

a class is like your house and the method is like the power in your house

What is an analogy that can be used to relate classes to methods?

10
New cards

it is an "at author tag"

What does @author mean?

11
New cards

System.out.println(); and System.out.print();

-a method inside the main method

-inside the parentheses, you put in a parameter/argument to get some output after the method acts on it

<p>-a method inside the main method</p><p>-inside the parentheses, you put in a parameter/argument to get some output after the method acts on it</p>
12
New cards

no, the spacing is just for readibility

-meaning that you can have single spaced or double spaced lines

Does spacing between lines matter when writing code? What is the spacing for?

13
New cards

1. it receives your code (the source code file)

2. it compiles (translates it to the computer)

3. now it has the bytecode file (a bunch of 0's and 1's)

4. now it executes (runs) the code

What are the four steps to a program running, in Java?

14
New cards

it receives you source code file (the code you wrote)

What is the first step in Java running a code?

15
New cards

it compiles the code (checks your code for any errors and then translates it to a bunch of 0's and 1's)

What is the second step in Java running code?

16
New cards

it gets the bytecode file (the code that only has 0's and 1's)

What is the third step in Java running code?

17
New cards

it executes the code (runs the code)

What is the fourth step in Java running code?

18
New cards

Compiling

-the second step in Java running your code

-basically, the computer checks for errors, and if there are no errors, then it converts your program to 0's and 1's

19
New cards

Execute

-the fourth and final step of Java running your code

-basically Java will follow all the commands and directions that you gave it in the code, and it will run your code

20
New cards

double quotations " "

What must we put all strings in?

21
New cards

string data type variables

What can strings be stored inside?

22
New cards

we can concatenate the two strings or the string and the variable

What can we do if we want to combine two or more strings or if we want to combine a string with something that is inside a variable?

23
New cards

-System.out.print();

-System.out.println();

What are the two methods used to print things in Java?

24
New cards

System.out.print(); prints code without forcing a new line, but when you use System.out.println();, Java forces a new line after it executes the print statement

How is System.out.print(); different from System.out.println();?

25
New cards

it adds a tab

What does the shortcut, /t, do?

26
New cards

it adds a new line

What does the shortcut, /n, do?

27
New cards

-compile-time error: incorrect syntax like spelling errors, no parentheses, etc.

-run time error: a problem during program execution that causes the program to terminate/stop

-logical error: the program runs but produces incorrect results (for example, if you used a wrong formula, etc.)

What are the 3 major types of errors when coding in Java?

28
New cards

Compile time error

incorrect syntax like spelling errors, no parantheses, etc.

<p>incorrect syntax like spelling errors, no parantheses, etc.</p>
29
New cards

Run time error

a problem during program execution that causes the program to terminate/stop

<p>a problem during program execution that causes the program to terminate/stop</p>
30
New cards

Logical error

the program runs but produces incorrect results (for example, if you used a wrong formula, etc.)

<p>the program runs but produces incorrect results (for example, if you used a wrong formula, etc.)</p>
31
New cards

-not having a semicolon ; after each line

-if DOUBLE quotes are not placed around strings

-if you forget to put brackets {} at the very start and the very end of the entire code

What are some common errors in Java?

32
New cards

a semicolon ;

What do you need to put after each line of code?

<p>What do you need to put after each line of code?</p>
33
New cards

brackets {}

What must be placed at the very beginning and end of the code?

34
New cards

Debugging

fixing errors in your programming

35
New cards

-numbers (1, 2, 3, etc.)

-letters (a, b, c, etc.)

-symbols (#, $, %, etc.)

What can strings contain, as long they are in double quotes?

36
New cards

they manage data

What do programs do?

37
New cards

in memory

Where is data stored?

38
New cards

slots

What does the computer's memory has, that tells us the address of data?

39
New cards

Variables

the names of each slot of the computer's memory that holds data from the program

40
New cards

its data type, its name, and its value

What does each variable have?

41
New cards

yes

Can the value of a variable change throughout the code?

42
New cards

-the variable's data type is String

-the name is quote

-the value is "Don't quit"

In the following declaration and assignment of the variable, what is the variable's data type, what is its name, and what is its value?:

String quote = "Don't quit";

43
New cards

the assignment operator, that sets the value of a variable

What is = in Java?

44
New cards

we can define it like this:

int fortniteWins

and then we can set it to a value like this:

int fortniteWins = 20

How do we define a variable and then set its value?

45
New cards

it gets some default value that is determined by its data type

If no value is set, then what value does a variable get? Why is this value determined by?

46
New cards

yessir

Can you declare multiple variables of the SAME data type on the same line?

47
New cards

no

Can you set the values of multiple variables of any data type (whether they have the same data type of not), on the same line?

48
New cards

nope

Can you declare multiple variables of DIFFERENT types on the same line?

49
New cards

-the name must be unique and cannot be a copy of some method in Java or something

-it cannot begin with a number

-the names are case sensitive (upper vs lower case)

-use camelCase style for longer name, where the first word is all lower case and then all the words afterwards start with a capitalized letter

What are the rules for writing variable names?

50
New cards

Concatenation

-values can be combined by using the + operator

-for example, String name = "Naruto"

System.out.print("My name is " + name)

-in this example, we ____________ the string, "My name is " with the variable name

-we never put variables in quote when ________________

51
New cards

never

Do we ever put variables in quotes when concatenating?

52
New cards

Scanner

a class that allows us to read text from a given input

53
New cards

import java.util.Scanner;

Scanner scan = new Scanner(System.in);

System.out.println(" ")

String input = scan.nextLine

-"scan" is the name of the scanner, "new Scanner" initiates a new scanner object, and "(System.in)" lets the user input into the console

-when we use the print method, we essentially let the user input something into the console

-In String input = scan.nextLine();, we are checking for what the user inputted into the console and then storing that in the variable, input

How do we use the scanner class?

54
New cards

-by doing something like this System.out.println(variable1 + " " + variable2);

-as you can see, we purposefully put a space between the two double quotes to create a space between the two variables

When we concatenate, how we put spaces between two variables?

55
New cards

-int

-byte

-short

-long

-double

-float

-char (a single letter)

-boolean

-we really only need to worry about double, int, and boolean

What are the 8 primitive data types?

56
New cards

reference data type

What type of data type are strings?

57
New cards

-128 to 127

What is the domain (range of input values) for a byte?

58
New cards

-32,000 to 32,000

What is the domain (range of input values) for a short?

59
New cards

-2 billion to 2 billion

What is the domain (range of input values) for an int?

60
New cards

-9 quintillion to 9 quintillion

What is the domain (range of input values) for a long?

61
New cards

6 to 9 significant figures

What is the domain (range of input values) for a float?

62
New cards

15 to 17 significant figures

What is the domain (range of input values) for a double?

63
New cards

-ints are 32 bit (take up less memory) and they CANNOT hold decimal values (only whole numbers)

-doubles are 64 bit (take up more memory), their values can either be decimals or whole numbers, and they add .0 to the output when a whole number is inputted

What is the difference between an int and a double?

64
New cards

double, since they are 64 bit, while ints are only 32 bit

Do ints or doubles take up more memory?

65
New cards

an int cannot hold a decimal value, but doubles can hold either decimals or whole numbers

Can an int hold a decimal value? What about a double?

66
New cards

Char

-16 bit

-it stores a single symbol using single quotes ' '

-it can store any symbol from the unicode character set

-English uses characters from a subset of unicode called ASC ||

-it can print special characters using the \u escape sequence, followed by the code

67
New cards

-without having to use the math class

-for example:

int number = 4;

int newNum = 4 * number;

System.out.print(newNum);

Basic expressions can be utilized without having to use what? What is an example of a basic expression?

68
New cards

for strings

What data type do we use scan.nextLine(); for?

69
New cards

for ints

What data type do we use scan.nextInt(); for?

70
New cards

for doubles

What data type do we use scan.nextDouble(); for?

71
New cards

-values of variables that have been locked in place using the final modifier, meaning that they cannot change later on

-these types of values cannot be changed by the user

-for example, you might want to use the final modifier for a number like pi when creating code that finds the area of a circle

What are final values?

72
New cards

-it goes through your datatypes and checks the domain of that variable/all the possible values you can store for that variable and also the functions that we can do with the data in the variable

-Java knows what the domain and functions are depending on the datatype

Before allocating memory for a certain variable, what does Java do?

73
New cards

a datatype of variables that can only hold integers (positive and negative whole numbers)

What is an int?

74
New cards

a datatype of variables that can hold either decimal values or integers

What is a double?

75
New cards

you can store numbers in strings, but you cannot use them for mathematical calculations (only for concatenation)

Can you store numbers in strings? Then can strings be used for mathematical calculations?

76
New cards

age

What is a variable that an int can be used to store?

77
New cards

rainfall

What is a variable that a double can be used to store?

78
New cards

street address

What is a variable that a string can be used to store?

79
New cards

-primitive data types have variables that hold the actual value that they are set to

-reference/class data types have variables that hold a reference to a memory location

How are primitive data types different fro reference data types?

80
New cards

a reference data type

What type of data type is a string?

81
New cards

-they ALWAYS START with a lower case letter

-for example:

int age;

-notice how the (i) is not capitalized

-another example:

double rainfall;

-notice how the (d) is not capitalized

How do names of primitive data types like int, double, etc, always start?

82
New cards

-they ALWAYS START with capitalized letters

-for example:

String name;

-notice how the (S) is capitalized

How do the names of reference data types like strings, always start with?

83
New cards

Java will concatenate the string stored in the variable with the number

What will happen if you put a plus sign (+), between a string variable that holds a STRING and some number?

84
New cards

Java will mathematically add the int/double with the other number and then once you output this, you see the sum of the int/double and the number

What will happen if you put a plus sign (+), between an int/double and some other number?

85
New cards

Boolean

-can only either a true value or a false value

-it is represented in memory as a single bit

-it is a primitive data type

-for example, we can set a value for this datatype like this:

boolean y = true

-in the example above, boolean is the data type, y is the name of the variable, and true is the value of the boolean variable

86
New cards

Bit

a binary value (either a 0 or a 1)

87
New cards

Integer.MIN_VALUE;

-tell us the minimum value in the domain of the integer data type

-we should get a value that is equal to around -2 billion

88
New cards

Integer.MAX_VALUE;

-tells us the maximum value in the domain of the integer data type

-we should get a value that is equal to around +2 billion

89
New cards

prevents the user (that's inputting into the console), from changing that primitive data type's variable's value

What does putting the word "final" before a primitive data type name (such as int), do?

90
New cards

-String, Integer, and Custom Classes

-don't confused Integer with int, because, one starts with an upper case "I" and the other with a lower case "i"

What are the three reference data types?

91
New cards

boolean, int, double, string

How would you arrange the following data types in terms of increasing memory required to store their values?: double, int, string, and boolean

92
New cards

Overflow

-when you add a number to the max value of some primitive data type's domain, and what happens is, the number wraps around and you are outputted the minimum value in the domain instead

-for example, adding 10 the maximum value in the domain of an int, which is 2 billion, would cause to be outputted the minimum value in the domain, which is around -2 billion (notice how the numbers wrapped around)

93
New cards

you'd get a run time error

What would happen if you previously defined the final value of an int or double (using the final modifier), and tried to add or subtract some number from that value, and then print it?

94
New cards

reference data types are data types that have variables that have been set values which cannot fit in the allocated memory spot given to them, so the reference data type directs Java to store the value of its variable in a location with plenty of space

What are reference data types?

95
New cards

variables that hold strings as values

What are string variables?

96
New cards

String literals

strings that are found inside the double quotes inside like the parentheses for the printing method

<p>strings that are found inside the double quotes inside like the parentheses for the printing method</p>
97
New cards

Modifier

-a word which we use before a variable declaration to modify its properties

-the modifier usually comes before the data type when declaring variables

-example: final

-example of the application of a modifier:

final double pi;

pi = 3.14

98
New cards

*

What operator do we use to do multiplication?

99
New cards

/

What operator do we use to do division?

100
New cards

+

What operator do we use to do addition?