What are the 3 primitive data types required for this unit?
Ints, doubles, booleans
What is the result of 17 % 5?
2
Given String s = "Computer";, what value is returned by s.length()?
8
What two components make up a method signature in Java?
Method name and parameter list. Ex: calculateSum(int a, double b);
What keyword is used to instantiate a new object using a constructor?
new
What is the result of:
System.out.println("Result: " + 5 + 3);
Result: 53
What is printed by System.out.println(7 / 2);?
3
Given String s = "JAVA";, what happens when you attempt to execute s.substring(4) vs s.substring(5)?
Empty string. IndexOutOfBounds
| J | A | V | A |
0 1 2 3 4
What keyword in a method header indicates that the method does not return any value?
Void
How do you recognize a constructor header inside a class definition?
It's the same name as the class.
What does a variable declared as a String store?
Reference or pointer
What is the value of x after int x = 10; x %= 4; x *= 3 ?
6
What does s.indexOf("cat") return if the substring "cat" is not found inside s?
-1
What term describes having multiple methods in the same class with the same name but different parameter lists?
Overload
Given String str = "AP CSA";, what does str.substring(1, 4) return?
P C
What error occurs at runtime if you attempt to call a method on an object set to null?
NullPointerExceptionError
Write a single expression using Math.random() that generates a random integer between 5 and 15 inclusive.
(int) (Math.random() * (15 - 5 + 1)) + 5
String word = "APCSA";
word.concat(" Rocks");
System.out.println(word);
What is printed?
APCSA
Need to reassign! word = word.concat(" Rocks");
Java passes arguments to methods using "Call by Value". What does this mean when passing a primitive variable into a method?
The method receives a copy of that variable's value, not the actual variable itself.
What is the comparison method for Strings?
str.equals();
How many bits is an integer and double?
32 and 64
What does Math.pow(2, 3) return? State the exact value and its data type.
8.0, double
Given String word1 = "apple"; and String word2 = "banana";, what does word1.compareTo(word2)return (positive, negative, or zero)?
Negative.
What is the key structural difference between calling a static class method versus an instance method?
Wether or not the method requires an object instance to execute.
Static: Class.method();
Instance: object.method();
What does it mean for String objects to be immutable? Explain how Strings work in memory.
Once it is created in memory, its value can never be changed or modified. When a new value is assigned, it creates a new variable in memory.