0% found this document useful (0 votes)
8 views8 pages

Question - Bank Java Oops

The document contains a comprehensive set of questions and tasks related to Java programming, covering various topics such as Java fundamentals, exception handling, collections framework, and Spring framework. It includes both 2-mark and 7-mark questions that explore concepts like inheritance, polymorphism, functional interfaces, and dependency injection. Additionally, there are programming tasks that require the implementation of classes and methods to demonstrate understanding of the concepts discussed.

Uploaded by

vivanshjaiswal14
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)
8 views8 pages

Question - Bank Java Oops

The document contains a comprehensive set of questions and tasks related to Java programming, covering various topics such as Java fundamentals, exception handling, collections framework, and Spring framework. It includes both 2-mark and 7-mark questions that explore concepts like inheritance, polymorphism, functional interfaces, and dependency injection. Additionally, there are programming tasks that require the implementation of classes and methods to demonstrate understanding of the concepts discussed.

Uploaded by

vivanshjaiswal14
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/ 8

UNIT-1

2 Marks question.

1. What is the main advantage of Java being platform-independent?


2. Name two key features of Java.
3. Who developed Java and in which year?
4. What is the role of the JVM in Java?
5. Differentiate between JDK and JRE.

6. What is bytecode in Java?


7. Write the structure of a basic Java class.
8. What command is used to compile a Java program?
9. What is the file extension of compiled Java code?
10. What is the purpose of the main method in Java?
11. What is a constructor in Java?
12. State the difference between static and instance variables.
13. Define the term "access specifier" with an example.
14. What is the use of the final keyword?
15. Name any two primitive data types in Java.
16. Write a simple for loop syntax in Java.
17. How is an array declared in Java?
18. What is the difference between == and .equals() in strings?
19. Name two types of control flow statements in Java.
20. Write a one-line Java statement to declare and initialize a string.
21. Define encapsulation in Java.
22. What is method overloading?
23. How is inheritance implemented in Java?
24. Mention one difference between an abstract class and an interface.
25. What does polymorphism mean in Java?
26. What is a Java package? Give one example.
27. How do you define a custom package in Java?
28. What is the purpose of the import statement in Java?
29. Differentiate between import and static import.
30. Write the syntax to import a single class from a package.
31. How do you set the CLASSPATH for a user-defined package?
32. What is the use of the jar command in Java?
33. Write the command to create a JAR file named library.jar containing class files.
34. Explain the naming convention used for Java packages.
35. What happens if you do not use the import statement in a Java file?

7 marks question (Unit-1)

1. Explain the architecture of the Java platform, including JVM, JRE, and JDK. How do
these components interact during the execution of a Java program?
(Include a labeled diagram for better clarity.)
2. Discuss the key features of Java that make it suitable for modern software development.
Provide examples where applicable.
3. Describe the structure of a Java source file. Write a simple Java program and explain the
compilation and execution steps involved.
4. What is bytecode? Explain the process by which Java achieves platform independence
using the JVM.
5. Differentiate between static and instance members in Java. Illustrate with a code
example that uses both.
6. Explain the different types of access specifiers in Java. Provide an example showing how
access levels affect class, method, and variable accessibility.
7. Write a Java program to demonstrate the use of arrays and control flow statements.
Explain the logic of your program.
8. What is inheritance in Java? Explain with an example. Also, differentiate between
method overloading and method overriding.
9. 9.Explain the concepts of abstraction and polymorphism in Java. Use appropriate
examples involving interfaces and abstract classes.
10. Discuss encapsulation and its importance in Java. How does it support data hiding and
security? Provide a code example.
11. What are packages in Java? How are they created and used? Explain with a code example
and show how to compile and run a program using a user-defined package.
12. Differentiate between import and static import with suitable examples. Also, explain
the naming convention for packages and the purpose of CLASSPATH.
13. What is a constructor in Java? How is it different from a method? Explain different types
of constructors (default, parameterized, copy constructor) with suitable examples.
14. Write a Java program that demonstrates the use of constructor overloading. Explain how
Java determines which constructor to call during object creation.
15. Discuss the concept of constructor chaining in Java using this() and super(). Write a
program that shows constructor chaining within a class and between a superclass and
subclass.
16. How does Java handle constructor inheritance in subclassing? Can a subclass inherit
constructors from its superclass? Justify your answer with an example.
17. Explain the importance of constructors in object initialization. What happens if you don’t
explicitly define a constructor in a class? Provide an example to support your
explanation.
18. Describe multiple inheritance, write a program to achieve multiple inheritance in java.

Unit -2 (2 marks question)

1. What is the difference between an exception and an error in Java?


