0% found this document useful (0 votes)
2 views108 pages

Bitwise Learning Pyqs + Solution

Uploaded by

mystudy5678
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)
2 views108 pages

Bitwise Learning Pyqs + Solution

Uploaded by

mystudy5678
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

Object Oriented Programming with Java (BCS-403)

PYQs WITH SOLUTIONS ALL 5 UNITS


(Last 2 Years)

UNIT-01

Topic-01 – JVM, JRE, History of Java & BYTECODE (TOP


PRIORITY – EVERY YEAR)
Asked in:
• 2023–24, 2024–25

Questions:

Q1. “Describe JVM and byte code in Java Architecture.”​


→ 2023–24 | Section A | 2 Marks | Theory

Answer:

JVM (Java Virtual Machine)

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:

●​ Executes Java bytecode


●​ Provides platform independence
●​ Performs memory management
●​ Provides security and garbage collection

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.

Java Architecture Flow:


Source Code (.java) → Java Compiler (javac) → Bytecode (.class) → JVM → Machine Code

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.

Java Virtual Machine (JVM)

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

1.​ Executes Java bytecode


2.​ Provides platform independence
3.​ Performs memory management
4.​ Provides garbage collection
5.​ Handles exception management
6.​ Provides security to Java applications

Working of JVM

●​ Java source code (.java) is compiled by the Java compiler.


●​ Compiler generates bytecode (.class file).
●​ JVM reads and converts bytecode into machine code.
●​ Machine code is executed by the operating system.

Java Runtime Environment (JRE)

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.

Difference Between JVM and JRE

JVM JRE

Executes bytecode Provides runtime environment

Part of JRE Contains JVM


Converts bytecode into machine code Contains libraries and supporting files

Platform dependent implementation Platform dependent package

Java Architecture Diagram

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.

Q4. “Explain Packages in Java. Discuss Defining Package, CLASSPATH Setting,


Making JAR Files, Import and Static Import, and Naming Convention for

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));
}
}

CLASSPATH Setting for Packages


CLASSPATH is an environment variable that tells Java compiler and JVM where to locate class files and packages.

Setting CLASSPATH in Windows


set classpath=.;

Compile Package Program


javac -d . [Link]

Run Package Program


java [Link]

Making JAR Files for Library Packages


JAR (Java Archive) file is used to combine multiple class files into a single file.

Command to Create JAR File


jar cf [Link] mypack

Advantages of JAR Files

1.​ Easy distribution


2.​ Reduces file size
3.​ Simplifies package management

Naming Convention for Packages


1.​ Package names should be written in lowercase letters.
2.​ Use meaningful names.
3.​ Usually based on organization or domain name.

Example
[Link]

Conclusion:

MOST REPEATED UNIT–I QUESTION (Guaranteed)​


Asked in both 2 marks + 7 marks​
Diagram (Java Architecture) can be added in long answer

Topic-02 – PLATFORM INDEPENDENCE (HIGH PRIORITY)


Asked in:

• 2024–25

Questions:

Q1. “Why is Java platform-independent?”​


→ 2024–25 | Section A | 2 Marks | Conceptual

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:

Direct short question​


Strongly linked with JVM & Bytecode​
Frequently asked concept in Unit–1

Topic-03 – DATA TYPES & CONTROL STRUCTURES (HIGH


PRIORITY)
Asked in:

• 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.

1. Data Types in Java

Data types specify the type of data that can be stored in a variable.

Java data types are divided into two categories:

(A) Primitive Data Types

These are predefined data types provided by Java.

Data Type Size Example

byte 1 byte byte a = 10;

short 2 bytes short b = 200;

int 4 bytes int x = 100;

long 8 bytes long y = 5000L;

float 4 bytes float p = 5.5f;


double 8 bytes double q = 10.25;

char 2 bytes char ch = ‘A’;

boolean 1 bit boolean flag = true;

Example Program

class DataTypeDemo

public static void main(String args[])

int a = 10;

float b = 5.5f;

char c = 'A';

boolean d = true;

[Link](a);

[Link](b);

[Link](c);

[Link](d);

(B) Non-Primitive Data Types

These are user-defined or reference data types.

Examples:
●​ String
●​ Array
●​ Class
●​ Interface

Example

String name = "Java";

int arr[] = {1,2,3};

2. Control Structures in Java

Control structures control the execution flow of a program.

They are of three types:

(A) Decision Making Statements

Used to take decisions based on conditions.

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");

(B) Looping Statements

Used to execute statements repeatedly.

1. for Loop

for(int i=1; i<=5; i++)

[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);

(C) Jump Statements

Used to transfer control from one statement to another.

1. break Statement

Terminates the loop.

2. continue Statement

Skips current iteration.

Example

for(int i=1; i<=5; i++)

if(i==3)

continue;

[Link](i);

Conclusion:

PURE UNIT–1 LONG QUESTION​


Example-based answer required​
No diagram needed
Topic-04 – CLASSES & OBJECTS (HIGH PRIORITY)
Asked in:

• 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:

●​ Car, Student, Employee are examples of classes.

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:

●​ A specific car like BMW or Audi is an object of class Car.

Example Program
class Student

int a = 10;

public static void main(String args[])

