0% found this document useful (0 votes)
15 views6 pages

Java Programming Concepts and VIVA Questions

The document outlines a series of Java programming tasks and corresponding viva questions covering various topics such as date and time API, string manipulation, modularization, exception handling, and threading. Each task includes a specific programming requirement along with a set of questions designed to test understanding of Java concepts. The tasks range from basic operations to more complex implementations involving object-oriented programming and concurrency.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views6 pages

Java Programming Concepts and VIVA Questions

The document outlines a series of Java programming tasks and corresponding viva questions covering various topics such as date and time API, string manipulation, modularization, exception handling, and threading. Each task includes a specific programming requirement along with a set of questions designed to test understanding of Java concepts. The tasks range from basic operations to more complex implementations involving object-oriented programming and concurrency.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Construct a Java program using the Date and Time API to display the current date,
the current time, and the current date-time separately.
VIVA QUESTIONS:
1. What is garbage collection in Java?
2. What are the four pillars of Object-Oriented Programming in Java?
3. What is bytecode in Java?
4. What is the difference between LocalDate, LocalTime, and LocalDateTime?
[Link] is the need of DATE AND TIME API?

[Link] a program using StringBuilder to check whether a given string is a palindrome or


not.

VIVA QUESTIONS:

1. What is a palindrome? Give examples.

[Link] is the difference between String, StringBuilder, and StringBuffer in Java?

[Link] is garbage collection in java?

[Link] is StringBuilder preferred over String for string manipulation?

[Link] java is platform independent?

[Link] modularization and switch-case control structure in Java to build a class


“MiniCalculator” that accepts two integers and an operator (+, -,* , /) from the user and
displays the calculated result.

VIVA QUESTIONS:
1. What is modularization in Java?
2. What happens if you forget to use break in a switch-case block?
3. What are the four pillars of Object-Oriented Programming in Java?
[Link] the types of operators in java?
5. Can switch-case work with String values in Java?

4. Apply filte r(), math () , reduce () methods to compute tha sum of square of even
numbers in a given list of number / integers.
VIVA QUESTIONS:
[Link] does filter() do in Java Streams?

[Link] is map() different from flatMap()?


[Link] do we use reduce() in this program?
[Link] can you identify even numbers using filter()?
[Link] Java Streams immutable or mutable?

5. Write a Java program that divides two integers. Handle the case where the denominator
is zero using ArithmeticException.

VIVA QUESTIONS:

[Link] is an exception in Java?

[Link] is the difference between checked and unchecked exceptions?

[Link] exception is thrown when dividing an integer by zero?

[Link] do you handle exceptions in Java?

5. What is the purpose of the try-catch block?

6. Write a program that filters out even numbers from a list using stream() and a lambda
expression.

VIVA QUESTIONS:

1. What is the purpose of the stream() method in Java?

[Link] does filter() work with a lambda expression?


[Link] a simple lambda expression to check if a number is even.
[Link] is the difference between forEach() and collect() in streams?
[Link] are streams considered more efficient than traditional loops

7. Create a superclass Employee with a variable salary. Create a subclass Manager that adds
a variable bonus. Write a program to calculate total earnings.

VIVA QUESTIONS:

[Link] is inheritance in Java?

[Link] is polymorphism?
3. What is the difference between super and this keywords?

[Link] a subclass override a method from its superclass?

5. What is the use of final keyword?

8. Write a Java program with a class Book that uses a default constructor to initialize values
and display them.

VIVA QUESTIONS:
1. What is the difference between a default constructor and a parameterized
constructor?
2. When is a constructor called in Java?
3. Can a constructor return a value? Why or why not?
4. What is a constructor in Java?
5. What is a parameterized constructor?

9. Write a program where a class Student implements two interfaces Sports and Academics.
Each interface should have a method, and Student should provide implementations.

VIVA QUESTIONS:
1. Can a class implement multiple interfaces?
2. How is implements different from extends?
3. Why must all methods in an interface be implemented in the class?
4. What is the default access modifier for interface methods?
5. What is an interface in Java?

10. Write a program to store 5 student names in an ArrayList and print them using an
iterator.

VIVA QUESTIONS:
1. What is polymorphism?
2. Difference between == and .equals()?
3. What is a constructor?
4. What is exception handling?
5. What is inheritance in Java?
11. Write a Java program to implement the Producer–Consumer problem using a
BlockingQueue.

 The Producer thread should generate integers from 1 to 10 and insert them into the
queue using put().

 The Consumer thread should retrieve and print the integers using take().

VIVA QUESTIONS:

1. Difference between put() and offer()?

2. Difference between take() and poll()?

3. What if queue is full on put()?

4. Can multiple producers/consumers share one queue?

5. What is BlockingQueue?

12. Write a program with classes Animal → Mammal → Dog. Override the sound() method
at each level and demonstrate polymorphism.

VIVA QUESTIONS:

1. Define polymorphism with an example.


2. Difference between compile-time and runtime polymorphism?
3. Why do we use @Override annotation?
4. Can a superclass reference hold a subclass object?
5. What is method overriding in Java?

13. Write a Java program that demonstrates the creation of threads using both Thread class
and Runnable interface.

 Create one thread by extending the Thread class that prints numbers from 1 to 5.
 Create another thread by implementing the Runnable interface that prints "Hello
from Runnable" five times.

VIVA QUESTIONS:

1. Why use start() instead of run()?

2. Can we extend multiple classes along with Thread?

3. What is the lifecycle of a thread?

4. How to create multiple threads in Java?

5. Difference between Thread class and Runnable interface?

14. Write a Java program that demonstrates deadlock using two threads and two resources.

 Thread 1 should lock Resource A and then try to lock Resource B.

 Thread 2 should lock Resource B and then try to lock Resource A.

Show how this leads to deadlock.

VIVA QUESTIONS:
1. Conditions for deadlock?
2. How to avoid deadlock?
3. Difference between lock and synchronized?
4. What is thread starvation?
5. What is deadlock?

15. Write a Java program using ReentrantLock to demonstrate deadlock avoidance between
two threads competing for two resources.

VIVA QUESTIONS:

1. Difference between synchronized and ReentrantLock?

2. Purpose of tryLock() method?

3. How does ReentrantLock help avoid deadlock?

4. What is ReentrantLock?
5. What is the difference between lock() and tryLock() in ReentrantLock?

You might also like