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

java qb

The document outlines a comprehensive set of programming exercises and concepts in Java, covering topics such as basic programming, classes and objects, inheritance, exception handling, multithreading, functional interfaces, lambda expressions, and sealed classes. It includes tasks for creating various programs, implementing interfaces, handling exceptions, and utilizing Java's stream API. Additionally, it discusses the differences between traditional control structures and modern Java features like switch expressions.

Uploaded by

rudrabes
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)
0 views3 pages

java qb

The document outlines a comprehensive set of programming exercises and concepts in Java, covering topics such as basic programming, classes and objects, inheritance, exception handling, multithreading, functional interfaces, lambda expressions, and sealed classes. It includes tasks for creating various programs, implementing interfaces, handling exceptions, and utilizing Java's stream API. Additionally, it discusses the differences between traditional control structures and modern Java features like switch expressions.

Uploaded by

rudrabes
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
You are on page 1/ 3

UNIT-1

1. Write a program to display “hello world”.


2. Write a program that shows the use of bit wise operators.
3. Write a program that shows the use of arithmetic operators.
4. Write a program that shows the use of increment and decrement operators.
5. Write a program to display the area of circle using command line argument.
6. Write a java program to find the Area of Circle using Constructor.
7. Write a program to display the addition result of any two integers.
8. Write a program for the swapping of two numbers. 8. Write a program to print all the prime numbers
between 1 to 100.
9. Write a program to print all the palindrome number between 100 to 500.

Classes and Objects


10. Write a program to display the student name, roll no and age of a student using class and object concept.
11. Write a program to display emp. no=101 and emp. name=”Martin” using class and object concept.
12. Write a program to display car no., model, color and price of a car using class and object concept (use
Scanner class).
Static Keyword
13. Write separate programs that shows the implementation of (i) static variable and static member function (ii)
static block concept.

Constructors & Inheritance (abstract class & Interface)


14. Write a program that shows the use of default, parameterized and copy constructor.
15. Write a program to display the area of triangle, rectangle and circle using constructors.
16. Define a class person with data member as Aadharno, name, Panno implement concept of constructor
overloading. Accept data for 5 object and print it.

17. Write a program for single inheritance mechanism.


18. Write a program for the addition, subtraction, multiplication and division of two numbers using constructor.
19. Write a program to pass the arguments from child class constructor to parent class constructor using super (
).
20. Write a program to display name, department and age of employee using interface mechanism.
21. Write a program to display the name, pages, price and author of a book using interface mechanism.
22. Write a program that shows the use of multiple inheritance mechanism using interface.
23. Write a java program to implement multilevel inheritance with 4 levels of hierarchy.

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

Unit-2 Exception Handling


1. Write a Java program that throws an exception and catch it using a try-catch block.
2. Write a Java program to create a method that takes an integer as a parameter and throws an exception if the
number is odd.
3. Write a Java program to create a method that takes a string as input and throws an exception if the string
does not contain vowels.

UNIT-2 Input Output Basics & Multithreading

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

1. Define Functional Interface and explain its types with example.


2. Define Method Reference and explain its types with example.
3. Create a functional interface Calculator with a method int operate(int a, int b). Use a lambda expression to
implement addition, subtraction, multiplication, and division.
4. Create a functional interface StringOperation with a method String modify(String s). Use a lambda to:
i. Convert to uppercase
ii. Reverse the string
iii. Append a specific word

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.

Streams & Sealed Classes


14. Write a java code to display the elements of an ArrayList or array using stream API forEach method.
15. Write a Java interface called Greeting with a default method sayHello() that prints "Hello from default
method!". Implement this interface in a class and call the default method.
16. Create an interface Vehicle with a default method start() that prints "Vehicle is starting". Create a class Car
that implements Vehicle and overrides the default method. Test the output.
17. Write an interface MathUtils with a static method add(int a, int b) that returns the sum. Call this static
method from a main class without implementing the interface.
18. Create two interfaces A and B, each with a default method show(). Create a class C that implements both
interfaces and resolve the conflict by overriding the show() method.
19. Create a sealed class Animal that permits only Dog and Cat to extend it. Implement both subclasses and
display a message from each class using method overriding.
20. Create a sealed class Shape that permits only Circle and Square. Make Circle a final class. Show that you
cannot further extend Circle.
21. Create a sealed interface Device that permits Laptop, Tablet, and Smartphone. Implement each class and
demonstrate their behavior in a main method.
22. Create a sealed class Employee that permits Manager and Developer. Make Developer a non-sealed class
and then create another class Intern that extends Developer. Demonstrate polymorphism among all classes.
23. Write a sealed class Transport that only permits Bus and Train. Try to create a third subclass Bike and
observe the compile-time error. Explain the reason.
24. Create a sealed interface Notification with classes Email, SMS, and PushNotification. Use a switch
expression to handle different types of notifications and print a specific message.

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.

You might also like