Govt Exams
Statement interface is used to execute SQL queries. Connection is used to establish database connection, ResultSet holds query results, and Driver manages database connections.
Serializable is a marker interface (contains no methods) that signals to the JVM that objects of that class can be serialized. The absence of abstract methods means implementing classes don't need to override any methods; they just need to implement the interface to indicate serialization support.
DataInputStream is specifically designed to read primitive data types like int, double, boolean, etc. from an input stream. BufferedInputStream provides buffering, FileInputStream reads from files, and ObjectInputStream deserializes objects.
FileOutputStream fos = new FileOutputStream("test.txt", true);
What does the 'true' parameter indicate?
The second parameter 'true' in FileOutputStream constructor indicates append mode. If 'false' or omitted, the file is overwritten. With 'true', new data is appended to the existing file.
The flush() method forces any buffered output bytes to be written out. It does not close the stream, allowing further writes after flushing.
The Serializable interface must be implemented to serialize objects. It is a marker interface with no methods. Classes implementing it can be serialized using ObjectOutputStream.
FileInputStream is a byte stream class, not a character stream. FileReader, BufferedWriter, and PrintWriter are all character stream classes.
DataOutputStream provides methods like writeInt(), writeFloat(), writeDouble() to write primitive types in binary format.
BufferedInputStream wraps another InputStream and buffers input, reducing the number of actual read operations and improving performance significantly.
flush() forces any buffered data to be written to the underlying stream immediately, ensuring data is not lost in the buffer.