OOPS UNIT 4 Two Marks
OOPS UNIT 4 Two Marks
OOPS UNIT 4 Two Marks
1. What is stream?
Stream is basically a channel on which the data flow from sender to receiver.
2. What is input stream and output stream?
An input object that reads the stream of data from a file is called input stream and the
output object that writes the stream of data to a file is called output stream.
3. What is byte stream? Enlist its super classes?
The byte stream is used for inputting or outputting the bytes. The InputStream and
OutputStream are the superclass of byte stream.
4. What is character stream? Enlist its super classes?
The character stream is used for inputting or outputting the characters. The Reader and
Writer are the superclass of character stream.
5. List the byte stream classes?
The Byte Stream classes are
FileInputStream
FilterInputStream
FileOutputStream
FilterOutputStream
PipedInputStream
ByteArrayInputStream
PipedOutputStream
ByteArrayOutputStream
6. What is the purpose of BufferedInputStream and BufferedOutputStream classes?
These are efficient classes used for speedy read and write operations.
We can specify Buffer size while using these classes.
7. Give an example of stream?
There are two types of streams - Byte stream and Character stream.
11.Write a Java code to check if the command line argument is file or not?
class Test
If(obj.isFile())
FileInputStream(String filename);
FileInputStream(File fileobject);
13.What is the use of Input Stream Reader and Output Stream Writer?
The InputStreamReader converts byte into character and OutputStreamWriter
converts the characters written into byte.
14.Give an example for reading data from files using FileInput Stream?
import java.io.FileInputStream;
try
int i=0;
while((i=fin.read())!= -1)
System.out.print((char)i);
fin.close();
catch(Exception e)
System.out.println(e);
}
15.Why generic programming is required? Or What is the need for generic
programming? Or List out motivation needed in generic programming?
Following some reasons for the need of generic programming are
a) It saves the programmers burden of creating separate methods
for handling data belonging to different data types.
b) It allows the code reusability.
c) Compact code can be created.
16.With an example define a generic class. Or Describe generic classes?
A generic class contains one or more variables of generic data type. Simple example
which shows how to define the generic class.
public Test(){val=null;}
this.val=val;
public getVal()
return val;
public setVal()
val=newValue;
}
17.Can generic be used with inheritance in several ways? What are they?
Following are the ways by which generic can be used with inheritance are
Consider a class and a subclass such as Employee and Trainee. There are two
pair classes Pair<Employee> and Pair<Trainee> which do not possess an
inheritance relation. That is, Pair<Trainee> is not a subclass of Pair<Employee>
even if these two classes are related to each other.
The parameterised raw type can be converted to a raw type.
The generic classes can extend to implement other generic classes.
18.List any two advantages of type parameters.
Due to the use of type parameter it saves the programmers burden of creating
separate methods for handling data belonging to different data types.
Due to type parameter the early error detection at compile time occurs. This
avoids crashing of the code(due to type incompatibility) at run time.
19.State any two challenges of generic programming in virtual machine?
o The virtual machine does not work with generic classes or generic methods.
Instead it makes uses raw types in which the raw types are replaced with
ordinary java types. Each type variable is replaced with its bound or with object,
if it is not bounded. This technique is called type erasure.
o In order to handle the type erasure methods the compiler has to generate bridge
methods in corresponding class.
20.Difference between String and String Buffer in Java?
21.Difference Between String, StringBuilder and StringBuffer in Java?