java qb
java qb
24. Write a Java program to create an abstract class Shape with abstract methods calculateArea() and
calculatePerimeter(). Create subclasses Circle and Triangle that extend the Shape class and implement the
respective methods to calculate the area and perimeter of each shape.
25. Write a Java program to create an abstract class BankAccount with abstract methods deposit() and
withdraw(). Create subclasses: SavingsAccount and CurrentAccount that extend the BankAccount class
and implement the respective methods to handle deposits and withdrawals for each account type.
26. Write a program to display name, department and age of employee using interface mechanism.
27. Write a Java program to create an interface Sortable with a method sort() that sorts an array of integers in
ascending order. Create two classes BubbleSort and SelectionSort that implement the Sortable interface and
provide their own implementations of the sort() method.
28. Develop a message abstract class which contains playMessage abstract method. Write a different sub-
classes like TextMessage, VoiceMessage and FaxMessage classes for to implementing the playMessage
method.
29. Develop a abstract Reservation class which has Reserve abstract method. Implement the subclasses like
ReserveTrain and ReserveBus classes and implement the same.
30. Develop an Interest interface which contains simpleInterest and compInterest methods and static final field
of Rate 25%. Write a class to implement those methods.
31. Develop a Library interface which has drawbook(), returnbook() (with fine), checkstatus() and
reservebook() methods. All the methods tagged with public.
Package
32. Write a program to display the area of circle, triangle and rectangle using user defined package
4. What is Multithreading? What are the ways to create multiple threads in java.
5. Explain about Thread Life Cycle.
6. Discuss how to set the priority to threads? What are the different ranges.
7. Write a java program to create two threads and execute simultaneously.
8. Write a java program to implement inter thread communication.
9. Write a Java program that creates three threads. First thread displays “Hello!” every one second, the second
thread displays “Wear Mask !” every two seconds and “Use Sanitizer !” every 5 seconds.
10. Write the difference between Extending thread and implementing runnable?
11. Write a program to create two threads, so one thread will print even numbers between 1 to 10 whereas
other will print odd numbers between 11 to 20.
12. Write any four methods of File Input stream class give their syntax.
13. Write a java program to copy the content of the file “file1.txt” into new file “file2.txt”.
14. Explain byte stream class in detail.
15. Differentiate between Input stream class and Reader class
16. Explain fileinputstream class to read the content of a file.
17. Write any two methods of file and file input stream class each.
18. Explain Stream Classes
19. Explain OutputStreamClass.
UNIT-3
Functional Interface, Lambda Expression & Method Reference
5. Use Java's Predicate<String> to test if a given string starts with a specific letter using a lambda expression.
6. Implement a Runnable using a lambda expression that prints "Running in a thread!".
7. Create a class MathUtils with a static method double square(double x). Use a method reference to refer to
this method via a functional interface DoubleFunction.
8. Create a class Person with a constructor Person(String name). Use a method reference to this constructor
with a functional interface and create a new instance.
9. Use Function<Integer, String> to convert an integer to its string equivalent and append " is a number" using
a lambda expression.
10. Explain types of functional interface with examples.
11. Create a class Printer with a method void print(String message). Use a method reference to refer to this
method from a functional interface and call it.
12. Explain YIELD keyword and Sealed classes.
13. Explain java module system and inner anonymous class.
25. Explain Java stream API and its applications. Describe Intermediate and terminal operations with suitable
example. Write a program to print sum of all even numbers form an ArrayList<Integer> containing all
integers from 1 to 10.
26. Compare and contrast switch-case statement with switch-expression in Java. Explain with suitable
example.