{
Student s = new Student();

[Link](s.a);

Output
10

Conclusion:

Basic OOP foundation question​


Mostly asked in 2 marks, but can expand to 7 marks

Topic-05 – CONSTRUCTORS (MODERATE PRIORITY)


Asked in:

• 2023–24​
• 2024–25

Questions:

Q1. “What is the role of a constructor in a Java class?”​


→ 2024–25 | Section A | 2 Marks | Theory

Answer:

Role of Constructor in Java Class

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:

1.​ Constructor name is same as class name.


2.​ It has no return type.
3.​ It is invoked automatically during object creation.

Example

class Student

Student()

[Link]("Constructor Called");

public static void main(String args[])

Student s = new Student();

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

1.​ Constructor name must be the same as class name.


2.​ It has no return type.
3.​ It is called automatically when object is created.
4.​ It is used to initialize data members.

Applications of Constructors

1.​ To initialize object values.


2.​ To reduce code complexity.
3.​ To assign default values to variables.
4.​ To create objects easily

Types of Constructors in Java

1. Default Constructor

A constructor with no parameters is called default constructor.

Example

class Demo

Demo()

[Link]("Default Constructor");

public static void main(String args[])


{

Demo d = new Demo();

2. Parameterized Constructor

A constructor that accepts parameters is called a parameterized constructor.

Example

class Demo

int a;

Demo(int x)

a = x;

public static void main(String args[])

Demo d = new Demo(10);

[Link](d.a);

}
Program: Student Class Using All Argument Constructor

class Student

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);

public static void main(String args[])

Student s1 = new Student(101, "Rahul", "CSE", "rahul@[Link]");

Student s2 = new Student(102, "Aman", "IT", "aman@[Link]");


[Link]();

[Link]();

Output

101 Rahul CSE rahul@[Link]

102 Aman IT aman@[Link]

Conclusion:

Asked in both short + long format​


Often includes program writing​
Sometimes mixed with Unit–2 (OOP concepts)

Topic-06 – BASIC PROGRAMMING (STRING / INPUT)


(LOW–MODERATE PRIORITY)
Asked in:

• 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

public static void main(String args[])

Scanner sc = new Scanner([Link]);

String str, rev = "";

[Link]("Enter a String:");

str = [Link]();

for(int i = [Link]()-1; i >= 0; i--)

rev = rev + [Link](i);

[Link]("Reverse String is: " + rev);

Output
Enter a String:

Java

Reverse String is: avaJ


Conclusion:

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.

Abstraction can be achieved using:

●​ Abstract classes
●​ Interfaces

Abstraction in Java
Abstraction means hiding implementation details and showing only functionality.

Real Life Example


When a user drives a car, they use steering and brakes without knowing the internal working of the engine.

Advantages of Abstraction

1.​ Reduces complexity


2.​ Improves security
3.​ Increases code reusability
4.​ Simplifies maintenance

Abstract Class
A class declared using the abstract keyword is called an abstract class.

Features of Abstract Class

1.​ Object of abstract class cannot be created.


2.​ It may contain abstract and non-abstract methods.
3.​ It is used to achieve partial abstraction.
4.​ Subclasses must implement abstract methods.

Syntax

abstract class Demo

abstract void show();

Abstract Method
A method declared without a body is called an abstract method.

Syntax

abstract void display();

Characteristics

1.​ Declared using abstract keyword


2.​ Does not contain implementation
3.​ Must be overridden in subclass
Program to Demonstrate Abstract Class
abstract class Shape

abstract void draw();

class Circle extends Shape

void draw()

[Link]("Drawing Circle");

class Test

public static void main(String args[])

Circle c = new Circle();

[Link]();

Output
Drawing Circle

Conclusion:

Core OOP concept​


Mostly asked as long question (7 marks)​
Example-based explanation required

Topic-02 – POLYMORPHISM & INHERITANCE (VERY HIGH


WEIGHT)
Asked in:

• 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.​ Increases code reusability


2.​ Improves flexibility
3.​ Makes code maintainable
4.​ Supports dynamic method calling
Types of Polymorphism in Java

1. Compile-Time Polymorphism
It is achieved using method overloading. The method call is resolved during compilation.

Example

class Demo

void add(int a, int b)

[Link](a+b);

void add(int a, int b, int c)

[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");

}
}

class Dog extends Animal

void sound()

[Link]("Dog Barks");

Difference Between Compile-Time and Run-Time Polymorphism


Compile-Time Polymorphism Run-Time Polymorphism

Achieved by method overloading Achieved by method overriding

Decision taken during compilation Decision taken during execution

Faster execution Slower than compile-time

Same class methods Parent-child class methods

Program to Demonstrate Method Overriding


class Shape

void displayArea()

[Link]("Area of Shape");

}
class Rectangle extends Shape

void displayArea()

int length = 5;

int breadth = 4;

int area = length * breadth;

[Link]("Area of Rectangle = " + area);

public static void main(String args[])

Rectangle r = new Rectangle();

[Link]();

Output
Area of Rectangle = 20

Q2. “Explain Inheritance in Java with Suitable Example”


Introduction
Inheritance is an important feature of Object-Oriented Programming (OOP) in which one class acquires the
properties and methods of another class.

The class whose properties are inherited is called the superclass (parent class) and the class that inherits
properties is called the subclass (child class).

Java uses the extends keyword for inheritance.

Advantages of Inheritance
1.​ Increases code reusability
2.​ Reduces code duplication
3.​ Supports method overriding
4.​ Improves program organization

Syntax of Inheritance
class Parent

