1Z0-819 Exam Questions
200 real 1Z0-819 exam questions with expert-verified answers and explanations. Page 4 of 4.
- Question #151Working with Arrays and Collections
Given the code fragment: public static void main(String[] args) { var even = List.of(1, even.add(-1); even.add(0, -2); even.add(0, -2); System.out.println(even); } What is the outp...
List.of() immutabilityUnsupportedOperationExceptionImmutable collectionsRuntime exceptions - Question #152Java Platform Module System
Which command line runs the main class com.acme.Main from the module com.example?
module pathmodule executionjava commandJPMS - Question #153Working with Arrays and Collections
Given: import java.util.*; public class Main { static Map<String, String> map = new HashMap<>(); static List<String> keys = new ArrayList<>(List.of("A", "B", "C", "D")); static Str...
instance vs static initializerscollection referencesCollection.clear()field state tracking - Question #154Controlling Program Flow
Given: public class Test { private int sum; public int compute() { int x = 0; while(x < 3) { sum += x++; } return sum; } public static void main(String[] args) { Test t = new Test(...
Post-increment operatorInstance variablesLoop stateVariable scope - Question #155Working with Arrays and Collections
Given: public class X { private Collection collection; public void set (Collection collection) { this.collection = collection; } } and public class Y extends X { public void set (M...
inheritancecollections hierarchymethod overloadingtype compatibility - Question #156Java Object-Oriented Approach
Given: package a; public abstract class Animal { protected abstract void walk(); } package b; public abstract class Human extends Animal { // line 1 } Which two lines inserted in l...
abstract methodsmethod overridingaccess modifiersinheritance - Question #157Working with Java Data Types
Given: public class Tester { public static void main(String[] args) { int x = 4; int y = 2; System.out.println("x+y=" + (x+y)); } } What is the result?
String concatenationOperator precedenceArithmetic operatorsType coercion - Question #158Working with Java Data Types
public class Tester { public static void main(String[] args) { byte x = 7, y = 6; // Line 1 System.out.println(z); } } Which expression when added at Line 1 will produce the output...
type castingMath.round()operator precedencefloat arithmetic - Question #159Controlling Program Flow
public class Main { public static public static void main(String[] args) { int i = 1; for(String s : args) { System.out.println((i++) + " " + s); } } } executed with this command:...
post-increment operatorenhanced for-each loopstring concatenationloop semantics - Question #160Working with Java Data Types
Which of these initialization statements are correct? (Choose three.)
type castingprimitive typesnumeric literalsarray initialization - Question #161Exception Handling
import java.io.FileNotFoundException; import java.io.IOException; public class Tester { public static void main(String[] args) { doA(); //Line 1 } private static void doA() throws...
Checked ExceptionsException HierarchyTry-Catch BlocksIOException - Question #162Java Object-Oriented Approach
What is the result of compiling and running the following code? public class Overload { static void print(int..., a2) { System.out.print("int...."); } static void print(long a, lon...
Method OverloadingType WideningMethod ResolutionPrimitive Conversion - Question #163Java Object-Oriented Approach
public class Test { private String strings; } Which two construct ors will compile and set the class field strings? (Choose two.)
constructorsvarargstype compatibilitymethod parameters - Question #164Working with Java Data Types
Given the following fragment: String s1 = new String("ORACLE"); String s2 = "ORACLE"; String s3 = s1.intern(); System.out.println(s1 == s2 + " "); System.out.println(s1 == s3 + " "...
string interningobject referencesstring poolreference equality - Question #165Java Object-Oriented Approach
import java.util.function.BiFunction; public class Pair<T, Boolean> { final BiFunction<T, Boolean, T> validator; T left = null; T right = null; private Pair() { validator = null; }...
EncapsulationAccess ModifiersClass InvariantsVisibility Control - Question #166Working with Java Data Types
var i = 10; var j = 5; var z = (++i + j++) / i - 2; System.out.println(i); What is the result?
increment operatorspre vs post incrementoperator precedenceexpression evaluation - Question #167Working with Java Data Types
public class Tester { private int x; private int y; public static void main(String[] args) { Tester t1 = new Tester(); t1.x = 2; t1.y = 3; Tester t2 = new Tester(); t2.x = 4; t2.y...
string concatenationtype coercionoperator precedenceprimitive types - Question #168Working with Streams and Lambda Expressions
public interface EulerInterface { double getEulerValue(); } public class EulerLambda { public static void main(String[] args) { EulerInterface myEulerInterface = () -> 2.71828; Sys...
lambda expressionsfunctional interfacescompilation rulestype inference - Question #169Working with Arrays and Collections
public class Myclass { public static void main(String[] args) { System.out.println(arg[1] + "--" + arg[3] + "--" + arg[0]); } } executed using this command: java Myclass My Car Is...
command-line argumentsarray indexingstring concatenationargs array - Question #170Java Platform Module System
Which describes a characteristic of setting up the Java development environment?
JDKJREIDE ConfigurationDevelopment Environment Setup - Question #171Java Object-Oriented Approach
Given: ```java package test.t1; public class A { public int x = 42; protected A() { } } package test.t2; import test.t1.*; public class B extends A { int x = 17; public B() { super...
inheritancefield shadowingreference vs object typecompile-time field resolution - Question #172Working with Java Data Types
Given: ```java String s = "this is it"; int x = s.indexOf("is"); s = s.substring(x+3); x = s.indexOf("is"); System.out.println(s+" "+x); ``` What is the result?
String.indexOf()String.substring()code tracingindex tracking - Question #173Working with Streams and Lambda Expressions
Given: ```java import java.util.ArrayList; import java.util.Arrays; public class TestMe { public static void main(String[] args) { String[] fruitNames = {"apple", "orange", "grape"...
Lambda ExpressionsComparator LogicArrayList SortingReverse Order - Question #174Controlling Program Flow
Given the code fragment: ```java int x = 0; while(x < 10) { System.out.print(x++); } ``` Which "for" loop produces the same output?
loop equivalencepost-increment vs pre-incrementfor loop syntaxloop control flow - Question #175Working with Streams and Lambda Expressions
Which of the following produces the same result as the given for loop? ```java for (int i = 1; i < 10; ++i) { System.out.println(i); } ```
Stream.iterate()method referenceslambda expressionsloop equivalence - Question #176Working with Arrays and Collections
Given: ```java String[][] arr = { {"Red", "White"}, {"Black"}, {"Blue", "Yellow", "Green", "Violet"} }; for(int row = 0; row < arr.length; row++) { int column = 0; for(; column < a...
2D arraysjagged arraysnested loopsarray indexing - Question #177Controlling Program Flow
Given: public class Main { public static void main(String[] args) { import java.time.LocalDate; import static java.time.DayOfWeek.*; var today = LocalDate.now().with(TUESDAY).getDa...
switch statementsDayOfWeek enumLocalDate with()enum case matching - Question #178Java Object-Oriented Approach
Given: public interface A { abstract void x(); } and public abstract class B /* position 1 */ { /* position 2 */ public void x() { } public abstract void z(); } and public class C...
abstract classesinterface implementationmethod inheritanceconcrete classes - Question #179Working with Streams and Lambda Expressions
Given: import java.util.function.Supplier; public class MyLambda { public static void main(String[] args) { int i = 25; Supplier<Integer> foo = () -> i; i++; System.out.println(foo...
lambda captureeffectively final variablesvariable scopecompiler constraints - Question #180Java Platform Module System
Which two statements are correct about modules in Java? (Choose two.)
module-info.javamodule exportsjava.base modulemodule descriptors - Question #181Java Platform Module System
Which two describe reasons to modularize the JDK? (Choose two.)
JDK ModularizationEncapsulation & SecurityModule System BenefitsCompilation Performance - Question #182Working with Streams and Lambda Expressions
Given: public class Employee { private String name; private String neighborhood; private LocalDate birthday; private int salary; // ...getters and setters } and List<Employee> rost...
Stream collectorsgroupingBymaxByOptional handling - Question #183
Given TripleThis.java: 1 import java.util.function.*; 2 3 public class TripleThis { 4 public static void main(String[] args) { 5 Function<Integer, Integer> tripler = x -> { return...
- Question #184
Given config: MessageBundle.properties: username = Username password = Password and MessageBundle_fr_FR.properties: username = Utilisateur password = le passe and MessageBundle_ru....
- Question #185
Given: public class Main { public static void main(String[] args) { List<String> list1 = new ArrayList<>(); list1.add("Plane"); list1.add("Automobile"); list1.add("Motorcycle"); Li...
- Question #186
Given the code fragment: public class Test { private int x = 1; static final int y; public Test(){ System.out.println(x); System.out.println(y); } { x = 2; } static { y = 3; } publ...
- Question #187
What change will cause the code to compile successfully? Given: public class Electronics { public Electronics(double price) { super(); } } and public class Plushy extends Electroni...
- Question #188
Given: import java.io.File; import java.io.FileOutputStream; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.util.Arrays; public class Test { public s...
- Question #189
```java public class X { protected void print(Object obj) { print(objects); } public final void print(Object... objects) { collection.forEach(System.out::println); } } public class...
- Question #190
Which method throws an exception for not-a-number and infinite input values?```java // A static float validate1(String s, float min, float max) throws IllegalArgumentException { re...
- Question #191
Given the `CopyServiceAPI` that has the org.copyservice.spi. Copy Interface To use this service in a module, which module- info java would be correct?
- Question #192
Given: `List<Integer> numbers = List.of(5, 3, 0, 8, 1, 9, 5, 7, 6, 4); int sum = numbers.stream().reduce(0, (n, m) -> n + m); // line 1` You want to make the reduction operation pa...
- Question #193
Given: ```java public class Tester { public static void main(String[] args) { String s = "Hat at store"; String t = new String("Hat"); s.substring(s.indexOf(' ') + 1); s.concat(" a...
- Question #194
Given: ```java public class GameObject { public GameObject() {} public GameObject(int x, int y) { System.out.println("move(" + x + "," + y + ")"); } public Integer move(Integer x,...
- Question #195
Given the code fragment: ```java for (i=0; i<10; i++) { System.out.print(i + " "); } ``` What is the result?
- Question #196
A company has an existing Java app that includes two Java 8 jar files, sales-3.10.jar and clients- 10.2.jar. The sales-3.10.jar uses packages in clients-10.2.jar, but clients-10.2....
- Question #197
How many Thing objects are eligible for garbage collection in line 1? ```java private String name; public Thing(String name) { this.name = name; } public String toString() { return...
- Question #198
Given the Customer table structure: `ID Number Primary Key NAME Varchar(20)` Given code fragment: `12. PreparedStatement stmt = con.prepareStatement("INSERT INTO CUSTOMER VALUES (?...
- Question #199
You want to implement the jav `MyPersistenceData` class so that it can be serialized and deserialized into a file. Which interface and methods would you implement?```java public cl...
- Question #200
Given: ```java public class ConSuper { public ConSuper() { this(2); } protected ConSuper(int a) { System.out.print("3"); } public ConSuper(int a) { System.out.print(a); } } public...