java 2 3
fdsa
fdsa
Kartei Details
Karten | 496 |
---|---|
Sprache | Deutsch |
Kategorie | Informatik |
Stufe | Andere |
Erstellt / Aktualisiert | 06.12.2020 / 24.01.2021 |
Weblink |
https://card2brain.ch/box/20201206_java_2_3
|
Einbinden |
<iframe src="https://card2brain.ch/box/20201206_java_2_3/embed" width="780" height="150" scrolling="no" frameborder="0"></iframe>
|
Whats the signature for closing a stream and releasing resoruces ? For what stream class(es)?
void close() - All streams
Whats the signature for reading a single byte/return -1 if no bytes are availiable? For what stream class(es)?
int read() -- all input-streams
Whats the signature for reading values into a buffer, returning the number of bytes read? For what stream class(es)?
int read(byte[] b) / int read(char[] c) : InputStream / Reader
Whats the signature for reading up to length values into a buffer starging from offset, returning number of bytes read? For what stream class(es)?
- int read(byte[] b, int offset, int length) - InputStream
- int read(char[] c, int offset, int length) - Reader
Whats the signature for writing a single byte? For what stream class(es)?
void write(int) - all output streams
Whats the signature for writing an array of values into the stream? For what stream class(es)?
- void write(byte[] b) - OutputStream
- void write(char[] c) - Writer
Whats the signature for writing length values from an array into the stream, starting with an offset index? For what stream class(es)?
- void write(byte[] b, int offset, int length) - OutputStream
- void write(char[] c, int offset, int length) - Writer
Whats the signature for returning true if the stream supports mark? For what stream class(es)?
boolean markSupported() - All input streams
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