java 2 3
fdsa
fdsa
-
- 1 / 496
-
Flashcards
Are there any neccessary special characters for outparameters?
No, it is optional to put ?= in front: "{?= call magic_number(?) }"
Whats important to register with OUT/INOUT parameters?
registerOutParamenter() for each OUT/INOUT parameter:
cs.registerOutParameter(1, Types.INTEGER)
Doe we call executeQuery for calls to stored procedures with OUT-parameters?
No, we use execute() since we are not returning a ResultSet
How to use a INOUT parameter here?:
var sql = "{call double_number(?)}"
try (var cs = conn.prepareCall(sql)) {
// fill in the gap
}
cs.setInt(1,8);
cs.registerOutParameter(1, Types.INTEGER);
cs.execute();
System.out.println(cs.getInt("num"));
Whats the order of closing DB resources?
ResultSet, Prepared/Callable-Statement, Connection
Is it neccessary to close DB resoruces in the right order?
Yes, to avoid resource leaks and exceptions
What happens with a resultset if we run another query from the same statement?
JDBC automatically closes a ResultSet when we run another SQLstatement from the same statement
What are the only I/O classes we have to know for the exam which doesnt have complementary InputStream or Reader classes?
PrintStream and PrintWriter
Is "Object" serializable?
No
Can a File-instance only represent a File?
No, also a directory
How to get the local separator character?
System.getProperty("file.separator");
What are the three main constructors for File?
Has the File to exist?
public File(String pathname)
public File(File parent, String child)
public File(String parent, String child)
-> Represents only the path to a file, not an actual file
What happens with new File(parent, child) if the parent is null?
Will be skipped and the method will revert to the single String constructor
Does a directory have to be empty for File.delete()?
Yes, if not it will return false
How to check if a file exists with the File-object?
boolean exists()
How to retrieve the absolute name of the file/directory with a File-object?
String getAbsolutePath()
How to retrieve the name of a file/directory with a File-Object?
String getName()
How to retrieve the parentDirectory of a File-Object? Whats if there is none?
String getParent() -> null if no parent
How to check if a File-object is a directory?
boolean isDirectory()
How to check if a File-Object is a File?
boolean isFile();
how to return the number of milliseconds since the epoch when the file was last modified for a File-Object?
long lastModified()
How to return the length of a File-Object? What if the file doesnt exist?
long length() -> 0L if not exists
How to retrieve a list of files within a directory with a Files-Object?
File[] listFiles()
How to create a directory with a File-Object?
boolean mkdir()
boolean mkdirs()
How to rename a file/directory with a File-Object?
boolean renameTo(File dest)
What is the benefit of a BufferedOutput-Stream?
Can write a large chunk of bytes at a time, reducing round-tips and improve perfomance
Which two sets of stream-classes are difined in the java.io.API? How does the names end?
- Byte-streams that end in InputStream/OutputStream
- Character streams that end in Reader/Writer
Are Reader/Writers still streams?
Yes, I/O Streams
What are advantages of using a characterstream even if byte streams can do everything?
They are specificially focused on managing character/stringdata -> no need to worry about the underlying characterencoding of the file
Does the class PrintReader exist compliant to PrintWriter?
No
Is there a InputStream class for PrintStream?
Npo
What are the four abstract parents of all Streams?
InputStream, OutputStream, Reader, Writer
Whats wrong here?:
- new BufferedInputStream(new FileReader("z.txt"));
- new BufferedWriter(new FileOutpuitStream("z.txt"));
- new ObjectInputStream(new FileOutputStream("z.txt"));
- new BufferedInputStream(new InputStream());
- Mix reader/writer
- "
- Mix outputStream with InputStream
- InputStream is a abstract class
Whats the stream-class for reading file data as bytes? Low/Highlvl?
FileInputStream - low
Whats the stream-class for writing file data as bytes? Low/Highlvl?
FileOutputStream - low
Whats the stream-class for reading file data as characters? Low/Highlvl?
FileReader -low
Whats the stream-class for writing file data as characters? Low/Highlvl?
FileWriter - low
Whats the stream-class for reading byte data from exsting InputStream in buffered manner? Low/Highlvl?
BufferedInputStream - high
Whats the stream-class for writing byte data to an existing outputstream in a buffered manner? Low/Highlvl?
BufferedOutputStream - High
Whats the stream-class for reading character data from exsting Reader in a buffered manner? Low/Highlvl?
BufferedReader - high