Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 122

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

    Correct Answer: A, C

    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
ASPushkinOptions: AE

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

d7bb0b2Options: AE

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

OmnisumemOptions: AE

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

dillemanOptions: AE

A and E

StavokOptions: AE

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"));

StavokOptions: AE

A and E are correct