0% found this document useful (0 votes)
5 views5 pages

Viva Questions Java

The document contains a comprehensive list of Java lab viva questions and answers, organized by experiments covering topics such as Java fundamentals, searching and sorting algorithms, classes and methods, inheritance, polymorphism, exception handling, multithreading, packages, JavaFX, and JDBC. Each section includes key concepts, definitions, and differences between related terms. It serves as a study guide for understanding core Java programming principles and practices.

Uploaded by

mahesh
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)
5 views5 pages

Viva Questions Java

The document contains a comprehensive list of Java lab viva questions and answers, organized by experiments covering topics such as Java fundamentals, searching and sorting algorithms, classes and methods, inheritance, polymorphism, exception handling, multithreading, packages, JavaFX, and JDBC. Each section includes key concepts, definitions, and differences between related terms. It serves as a study guide for understanding core Java programming principles and practices.

Uploaded by

mahesh
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 LAB – VIVA QUESTIONS & ANSWERS (Experiment-wise)

EXPERIMENT – 1: Java Fundamentals


1. What are primitive data types in Java?
Primitive data types are basic data types that store simple values.
They are: byte, short, int, long, float, double, char, boolean.

2. What is the default value of primitive data types?


Data Type Default Value
byte 0
short 0
int 0
long 0L
float 0.0f
double 0.0
char '\u0000'
boolean false

3. What is a control structure?


Control structures determine the flow of execution of a program.
Examples: if, if-else, switch, for, while, do-while.

4. What is a quadratic equation?


An equation of the form ax² + bx + c = 0, where a ≠ 0.

5. What is discriminant?
Discriminant D = b² − 4ac determines the nature of roots.

6. Nature of roots based on discriminant value?


D > 0 → Two distinct real roots
D = 0 → Two equal real roots
D < 0 → Complex roots

EXPERIMENT – 2: Searching, Sorting, Strings


7. What is binary search?
Binary search is a searching technique that works on sorted arrays by repeatedly dividing the
search interval into half.

8. Time complexity of binary search?


O(log n)
9. What is bubble sort?
Bubble sort repeatedly compares adjacent elements and swaps them if they are in the wrong
order.

10. Time complexity of bubble sort?


Worst case: O(n²)
Best case: O(n) (optimized)

11. What is StringBuffer?


StringBuffer is a mutable class used to modify strings.

12. Difference between String and StringBuffer?


String StringBuffer
Immutable Mutable
Slower Faster
Thread-safe Thread-safe

EXPERIMENT – 3: Classes, Methods, Constructors


13. What is a class?
A class is a blueprint that defines properties and methods of an object.

14. What is an object?


An object is an instance of a class.

15. What is a method?


A method is a block of code that performs a specific task.

16. What is method overloading?


Defining multiple methods with the same name but different parameters.

17. Is method overloading compile-time or run-time?


Compile-time polymorphism

18. What is a constructor?


A constructor is a special method used to initialize objects.

19. Rules for constructors?


Same name as class
No return type
Automatically invoked

20. What is constructor overloading?


Multiple constructors in a class with different parameter lists.
EXPERIMENT – 4: Inheritance & Abstraction
21. What is inheritance?
Inheritance allows one class to acquire properties of another class using extends keyword.

22. Types of inheritance in Java?


Single
Multilevel
Hierarchical
(Multiple inheritance is not supported using classes)

23. What is an abstract class?


A class declared with abstract keyword that may contain abstract methods.

24. Can we create object of abstract class?


❌No, we cannot instantiate an abstract class.

25. Why abstract classes are used?


To provide partial implementation and enforce method overriding.

EXPERIMENT – 5: Polymorphism, Interface, super


26. What is super keyword?
Used to:
Refer parent class variables
Call parent class constructor

27. What is an interface?


An interface is a blueprint containing abstract methods and constants.

28. How do we implement an interface?


Using the implements keyword.

29. What inheritance does interface support?


Multiple inheritance

30. What is runtime polymorphism?


Method overriding where method call is resolved at runtime.

31. Which keyword is used for runtime polymorphism?


method overriding

EXPERIMENT – 6: Exception Handling


32. What is an exception?
An exception is an event that disrupts normal execution of a program.
33. Difference between error and exception?
Error Exception
Compile/Runtime Runtime
Not recoverable Recoverable

34. What are keywords used in exception handling?


try, catch, finally, throw, throws

35. What is multiple catch?


Handling multiple exceptions using multiple catch blocks.

36. What is a user-defined exception?


Custom exception created by extending Exception class.

EXPERIMENT – 7: Multithreading
37. What is a thread?
A thread is a lightweight process.

38. How to create a thread?


Extend Thread class
Implement Runnable interface

39. Difference between Thread and Runnable?


Runnable is preferred because it supports multiple inheritance.

40. What is isAlive() method?


Checks whether a thread is still running.

41. What is join() method?


Makes one thread wait until another thread completes.

42. What is a daemon thread?


A background thread that runs until all user threads finish.

43. What is Producer-Consumer problem?


A classic synchronization problem using wait() and notify().

EXPERIMENT – 8: Packages & JavaFX


44. What is a package?
A package is a group of related classes and interfaces.
45. Why packages are used?
Code reusability
Namespace management
Access protection

46. What is JavaFX?


JavaFX is a framework for building GUI applications in Java.

47. What is Label in JavaFX?


Used to display text.

48. What is ImageView?


Used to display images in JavaFX.

49. What is event handling?


Responding to user actions like button click.

EXPERIMENT – 9: JDBC
50. What is JDBC?
Java Database Connectivity is an API to connect Java applications with databases.

51. Steps to connect JDBC?


Load driver
Create connection
Create statement
Execute query
Close connection

52. What is DriverManager?


Manages database drivers.

53. What is PreparedStatement?


Used to execute parameterized queries.

54. Advantage of JDBC?


Platform independent
Secure database interaction

55. What SQL operations are commonly used?


SELECT, INSERT, UPDATE, DELETE

You might also like