OCP Oracle Certified Professional Java SE 17 Developer Study Guide. Jeanne Boyarsky
Читать онлайн книгу.
Assessment Test
Use the following assessment test to gauge your current level of skill in Java for the 1Z0-829. This test is designed to highlight some topics for your strengths and weaknesses so that you know which chapters you might want to read multiple times. Even if you do well on the assessment test, you should still read the book from cover to cover, as the real exams are quite challenging.
1 What is the result of executing the following code snippet?41: final int score1 = 8, score2 = 3; 42: char myScore = 7; 43: var goal = switch (myScore) { 44: default -> {if(10>score1) yield "unknown";} 45: case score1 -> "great"; 46: case 2, 4, 6 -> "good"; 47: case score2, 0 -> {"bad";} 48: }; 49: System.out.println(goal);unknowngreatgoodbadunknowngreatgoodbadExactly one line needs to be changed for the code to compile.Exactly two lines need to be changed for the code to compile.None of the above
2 What is the output of the following code snippet?int moon = 9, star = 2 + 2 * 3; float sun = star>10 ? 1 : 3; double jupiter = (sun + moon) - 1.0f; int mars = --moon <= 8 ? 2 : 3; System.out.println(sun+", "+jupiter+", "+mars);1, 11, 23.0, 11.0, 21.0, 11.0, 33.0, 13.0, 33.0f, 12, 2The code does not compile because one of the assignments requires an explicit numeric cast.
3 Which changes, when made independently, guarantee the following code snippet prints 100 at runtime? (Choose all that apply.)List<Integer> data = new ArrayList<>(); IntStream.range(0,100).parallel().forEach(s -> data.add(s)); System.out.println(data.size());Change data to an instance variable and mark it volatile.Remove parallel() in the stream operation.Change forEach() to forEachOrdered() in the stream operation.Change parallel() to serial() in the stream operation.Wrap the lambda body with a synchronized block.The code snippet will