0% found this document useful (0 votes)
6 views3 pages

Java Viva Questions

The document contains a series of Java viva questions covering various topics such as constructors, function overloading, inheritance, abstract classes, I/O streams, type conversion, exception handling, networking concepts, JDBC, event handling, and JavaFX GUI. Each section includes definitions and explanations of key concepts, mechanisms, and components relevant to Java programming. The content serves as a comprehensive guide for understanding fundamental Java principles and practices.

Uploaded by

zendrous961
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Java Viva Questions

The document contains a series of Java viva questions covering various topics such as constructors, function overloading, inheritance, abstract classes, I/O streams, type conversion, exception handling, networking concepts, JDBC, event handling, and JavaFX GUI. Each section includes definitions and explanations of key concepts, mechanisms, and components relevant to Java programming. The content serves as a comprehensive guide for understanding fundamental Java principles and practices.

Uploaded by

zendrous961
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java viva questions

1. Constructors and Destructors (Array of Objects)


Q1. What is a constructor?
A constructor is a special method in a class that is automatically called when an object is
created. It is used to initialize object variables. It has the same name as the class and no return
type.
Q2. What is a destructor?
A destructor is used to release resources when an object is destroyed. In Java, destructors are
not explicit; memory management is handled by the garbage collector. The finalize() method
was used earlier but is now deprecated.
Q3. What is an array of objects?
An array of objects is a collection where each element is an object of a class. First, the array is
declared, and then each element is initialized individually. It helps manage multiple objects
efficiently.
2. Function Overloading
Q1. What is function overloading?
Function overloading allows multiple methods with the same name but different parameter lists.
It improves code readability and reusability. It is an example of compile-time polymorphism.
Q2. What is compile-time polymorphism?
It is the ability of a program to decide which method to call at compile time. Method overloading
and operator overloading are examples. It improves performance as decisions are made early.
Q3. Can return type alone differentiate overloaded methods?
No, methods cannot be overloaded based only on return type. The parameter list must differ in
number, type, or order. Otherwise, it leads to a compilation error.
3. Inheritance
Q1. What is inheritance?
Inheritance is a mechanism where one class acquires properties and methods of another class.
It promotes code reuse and hierarchical classification. The parent class is called the superclass,
and the child is the subclass.
Q2. What is multilevel inheritance?
In multilevel inheritance, a class is derived from another derived class. It forms a chain-like
structure (A → B → C). Each level inherits features from the previous one.
Q3. Why Java does not support multiple inheritance?
Java does not support multiple inheritance using classes to avoid ambiguity problems. Instead,
it uses interfaces to achieve multiple inheritance. This ensures better clarity and avoids conflicts.
4. Abstract Classes
Q1. What is an abstract class?
An abstract class is a class that cannot be instantiated and may contain abstract and concrete
methods. It is used as a base class for other classes. It helps achieve abstraction.
Q2. What is an abstract method?
An abstract method is declared without implementation and must be defined in a subclass. It
ensures that subclasses provide specific functionality. It is declared using the ‘abstract’ keyword.
Q3. Why use abstract classes?
Abstract classes provide a common template for related classes. They help in achieving
abstraction and code reuse. They also enforce method implementation in derived classes.
5. I/O Streams
Q1. What is a stream?
A stream is a sequence of data used for input and output operations. It connects a program to a
data source or destination. Streams can be byte-based or character-based.
Q2. Difference between byte and character streams?
Byte streams handle raw binary data like images and files. Character streams handle text data
and support Unicode. Character streams are more suitable for text processing.
Q3. What are FileInputStream and FileOutputStream?
FileInputStream is used to read data from a file. FileOutputStream is used to write data to a file.
Both are byte stream classes in Java.
6. Type Conversion
Q1. What is type casting?
Type casting is converting one data type into another. It can be done automatically or manually.
It is useful when working with different data types.
Q2. What is implicit conversion?
Implicit conversion is done automatically by the compiler when converting a smaller data type to
a larger one. It is safe and does not cause data loss. Example: int to double.
Q3. What is explicit conversion?
Explicit conversion is manually done by the programmer using casting. It is used when
converting larger data types to smaller ones. It may lead to data loss.
7. Exception Handling
Q1. What is an exception?
An exception is an error that occurs during program execution. It disrupts the normal flow of the
program. Java provides mechanisms to handle such errors.
Q2. What is try-catch block?
The try block contains code that may cause an exception. The catch block handles the
exception. This prevents program termination and ensures smooth execution.
Q3. What is finally block?
The finally block always executes whether an exception occurs or not. It is used to release
resources like closing files. It ensures cleanup operations are performed.
8. Networking Concepts
Q1. What is a socket?
A socket is an endpoint for communication between two machines over a network. It enables
data transfer between client and server. It uses IP address and port number.
Q2. What is an IP address?
An IP address is a unique identifier assigned to each device in a network. It helps in locating
and communicating with devices. It can be IPv4 or IPv6.
Q3. What is TCP?
TCP is a reliable communication protocol. It ensures data is delivered accurately and in order. It
is widely used for applications like web browsing and email.
9. JDBC
Q1. What is JDBC?
JDBC stands for Java Database Connectivity. It is used to connect Java applications with
databases. It allows executing SQL queries and retrieving results.
Q2. What are the steps in JDBC?
First, load the driver, then establish a connection. Next, create a statement and execute queries.
Finally, close the connection to free resources.
Q3. What is ResultSet?
ResultSet is an object that stores data returned from a database query. It allows traversal of
data row by row. It provides methods to retrieve column values.
10. Event Handling (Calculator)
Q1. What is an event?
An event is an action performed by the user, like clicking a button. It triggers a response in the
program. Events are handled using event-handling mechanisms.
Q2. What is an event listener?
An event listener is an interface that handles events. It contains methods that respond to
specific actions. It is attached to components like buttons.
Q3. What is ActionListener?
ActionListener is an interface used to handle button click events. It contains the method
actionPerformed(). It is commonly used in GUI applications.
11. JavaFX GUI
Q1. What is JavaFX?
JavaFX is a framework used to build graphical user interfaces. It provides rich UI components
and layouts. It is used for modern desktop applications.
Q2. What is a Stage?
Stage is the main window of a JavaFX application. It acts as the top-level container. All UI
components are displayed inside it.
Q3. What is a Scene?
A Scene is a container that holds all UI elements. It is placed inside the Stage. It organizes and
displays components like buttons and layouts.

You might also like