130. Why should we use object serialization?
The transient keyword is used to indicate the JVM that the variables that are marked as transient in an object is not part of the persistent state of the object and it should be excluded while saving the object.
- FileReader and FileWriter : Read data from or write data to a file on the native file system.
- PipedReader and PipedWriter : They are used to channel the output of a program or thread into the input of another program or thread.
- CharArrayReader and CharArrayWriter : Read data from or write data to a char array in memory.
134. What are FilterReader/FilterWriter, BufferedReader/BufferedWriter and PrintWriter?
- FilterReader and FilterWriters are subclasses of Reader and Writer, respectively. These classes define the interface for filtered streams which process data as it's being read or written.
- BufferedReader and BufferedWriter : They buffer data while reading or writing, in order to reduce the number of read/write access on the original data source.
- PrintWriter : An output stream with convenient print methods
135. What is a File class?
It represents a file on the native file system. We can create a File object for each file in the file system, so that we fetch the information about the file from the object. For example, Name, Full pathname etc.
136. What are the functionalaties we get using File class?
The File class in the java.io package provides various methods to access the properties of a file or a directory, such as file permissions, date and time of creation, and path of a directory.
Java Interview Questions on Threads
137. What are the benefit's of using threads in an application?
- It improves performance .
- It minimizes system resource usage.
- We can access multiple applications simultaneously.
- Threads simplifies the program structure.
- We can send & receive data on the network at the same time.
- We can read & write files to disk simultaneously.
138. What are the differences between process and threads?
Process
It is an executable program loaded in the memory. It has its own address space – variables & data structures (in memory). Process communicates via the operating system, files, network. A process may contain multiple threads.
Threads
It is sequentially executed stream of instructions. It shares an address space with other threads and it has it's own execution context.
139. What are the types of thread?
There are two types of thread:
- Single Threaded Process
- Multi Threaded Process
140. What is single threaded and multi threaded process?
- Single Threaded Process: A thread is defined as the independent path of execution within a program. A process that is made of one thread is known as single-threaded process.
- Multi Threaded Process: A process that creates two or more threads is called a multithreaded process.