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
Q

What is an example of something that is static for everyone in canada

A

We all have the same prime minister, so prime minister in this case would be static

26
Q

What is a quick way to immediately know something is a method

A

When you see () you know something is a method

27
Q

What does the word CLASS represent

A

Class represents things with common characteristics

28
Q

What is special to remember about using modulus

A

It only returns the remainder

29
Q

What is special about int to long conversion

A

There is no loss of data

30
Q

What is special about long to int conversion

A

There is a loss of data

31
Q

T/F: You can always assign an int value to a long variable without loss of information

A

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
Q

T/F: Logic errors occur during program compilation

A

FALSE. They only occur when you run it and get an unexpected answer

33
Q

T/F: Constants are data items whose value, once assigned, cannot be changed

A

TRUE: Constants never change (example: PI)

34
Q

T/F: A constructor of a class has the same name as the class

A

TRUE: A constructor always has the same name

35
Q

T/F: The decimal format class is in the java.text package

A

TRUE: The decimal format class is in the java.text.decimalformat package

36
Q

T/F: Both java classes Scanner and Random are in the java.util package

A

TRUE: Scanner and Random is in the java.util package

37
Q

T/F: The integer wrapper class provides methods for converting between ints and Strings

A

TRUE: Int to string using integer.parseint

String to int using integer.tostring

38
Q

T/F: A final variable must be assigned a value immediately after it has been declared

A

FALSE: A final does not have to be assigned immediately

39
Q

T/F: A wrapper class provides an object interface for a primitive data type:

A

TRUE

40
Q

What would be the function of an object interface

A

Provides a way to support and modify primitive data types

41
Q

T/F: Named constants are initialized with a value, that value cannot be changed during the execution of the program

A

TRUE: Named constants are FINAL VARIABLES

42
Q

T/F: Both character literals and string literals can be assigned to a char variable

A

FALSE: You cannot assign a string to a character

43
Q

(WHY IS THIS TRUE) A literal is a value that is written into the code of a program

A

It is true because a literal is any value in the code that is unchanging and cannot be changed after compiling

44
Q

T/F: Can identifiers contain spaces?

A

NO IDENTIFIERS CANNOT CONTAIN SPACES BUT THEY CAN CONTAIN AN UNDERSCORE OR A DOLLAR SIGN

45
Q

What occurs if you try to do 20%100

A

You cannot fit any 100s into 20 so the answer remains 20

46
Q

In the following Java Statement, what is the value of the variable name? String name = “John Doe”;

A

THE MEMORY ADDRESS WHERE JOHN DOE IS LOCATED

47
Q

FILL IN THE BLANK: Calculations are normally performed by ______ statements

A

Assignment statements: (When something equals something)

48
Q

FILL IN THE BLANK: When parentheses in arithmetic expressions are nested, the ______ set of parenthesis is evaluated first

A

INNERMOST

49
Q

(Show the value of the string variable str after each statement is performed):
str = 2 + 3 + “abc” + 2 + 3;

A

5 abc 23

50
Q

What happens to any addition or subtraction that occurs after a string

A

Any addition or subtraction that occurs after a string becomes a string itself

51
Q

(Show the value of the string variable str after each statement is performed):
str = 2 + 3 + “abc” + 2 + 3 + 2 + 3;

A

abc 2323