class Child extends Parent

Types of Inheritance in Java


1.​ Single Inheritance
2.​ Multilevel Inheritance
3.​ Hierarchical Inheritance

Note: Java does not support multiple inheritance using classes.

Example of Inheritance
class Animal

void eat()

[Link]("Animal Eats Food");

class Dog extends Animal

void bark()

[Link]("Dog Barks");

public static void main(String args[])

Dog d = new Dog();

[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:

VERY IMPORTANT OOP QUESTION​


Comes with theory + program​
Covers multiple subtopics in one question

Topic-03 – INTERFACES (HIGH PRIORITY)


Asked in:

• 2023–24

Questions:

Q1. “Explain Interfaces in Java with suitable examples.”​


→ 2023–24 | Section A | 2 Marks | Theory + Example

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

1.​ Contains abstract methods by default


2.​ Supports multiple inheritance
3.​ Cannot create objects of interface

Example

interface Demo
{

void show();

class Test implements Demo

public void show()

[Link]("Interface Method");

public static void main(String args[])

Test t = new Test();

[Link]();

Output

Interface Method

Topic–04 – FUNCTIONAL INTERFACES & LAMBDA


EXPRESSIONS (VERY HIGH WEIGHT)

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:

●​ Single Abstract Method (SAM) Interface

Features of Functional Interface

1.​ Contains only one abstract method


2.​ Can have default and static methods
3.​ Used with lambda expressions
4.​ Declared using @FunctionalInterface annotation

Examples

●​ Runnable
●​ Comparator
●​ Callable

Syntax of Functional Interface


@FunctionalInterface

interface Demo

void show();

Lambda Expression
A lambda expression is an anonymous function used to implement functional interfaces in a simpler way.

Syntax

(parameters) -> expression

Advantages of Lambda Expression

1.​ Reduces code size


2.​ Improves readability
3.​ Eliminates unnecessary boilerplate code
4.​ Supports functional programming

Program Using Functional Interface and Lambda Expression


@FunctionalInterface

interface Demo

void display();

class Test

public static void main(String args[])

{
Demo d = () ->

[Link]("Lambda Expression Example");

};

[Link]();

Output
Lambda Expression Example

Q2. “What is a functional interface? Give an example.”​


→ 2024–25 | Section A | 2 Marks | Conceptual

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.

Functional interfaces are mainly used with lambda expressions.

Features of Functional Interface

1.​ Contains only one abstract method


2.​ Can contain default and static methods
3.​ Supports functional programming
4.​ Declared using @FunctionalInterface

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

Advantages of Lambda Expression

1.​ Reduces code length


2.​ Improves readability
3.​ Eliminates boilerplate code
4.​ Makes programming easier

Implementation of Functional Interface Using Lambda Expression


A lambda expression provides the implementation of the abstract method present in the functional interface.

Program Example
@FunctionalInterface

interface Demo

void display();

class Test

public static void main(String args[])

Demo d = () ->

[Link]("Functional Interface Using Lambda Expression");

};
[Link]();

Output
Functional Interface Using Lambda Expression

Conclusion:

MOST REPEATED UNIT–02 TOPIC​


Asked in both 2 marks + 7 marks​
Strong focus on lambda expressions

Topic–05 – CONSTRUCTORS (OVERLAP WITH UNIT–01, BUT


USED IN OOP)
Asked in:

• 2023–24​
• 2024–25

Questions:

Q1. “What is the role of a constructor in a Java class?”​


→ 2024–25 | Section A | 2 Marks

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

1.​ Initializes object data members


2.​ Assigns initial values to variables
3.​ Reduces code complexity
4.​ Invoked automatically during object creation

Example

class Demo

Demo()

[Link]("Constructor Called");

public static void main(String args[])

Demo d = new Demo();

Q2. “Illustrate Constructors and their applications in Java…”​


→ 2023–24 | Section C | 7 Marks | Program + Theory

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

Types of Constructors in Java

1. Default Constructor
A constructor without parameters is called default constructor.

Example

class Demo

Demo()

[Link]("Default Constructor");

public static void main(String args[])

Demo d = new Demo();

2. Parameterized Constructor
A constructor with parameters is called parameterized constructor.

Example

class Demo

int a;

Demo(int x)

a = x;

public static void main(String args[])

Demo d = new Demo(10);

[Link](d.a);

Program Using Student Class


class Student

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);

public static void main(String args[])

Student s1 = new Student(101, "Rahul", "CSE", "rahul@[Link]");

Student s2 = new Student(102, "Aman", "IT", "aman@[Link]");

[Link]();

[Link]();

Output
101 Rahul CSE rahul@[Link]
102 Aman IT aman@[Link]

Conclusion:

Used as OOP foundation​


Frequently combined with class/object questions

Topic-06 – SEALED CLASSES (Medium Priority)


Asked in:

• 2023–24

Questions:

Q1. “Explain the concept of Sealed classes in Java with suitable example.”​
→ 2023–24 | Section A | 2 Marks | Theory

Answer:

Explain the Concept of Sealed Classes in Java with Suitable Example


A sealed class in Java is a class that restricts which classes can inherit it. It is declared using the sealed keyword
along with the permits keyword.

Sealed classes improve security and provide controlled inheritance.

Example

sealed class Shape permits Circle

final class Circle extends Shape

}
In this example, only the Circle class is allowed to inherit the Shape class.

