1z0-819 Exam QuestionsBrowse all questions from this exam

1z0-819 Exam - Question 122


Which two expressions create a valid Java Path instance? (Choose two.)

Show Answer
Correct Answer: ACE

To create a valid Java Path instance, the Paths.get method is commonly used. The statement Paths.get("foo") is valid. Additionally, Path can be created using a URI, but the correct method is Path.of(URI), which is similar to the Paths.get method. As such, Paths.get(new URI("file:///domains/oracle/test.txt")) would be valid if changed to Paths.get(URI.create("file:///domains/oracle/test.txt"). However, the provided incorrect option Paths.get(new URI()) is assumed to be an error in transcription. 'Paths.get(URL.create("file:///domains/oracle/test.txt"))' is incorrect because URL does not have a create method. 'Paths.getPath("too")' and 'new Path("foo")' are also incorrect since Paths does not have a method named getPath, and Path is an interface that cannot be instantiated.

Discussion

6 comments
Sign in to comment
StavokOptions: AE
Jul 20, 2023

A and E are correct

StavokOptions: AE
Jul 30, 2023

You can easily create a Path object by using one of the following get methods from the Paths (note the plural) helper class: Path p1 = Paths.get("/tmp/foo"); Path p2 = Paths.get(args[0]); Path p3 = Paths.get(URI.create("file:///Users/joe/FileTest.java"));

dillemanOptions: AE
Sep 29, 2023

A and E

OmnisumemOptions: AE
Oct 3, 2023

tested: AE. We suppose it is URI.create instead of URL.create...

d7bb0b2Options: AE
Jan 8, 2024

A = ok E = ok (paths.get accepts string and URI as argument)

ASPushkinOptions: AE
May 17, 2024

E correct if URL changes to URI (URL doesn't have create method) A correct B failed Paths doesn't have method getPath() C failed Path doesn't have get(). It has of(). D failed Path - interface