THE OCA EXAM TOPICS COVERED IN THIS PRACTICE TEST INCLUDE THE FOLLOWING:
What is the best reason for using StringBuilder instead of String? What is not true about a String? Which of the following creates a StringBuilder with a different value than the other options? What is the output of the following? How many of the types ArrayList, List, and Object can fill in the blank to produce code that compiles? What is the output of the following? What is the result of the following code? What is the output of the following? What is the output of the following? What is the main benefit of a lambda expression? What is the output of the following? The author of this method forgot to include the data type. Which of the following reference types can fill in the blank to complete this method? Which portion of code can be removed so that this line of code continues to compile? What is the output of the following? What is the output of the following? How many of these lines fail to compile? What does the following do? What is the output of the following? Which of these classes are in the java.util package?
Which of the answer choices results in a different value being output than the other three choices? What is the output of the following? Which is a true statement? What is the output of the following? The author of this method forgot to include the data type. Which of the following reference types can fill in the blank to complete this method? Which statement is true about the following figure while ensuring the code continues to compile? Which of the following can fill in the blank to make the code compile? What is the output of the following? What does the following output? Of the classes LocalDate, LocalDateTime, LocalTime, and LocalTimeStamp, how many include hours, minutes, and seconds? What is the output of the following class? Which equivalent code can replace i -> i != 0 in the following line? What is the output of the following? What is the output of the following? What does the following output? Which starts counting from one rather than zero? Which statement is not true of Predicate? Which of these periods represents a larger amount of time? What is the result of the following? Which of the following can fill in the blank so the following code prints true? Which is not a true statement about the Period class? What is the output of the following class? What does the following output? The author of this method forgot to include the data type. Which of the following reference types can best fill in the blank to complete this method? What is the smallest unit you can add to a LocalTime object? What is the result of the following? Which of the following types can you pass as a parameter to the replace() method on the String class?
How many lines does this code output? What is the output of the following? What is the output of the following? What is the result of the following?
StringBuilder teams = new StringBuilder("333");
teams.append(" 806");
teams.append(" 1601");
System.out.print(teams);
List frisbees = new ____________();
List<String> tools = new ArrayList<>();
tools.add("hammer");
tools.add("nail");
tools.add("hex key");
System.out.println(tools.get(1));
StringBuilder sb = new StringBuilder("radical")
.insert(sb.length(), "robots");
System.out.println(sb);
List<String> museums = new ArrayList<>(1);
museums.add("Natural History");
museums.add("Science");
museums.add("Art");
museums.remove(2);
System.out.println(museums);
12: StringBuilder b = new StringBuilder("12");
13: b = b.append("3");
14: b.reverse();
15: System.out.println(b.toString());
5: StringBuilder line = new StringBuilder("-");
6: StringBuilder anotherLine = line.append("-");
7: System.out.print(line == anotherLine);
8: System.out.print(" ");
9: System.out.print(line.length());
public static void secret( ____________mystery) {
mystery.add("metal");
String str = mystery.get(0);
int num = mystery.length();
}
Predicate<StringBuilder> p = (StringBuilder b) ‐> {return true;};
20: List<Character> chars = new ArrayList<>();
21: chars.add('a');
22: chars.add('b');
23: chars.set(1, 'c');
24: chars.remove(0);
25: System.out.print(chars.size() + " " + chars.contains('b'));
12: String b = "12";
13: b += "3";
14: b.reverse();
15: System.out.println(b.toString());
Predicate<String> pred1 = s ‐> false;
Predicate<String> pred2 = (s) ‐> false;
Predicate<String> pred3 = String s ‐> false;
Predicate<String> pred4 = (String s) ‐> false;
public class Shoot {
interface Target {
boolean needToAim(double angle);
}
static void prepare(double angle, Target t) {
boolean ready = t.needToAim(angle); // k1
System.out.println(ready);
}
public static void main(String[] args) {
prepare(45, d -> d > 5 || d < -5); // k2
}
}
String teams = new String("694");
teams.concat(" 1155");
teams.concat(" 2265");
teams.concat(" 2869");
System.out.println(teams);
StringBuilder sb = new StringBuilder("radical ");
sb = ________________________;
System.out.print(sb);
String[] array = {"Natural History", "Science"};
List<String> museums = Arrays.asList(array);
museums.set(0, "Art");
System.out.println(museums.contains("Art"));
20: List<Character> chars = new ArrayList<>();
21: chars.add('a');
22: chars.add('b');
23: chars.set(1, 'c');
24: chars.remove(0);
25: System.out.print(chars.length());
public static void secret(_____________ mystery) {
mystery = mystery.replace("1", "8");
mystery.startsWith("paper");
String s = mystery.toString();
}
import java.util.function.*;
public class Card {
public static void main(String[] s) {
Predicate<String> pred =____________ ‐> true;
}
}
5: String line = new String("-");
6: String anotherLine = line.concat("-");
7: System.out.print(line == anotherLine);
8: System.out.print(" ");
9: System.out.print(line.length());
Predicate dash = c -> c.startsWith("‐");
System.out.println(dash.test(""));
1: package rocket;
2: public class Countdown {
3: public static void main(String[] args) {
4: String builder = "54321";
5: builder = builder.substring(4);
6: System.out.println(builder.charAt(2));
7: }
8: }
Predicate<Integer> ip = i ‐> i != 0;
LocalDate xmas = LocalDate.of(2016, 12, 25);
xmas.plusDays(-1);
System.out.println(xmas.getDayOfMonth());
1: public class Legos {
2: public static void main(String[] args) {
3: StringBuilder sb = new StringBuilder();
4: sb.append("red");
5: sb.deleteCharAt(0);
6: sb.delete(1, 2);
7: System.out.println(sb);
8: }
9: }
Predicate clear = c -> c.equals("clear");
System.out.println(clear.test("pink"));
Period period1 = Period.ofWeeks(1).ofDays(3);
Period period2 = Period.ofDays(10);
import java.time.*;
import java.time.format.*;
public class HowLong {
public static void main(String[] args) {
LocalDate newYears = LocalDate.of(2017, 1, 1);
Period period = Period.ofDays(1);
DateTimeFormatter format = DateTimeFormatter.ofPattern("MM-dd-yyyy");
System.out.print(format.format(newYears.minus(period)));
}
}
String happy = " :) - (: ";
String really = happy.trim();
String question = ______________________;
System.out.println(really.equals(question));
1: package rocket;
2: public class Countdown {
3: public static void main(String[] args) {
4: StringBuilder builder = new StringBuilder("54321");
5: builder.substring(2);
6: System.out.println(builder.charAt(1));
7: }
8: }
List<Integer> pennies = new ArrayList<>();
pennies.add(3);
pennies.add(2);
pennies.add(1);
pennies.remove(2);
System.out.println(pennies);
public static void secret(_____________ mystery) {
char ch = mystery.charAt(3);
mystery = mystery.insert(1, "more");
int num = mystery.length();
}
import java.time.*;
import java.time.format.*;
public class HowLong {
public static void main(String[] args) {
LocalDate newYears = LocalDate.of(2017, 1, 1);
Period period = Period.ofDays(1);
DateTimeFormatter format = DateTimeFormatter.ofPattern("mm-dd-yyyy");
System.out.print(format.format(newYears.minus(period)));
}
}
import java.util.*;
import java.util.function.*;
public class PrintNegative {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("-5");
list.add("0");
list.add("5");
print(list, e -> e < 0);
}
public static void print(List<String> list, Predicate<Integer> p) {
for (String num : list)
if (p.test(num))
System.out.println(num);
}
}
12: List<String> magazines = new ArrayList();
13: magazines.add("Readers Digest");
14: magazines.add("People");
15: magazines.clear();
16: magazines.add("The Economist");
17: magazines.remove(1);
18: System.out.println(magazines.size());
public class Costume {
public static void main(String[] black) {
String witch = 'b';
String tail = "lack";
witch = witch.concat(tail);
System.out.println(witch);
}
}
LocalDate xmas = LocalDate.of(2016, 12, 25);
xmas.setYear(2017);
System.out.println(xmas.getYear());