b2-c09 Flashcards

1
Q

Name the five key interfaces of JDBC

A

Driver: Establishes a connection to the database
Connection: Sends commands to a database
PreparedStatement: Executes a SQL query
CallableStatement: Executes commands stored in the database
ResultSet: Reads results of a query

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the NIO.2 acronym stand for?

A

The second version of the Non-blocking Input/Output API. It is sometimes referred to as the “New I/O.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which legacy class is NIO.2 / java.nio.file.Path is intended to replace?

A

java.io.File

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the similarities between java.nio.file.Path and java.io.File?

A
  1. Both may refer to an absolute path or relative path within the file system.
  2. Both may refer to a file or a directory.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the differences between java.nio.file.Path and java.io.File?

A

Unlike the java.io.File class, the Path interface contains support for creating, detecting, and navigating symbolic link.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is symbolic link?

A

A symbolic link is a special file within a file system that serves as a reference or pointer to another file or directory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In general, symbolic links are transparent to the user, as the operating system takes care of resolving the reference to the actual file.

True/False

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the rationale for making Path an interface as opposed to a class

A

When a Path is created, the JVM returns a file system–specific implementation, such as a Windows or Unix Path class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

List six ways to create Path object

A

With/from:

  1. Path interface - Path.of()
  2. Paths class - Paths.get()
  3. URI class
  4. FileSystem class
  5. java.io.File class
  6. String values
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The simplest and most straightforward way to obtain a Path object is to use ________________________________________________________.

A

the static factory method defined within the Path interface.

public static Path of(String first, String… more)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Describe absolute path and relative path

A
  • if path starts with / it is absolute (Unix)
  • if path starts with a drive letter (c:), it is absolute (Windows)
  • otherwise, it is relative
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Path.of() can take a varargs besides a connected string of path elements. What is the benefit of this capability?

A

The advantage of the varargs is that it is more robust, as it inserts the proper operating system path separator for you.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Describe Path.of()

A

-a static method defined in Path interface

-Path factory method
public static Path of(String first, String… more)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How can a Path object be constructed from String values?

A

Relative

Path path1 = Path.of(“pandas/cuddly.png”);

Absolute -Windows

Path path2 = Path.of(“c:\zooinfo\November\employees.txt”);

Absolute - Unix

Path path3 = Path.of(“/home/zoodirectory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What parameters types does Path.of() take?

A
  1. String values

Path path1 = Path.of(“pandas/cuddly.png”);

Path path2 = Path.of(“c:\zooinfo\November\employees.txt”);

Path path3 = Path.of(“/home/zoodirectory

Or

  1. Varargs

Path path1 = Path.of(“pandas”, “cuddly.png”);

Path path2 = Path.of(“c:”, “zooinfo”, “November”, “employees.txt”);

Path path3 = Path.of(“/”, “home”, “zoodirectory”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Describe Paths.get()

A

-static method defined in java.nio.file.Paths factory class

-Paths factory method
public static Path get​(String first, String… more)

-Paths creates instances of Path interface

17
Q

What type of parameters does Paths.get() take?

A

-a String value

Path path1 = Paths.get(“pandas/cuddly.png”);

Path path2 = Paths.get(“c:\zooinfo\November\employees.txt”);

Or

-varargs

Path path3 = Paths.get(“/”, “home”, “zoodirectory”);

18
Q

Describe URI

A

-a constructor from java.net.URI class

  • a uniform resource identifier (URI) starts with schema words:
    file: // for local file systems,
    http: //, https://, ftp:// for remote file systems.
-URI Constructor
public URI(String str) throws URISyntaxException
19
Q

How do you convert URI to Path and Vice versa?

A

-URI to Path, using Path factory method
public static Path of(URI uri)

-URI to Path, using Paths factory method
public static Path get(URI uri)

-Path to URI, using Path instance method
public URI toURI()

URI a = new URI("file://icecream.txt");
Path b = Path.of(a);
Path c = Paths.get(a);
URI d = b.toUri();
20
Q

What are the other URI types (other than file://…)

A

http://

Path path5 = Paths.get(new URI(“http://www.wiley.com”));

ftp://

Path path6 = Paths.get(new URI(“ftp://username:secret@ftp.example.com”));

N.B. Knowing these syntaxes not expected for the exam; just know they exist.

21
Q

Describe FileSystems/FileSystem classes

A

-FileSystems creates instances of the abstract FileSystem

-FileSystems factory method
public static FileSystem getDefault()

22
Q

Describe getPath​(String first, String… more)

A

-FileSystem instance method

public Path getPath​(String first, String… more)

23
Q

Illustrate how to obtain Path instance using FileSystem

A

Path path1 = FileSystems.getDefault().getPath(“pandas/cuddly.png”);
Path path2 = FileSystems.getDefault()
.getPath(“c:\zooinfo\November\employees.txt”);
Path path3 = FileSystems.getDefault().getPath(“/home/zoodirectory”);

24
Q

How do you get remote file with FileSystems?

A

-FileSystems factory method
public static FileSystem getFileSystem​(URI uri)

-example

FileSystem fs = FileSystems.getFileSystem(
      new URI("http://www.selikoff.net")
       );
Path path = fs.getPath("duck.txt");
25
Q

Using a diagram, show relationships within NIO.2

A

Photo herefile:///var/folders/52/w8f7mgjn6ys319x4f_s5mpwh0000gn/T/com.apple.Safari/WebKitDropDestination-l4d49GeV/IMG_3144.jpeg

26
Q

How do you convert Path to java.io.File and vice versa?

A

-Path to File, using Path instance method
public default File toFile()

-File to Path, using java.io.File instance method
public Path toPath()

-examples:

File file = new File("husky.png");
Path path = file.toPath();
File backToFile = path.toFile();
27
Q

Describe the 2 file system symbols

A

. current directory

.. parent of current directory