Conclusion:

New Java feature​


Low frequency but possible

UNIT-02

Topic–01 – EXCEPTION HANDLING (TOP PRIORITY –


EVERY YEAR)
Asked in:

• 2023–24​
• 2024–25

Questions:

Q1. “Describe all the keywords used for exception handling in Java.”​
→ 2023–24 | Section A | 2 Marks | Theory

Answer:

Keywords Used for Exception Handling in Java


Java provides the following keywords for exception handling:

1.​ try – Used to define a block where exceptions may occur.


2.​ catch – Used to handle the exception.
3.​ finally – Executes always whether exception occurs or not.
4.​ throw – Used to explicitly throw an exception.
5.​ throws – Declares exceptions that may occur in a method.

These keywords help in handling runtime errors effectively in Java.

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.

Difference Between Checked and Unchecked Exceptions


Checked Exception Unchecked Exception

Checked at compile time Checked at runtime

Must be handled using try-catch or throws Handling is optional

Subclass of Exception class Subclass of RuntimeException

Program will not compile if not handled Program compiles successfully

Example: IOException Example: ArithmeticException

Arithmetic Exception
ArithmeticException occurs when an illegal arithmetic operation is performed, such as division by zero.

Java Program for Arithmetic Exception Handling


class ExceptionDemo

public static void main(String args[])

