Practice Exam 1 + 2 - Sara's Errors Flashcards

1
Q

T/F: The expressions 1.0/2, 1/2.0, and 1.0/2.0 each values to the value (1/2)

A

FALSE because 1.0/2, 1.0/2.0 (DOUBLES) and 1.0/2.0 each evaluates to the value (1/2) (INTERGERS)

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

T/F: Run-time errors are detected by the compiler

A

FALSE because run time errors only occur during running and happen if an unexpected value is entered

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

T/F: Identifiers are symbolic names for classes, methods, and data

A

TRUE: Identifiers (names) are symbolic names (representation) for classes, methods, and data

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

T/F: The clients of a class are programs that use it

A

TRUE

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

T/F: An object reference is a variable name for an object and points to the data of that object

A

TRUE: you’re referencing the data of that object

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

T/F: The data of a class consists of only static variables

A

FALSE: the data of a class doesn’t only have to be static variables.

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

T/F: Accessor methods are also called getter methods

A

TRUE

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

T/F: The garbage collector deletes objects thats have no object reference pointing to them.

A

TRUE: Removes it from runtime

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

T/F: Static methods of a class can be called without instantiating an object

A

TRUE: because the methods are static

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

T/F: The NumberFormat class provides static methods for creating objects to format numeric output such as percentage

A

TRUE: Number format is static –> don’t create an object to use it

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

T/F: The character wrapper class provides a method for testing whether a character is a digit

A

TRUE: Wrapper class (Full words like Character or Interger) provides support methods for primitive types

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

T/F: The character wrapper class provides a method for converting letters to lowercase

A

TRUE: It’s static

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

T/F: The expressions 1.0/2.0 (0.5) and 1/2 (0 remainder 1 but ignore the remainder) evaluate to the same value

A

FALSE: because the first one is a floating point division and the second is integer division.

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

T/F: Variables must be declared before they are used

A

TRUE

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

T/F: Java packages are groups of classes arranged according to functionality

A

TRUE: Related classes are grouped

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

T/F: Static methods of a class are also called the class methods

A

TRUE: because you don’t create an object to use those methods

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

T/F: The NumberFormat class provides static methods for creating objects to format numeric output such as currency

A

TRUE

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

T/F: The double wrapper class provides a method for converting between doubles and Strings

A

TRUE: Use double.tostring

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

T/F: A variable’s scope is the part of the program that has access to the variable

A

TRUE: because scope of that variable is where you can access the variable

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

A/B/C/D: Which of the following will correctly convert the data type, if x is an integer and y is a double?

A

a) x= y;
b) x = int y;
c) x = (int)y; –> has to have brackets to type cast
d) x = y;

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

What could be an example of data

A

Data = fields, and an example is the color of a car

22
Q

What could be an example of operations

A

Operations = Methods, and an example is the function of a car

23
Q

What is a mutator

A

A setter and can also modify data

24
Q

What is an accessor or a getter:

A

Getter methods fetch and return the value of a field such as a class or instance variable

25
What is an example of something that is static for everyone in canada
We all have the same prime minister, so prime minister in this case would be static
26
What is a quick way to immediately know something is a method
When you see () you know something is a method
27
What does the word CLASS represent
Class represents things with common characteristics
28
What is special to remember about using modulus
It only returns the remainder
29
What is special about int to long conversion
There is no loss of data
30
What is special about long to int conversion
There is a loss of data
31
T/F: You can always assign an int value to a long variable without loss of information
TRUE: There is no loss of information when converting a shorter to a longer. The only loss that occurs is when you convert a longer to a shorter
32
T/F: Logic errors occur during program compilation
FALSE. They only occur when you run it and get an unexpected answer
33
T/F: Constants are data items whose value, once assigned, cannot be changed
TRUE: Constants never change (example: PI)
34
T/F: A constructor of a class has the same name as the class
TRUE: A constructor always has the same name
35
T/F: The decimal format class is in the java.text package
TRUE: The decimal format class is in the java.text.decimalformat package
36
T/F: Both java classes Scanner and Random are in the java.util package
TRUE: Scanner and Random is in the java.util package
37
T/F: The integer wrapper class provides methods for converting between ints and Strings
TRUE: Int to string using integer.parseint | String to int using integer.tostring
38
T/F: A final variable must be assigned a value immediately after it has been declared
FALSE: A final does not have to be assigned immediately
39
T/F: A wrapper class provides an object interface for a primitive data type:
TRUE
40
What would be the function of an object interface
Provides a way to support and modify primitive data types
41
T/F: Named constants are initialized with a value, that value cannot be changed during the execution of the program
TRUE: Named constants are FINAL VARIABLES
42
T/F: Both character literals and string literals can be assigned to a char variable
FALSE: You cannot assign a string to a character
43
(WHY IS THIS TRUE) A literal is a value that is written into the code of a program
It is true because a literal is any value in the code that is unchanging and cannot be changed after compiling
44
T/F: Can identifiers contain spaces?
NO IDENTIFIERS CANNOT CONTAIN SPACES BUT THEY CAN CONTAIN AN UNDERSCORE OR A DOLLAR SIGN
45
What occurs if you try to do 20%100
You cannot fit any 100s into 20 so the answer remains 20
46
In the following Java Statement, what is the value of the variable name? String name = "John Doe";
THE MEMORY ADDRESS WHERE JOHN DOE IS LOCATED
47
FILL IN THE BLANK: Calculations are normally performed by ______ statements
Assignment statements: (When something equals something)
48
FILL IN THE BLANK: When parentheses in arithmetic expressions are nested, the ______ set of parenthesis is evaluated first
INNERMOST
49
(Show the value of the string variable str after each statement is performed): str = 2 + 3 + "abc" + 2 + 3;
5 abc 23
50
What happens to any addition or subtraction that occurs after a string
Any addition or subtraction that occurs after a string becomes a string itself
51
(Show the value of the string variable str after each statement is performed): str = 2 + 3 + "abc" + 2 + 3 + 2 + 3;
abc 2323