Java Interview QA

What is significance of import java.io.* in your program?
A: The line imports all the classes of the java.io package into the current program.
Name the primitive data-types in java.
A: byte, short, int, long, float, double, char and Boolean
Give some examples of packages.
A: java.util, java.lang etc.
What is a class?
A: A class is the blueprint from which individual objects are created.
What is an object?
A: An object is an instance of a class.
Why do you write BufferedReader br = new ……. ?
A: To activate the Buffer memory for efficient input and output operations. ‘br’ is an object of the BufferedReader class.
Why do we have main() function?
A: The execution of the program begins from the main() method.
Why is the main method public?
A: So that it be accessible to the JVM which begins to execute the program from outside of the class.
Why is the main method static?
A: So that it be available for execution without the need of any object.
Is it compulsory to write String args[]?
A: No it is not.
Why do you write ‘throws IOException’?
A: For handling any input/output exceptions.
What are exceptions?
A: Exceptions are runtime errors which prevent the program from working normally.
Mention the two types of exceptions?
A: Checked Exceptions – Exceptions which are checked (handled) during compile time.
Example: IOException.
Unchecked Exceptions – Exceptions which are not checked during compile time.
Example: ArrayIndexOutOfBound.
Mention other ways in which java handles exceptions.
A: Java can handle exception using the try-catch block, throws keyword and throw keyword.
What is the difference between throws and throw?
A: Using throws keyword, we can give system defined error message if any error occurs, while using throw keyword, we can force an exception and give user-defined error messages.
What are wrapper class?
A wrapper class is a class which wraps (encloses) around a data type and gives it an object appearance. Wherever, the data type is required as an object, this object can be used.
What is type conversion? Name its types.
A: Converting a calue of a particular data type into another data-type is called type conversion. It is of two types:

(a) Implicit Type Conversion: When the conversion takes place on its own without the programmer’s intervention.
(b) Explicit Type Conversion: When the conversion takes place with the programmer’s intervention.
What are comments? Name the different types.
A: Comments are statements which enhances the readability and understanding of the program. They are not part of the program.

The different types are: single line (//….), multiple line (/* … */) and documenting comment (/**….*/).
What is Bubble sort?
A: Bubble sort is one of the easiest method of Sorting . This method based on successively selecting the smallest element, second smallest, third smallest and so on. The larger element push to down and do the sorting in ascending order.

SHARE THIS
Previous Post
Next Post