b2-c09 Flashcards
Name the five key interfaces of JDBC
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
What does the NIO.2 acronym stand for?
The second version of the Non-blocking Input/Output API. It is sometimes referred to as the “New I/O.”
Which legacy class is NIO.2 / java.nio.file.Path is intended to replace?
java.io.File
What are the similarities between java.nio.file.Path and java.io.File?
- Both may refer to an absolute path or relative path within the file system.
- Both may refer to a file or a directory.
What are the differences between java.nio.file.Path and java.io.File?
Unlike the java.io.File class, the Path interface contains support for creating, detecting, and navigating symbolic link.
What is symbolic link?
A symbolic link is a special file within a file system that serves as a reference or pointer to another file or directory
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
True
What is the rationale for making Path an interface as opposed to a class
When a Path is created, the JVM returns a file system–specific implementation, such as a Windows or Unix Path class.
List six ways to create Path object
With/from:
- Path interface - Path.of()
- Paths class - Paths.get()
- URI class
- FileSystem class
- java.io.File class
- String values
The simplest and most straightforward way to obtain a Path object is to use ________________________________________________________.
the static factory method defined within the Path interface.
public static Path of(String first, String… more)
Describe absolute path and relative path
- if path starts with / it is absolute (Unix)
- if path starts with a drive letter (c:), it is absolute (Windows)
- otherwise, it is relative
Path.of() can take a varargs besides a connected string of path elements. What is the benefit of this capability?
The advantage of the varargs is that it is more robust, as it inserts the proper operating system path separator for you.
Describe Path.of()
-a static method defined in Path interface
-Path factory method
public static Path of(String first, String… more)
How can a Path object be constructed from String values?
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
What parameters types does Path.of() take?
- 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
- Varargs
Path path1 = Path.of(“pandas”, “cuddly.png”);
Path path2 = Path.of(“c:”, “zooinfo”, “November”, “employees.txt”);
Path path3 = Path.of(“/”, “home”, “zoodirectory”);
Describe Paths.get()
-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
What type of parameters does Paths.get() take?
-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”);
Describe URI
-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
How do you convert URI to Path and Vice versa?
-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();
What are the other URI types (other than file://…)
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.
Describe FileSystems/FileSystem classes
-FileSystems creates instances of the abstract FileSystem
-FileSystems factory method
public static FileSystem getDefault()
Describe getPath(String first, String… more)
-FileSystem instance method
public Path getPath(String first, String… more)
Illustrate how to obtain Path instance using FileSystem
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”);
How do you get remote file with FileSystems?
-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");
Using a diagram, show relationships within NIO.2
Photo herefile:///var/folders/52/w8f7mgjn6ys319x4f_s5mpwh0000gn/T/com.apple.Safari/WebKitDropDestination-l4d49GeV/IMG_3144.jpeg
How do you convert Path to java.io.File and vice versa?
-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();
Describe the 2 file system symbols
. current directory
.. parent of current directory