1Z0-829 Exam Questions
49 real 1Z0-829 exam questions with expert-verified answers and explanations. Page 1 of 1.
- Question #1Managing concurrent code execution
Given the code fragments: class Test { volatile int x = 1; AtomicInteger xObj = new AtomicInteger(1); } and public static void main(String[] args) { Test t = new Test(); Runnable r...
volatile keywordAtomicIntegerthread safetyrace condition - Question #2Managing concurrent code execution
Which statement is true?
thread statesInterruptedExceptionconcurrent executionexception handling - Question #3Managing concurrent code execution
Given the code fragment: ExecutorService executorService = Executors.newSingleThreadExecutor(); Set<Callable<String>> workers = new HashSet<Callable<String>>(); workers.add(new Cal...
ExecutorServiceinvokeAllCallableFuture - Question #4Working with Java Primitive Data Types and String APIs
Given the code fragment: String a = "Hello! Java"; System.out.print(a.indexOf("Java")); a.replace("Hello!", "Welcome!"); System.out.print(a.indexOf("Java")); StringBuilder b = new...
String immutabilityindexOfStringBuilderreplace - Question #5Working with Java Primitive Data Types and String APIs
Given the code fragment: String myStr = "Hello Java 17"; String myTextBlk1 = """ Hello Java 17"""; String myTextBlk2 = """ Hello Java 17 """; System.out.print(myStr.equals(myTextBl...
text blocksString.internequalstrailing newline - Question #6Handling date, time, text, numeric and boolean values
Which two statements at Line n1 independently enable you to print 1250?
String to Integer conversionInteger.parseInt vs valueOfAuto-boxingNumeric type handling - Question #7Handling date, time, text, numeric and boolean values
Given the code fragment: int a = 2; int b = ~a; int c = a^b; boolean d = a < b & a > c++; boolean e = a > b && a > c++; System.out.println(d + " " + c); System.out.println(e + " "...
bitwise operatorslogical operatorsshort-circuit evaluationpost-increment - Question #7Working with Java Objects and Classes
What is the result?
object comparisonboolean output - Question #8Controlling Program Flow
Given: public class Test { public static void main(String[] args) { final int x = 2; int y = x; while (y<3) { switch (y) { case 0+x: y++; case 1: y++; } } System.out.println(y); }...
switch statementsfinal variablesconstant expressionscompilation - Question #9Controlling Program Flow
Given the code fragment: Integer rank = 4; switch (rank) { case 1,4 -> System.out.println("Range1"); case 5,8 -> System.out.println("Range2"); case 9,10 -> System.out.println("Rang...
switch expressionspattern matchingmultiple case labelsarrow syntax - Question #10Working with Streams and Lambda expressions
Given the code fragment: List<String> specialDays = List.of("NewYear", "Valentines","Spring","Labour"); System.out.println(specialDays.stream().allMatch(s -> s.equals("Labour")));...
Stream terminal operationsallMatch/anyMatch/noneMatchfindFirstOptional - Question #11Working with Streams and Lambda expressions
Given: class Product { String name; double price; Product(String s, double d) { this.name = s; this.price = d; } } class ElectricProduct extends Product { ElectricProduct(String na...
Streams & CollectorsLambda expressionsDoubleSummaryStatisticsPolymorphism - Question #12Working with Arrays and Collections
Given the code fragment: class Book { String author; String title; Book(String authorname, String title) { this.author = authorname; this.title = title; } } class SortBook { public...
CollectionsLambda ExpressionsImmutable ListsComparators - Question #13Working with Arrays and Collections
Given the code fragment: List lst = new ArrayList<>(); lst.add("e1"); lst.add("e3"); lst.add("e2"); int x1 = Collections.binarySearch(lst, "e3"); System.out.println(x1); Collection...
Collections.binarySearchCollections.sortsorted collectionspreconditions - Question #14Java Object-Oriented Approach
Given: class A { public void mA() {System.out.println("mA");}} class B extends A {public void mB() {System.out.println("mB");}} class C extends B {public void mC() {System.out.prin...
Pattern MatchinginstanceofInheritancePolymorphism - Question #15Java Object-Oriented Approach
Given the directory structure: module1: p1\ Doc.java p2\ Util.java Given the definition of the Doc class: package p1; public sealed class Doc permits WordDoc { } Which two are vali...
sealed classespermitted subclassesclass modifierspackage scope - Question #16Working with Streams and Lambda expressions
public enum Desig { CEO('A'), CMO('B'), CTO('C'), CFO('D'); char c; private Desig(char c) { this.c = c; } } and the code fragment: Arrays.stream(Desig.values()).dropWhile(s -> s.eq...
enumspattern matchingstreamsswitch expressions - Question #17Utilizing Java Object-Oriented Approach
public class Weather { public enum Forecast { SUNNY, CLOUDY, RAINY; } @Override public String toString() { return "SNOWY";} public static void main(String[] args) { System.out.prin...
enumsordinal()valueOf()toString() override - Question #18Using Java I/O API
Given the product class: import java.io.*; public class Product implements Serializable { private static float averagePrice = 2.99f; private String description; private transient f...
serializationreadObject contracttry-with-resources syntaxcompilation errors - Question #19Using Java I/O API
Given: import java.io.Serializable; public class Software implements Serializable { private String title; public Software(String title) { this.title = title; } System.out.print("So...
Instance initializer blocksSerialization/DeserializationInheritanceMethod overriding - Question #20Using Java I/O API
Given the code fragments: class Car implements Serializable { private static long serialVersionUID = 454l; String name; public Car(String name) { this.name = name; } public String...
serializationexception handlingobject I/Oinheritance - Question #21Using Java I/O API
Assuming that the data, txt file exists and has the following content: Text1 Text2 Text3 Given the code fragment: try { Path p = new File("data.txt").toPath(); String lines = Files...
Files.lines()Collectors.joining()Files.readAllLines()List indexing - Question #22Java Object-Oriented Approach
Given: public class Test { static interface Animal { } static class Dog implements Animal { } private static void play(Animal a) { System.out.print("flips"); } private static void...
method overloadingvariable declarationcompile-time type resolutionundefined variable - Question #23Java Object-Oriented Approach
Given: public class Test { public void sum(int a, int b) { System.out.print("A"); } public void sum(int a, float b) { System.out.print("B"); } public void sum(float a, float b) { S...
Method OverloadingType PromotionVarargsType Matching - Question #24Java Object-Oriented Approach
1. class Item { 2. String name; 3. public static void display() { 4. name = "Vase"; 5. System.out.println(name); 6. } 7. public void display(String design) { 8. this.name += name;...
static methodsinstance variablesscope rulesmethod overloading - Question #24Handling date, time, text, numeric and boolean values
Given: public class Main { void print(int i) { System.out.println("hello"); } void print(long j) { System.out.println("there"); } public static void main(String[] args) { new Main(...
Method overloadingBinary literalsType resolutionNumeric values - Question #25Working with Streams and Lambda expressions
Given the code fragment: Stream<String> s1 = Stream.of("A", "B", "C", "B"); Stream<String> s2 = Stream.of("A", "D", "E", "B"); Stream.concat(s1, s2).parallel().distinct().forEach(e...
Stream.concat()parallel()distinct()stream ordering - Question #26Working with Streams and Lambda expressions
Given: public class Test { public String attach1(List<String> data) { return data.parallelStream().reduce("w", (n,m) -> n+m, String::concat); } public String attach2(List<String> d...
Parallel StreamsStream.reduce()Type InferenceLambda Expressions - Question #27Working with Streams and Lambda expressions
Given: public class Test { public static void main(String[] args) { List<String> elements = Arrays.asList("car", "truck", "car", "bicycle", "car", "truck", "motorcycle"); Map<Strin...
CollectorsgroupingByStream APIFunctional interfaces - Question #28Java Object-Oriented Approach
record Product(int pNumber, String pName) { int regNo = 100; public int getRegNumber() { return regNo; } } public class App { public static void main(String[] args) { Product p1 =...
RecordsInstance fieldsInitializationSyntax rules - Question #30Accessing databases using JDBC
Given the course table: COURSE_ID COURSE_NAME COURSE_FEE COURSE_LEVEL 1021 Java Programmer 400.00 1 1022 Java Architect 600.00 2 1023 Java Master 800.00 3 Given the code fragment:...
JDBC PreparedStatementexecuteUpdate()SQL UPDATErow count - Question #31Using Java I/O API
Which code line n1, obtains the java.io.Console object?
Console I/OSystem.console()Java I/O APIobtaining streams - Question #31Working with Streams and Lambda expressions
Given the code fragment: List<Integer> listOfNumbers = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); Which code fragment returns different values?
reduce()streamslambda expressionsaccumulator - Question #32Handling date, time, text, numeric and boolean values
Given the code fragment: Duration duration = Duration.ofMillis(5000); System.out.println(duration); duration = Duration.ofSeconds(60); System.out.println(duration); Period period =...
DurationPeriodDate-Time APIISO-8601 formatting - Question #33Handling date, time, text, numeric and boolean values
Daylight Saving Time (DST) is the practice of advancing clocks at the start of spring by one hour and adjusting them backward by one hour in autumn. Considering that in 2021, DST i...
ZonedDateTimeDaylight Saving TimeTimezone transitionsDST ambiguity - Question #34Java Object-Oriented Approach
Given: public class App { public int x = 100; public static void main(String[] args) { int x = 1000; App t = new App(); t.myMethod(x); System.out.println(x); } public void myMethod...
Variable scopePass-by-valuethis keywordInstance variables - Question #34Handling date, time, text, numeric and boolean values
Given the code fragment: // login time:2021-01-12T21:58:18.817Z Instant loginTime = Instant.now(); Thread.sleep(1000); // logout time:2021-01-12T21:58:19.880Z Instant logoutTime =...
InstantChronoUnit.MINUTESTemporal TruncationConditional Logic - Question #35Utilizing Java Object-Oriented Approach
Given the code fragment: abstract sealed interface Sint permits Story, Art { default String getTitle() { return "Book Title"; } } Which set of class definitions compiles?
sealed interfacespermits clauseinterface inheritancedeclaration modifiers - Question #36Utilizing Java Object-Oriented Approach
Given: interface IFace { public void m1(); public default void m2() { System.out.println("m2"); } public static void m3() { System.out.println("m3"); } private void m4() { System.o...
interface methodsdefault methodsstatic methodsmethod visibility - Question #36Packaging and Deploying Java code
Assume you have an automatic module from the module path display-ascii-0.2. jar. Which name is given to the automatic module based on the given JAR file?
Java Module SystemAutomatic ModulesModule NamingJPMS - Question #37Packaging and Deploying Java code
Which statement is true about migration?
Java module system (JPMS)bottom-up migrationmodule pathmodule dependencies - Question #38Using Java I/O API
Given the content of the in. tart file: 23456789 and the code fragment: char[] buffer = new char[8]; int count = 0; try (FileReader in = new FileReader("in.txt"); FileWriter out =...
FileReader/FileWriterBuffer managementI/O operationsCharacter arrays - Question #39Working with Java Objects and Classes
Which two code fragments compile?
var keywordlocal variable type inferencetype inference rulescompilation rules - Question #40Packaging and Deploying Java code
Which statement is true about modules?
Java modulesmodule pathJPMSmodule types - Question #41Implementing Localization
Given: Captions.properties file: user = UserName Captions_en.properties file: user = User name (EN) Captions_US.properties file: message = User name (US) Captions_en_US.properties...
ResourceBundleLocale fallbacknaming conventionslocalization - Question #44Java Object-Oriented Approach
Given: public class App{ String name; public App(String name){ this.name = name; } public static void main(String args[]) { App t1 = new App("t1"); App t2 = new App("t2"); t1 = t2;...
object referencesgarbage collectionmemory managementobject lifecycle - Question #45Java Object-Oriented Approach
Given the code fragment: Pet p = new Pet("Dog"); Pet p1 = p; p1.name = "Cat"; p = p1; System.out.println(p.name); p = null; System.out.println(p1.name); What is the result?
object referencesreference aliasingmutable statenull assignment - Question #46Working with Exceptions and Assertions
Given: ```java public class StockException extends Exception { public StockException(String s) { super(s); } } public class OutofStockException extends StockException { public Outo...
custom exceptionschecked exceptionsthrows declarationexception hierarchy - Question #48Working with Modules
Given: ```java package com.transport.vehicle.cars; public interface Car { int getSpeed(); } ``` and ```java package com.transport.vehicle.cars.impl; import com.transport.vehicle.ca...
module-infoservice provider interfaceprovides directiveuses directive