2. Define the term “exception” with an example.
3. Name any two built-in exception classes in Java.
4. What is the role of the finally block in exception handling?
5. Write the syntax for using try-catch in Java.
6. Differentiate between checked and unchecked exceptions.
7. What does the throw keyword do in Java?
8. What is the purpose of the throws keyword?
9. Name two unchecked exceptions.
10. Can we have multiple catch blocks for a single try block? Give an example scenario.
11. What is the difference between byte stream and character stream in Java?
12. Name any two classes used for file reading and writing in Java.
13. Which class is used to read data from a file using byte streams?
14. What is the purpose of FileReader and FileWriter in Java?
15. Write a one-line Java statement to create a FileInputStream object.
16. What is a thread in Java?
17. Name two ways to create a thread in Java.
18. What are the different states in the life cycle of a thread?
19. Define thread synchronization with an example use case.
20. What is thread priority? How can it be set?
21. What is inter-thread communication in Java?
22. Write a statement to create a thread using the Runnable interface.
23. What is the use of the join() method in threads?
24. Define the purpose of the sleep() method in a Java thread.
25. What happens if we call start() on a thread more than once?
26. Define the purpose of the run() method in a Java thread.
27. Define the purpose of the wait(), notify(),notifyALL() method in a Java thread.

7 Marks Question (Unit – 2)

1. Explain the control flow of exception handling in Java using try, catch, finally,
throw, and throws.
o Include a program that demonstrates how each is used.
2. Differentiate between checked and unchecked exceptions with examples.
o Give two examples of each.
o Explain how Java handles both at compile-time and runtime.
3. What is the purpose of creating user-defined exceptions in Java? How can you
create and use one?
o Write a program demonstrating a custom exception for invalid input.
4. How does the JVM react when an exception is not caught by the program?
o Describe the default exception handling mechanism.
o Give an example program where an exception is not handled.

5. Explain the difference between byte streams and character streams in Java.
o Name at least two classes used for each.
o Write a program that reads and writes data to a file using either stream.
6. Write a Java program that reads text from one file and writes it into another using
FileReader and FileWriter.
o Explain how file handling works in Java with character streams.
7. What are the different states in the life cycle of a Java thread? Explain with a
diagram.

 Include method names that cause transitions between states.


8. Describe two ways to create threads in Java: extending Thread and implementing
Runnable.

 Write a program using both approaches.

9. What is thread synchronization? Why is it important?

 Write a Java program that demonstrates thread synchronization using the synchronized
keyword.

10. Explain inter-thread communication in Java.

 Describe wait(), notify(), and notifyAll() methods with a code example.

11. Explain the Exception Hierarchy in Java. How are exceptions categorized?
Distinguish between Throwable, Exception, Error, Checked, and Unchecked
exceptions with examples.

Unit-3 (2 marks Question)

1. What is a functional interface? Give one example.


2. Write the syntax of a lambda expression in Java.
3. What is the purpose of method references in Java?
4. Name any two operations provided by the Stream API.
5. What is the use of the default method in an interface?
6. Differentiate between default and static methods in interfaces.
7. What is Base64 encoding used for in Java?
8. What is the purpose of the try-with-resources statement?
9. What are type annotations in Java?
10. What is a repeating annotation?
11. What is the use of the Java Module System introduced in Java 9?
12. Write a line of code that uses the diamond (<>) operator with generics.
13. What is an inner anonymous class in Java?
14. Define local variable type inference in Java (using var).
15. What are switch expressions? How are they different from switch statements?
16. What is the role of the yield keyword in switch expressions?
17. What is a text block in Java?
18. What is a record in Java? Give one use-case.
19. What are sealed classes and how do they improve class hierarchies?
20. Write one use of the forEach() method in Java 8.

7 marks question (Unit-3 )

1. Explain the concept of functional interfaces and lambda expressions in Java. How
do they simplify code? Write a Java program using a functional interface and a
lambda expression.
2. What is the Stream API in Java? Explain its advantages and basic operations like filter(),
map(), and collect() with an example.
3. Compare default methods and static methods in Java interfaces. Why were default
methods introduced in Java 8? Provide examples.
4. Describe the purpose and syntax of try-with-resources in Java. How does it differ
from traditional try-catch-finally for resource management? Include a program to
demonstrate.
5. What are records in Java? How do they reduce boilerplate code? Write a sample Java
program using a record and explain its benefits.
6. Explain local variable type inference using var in Java. What are its advantages and
limitations? Include a code example to demonstrate its use.
7. Discuss the Java Module System introduced in Java 9. Why was it introduced and how
does it help in large applications? Provide the syntax to define a module.
8. What are sealed classes in Java? How do they provide better control over
inheritance? Write a sample code using a sealed class and permitted subclasses.
9. What are switch expressions in Java? How are they different from traditional switch
statements? Illustrate your answer with a suitable code example.

