java 2 3
fdsa
fdsa
-
- 1 / 496
-
Flashcards
Whats the signature for marking the current positin in the stream? For what stream class(es)?
mark(int readLimit) - all input streams
Whats the signature for attempting to reset the stream to the mark() position? For what stream class(es)?
void reset() - all inputstreams
Whats the signature for reading and discarding a specified number of characters? For what stream class(es)?
long skip(long n) - all input streams
Whats the signature for flushing buffered data through the stream? For what stream class(es)?
void flush() - all output streams
What are the constructors for FileInputStream?
- public FileInputStream(File file) throws FileNotFoundException
- public FileInputStream(String name) throws FileNotFoundException
What are the Constroucts for FileOutputStream?
- public FileOutputStream(File file) throws FileNotFoundException
- public FileOutputStream(String name) throws FileNotFoundException
What are the constructs of BufferedInputstream and BufferedOutputStream?
- public BufferedInputStream(InputStream in)
- public BufferedOutputStream(OutputStream out)
What are the Constructors of FileReader and FileWriter?
- public FileReader(File file) throws FileNotFoundException
- public FileReader(String name) throws FileNotFoundException
- public FileWriter(File file) throws FileNotFoundException
- public FileWriter(String name) throws FileNotFoundException
What are the constructors of BufferedReader/Writer?
- public BufferedReader(Reader in)
- public BufferedWriter(Writer out)
What are two additional Methods on BufferedReader/Writer for working with String-values?
- BufferedReader: public String readLine() throws IOException
- BufferedWriter : public void newLine() throws IOException
What happens if a process tries to serialize an object but it doesnt implement the serializable interface?
throws NotSerializableException
What are the constructos of ObjectOutputStream/ObjectInputStream?
- public ObjectInputStream(InputStream in) throws IOException
- public ObjectOutputStream(OutputStream out) throws IOException
Does null or -1 have a special meaning in ObjectInputStream.readObject()?
no as someone might have serialized objects with those values
How does the serialization work?
Java only calls the constructor of the first non-serializable parent class in the hierarchy
What are Constructors of PrintStream/PrintWriter?
- public PrintStream(File file) throws FileNotfoundException
- public PrintStream(String fileName) throws FileNotfoundException
- public PrintWriter(File file) throws FileNotfoundException
- public PrintWriter(String fileName) throws FileNotfoundException
How to check if there was a error within a printStream-class (as they do not throw checked exceptions)?
with checkError()
What are the signatures of PrintStream/PrintWriter.format-methods?
- public PrintStream format(String format, Object args...)
- public PrintStream format(Locale loc, String format, Object args...)
- public PrintWriter format(String format, Object args...)
- public PrintWriter format(Locale loc, String format, Object args...)
What happens here?
System.out.format("Food: %d tons", 2.0);
IllegalFormatConversionException -> int expected, floating point provided -> use %f instead
Why is it unnecessary/ unrecommended to close SystemStreams (like System.out)?
The JVM creates and opens them for us -> closing makes them permantly unavailiable for all threads in the remainder of the programm
What happens here?:
try(var out = System.out) {}
System.out.println("Hello");
Prints nothing
What happens here?
try (var err = System.err) {}
System.err.println("Hello");
Prints nothing
What happens here?
var reader = new BufferedReader(new InputStreamReader(System.in));
try(reader) {}
String data = reader.readLine();
IOException at runtime -> most InputStream classes will throw an exception if you try to operate on a closed stream
Which exception is thrown by Files.deleteIfExists?
IOException
Whats the NIO2 replacement for java.io.File.class?
java.nio.file.Path
Do we make a difference in how we treat a instance if it is a file or directory in NIO2?
No
Does Path support symbolic links?
Yes
Does java.io.File support symbolic Links?
No
Can we create an instance of Path directly?
No, is a interface
Whats the syntax of the Path factory method?
public static Path of(String first, String... more)
Whats the characteristics of a relative / absolute path for the exam?
A absolute starts with / -> the root directory or with c: .. / d://
a relative would be f.e.: bird/parrot.png
What does the varags in Path.of do?
accepts additional path elements whcih will be combined and automatically be separated by the operation system-depending file separator
What are two ways to get a instance of Path?
Path.of and Paths.get
What are ways to get a Path instance from a Uri?
f.e.: URI a = new URI("file://iceman.txt");
Path b = Path.of(a);
Path c = Paths.get(a);
URI d = b.toUri();
How to get a Path via Filesystems? Whats the syntax?=
FileSystems.getDefault().getPath("/home/zooDirectory");
How to convert a Fileto a Path? How the other way around?
File file = new File("some.png");
Path path = file.toPath();
File backToFile = path.toFile();
Whats the enum value,type and inherited interface for not following symoblic links?
NOFOLLOW_LINKS , LinkOption, CopyOption/OpenOption
Whats the enum value,type and inherited interface for moving a file as atomic file system operation?
ATOMIC_MOVE, StandardCopyOption , CopyOption
Whats the enum value,type and inherited interface for coping existing attributes to new file?
COPY_ATTRIBUTES , StandardCopyOption , CopyOption
Whats the enum value,type and inherited interface for overwriting files if it already exist?
REPLACE_EXISTING , StandardCopyOption , CopyOption
Whats the enum value,type and inherited interface for appending to the end of a file if it is already open for write
APPEND, StandardOpenOption , OpenOption