Bitwise Learning Pyqs + Solution
Bitwise Learning Pyqs + Solution
UNIT-01
Questions:
Answer:
JVM is an important part of Java architecture that provides a runtime environment to execute Java programs. It converts
the compiled bytecode into machine-level code and allows Java programs to run on any platform.
Functions of JVM:
Bytecode
Bytecode is the intermediate code generated by the Java compiler after compiling a .java file. It is stored in a .class file and
can run on any operating system that has JVM installed.
Key Point:
Because bytecode can run on any JVM, Java is called a platform-independent language.
Q2. “Explain the concept of Java Virtual Machine and Java Runtime Environment.”
→ 2024–25 | Section C | 7 Marks | Theory (Diagram possible)
Answer:
Introduction
Java is a platform-independent programming language. This platform independence is achieved with the help of
JVM and JRE. JVM executes Java programs, while JRE provides the environment required to run Java
applications.
JVM stands for Java Virtual Machine. It is an abstract machine that provides a runtime environment in which
Java bytecode can be executed.
JVM converts bytecode into machine code and enables Java programs to run on different operating systems.
Functions of JVM
Working of JVM
JRE stands for Java Runtime Environment. It is a software package that provides all libraries and files
required to run Java applications.
JRE contains:
● JVM
● Java class libraries
● Supporting files
JRE is mainly used for running Java programs but not for developing them.
JVM JRE
Conclusion
JVM and JRE are important components of Java architecture. JVM executes Java bytecode and provides
platform independence, while JRE provides the complete runtime environment required to run Java applications
successfully.
Q3. “History of Java”
Answer:
History of Java
1. Java was developed by James Gosling and his team at Sun Microsystems in 1991.
2. Initially, Java was named Oak.
3. The name Oak was changed to Java in 1995 due to trademark issues.
4. Java was designed for platform-independent applications.
5. Its main feature is “Write Once, Run Anywhere (WORA)”.
6. Java uses JVM to execute bytecode on different platforms.
7. Sun Microsystems was acquired by Oracle Corporation in 2010.
Packages.”
Answer:
Introduction
A package in Java is a collection of related classes, interfaces, and sub-packages. Packages are used to organize code and
avoid naming conflicts.
Advantages of Packages
1. Avoids naming conflicts
2. Provides access protection
3. Improves code reusability
4. Organizes classes properly
Defining a Package
A package is defined using the package keyword at the beginning of the program.
Syntax
package mypack;
Example
package mypack;
class Demo
{
void show()
{
[Link]("Package Example");
}
}
Import Statement
The import keyword is used to access classes of another package.
Syntax
import package_name.class_name;
Example
import [Link];
Static Import
Static import allows direct access to static members without using class name.
Syntax
import static [Link].*;
Example
import static [Link].*;
class Demo
{
public static void main(String args[])
{
[Link](sqrt(25));
}
}
Example
[Link]
Conclusion:
• 2024–25
Questions:
Answer:
● Java is called platform independent because Java source code is converted into bytecode, which can run on any
operating system having a Java Virtual Machine (JVM).
● The JVM converts bytecode into machine code according to the operating system. Therefore, the same Java
program can run on Windows, Linux, or Mac without modification.
● This feature is known as “Write Once, Run Anywhere (WORA)”.
Conclusion:
• 2024–25
Questions:
Q1. “Discuss the different data types and control structures in Java with examples.”
→ 2024–25 | Section B | 7 Marks | Theory + Examples
Answer:
Introduction
Java provides different types of data types to store values and control structures to control the flow of program execution.
These features help in writing efficient and flexible programs.
Data types specify the type of data that can be stored in a variable.
Example Program
class DataTypeDemo
int a = 10;
float b = 5.5f;
char c = 'A';
boolean d = true;
[Link](a);
[Link](b);
[Link](c);
[Link](d);
Examples:
● String
● Array
● Class
● Interface
Example
1. if Statement
Example
int a = 10;
if(a > 5)
[Link]("Greater");
2. if-else Statement
Example
int num = 4;
if(num % 2 == 0)
[Link]("Even");
else
[Link]("Odd");
3. switch Statement
Example
int day = 2;
switch(day)
case 1:
[Link]("Monday");
break;
case 2:
[Link]("Tuesday");
break;
default:
[Link]("Invalid");
1. for Loop
[Link](i);
2. while Loop
int i = 1;
while(i<=5)
[Link](i);
i++;
3. do-while Loop
int i = 1;
do
{
[Link](i);
i++;
while(i<=5);
1. break Statement
2. continue Statement
Example
if(i==3)
continue;
[Link](i);
Conclusion:
• 2023–24
Questions:
Q1. “Define the concept of classes and objects in Java with a suitable example.”
→ 2023–24 | Section A | 2 Marks | Theory + Example
Answer:
Class
A class is a user-defined blueprint or template used to create objects. It contains data members (variables) and
member functions (methods).
Example:
Object
An object is an instance of a class. It represents a real-world entity and is used to access the properties and
methods of a class.
Example:
Example Program
class Student
int a = 10;
{
Student s = new Student();
[Link](s.a);
Output
10
Conclusion:
• 2023–24
• 2024–25
Questions:
Answer:
A constructor is a special member function in Java that is automatically called when an object is created. Its
main role is to initialize the object and assign initial values to data members.
Characteristics:
Example
class Student
Student()
[Link]("Constructor Called");
Q2. “Illustrate Constructors and their applications in Java. Describe the types of
constructors used in Java. Write a class with the name Student…”
→ 2023–24 | Section C | 7 Marks | Program + Theory (Mixed with OOP)
Answer:
Introduction
A constructor is a special member function in Java that is used to initialize objects. It is automatically invoked
when an object is created.
Characteristics of Constructor
Applications of Constructors
1. Default Constructor
Example
class Demo
Demo()
[Link]("Default Constructor");
2. Parameterized Constructor
Example
class Demo
int a;
Demo(int x)
a = x;
[Link](d.a);
}
Program: Student Class Using All Argument Constructor
class Student
int roll_number;
String name;
String branch;
String email;
roll_number = r;
name = n;
branch = b;
email = e;
void display()
[Link](roll_number + " " + name + " " + branch + " " + email);
[Link]();
Output
Conclusion:
• 2024–25
Questions:
Q1. “Write a Java program to take user input and display the reverse of a string.”
→ 2024–25 | Section C | 7 Marks | Program
Answer:
import [Link];
class ReverseString
[Link]("Enter a String:");
str = [Link]();
Output
Enter a String:
Java
Programming-based question
Simple logic (string + input)
Not always repeated
UNIT-03
Topic-01 – ABSTRACTION & ABSTRACT CLASSES (TOP
PRIORITY)
Asked in:
• 2023–24
Questions:
Q1. “Explain abstraction and abstract classes in Java. Describe abstract method.
With a suitable example demonstrate the application of abstract classes.”
→ 2023–24 | Section B | 7 Marks | Theory + Example
Answer:
Introduction
Abstraction is an important concept of Object-Oriented Programming in Java. It hides internal implementation
details and shows only essential features to the user.
● Abstract classes
● Interfaces
Abstraction in Java
Abstraction means hiding implementation details and showing only functionality.
Advantages of Abstraction
Abstract Class
A class declared using the abstract keyword is called an abstract class.
Syntax
Abstract Method
A method declared without a body is called an abstract method.
Syntax
Characteristics
void draw()
[Link]("Drawing Circle");
class Test
[Link]();
Output
Drawing Circle
Conclusion:
• 2023–24
Questions:
Q1. “Illustrate polymorphism and its types in Java. Differentiate between run-time
and compile-time polymorphism. Write super class Shape with method
displayArea() and sub class Rectangle. Demonstrate method overriding with this
example.”
→ 2023–24 | Section C | 7 Marks | Theory + Program
Answer:
Introduction
Polymorphism is an important feature of Object-Oriented Programming (OOP). The word polymorphism means
“many forms”. In Java, a single method can perform different tasks depending on the situation.
Polymorphism in Java
Polymorphism allows one object to behave in multiple forms.
Advantages
1. Compile-Time Polymorphism
It is achieved using method overloading. The method call is resolved during compilation.
Example
class Demo
[Link](a+b);
[Link](a+b+c);
2. Run-Time Polymorphism
It is achieved using method overriding. The method call is resolved during execution.
Example
class Animal
void sound()
[Link]("Animal Sound");
}
}
void sound()
[Link]("Dog Barks");
void displayArea()
[Link]("Area of Shape");
}
class Rectangle extends Shape
void displayArea()
int length = 5;
int breadth = 4;
[Link]();
Output
Area of Rectangle = 20
The class whose properties are inherited is called the superclass (parent class) and the class that inherits
properties is called the subclass (child class).
Advantages of Inheritance
1. Increases code reusability
2. Reduces code duplication
3. Supports method overriding
4. Improves program organization
Syntax of Inheritance
class Parent
Example of Inheritance
class Animal
void eat()
void bark()
[Link]("Dog Barks");
[Link]();
[Link]();
Output
Animal Eats Food
Dog Barks
Explanation
1. Animal is the parent class.
2. Dog is the child class.
3. Dog inherits the eat() method from Animal.
4. Child class can use both inherited and its own methods.
Conclusion:
• 2023–24
Questions:
Answer:
An interface in Java is a collection of abstract methods used to achieve full abstraction and multiple inheritance.
It is declared using the interface keyword.
Features of Interface
Example
interface Demo
{
void show();
[Link]("Interface Method");
[Link]();
Output
Interface Method
Asked in:
• 2023–24
• 2024–25
Questions:
Q1. “Explain the functional interfaces in Java. Describe lambda expressions with the
help of functional interfaces.”
→ 2023–24 | Section B | 7 Marks | Theory + Example
Answer:
Introduction
Java provides functional interfaces and lambda expressions to support functional programming. These features
were introduced in Java 8 to make code simpler and more readable.
Functional Interface
A functional interface is an interface that contains only one abstract method.
It is also called:
Examples
● Runnable
● Comparator
● Callable
interface Demo
void show();
Lambda Expression
A lambda expression is an anonymous function used to implement functional interfaces in a simpler way.
Syntax
interface Demo
void display();
class Test
{
Demo d = () ->
};
[Link]();
Output
Lambda Expression Example
Answer:
A functional interface in Java is an interface that contains only one abstract method. It is also called a Single
Abstract Method (SAM) interface and is mainly used with lambda expressions.
Example
@FunctionalInterface
interface Demo
void show();
Here, Demo is a functional interface because it contains only one abstract method show().
Q3. “What are functional interfaces and how are they implemented using lambda
expressions?”
→ 2024–25 | Section C | 7 Marks | Theory
Answer:
Introduction
Functional interfaces and lambda expressions are important features introduced in Java 8. They support
functional programming and reduce code complexity.
Functional Interface
A functional interface is an interface that contains only one abstract method. It is also known as a Single
Abstract Method (SAM) interface.
Syntax
@FunctionalInterface
interface Demo
void show();
Lambda Expression
A lambda expression is an anonymous function used to implement functional interfaces without creating a
separate class.
Syntax
(parameters) -> expression
Program Example
@FunctionalInterface
interface Demo
void display();
class Test
Demo d = () ->
};
[Link]();
Output
Functional Interface Using Lambda Expression
Conclusion:
• 2023–24
• 2024–25
Questions:
Answer:
A constructor in Java is a special member function used to initialize objects of a class. It is automatically called
when an object is created.
Roles of Constructor
Example
class Demo
Demo()
[Link]("Constructor Called");
Answer:
Introduction
A constructor is a special member function in Java used to initialize objects. It is automatically invoked when an
object is created.
Features of Constructor
1. Constructor name is same as class name.
2. It has no return type.
3. It is called automatically during object creation.
4. Used to initialize instance variables.
Applications of Constructors
1. Initializes object data members
2. Reduces code complexity
3. Assigns default values
4. Helps in object creation easily
1. Default Constructor
A constructor without parameters is called default constructor.
Example
class Demo
Demo()
[Link]("Default Constructor");
2. Parameterized Constructor
A constructor with parameters is called parameterized constructor.
Example
class Demo
int a;
Demo(int x)
a = x;
[Link](d.a);
int roll_number;
String name;
String branch;
String email;
Student(int r, String n, String b, String e)
roll_number = r;
name = n;
branch = b;
email = e;
void display()
[Link](roll_number + " " + name + " " + branch + " " + email);
[Link]();
[Link]();
Output
101 Rahul CSE rahul@[Link]
102 Aman IT aman@[Link]
Conclusion:
• 2023–24
Questions:
Q1. “Explain the concept of Sealed classes in Java with suitable example.”
→ 2023–24 | Section A | 2 Marks | Theory
Answer:
Example
}
In this example, only the Circle class is allowed to inherit the Shape class.
Conclusion:
UNIT-02
• 2023–24
• 2024–25
Questions:
Q1. “Describe all the keywords used for exception handling in Java.”
→ 2023–24 | Section A | 2 Marks | Theory
Answer:
Q2. “Differentiate between checked and unchecked exceptions in Java. Write a Java
program to demonstrate Arithmetic Exception handlings.”
→ 2023–24 | Section C | 7 Marks | Theory + Program
Answer:
Introduction
An exception is an unwanted event that occurs during program execution and interrupts the normal flow of the
program. Java provides exception handling mechanisms to handle such errors.
Arithmetic Exception
ArithmeticException occurs when an illegal arithmetic operation is performed, such as division by zero.
{
int a = 10;
int b = 0;
try
int c = a / b;
[Link](c);
catch(ArithmeticException e)
[Link]("Program Continues");
Output
Arithmetic Exception Handled
Program Continues
Q3. “What is the purpose of the finally block in Java exception handling?”
→ 2024–25 | Section A | 2 Marks | Conceptual
Answer:
Features
Example
try
int a = 10/0;
catch(Exception e)
[Link]("Exception");
finally
Answer:
Example
Answer:
Introduction
Multiple exceptions occur when a program can generate more than one type of exception. Java handles them
using multiple catch blocks along with the finally block.
Program
class MultipleException
try
int x = 10 / 0;
a[10] = 50;
catch(ArithmeticException e)
catch(ArrayIndexOutOfBoundsException e)
finally
[Link]("Program Continues");
}
}
Output
Arithmetic Exception Handled
Program Continues
Explanation
1. try block contains statements that may generate exceptions.
2. catch blocks handle different exceptions separately.
3. finally block executes always.
4. Program execution continues normally after exception handling.
Conclusion:
Asked in:
• 2023–24
• 2024–25
Questions:
Q1. “Describe various states achieved by the thread in its life cycle.”
→ 2023–24 | Section A | 2 Marks | Theory
Answer:
Q2. “Describe the ways to create the threads in Java with suitable code. Also explain
which method is more suitable to create threads.”
→ 2023–24 | Section B | 7 Marks | Theory + Code
Answer:
Introduction
Thread is a lightweight subprocess used for multitasking in Java. Multithreading allows multiple tasks to
execute simultaneously.
Program
class MyThread extends Thread
{
[Link]("Thread is Running");
[Link]();
Output
Thread is Running
Program
class Demo implements Runnable
[Link]("Thread is Running");
{
Demo d = new Demo();
[Link]();
Output
Thread is Running
Answer:
Introduction
Multithreading is a process in which multiple threads execute simultaneously within a program. It helps in
performing multiple tasks at the same time and improves CPU utilization.
Advantages of Multithreading
1. Improves performance
2. Saves CPU time
3. Enables multitasking
4. Improves responsiveness of applications
}
class OddThread extends Thread
class Test
[Link]();
[Link]();
Output
Odd: 1
Even: 2
Odd: 3
Even: 4
...
Explanation
1. Two thread classes are created:
○ EvenThread
○ OddThread
2. Both classes override the run() method.
3. start() method is used to execute threads simultaneously.
4. One thread prints even numbers while the other prints odd numbers.
Q4. “Write a Java program that creates two threads – one to print even numbers
and the other for odd numbers.”
→ 2024–25 | Section C | 7 Marks | Program
Answer:
Program
class EvenThread extends Thread
}
}
class Test
[Link]();
[Link]();
Output
Odd Number: 1
Even Number: 2
Odd Number: 3
Even Number: 4
...
Explanation
1. Two classes are created by extending the Thread class.
2. EvenThread prints even numbers.
3. OddThread prints odd numbers.
4. start() method is used to execute both threads simultaneously.
Conclusion:
• 2023–24
Questions:
Introduction
wait() and notify() methods are used for inter-thread communication in Java. These methods belong to the
Object class and are mainly used in synchronization.
Used when thread waits for condition Used to signal another thread
wait() Method
The wait() method pauses the execution of the current thread until another thread calls notify().
Example
synchronized(obj)
[Link]();
notify() Method
The notify() method wakes up one waiting thread.
Example
synchronized(obj)
[Link]();
Program Example
class Demo
try
wait();
[Link]("Thread Resumed");
catch(Exception e)
[Link](e);
notify();
[Link]("Notification Sent");
Conclusion:
Concept-based question
Often asked as part of mixed question
Related to synchronization
• 2024–25
Questions:
Q1. “What is the purpose of the finally block in Java exception handling?”
→ 2024–25 | Section A | 2 Marks
Answer:
Features
Example
try
int a = 10/0;
catch(Exception e)
[Link]("Exception Handled");
finally
Answer:
Example
throw new ArithmeticException();
Conclusion:
UNIT-04
Asked in:
• 2023–24
• 2024–25
Questions:
Answer:
Introduction
The Collection Framework in Java is a set of classes and interfaces used to store and manipulate groups of
objects dynamically. It provides reusable data structures and algorithms.
1. List Interface
The List interface stores elements in ordered form and allows duplicate values.
Features
Classes of List
● ArrayList
● LinkedList
● Vector
Example
2. Set Interface
The Set interface stores unique elements and does not allow duplicates.
Features
Classes of Set
● HashSet
● TreeSet
● LinkedHashSet
Example
3. Queue Interface
The Queue interface stores elements in FIFO (First In First Out) order.
Features
Classes of Queue
● PriorityQueue
● LinkedList
Example
Answer:
Introduction
The Collection Framework in Java is a group of interfaces and classes used to store and manipulate data
dynamically. It provides ready-made data structures such as List, Set, Queue, and Map.
List Interface
The List interface stores elements in ordered form and allows duplicate values.
Features
Example Classes
● ArrayList
● LinkedList
Set Interface
The Set interface stores unique elements only.
Features
Example Classes
● HashSet
● TreeSet
Map Interface
The Map interface stores data in key-value pairs.
Features
Example Classes
● HashMap
● TreeMap
Conclusion:
• 2023–24
• 2024–25
Questions:
Q1. “Write a Java program to create an ArrayList with five items and display all the
elements using forEach method.”
→ 2023–24 | Section A | 2 Marks (Program-based)
Answer:
import [Link];
class Demo
{
public static void main(String args[])
[Link]("Java");
[Link]("Python");
[Link]("C");
[Link]("C++");
[Link]("HTML");
Output
Java
Python
C++
HTML
Q2. “Compare and contrast ArrayList and LinkedList in terms of performance and
usage.”
→ 2024–25 | Section B | 7 Marks | Theory
Answer:
Introduction
ArrayList and LinkedList are important classes of the List interface in Java Collection Framework. Both are
used to store ordered data, but their internal working and performance are different.
ArrayList
ArrayList uses a dynamic array to store elements.
Features
Example
LinkedList
LinkedList uses a doubly linked list to store elements.
Features
Example
Performance Comparison
ArrayList Performance
● Access: Fast → O(1)
● Insertion/Deletion: Slow → O(n)
LinkedList Performance
● Access: Slow → O(n)
● Insertion/Deletion: Fast → O(1)
Usage of ArrayList
1. When frequent searching is required
2. When data access is more important
Usage of LinkedList
1. When frequent insertion/deletion is required
2. When memory allocation is dynamic
Q3. “Describe Linked List in Java collection framework. With suitable example
describe any five methods available in Linked Lists.”
→ 2023–24 | Section C | 7 Marks | Theory + Example
Answer:
Introduction
LinkedList is a class of Java Collection Framework that implements the List interface. It uses a doubly linked
list data structure to store elements dynamically.
Syntax
LinkedList<Integer> list = new LinkedList<Integer>();
Program Example
import [Link];
class Demo
{
[Link]("Java");
[Link]("Python");
[Link]("C");
[Link]("Python");
[Link](1, "C++");
Output
List: [Java, Python, C]
Element at Index 1: C
Size: 2
Conclusion:
● Program (ArrayList)
● Theory + comparison (ArrayList vs LinkedList)
Must prepare methods + differences
• 2023–24
• 2024–25
Questions:
Answer:
Introduction
HashMap is a class of Java Collection Framework that stores data in the form of key-value pairs. It is a part of
the [Link] and implements the Map interface.
Features of HashMap
1. Stores data in key-value pairs
2. Keys are unique
3. Allows null values
4. Does not maintain insertion order
5. Provides fast data retrieval
Syntax
HashMap<Integer, String> map = new HashMap<Integer, String>();
Program Example
import [Link];
class Demo
[Link](2, "Python");
[Link](3, "C++");
[Link](3);
Output
HashMap: {1=Java, 2=Python, 3=C++}
Size: 2
Q2. “Write a program to demonstrate the use of HashMap and iterate through keys
and values.”
→ 2024–25 | Section C | 7 Marks | Program
Answer:
Program
import [Link];
import [Link];
class Demo
[Link](1, "Java");
[Link](2, "Python");
[Link](3, "C++");
[Link]("Keys:");
[Link](key);
}
[Link]("Values:");
[Link](value);
Output
Keys:
Values:
Java
Python
C++
Keys and Values:
1 Java
2 Python
3 C++
Explanation
1. put() method inserts key-value pairs into HashMap.
2. keySet() is used to iterate keys.
3. values() is used to iterate values.
4. entrySet() is used to iterate both keys and values together.
Conclusion:
● Key-value concept
● Iteration methods
• 2024–25
Questions:
Answer:
Differentiate Between List, Set, and Map in Java
Introduction
List, Set, and Map are important interfaces of the Java Collection Framework used for storing and managing
data in different ways.
Stores elements in ordered form Stores unique elements Stores data in key-value pairs
Allows duplicate elements Does not allow duplicates Duplicate keys not allowed
Maintains insertion order May or may not maintain Stores mapping between key and
order value
Extends Collection interface Extends Collection interface Does not extend Collection interface
List Interface
The List interface stores elements in sequence and allows duplicates.
Example
Set Interface
The Set interface stores only unique elements.
Example
Map Interface
The Map interface stores elements in key-value pairs.
Example
Conclusion:
• 2024–25
Questions:
Answer:
Follows LIFO (Last In First Out) principle Follows FIFO (First In First Out) principle
Insertion and deletion occur from same end Insertion and deletion occur from different ends
Uses push() and pop() methods Uses enqueue and dequeue operations
Example
Conclusion:
UNIT-05
• 2023–24
• 2024–25
Questions:
Q1. “Explain Java stream API and its applications. Describe Intermediate and
terminal operations with suitable examples. Write a program to print the sum of all
even numbers from an ArrayList containing all integers from 1 to 10.”
→ 2023–24 | Section C | 7 Marks | Theory + Program
Answer:
Introduction
Stream API was introduced in Java 8 to process collections of data efficiently. It supports functional-style
operations and reduces code complexity.
A stream does not store data; it processes data from collections such as List, Set, etc.
Applications of Stream API
1. Filtering data
2. Sorting elements
3. Performing mathematical operations
4. Reducing code complexity
5. Supporting functional programming
1. Intermediate Operations
Intermediate operations transform a stream into another stream. They are lazy in nature.
Examples
● filter()
● map()
● sorted()
Example
2. Terminal Operations
Terminal operations produce the final result and terminate the stream.
Examples
● forEach()
● collect()
● reduce()
● count()
Example
[Link]().forEach([Link]::println);
[Link](i);
.filter(x -> x % 2 == 0)
.mapToInt(x -> x)
.sum();
Output
Sum of Even Numbers = 30
Explanation
1. stream() converts collection into stream.
2. filter() selects even numbers.
3. mapToInt() converts stream into integer stream.
4. sum() calculates total sum.
Q2. “What is the Stream API in Java? How does it help in functional-style
operations?”
→ 2024–25 | Section B | 7 Marks | Theory
Answer:
Introduction
Stream API was introduced in Java 8 to process collections of data efficiently. It supports functional
programming and allows operations on collections in a simple and readable way.
A stream is a sequence of elements used for processing data from collections such as List, Set, etc.
● Filtering
● Sorting
● Mapping
● Searching
● Aggregation
Syntax
[Link]();
● filter()
● map()
● sorted()
● reduce()
● forEach()
1. Intermediate Operations
These operations return another stream and are lazy in nature.
Examples
● filter()
● map()
● sorted()
Example
2. Terminal Operations
These operations produce the final result.
Examples
● forEach()
● collect()
● count()
● reduce()
Example
[Link]().forEach([Link]::println);
import [Link];
class Demo
[Link]()
.filter(x -> x % 2 == 0)
.forEach([Link]::println);
Output
2
Conclusion:
• 2023–24
• 2024–25
Questions:
Answer:
Introduction
Spring Boot is a Java-based framework used to develop stand-alone and production-ready Spring applications
easily. It is built on top of the Spring Framework and reduces configuration complexity.
● Auto configuration
● Embedded servers
● Ready-to-use features
● Faster application development
import [Link];
@SpringBootApplication
class DemoApplication
[Link]([Link], args);
}
Q2. “What is Spring Boot? How is it different from the traditional Spring
framework?”
→ 2024–25 | Section B | 7 Marks | Theory
Answer:
Introduction
Spring Boot is a Java-based framework built on top of the Spring Framework. It is used to create stand-alone
and production-ready applications with minimal configuration.
Spring Boot simplifies the development process by providing auto configuration and embedded servers.
Spring Boot
Spring Boot helps developers create applications quickly without writing large amounts of XML configuration.
import [Link];
@SpringBootApplication
class DemoApplication
[Link]([Link], args);
}
Q3. “Describe the structure of a basic Spring Boot application. What are the
advantages of using Spring Boot over traditional web frameworks?”
→ 2024–25 | Section C | 7 Marks | Theory
Answer:
Introduction
Spring Boot is a framework used to develop stand-alone and production-ready Java applications easily. It
simplifies application development by reducing configuration and setup complexity.
import [Link];
import [Link];
@SpringBootApplication
class DemoApplication
[Link]([Link], args);
Controller Class
The controller handles client requests.
Example
import [Link];
import [Link];
@RestController
class DemoController
@GetMapping("/")
Conclusion:
● Definition
● Advantages
● Comparison with Spring
● Application structure
Topic–03 – DEPENDENCY INJECTION (SPRING CORE) (HIGH
PRIORITY)
Asked in:
• 2023–24
• 2024–25
Questions:
Q1. “Explain the difference between Dependency Injection (DI) and Inversion of
Control (IoC) in Spring.”
→ 2023–24 | Section B | 7 Marks | Theory
Answer:
Introduction
In Spring Framework, IoC and DI are important concepts used for loose coupling and better object management.
Features of IoC
Types of DI
void start()
[Link]("Engine Started");
class Car
{
Engine e;
Car(Engine e)
this.e = e;
void drive()
[Link]();
Q2. “Explain the concept of Dependency Injection and its types in Spring. Develop a
simple API in Spring Boot to perform CRUD operations using a list as storage.”
→ 2024–25 | Section C | 7 Marks | Theory + Application (Mixed)
Answer:
Introduction
Dependency Injection (DI) is an important feature of the Spring Framework used to achieve loose coupling
between classes. In DI, the Spring container provides required objects automatically instead of creating them
manually.
Dependency Injection (DI)
Dependency Injection means injecting one object into another object as a dependency.
1. Constructor Injection
Dependencies are injected through constructor.
Example
class Car
Engine e;
Car(Engine e)
this.e = e;
2. Setter Injection
Dependencies are injected using setter methods.
Example
class Car
Engine e;
void setEngine(Engine e)
this.e = e;
Program
import [Link].*;
import [Link].*;
@RestController
class StudentController
@GetMapping("/students")
return students;
}
@PostMapping("/add/{name}")
[Link](name);
@PutMapping("/update/{index}/{name}")
[Link](index, name);
@DeleteMapping("/delete/{index}")
[Link](index);
}
CRUD Operations
Operation HTTP Method
Create POST
Read GET
Update PUT
Delete DELETE
Explanation
1. @RestController creates REST API controller.
2. @GetMapping retrieves data.
3. @PostMapping adds data.
4. @PutMapping updates data.
5. @DeleteMapping removes data.
6. ArrayList is used as temporary storage.
Conclusion:
● DI types
● IoC vs DI
• 2024–25
Questions:
Q1. “Explain the concept of Dependency Injection and its types in Spring. Develop a
simple API in Spring Boot to perform CRUD operations using a list as storage.”
→ 2024–25 | Section C | 7 Marks (mixed question)
Answer:
Introduction
Dependency Injection (DI) is a technique used in Spring Framework to provide objects automatically to another
object. It helps in achieving loose coupling and improves code maintainability.
1. Constructor Injection
Dependencies are provided through constructor.
Example
class Car
Engine e;
Car(Engine e)
this.e = e;
}
2. Setter Injection
Dependencies are provided using setter methods.
Example
class Car
Engine e;
void setEngine(Engine e)
this.e = e;
Program
import [Link].*;
import [Link].*;
@RestController
class StudentController
@GetMapping("/students")
return students;
@PostMapping("/add/{name}")
[Link](name);
@PutMapping("/update/{index}/{name}")
[Link](index, name);
@DeleteMapping("/delete/{index}")
[Link](index);
CRUD Operations
Operation HTTP Method
Create POST
Read GET
Update PUT
Delete DELETE
Explanation
1. @RestController creates REST API controller.
2. @GetMapping retrieves data.
3. @PostMapping adds data.
4. @PutMapping updates existing data.
5. @DeleteMapping removes data.
6. ArrayList is used as temporary storage.
Conclusion:
Appears as part of mixed question
Focus on:
• 2024–25
Questions:
Answer:
Example