Unit-4(2 marks question)

1. What is the difference between List and Set in Java?


2. What is the purpose of the Iterator interface in Java Collections?
3. Define HashMap. How does it store key-value pairs?
4. What is the difference between ArrayList and LinkedList?
5. What is the use of the Comparable interface in sorting?
6. How does a TreeSet differ from a HashSet?
7. State one key feature of the Properties class in Java.
8. What is the difference between HashMap and TreeMap?
9. How does Vector differ from ArrayList in terms of synchronization?
10. What is the purpose of the Comparator interface in Java?
11. List any two differences between Stack and Queue.
12. What is the use of the SortedSet interface? Name a class that implements it.
13. Explain the concept of fail-fast behavior in Java collections.
14. How does LinkedHashSet maintain the order of elements?
15. What is the output order of elements in a HashSet? Justify your answer.
16. What method is used to add key-value pairs to a Properties object?
17. Give one advantage of using TreeSet over HashSet.
18. Differentiate between Hashtable and HashMap.
19. What is the default sorting order used by TreeMap?
20. What does the hasNext() method of the Iterator interface do?

7 marks Question (Unit-4)

1. Explain the hierarchy of the Java Collections Framework. Describe the major interfaces
and their commonly used classes with suitable examples.
2. Compare and contrast ArrayList, LinkedList, Vector, and Stack in terms of performance,
use cases, and internal structure. Provide examples.
3. What is the difference between HashMap, TreeMap, LinkedHashMap, and Hashtable?
Explain with examples where each should be used.
4. . Explain the working and features of the Set interface in Java. Compare
HashSet, LinkedHashSet, and TreeSet with examples.
5. Describe how sorting is achieved in Java Collections using Comparable and Comparator
interfaces. Provide code examples for both.
6. Explain the Queue interface and its implementation in Java. Discuss the
working of common queue classes with examples.
7. What is the role of the Iterator interface in Java Collections? How is it different
from ListIterator? Provide code examples.
8. Explain the usage of the Properties class in Java. How is it used for configuration and file
handling? Give a suitable example.
9. How does Java ensure thread safety in collections? Compare synchronized
classes like Vector and Hashtable with non-synchronized ones like ArrayList
and HashMap.

Unit -5(2 marks question)

1. What is Inversion of Control (IoC) in Spring?


2. Define dependency injection. How is it used in Spring?
3. List any two bean scopes in Spring.
4. What is the purpose of @Autowired in Spring?
5. What are the two main build systems supported by Spring Boot?
6. What is a RestController in Spring Boot?
7. Differentiate between @RequestParam and @PathVariable.
8. Mention two advantages of using Spring Boot.
9. What does the @RequestBody annotation do?
10. Define AOP (Aspect-Oriented Programming) in Spring.
11. What is the default bean scope in Spring?
12. Name two lifecycle callback methods for a Spring bean.
13. What is the use of the CommandLineRunner in Spring Boot?
14. Write the annotation to define a Spring bean class.
15. Name the HTTP methods supported by Spring Boot for RESTful APIs.

7 marks question (Unit-5)

1. Explain dependency injection in Spring. Describe constructor-based and setter-


based injection with examples.
2. What are the different bean scopes available in Spring? Describe Singleton and
Prototype scopes with examples.
3. What is Spring Boot? How is it different from the Spring Framework? List its key
features and explain the folder structure of a basic Spring Boot application.
4. Explain the use of annotations in Spring for bean configuration. How do
@Component, @Autowired, and @Qualifier work together? Provide code
examples.
5. What is AOP (Aspect-Oriented Programming) in Spring? Explain the key concepts
such as advice, join point, and aspect with an example.
6. How do you create a RESTful web service using Spring Boot? Explain with
annotations and method mappings (GET, POST, PUT, DELETE).
7. Describe the Spring Boot build process using Maven or Gradle. What files are
generated and how is a project structured?
8. Explain the lifecycle of a Spring bean. Describe the initialization and
destruction callbacks with annotation-based configuration.

1. Write a Java program to create a class Employee with a method called


calculateSalary(). Create two subclasses Manager and Programmer. In each
subclass, override the calculateSalary() method to calculate and return the
salary based on their specific roles.

2. Write a Java program to create a class called Employee with private instance
variables employee_id, employee_name, and employee_salary. Provide
public getter and setter methods to access and modify the id and name
variables, but provide a getter method for the salary variable that returns a
formatted string.
3. 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.

4. Write a Java program to create a class called "Book" with instance


variables title, author, and price. Implement a default constructor and
two parameterized constructors:

 One constructor takes title and author as parameters.

 The other constructor takes title, author, and price as parameters.


 Print the values of the variables for each constructor.

You might also like