{
int a = 10;

int b = 0;

try

int c = a / b;

[Link](c);

catch(ArithmeticException e)

[Link]("Arithmetic Exception Handled");

[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:

Purpose of finally Block in Java Exception Handling


The finally block in Java is used to execute important statements whether an exception occurs or not. It is
mainly used for resource cleanup operations such as closing files, database connections, etc.

Features

1.​ Executes always


2.​ Used after try-catch block
3.​ Helps in cleanup operations

Example

try

int a = 10/0;

catch(Exception e)

[Link]("Exception");

finally

[Link]("Finally Block Executed");

Q4. “How is throw different from throws?”​


→ 2024–25 | Section A | 2 Marks | Conceptual

Answer:

Difference Between throw and throws in Java


throw throws

Used to explicitly throw an exception Used to declare exceptions

Used inside method body Used in method declaration

Throws a single exception object Can declare multiple exceptions

Followed by exception object Followed by exception class names

Example

throw new ArithmeticException();

void show() throws IOException

Q5. “Write a Java program to handle multiple exceptions using try-catch-finally.”​


→ 2024–25 | Section C | 7 Marks | Program

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.

The finally block always executes whether an exception occurs or not.

Program
class MultipleException

public static void main(String args[])


{

int a[] = new int[5];

try

int x = 10 / 0;

a[10] = 50;

catch(ArithmeticException e)

[Link]("Arithmetic Exception Handled");

catch(ArrayIndexOutOfBoundsException e)

[Link]("Array Index Exception Handled");

finally

[Link]("Finally Block Executed");

[Link]("Program Continues");

}
}

Output
Arithmetic Exception Handled

Finally Block Executed

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:

MOST REPEATED UNIT–03 TOPIC (100% coverage)​


Asked in 2 marks + 7 marks + program​
Includes:

●​ Keywords (try, catch, throw, throws, finally)


●​ Types of exceptions
●​ Program-based handling

Topic-02 – MULTITHREADING (VERY HIGH WEIGHT)

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:

Various States of Thread in Java Life Cycle


A thread in Java passes through different states during its execution. The main thread states are:

1.​ New State – Thread object is created but not started.


2.​ Runnable State – Thread is ready for execution.
3.​ Running State – Thread is currently executing.
4.​ Blocked/Waiting State – Thread waits for resources or another thread.
5.​ Terminated State – Thread execution is completed.

These states together form the life cycle of a thread in Java.

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.

Java mainly provides two ways to create threads:

1.​ By extending Thread class


2.​ By implementing Runnable interface

1. Creating Thread by Extending Thread Class


In this method, a class extends the Thread class and overrides the run() method.

Program
class MyThread extends Thread

public void run()

{
[Link]("Thread is Running");

public static void main(String args[])

MyThread t = new MyThread();

[Link]();

Output
Thread is Running

2. Creating Thread by Implementing Runnable Interface


In this method, a class implements the Runnable interface and defines the run() method.

Program
class Demo implements Runnable

public void run()

[Link]("Thread is Running");

public static void main(String args[])

{
Demo d = new Demo();

Thread t = new Thread(d);

[Link]();

Output

Thread is Running

Which Method is More Suitable?


The Runnable interface method is more suitable because:

1.​ Java does not support multiple inheritance with classes.


2.​ A class can implement multiple interfaces.
3.​ Better object-oriented approach.
4.​ Increases flexibility and code reusability.

Difference Between Both Methods


Extending Thread Class Implementing Runnable Interface

Inherits Thread class Implements Runnable interface

Cannot extend another class Can extend another class

Less flexible More flexible

Simpler for small programs Better for large applications


Q3. “Explain the concept of multithreading. Write a program to implement two
threads printing numbers alternatively.”​
→ 2024–25 | Section B | 7 Marks | Theory + Program

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.

A thread is a lightweight subprocess.

Advantages of Multithreading
1.​ Improves performance
2.​ Saves CPU time
3.​ Enables multitasking
4.​ Improves responsiveness of applications

Program to Print Numbers Using Two Threads


class EvenThread extends Thread

public void run()

for(int i=2; i<=10; i=i+2)

[Link]("Even: " + i);

}
class OddThread extends Thread

public void run()

for(int i=1; i<=10; i=i+2)

[Link]("Odd: " + i);

class Test

public static void main(String args[])

EvenThread t1 = new EvenThread();

OddThread t2 = new OddThread();

[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

public void run()

for(int i=2; i<=10; i=i+2)

[Link]("Even Number: " + i);

}
}

class OddThread extends Thread

public void run()

for(int i=1; i<=10; i=i+2)

[Link]("Odd Number: " + i);

class Test

public static void main(String args[])

EvenThread t1 = new EvenThread();

OddThread t2 = new OddThread();

[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:

VERY IMPORTANT (appears both years)​


Mostly asked as program-based 7 marks​
Key areas:

●​ Thread creation methods


●​ Lifecycle
●​ Practical implementation

Topic-03 – THREAD METHODS & SYNCHRONIZATION


(MODERATE PRIORITY)
Asked in:

• 2023–24

Questions:

Q1. “Differentiate between with suitable examples: wait() and notify()”​


→ 2023–24 | Section C | 7 Marks (part question) | Theory
Answer:

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.

Difference Between wait() and notify()


wait() notify()

Causes the thread to wait Wakes up a waiting thread

Releases the object lock Does not release lock immediately

Thread enters waiting state Thread becomes runnable

Used when thread waits for condition Used to signal another thread

Called inside synchronized block Called inside synchronized block

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

synchronized void show()

try

wait();

[Link]("Thread Resumed");

catch(Exception e)

[Link](e);

synchronized void display()


{

notify();

[Link]("Notification Sent");

Conclusion:

Concept-based question​
Often asked as part of mixed question​
Related to synchronization

Topic–04 – BASIC EXCEPTION CONCEPTS (LOW–MODERATE


PRIORITY)
Asked in:

• 2024–25

Questions:

Q1. “What is the purpose of the finally block in Java exception handling?”​
→ 2024–25 | Section A | 2 Marks

Answer:

Purpose of finally Block in Java Exception Handling


The finally block in Java is used to execute important statements whether an exception occurs or not. It is
mainly used for cleanup operations such as closing files, releasing resources, and database connections.

Features

1.​ Executes always


2.​ Used after try-catch block
3.​ Helps in resource cleanup

Example
try

int a = 10/0;

catch(Exception e)

[Link]("Exception Handled");

finally

[Link]("Finally Block Executed");

Q2. “How is throw different from throws?”​


→ 2024–25 | Section A | 2 Marks

Answer:

Difference Between throw and throws in Java


throw throws

Used to explicitly throw an exception Used to declare exceptions

Used inside method body Used with method declaration

Throws one exception at a time Can declare multiple exceptions

Followed by exception object Followed by exception class names

Example
throw new ArithmeticException();

void show() throws IOException

Conclusion:

Short conceptual questions​


Frequently appear in Section A

UNIT-04

Topic–01 – COLLECTION FRAMEWORK HIERARCHY (TOP


PRIORITY)

Asked in:

• 2023–24​
• 2024–25

Questions:

Q1. “Describe Collections framework in Java with a suitable diagram displaying


interfaces and classes and their hierarchy. Also explain the List, Set and Queue
interfaces.”​
→ 2023–24 | Section B | 7 Marks | Theory + Diagram

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.

Advantages of Collection Framework


1.​ Reduces programming effort
2.​ Provides dynamic memory management
3.​ Increases code reusability
4.​ Offers ready-made data structures

Hierarchy of Collection Framework

Main Interfaces in Collection Framework

1. List Interface
The List interface stores elements in ordered form and allows duplicate values.

Features

1.​ Maintains insertion order


2.​ Allows duplicate elements
3.​ Elements can be accessed using index

Classes of List

●​ ArrayList
●​ LinkedList
●​ Vector

Example

List<Integer> l = new ArrayList<Integer>();

2. Set Interface
The Set interface stores unique elements and does not allow duplicates.

Features

1.​ Does not allow duplicate elements


2.​ Unordered collection
3.​ Used for unique data storage

Classes of Set

●​ HashSet
●​ TreeSet
●​ LinkedHashSet

Example

Set<Integer> s = new HashSet<Integer>();

3. Queue Interface
The Queue interface stores elements in FIFO (First In First Out) order.

Features

1.​ Follows FIFO principle


2.​ Used in scheduling operations
3.​ Allows insertion and deletion from ends

Classes of Queue

●​ PriorityQueue
●​ LinkedList

Example

Queue<Integer> q = new LinkedList<Integer>();


Q2. “Discuss the hierarchy of the Collection framework in Java. Differentiate
between List, Set, and Map.”​
→ 2024–25 | Section C | 7 Marks | Theory + Comparison

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.

Hierarchy of Collection Framework

List Interface
The List interface stores elements in ordered form and allows duplicate values.

Features

1.​ Maintains insertion order


2.​ Allows duplicate elements
3.​ Supports indexing

Example Classes

●​ ArrayList
●​ LinkedList

Set Interface
The Set interface stores unique elements only.

Features

1.​ Does not allow duplicates


2.​ Unordered collection
3.​ Used for unique data storage

Example Classes

●​ HashSet
●​ TreeSet

Map Interface
The Map interface stores data in key-value pairs.

Features

1.​ Stores values using keys


2.​ Keys must be unique
3.​ Values can be duplicate

Example Classes

●​ HashMap
●​ TreeMap

Difference Between List, Set, and Map


List Set Map

Stores ordered elements Stores unique elements Stores key-value pairs


Allows duplicates Does not allow duplicates Duplicate keys not allowed

Uses index No indexing Uses keys

Example: ArrayList Example: HashSet Example: HashMap

Conclusion:

MOST IMPORTANT TOPIC (asked both years)​


Diagram-based question (very important)​
Covers:

●​ Interfaces (List, Set, Queue, Map)


●​ Hierarchy structure

Topic–02 – ARRAYLIST & LINKEDLIST (VERY HIGH


PRIORITY)
Asked in:

• 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[])

ArrayList<String> list = new ArrayList<String>();

[Link]("Java");

[Link]("Python");

[Link]("C");

[Link]("C++");

[Link]("HTML");

[Link](item -> [Link](item));

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

1.​ Maintains insertion order


2.​ Allows duplicate elements
3.​ Fast random access using index
4.​ Slow insertion and deletion in middle

Example

ArrayList<Integer> list = new ArrayList<Integer>();

LinkedList
LinkedList uses a doubly linked list to store elements.

Features

1.​ Maintains insertion order


2.​ Allows duplicate elements
3.​ Fast insertion and deletion
4.​ Slow data access

Example

LinkedList<Integer> list = new LinkedList<Integer>();

Difference Between ArrayList and LinkedList


ArrayList LinkedList

Uses dynamic array Uses doubly linked list

Faster data retrieval Slower data retrieval

Slower insertion/deletion Faster insertion/deletion


Requires less memory Requires more memory

Best for searching operations Best for frequent insertion/deletion

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.

LinkedList maintains insertion order and allows duplicate elements.


Features of LinkedList
1.​ Dynamic in size
2.​ Allows duplicate elements
3.​ Maintains insertion order
4.​ Fast insertion and deletion
5.​ Implements List and Queue interfaces

Syntax
LinkedList<Integer> list = new LinkedList<Integer>();

Common Methods of LinkedList


Method Description

add() Adds element to list

remove() Removes element

get() Accesses element

set() Updates element

size() Returns size of list

Program Example
import [Link];

class Demo
{

public static void main(String args[])

LinkedList<String> list = new LinkedList<String>();

[Link]("Java");

[Link]("Python");

[Link]("C");

[Link]("List: " + list);

[Link]("Python");

[Link]("After Remove: " + list);

[Link]("Element at Index 1: " + [Link](1));

[Link](1, "C++");

[Link]("Updated List: " + list);

[Link]("Size: " + [Link]());

Output
List: [Java, Python, C]

After Remove: [Java, C]

Element at Index 1: C

Updated List: [Java, C++]

Size: 2

Conclusion:

VERY FREQUENT TOPIC​


Asked as:

●​ Program (ArrayList)
●​ Theory + comparison (ArrayList vs LinkedList)​
Must prepare methods + differences

Topic–03 – HASHMAP (HIGH PRIORITY)


Asked in:

• 2023–24​
• 2024–25

Questions:

Q1. “Describe HashMap in Java collection framework. With suitable example


describe any five methods available in HashMaps.”​
→ 2023–24 | Section C | 7 Marks | Theory + Example

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.

HashMap allows one null key and multiple null values.

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>();

Common Methods of HashMap


Method Description

put() Inserts key-value pair

get() Retrieves value using key

remove() Removes element

containsKey() Checks key existence

size() Returns size of HashMap

Program Example
import [Link];

class Demo

public static void main(String args[])

HashMap<Integer, String> map = new HashMap<Integer, String>();


[Link](1, "Java");

[Link](2, "Python");

[Link](3, "C++");

[Link]("HashMap: " + map);

[Link]("Value at key 2: " + [Link](2));

[Link](3);

[Link]("After Remove: " + map);

[Link]("Contains Key 1: " + [Link](1));

[Link]("Size: " + [Link]());

Output
HashMap: {1=Java, 2=Python, 3=C++}

Value at key 2: Python

After Remove: {1=Java, 2=Python}

Contains Key 1: true

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

public static void main(String args[])

HashMap<Integer, String> map = new HashMap<Integer, String>();

[Link](1, "Java");

[Link](2, "Python");

[Link](3, "C++");

[Link]("Keys:");

for(Integer key : [Link]())

[Link](key);

}
[Link]("Values:");

for(String value : [Link]())

[Link](value);

[Link]("Keys and Values:");

for([Link]<Integer, String> e : [Link]())

[Link]([Link]() + " " + [Link]());

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:

IMPORTANT MAP-BASED QUESTION​


Comes as theory + program​
Focus on:

●​ Key-value concept
●​ Iteration methods

Topic–04 – LIST, SET, MAP DIFFERENCE (HIGH PRIORITY)


Asked in:

• 2024–25

Questions:

Q1. “Differentiate between List, Set, and Map.”​


→ 2024–25 | Section C | 7 Marks (part of hierarchy question)

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.

Difference Between List, Set, and Map


List Set Map

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

Uses index for accessing No indexing Uses keys to access values


elements

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

Example: ArrayList, LinkedList Example: HashSet, TreeSet Example: HashMap, TreeMap

List Interface
The List interface stores elements in sequence and allows duplicates.

Example

List<Integer> list = new ArrayList<Integer>();

Set Interface
The Set interface stores only unique elements.
Example

Set<Integer> set = new HashSet<Integer>();

Map Interface
The Map interface stores elements in key-value pairs.

Example

Map<Integer, String> map = new HashMap<Integer, String>();

Conclusion:

Frequently asked along with hierarchy​


Comparison-based answer (table preferred)

Topic–05 – STACK & QUEUE (LOW–MODERATE PRIORITY)


Asked in:

• 2024–25

Questions:

Q1. “How does Stack differ from Queue?”​


→ 2024–25 | Section A | 2 Marks | Conceptual

Answer:

Difference Between Stack and Queue


Stack Queue

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: Stack of books Example: Queue at ticket counter

Example

●​ Stack → Last inserted element is removed first.


●​ Queue → First inserted element is removed first.

Conclusion:

Short conceptual question​


Basic DS understanding required

UNIT-05

Topic–01 – STREAM API (TOP PRIORITY – BOTH YEARS)


Asked in:

• 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

Types of Stream Operations

1. Intermediate Operations
Intermediate operations transform a stream into another stream. They are lazy in nature.

Examples

●​ filter()
●​ map()
●​ sorted()

Example

[Link]().filter(x -> x > 5);

2. Terminal Operations
Terminal operations produce the final result and terminate the stream.

Examples

●​ forEach()
●​ collect()
●​ reduce()
●​ count()

Example

[Link]().forEach([Link]::println);

Program to Print Sum of Even Numbers from 1 to 10


import [Link];
class Demo

public static void main(String args[])

ArrayList<Integer> list = new ArrayList<Integer>();

for(int i=1; i<=10; i++)

[Link](i);

int sum = [Link]()

.filter(x -> x % 2 == 0)

.mapToInt(x -> x)

.sum();

[Link]("Sum of Even Numbers = " + 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.

Stream API in Java


The Stream API provides methods to perform operations such as:

●​ Filtering
●​ Sorting
●​ Mapping
●​ Searching
●​ Aggregation

Streams do not store data; they only process data.

Syntax

[Link]();

Features of Stream API


1.​ Reduces code complexity
2.​ Supports functional programming
3.​ Improves readability
4.​ Enables parallel processing
5.​ Provides efficient data processing

Functional-Style Operations in Stream API


Functional-style operations are operations performed using lambda expressions and functional interfaces.

Stream API supports these operations using methods like:

●​ filter()
●​ map()
●​ sorted()
●​ reduce()
●​ forEach()

Types of Stream Operations

1. Intermediate Operations
These operations return another stream and are lazy in nature.

Examples

●​ filter()
●​ map()
●​ sorted()

Example

[Link]().filter(x -> x > 5);

2. Terminal Operations
These operations produce the final result.

Examples

●​ forEach()
●​ collect()
●​ count()
●​ reduce()

Example

[Link]().forEach([Link]::println);

Example of Stream API


import [Link];

import [Link];
class Demo

public static void main(String args[])

List<Integer> list = [Link](1,2,3,4,5,6);

[Link]()

.filter(x -> x % 2 == 0)

.forEach([Link]::println);

Output
2

Conclusion:

MOST IMPORTANT UNIT–05 TOPIC​


Asked in both years (100%)​
Focus on:

●​ Intermediate vs Terminal operations


●​ Functional programming style
●​ Program using streams

Topic–02 – SPRING BOOT (VERY HIGH PRIORITY)


Asked in:

• 2023–24​
• 2024–25

Questions:

Q1. “Describe following: Spring boot framework and its benefits”​


→ 2023–24 | Section C | 7 Marks (part question) | Theory

Answer:

Spring Boot Framework and its Benefits

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.

Spring Boot was introduced to simplify the development of Spring applications.

Spring Boot Framework


Spring Boot provides:

●​ Auto configuration
●​ Embedded servers
●​ Ready-to-use features
●​ Faster application development

It helps developers create web applications with minimal configuration.

Features of Spring Boot


1.​ Auto configuration support
2.​ Embedded Tomcat server
3.​ Simplified dependency management
4.​ Production-ready applications
5.​ Faster development process

Architecture of Spring Boot


Benefits of Spring Boot
1.​ Reduces XML configuration
2.​ Simplifies application setup
3.​ Provides embedded servers
4.​ Easy dependency management
5.​ Faster development and deployment
6.​ Supports microservices architecture
7.​ Production-ready features available

Example of Spring Boot Application


import [Link];

import [Link];

@SpringBootApplication

class DemoApplication

public static void main(String args[])

[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.

Features of Spring Boot

1.​ Auto configuration


2.​ Embedded Tomcat server
3.​ Simplified dependency management
4.​ Production-ready applications
5.​ Faster application development

Example of Spring Boot Application


import [Link];

import [Link];

@SpringBootApplication

class DemoApplication

public static void main(String args[])

[Link]([Link], args);
}

Difference Between Spring Boot and Traditional Spring Framework


Spring Boot Traditional Spring Framework

Minimal configuration required Requires extensive configuration

Provides auto configuration Manual configuration needed

Embedded servers available External server required

Faster development Development takes more time

Easy dependency management Dependency management is complex

Production-ready features available Additional setup required

Advantages of Spring Boot


1.​ Simplifies application development
2.​ Reduces boilerplate code
3.​ Provides embedded server support
4.​ Easy deployment
5.​ Supports microservices architecture

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.

Structure of a Basic Spring Boot Application


A basic Spring Boot application mainly contains:

1.​ Main Application Class


2.​ Controller Class
3.​ Service Layer
4.​ Repository Layer
5.​ Configuration Files

Basic Structure Diagram

Main Application Class


The main class contains the main() method and @SpringBootApplication annotation.
Example

import [Link];

import [Link];

@SpringBootApplication

class DemoApplication

public static void main(String args[])

[Link]([Link], args);

Controller Class
The controller handles client requests.

Example

import [Link];

import [Link];

@RestController

class DemoController

@GetMapping("/")

public String show()

return "Hello Spring Boot";


}

Advantages of Spring Boot Over Traditional Web Frameworks


Spring Boot Traditional Web Framework

Minimal configuration required Requires heavy configuration

Embedded server support External server required

Faster development Slower development

Auto configuration available Manual configuration needed

Easy dependency management Complex dependency management

Additional Advantages of Spring Boot


1.​ Simplifies application setup
2.​ Reduces boilerplate code
3.​ Easy deployment
4.​ Production-ready applications
5.​ Supports microservices architecture

Conclusion:

VERY FREQUENT THEORY QUESTION​


Focus areas:

●​ 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.

●​ IoC is a design principle.


●​ DI is a technique used to implement IoC.

Inversion of Control (IoC)


Inversion of Control means transferring the control of object creation and management from the programmer to
the Spring container.

The Spring container creates and manages objects automatically.

Features of IoC

1.​ Reduces dependency between classes


2.​ Improves flexibility
3.​ Managed by Spring container
4.​ Simplifies object management

Dependency Injection (DI)


Dependency Injection is a technique in which one object provides dependencies to another object.

Spring injects required objects automatically instead of creating them manually.

Types of DI

1.​ Constructor Injection


2.​ Setter Injection

Difference Between IoC and DI


IoC DI

Design principle Technique to implement IoC

Transfers control to container Injects dependencies into objects

Manages object creation Provides required objects

Implemented using DI Part of IoC mechanism

Example of Dependency Injection


class Engine

void start()

[Link]("Engine Started");

class Car
{

Engine e;

Car(Engine e)

this.e = e;

void drive()

[Link]();

Advantages of IoC and DI


1.​ Loose coupling
2.​ Better code reusability
3.​ Easier testing
4.​ Simplified maintenance
5.​ Better flexibility

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.

Spring container manages object creation and injection automatically.

Types of Dependency Injection

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;

Advantages of Dependency Injection


1.​ Loose coupling
2.​ Better code reusability
3.​ Easy testing
4.​ Simplifies maintenance

Spring Boot CRUD API Using List Storage

Program
import [Link].*;

import [Link].*;

@RestController

class StudentController

List<String> students = new ArrayList<String>();

@GetMapping("/students")

public List<String> getStudents()

return students;

}
@PostMapping("/add/{name}")

public String addStudent(@PathVariable String name)

[Link](name);

return "Student Added";

@PutMapping("/update/{index}/{name}")

public String updateStudent(@PathVariable int index,

@PathVariable String name)

[Link](index, name);

return "Student Updated";

@DeleteMapping("/delete/{index}")

public String deleteStudent(@PathVariable int index)

[Link](index);

return "Student Deleted";

}
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:

IMPORTANT CONCEPTUAL QUESTION​


Often mixed with Spring Boot / API questions​
Focus on:

●​ DI types
●​ IoC vs DI

Topic–04 – REST API / WEB SERVICES (MODERATE PRIORITY)


Asked in:

• 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.

Spring Boot uses DI extensively for managing application components.

Dependency Injection (DI)


Dependency Injection means injecting dependencies into a class instead of creating them manually.

The Spring container manages object creation and injection automatically.

Types of Dependency Injection

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;

Advantages of Dependency Injection


1.​ Loose coupling
2.​ Easy testing
3.​ Better maintainability
4.​ Improved code reusability

Spring Boot CRUD API Using List Storage

Program
import [Link].*;

import [Link].*;
@RestController

class StudentController

List<String> students = new ArrayList<String>();

@GetMapping("/students")

public List<String> getStudents()

return students;

@PostMapping("/add/{name}")

public String addStudent(@PathVariable String name)

[Link](name);

return "Student Added";

@PutMapping("/update/{index}/{name}")

public String updateStudent(@PathVariable int index,

@PathVariable String name)

[Link](index, name);

return "Student Updated";


}

@DeleteMapping("/delete/{index}")

public String deleteStudent(@PathVariable int index)

[Link](index);

return "Student Deleted";

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:

●​ Basic REST concepts


●​ CRUD operations

Topic–05 – GET vs POST (LOW PRIORITY)


Asked in:

• 2024–25

Questions:

Q1. “What is a GET vs POST request?”​


→ 2024–25 | Section A | 2 Marks | Conceptual

Answer:

Difference Between GET and POST Request


GET Request POST Request

Used to retrieve data from server Used to send data to server

Data is sent through URL Data is sent in request body

Less secure More secure

Limited data size Large amount of data can be sent

Faster request Slightly slower request

Example

●​ GET → Fetching webpage data


●​ POST → Submitting login or registration form
Conclusion:

Short conceptual question​


Basic web knowledge required

ALL THE VERY BEST - BITWISE LEARNING

You might also like