Practice Exam 1 + 2 - Sara's Errors Flashcards
T/F: The expressions 1.0/2, 1/2.0, and 1.0/2.0 each values to the value (1/2)
FALSE because 1.0/2, 1.0/2.0 (DOUBLES) and 1.0/2.0 each evaluates to the value (1/2) (INTERGERS)
T/F: Run-time errors are detected by the compiler
FALSE because run time errors only occur during running and happen if an unexpected value is entered
T/F: Identifiers are symbolic names for classes, methods, and data
TRUE: Identifiers (names) are symbolic names (representation) for classes, methods, and data
T/F: The clients of a class are programs that use it
TRUE
T/F: An object reference is a variable name for an object and points to the data of that object
TRUE: you’re referencing the data of that object
T/F: The data of a class consists of only static variables
FALSE: the data of a class doesn’t only have to be static variables.
T/F: Accessor methods are also called getter methods
TRUE
T/F: The garbage collector deletes objects thats have no object reference pointing to them.
TRUE: Removes it from runtime
T/F: Static methods of a class can be called without instantiating an object
TRUE: because the methods are static
T/F: The NumberFormat class provides static methods for creating objects to format numeric output such as percentage
TRUE: Number format is static –> don’t create an object to use it
T/F: The character wrapper class provides a method for testing whether a character is a digit
TRUE: Wrapper class (Full words like Character or Interger) provides support methods for primitive types
T/F: The character wrapper class provides a method for converting letters to lowercase
TRUE: It’s static
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
FALSE: because the first one is a floating point division and the second is integer division.
T/F: Variables must be declared before they are used
TRUE
T/F: Java packages are groups of classes arranged according to functionality
TRUE: Related classes are grouped
T/F: Static methods of a class are also called the class methods
TRUE: because you don’t create an object to use those methods
T/F: The NumberFormat class provides static methods for creating objects to format numeric output such as currency
TRUE
T/F: The double wrapper class provides a method for converting between doubles and Strings
TRUE: Use double.tostring
T/F: A variable’s scope is the part of the program that has access to the variable
TRUE: because scope of that variable is where you can access the variable
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) x= y;
b) x = int y;
c) x = (int)y; –> has to have brackets to type cast
d) x = y;
What could be an example of data
Data = fields, and an example is the color of a car
What could be an example of operations
Operations = Methods, and an example is the function of a car
What is a mutator
A setter and can also modify data
What is an accessor or a getter:
Getter methods fetch and return the value of a field such as a class or instance variable
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
What is a quick way to immediately know something is a method
When you see () you know something is a method
What does the word CLASS represent
Class represents things with common characteristics
What is special to remember about using modulus
It only returns the remainder
What is special about int to long conversion
There is no loss of data
What is special about long to int conversion
There is a loss of data
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
T/F: Logic errors occur during program compilation
FALSE. They only occur when you run it and get an unexpected answer
T/F: Constants are data items whose value, once assigned, cannot be changed
TRUE: Constants never change (example: PI)
T/F: A constructor of a class has the same name as the class
TRUE: A constructor always has the same name
T/F: The decimal format class is in the java.text package
TRUE: The decimal format class is in the java.text.decimalformat package
T/F: Both java classes Scanner and Random are in the java.util package
TRUE: Scanner and Random is in the java.util package
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
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
T/F: A wrapper class provides an object interface for a primitive data type:
TRUE
What would be the function of an object interface
Provides a way to support and modify primitive data types
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
T/F: Both character literals and string literals can be assigned to a char variable
FALSE: You cannot assign a string to a character
(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
T/F: Can identifiers contain spaces?
NO IDENTIFIERS CANNOT CONTAIN SPACES BUT THEY CAN CONTAIN AN UNDERSCORE OR A DOLLAR SIGN
What occurs if you try to do 20%100
You cannot fit any 100s into 20 so the answer remains 20
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
FILL IN THE BLANK: Calculations are normally performed by ______ statements
Assignment statements: (When something equals something)
FILL IN THE BLANK: When parentheses in arithmetic expressions are nested, the ______ set of parenthesis is evaluated first
INNERMOST
(Show the value of the string variable str after each statement is performed):
str = 2 + 3 + “abc” + 2 + 3;
5 abc 23
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
(Show the value of the string variable str after each statement is performed):
str = 2 + 3 + “abc” + 2 + 3 + 2 + 3;
abc 2323