1. Explain MVP Architecture

Definition

MVP (Model–View–Presenter) is a software architectural pattern that divides an application into three components—Model, View, and Presenter—to separate data, user interface, and business logic.


Architecture Diagram

Components of MVP Architecture
1. Model
  • Represents data and business logic
  • Handles data processing, database operations, and rules
  • Independent of UI and Presenter
  • Notifies Presenter when data changes

Example:
Student records, database access classes


2. View
  • Represents user interface (UI)
  • Displays data received from Presenter
  • Sends user actions (clicks, inputs) to Presenter
  • Does not contain business logic

Example:
Java Swing forms, buttons, text fields


3. Presenter
  • Acts as a mediator between Model and View
  • Receives input from View
  • Processes logic and updates Model
  • Retrieves data from Model and updates View
  • Contains core application logic

Working Flow of MVP Architecture
  1. User interacts with View (e.g., button click)
  2. View forwards request to Presenter
  3. Presenter processes request and interacts with Model
  4. Model performs operations and returns result
  5. Presenter updates View with processed data

Detailed Interaction
View → Presenter → Model Model → Presenter → View View and Model do not communicate directly Presenter controls the entire flow

Features of MVP
  • Separation of concerns (UI, logic, data separated)
  • Loose coupling between components
  • High testability (Presenter can be tested independently)
  • Better code organization

Advantages
  • Easier debugging and maintenance
  • Reusable components
  • Improved scalability
  • Clear responsibility of each component

Disadvantages
  • Increased number of classes
  • More complex structure for small applications
  • Requires proper design understanding

Applications of MVP
  • Desktop GUI applications (Java Swing, JavaFX)
  • Android applications
  • Enterprise-level applications
  • Systems requiring clear UI and logic separation

Example Structure (Java Concept)
// Model class Student { String name; } // View interface StudentView { void display(String name); } // Presenter class StudentPresenter { Student model; StudentView view; StudentPresenter(Student m, StudentView v) { model = m; view = v; } void updateView() { view.display(model.name); } }
2. String Components

Definition

A String in Java is a sequence of characters represented using the String class from the java.lang package and is used to store and manipulate textual data.


Internal Representation of String

Types of Strings in Java
1. String Literal
  • Created using double quotes
  • Stored in String pool
  • Memory efficient

Example:

String s1 = "Hello";

2. String Object
  • Created using new keyword
  • Stored in heap memory
  • Creates a new object every time

Example:

String s2 = new String("Hello");

String Classes (Components)
1. String Class
  • Immutable (cannot be modified after creation)
  • Stored in String pool
  • Provides various built-in methods

Common Methods:

  • length() → returns length
  • charAt() → returns character
  • substring() → extracts part of string
  • equals() → compares strings

2. StringBuffer Class
  • Mutable (can be modified)
  • Thread-safe (synchronized)
  • Slower than StringBuilder

Methods:

  • append()
  • insert()
  • delete()

3. StringBuilder Class
  • Mutable and faster than StringBuffer
  • Not thread-safe
  • Used for high-performance string operations

String Pool Concept
  • Special memory area inside heap
  • Stores string literals
  • Avoids duplicate objects
  • Improves memory efficiency

Operations on Strings
  • Concatenation → + operator or concat()
  • Comparison → equals()
  • Searching → indexOf()
  • Conversion → toUpperCase(), toLowerCase()

Example Program
class StringExample { public static void main(String[] args) { String s1 = "Java"; String s2 = "Programming"; System.out.println(s1 + " " + s2); } }
3. Packages in Java

Definition

A package in Java is a collection of related classes, interfaces, and sub-packages grouped together to organize code and avoid naming conflicts.


Concept of Package (Structure)

Need for Packages
  • Organizes large programs into logical groups
  • Avoids class name conflicts
  • Provides better code maintainability
  • Supports access protection (security)
  • Helps in code reuse and modularity

Types of Packages
1. Built-in Packages
  • Predefined packages provided by Java API
  • Contain standard classes and interfaces

Examples:

  • java.lang → basic classes (String, System)
  • java.util → utilities (ArrayList, Scanner)
  • java.io → input/output operations
  • java.awt, javax.swing → GUI components

2. User-Defined Packages
  • Created by programmers to group related classes
  • Improves project structure

Example:

package mypackage; public class Test { public void display() { System.out.println("User-defined package"); } }

Creating a Package
  1. Use package keyword at the beginning of the program
  2. Compile using javac -d . ClassName.java
  3. Directory structure will be created automatically

Accessing a Package

Using import statement

import java.util.Scanner;

Import entire package

import java.util.*;

Advantages of Packages
  • Prevents naming conflicts
  • Provides access control using modifiers
  • Improves readability and organization
  • Supports reusability of code

Example Program
import java.util.*; public class Demo { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter number:"); int n = sc.nextInt(); System.out.println(n); } }
4. Thread Life Cycle in Java

Definition

Thread life cycle represents the different states through which a thread passes from its creation to termination during execution.


Thread Life Cycle Diagram

States of Thread Life Cycle
1. New (Born State)
  • Thread is created but not yet started
  • Created using new Thread()
  • No execution at this stage

2. Runnable State
  • Thread is ready for execution
  • After calling start() method
  • Waiting for CPU allocation

3. Running State
  • Thread is actively executing
  • CPU is assigned to the thread
  • Performs task defined in run() method

4. Blocked / Waiting State
  • Thread is temporarily inactive
  • Waiting for resources or another thread
  • Methods causing this state:
  • sleep()
  • wait()
  • join()

5. Terminated (Dead State)
  • Thread completes execution or is stopped
  • Cannot be restarted again

State Transitions
  • New → Runnable → using start()
  • Runnable → Running → CPU scheduler selects thread
  • Running → Waiting/Blocked → due to sleep(), wait()
  • Waiting → Runnable → after condition is satisfied
  • Running → Terminated → after execution completes

Example Program
class MyThread extends Thread { public void run() { System.out.println("Thread is running"); } } public class Test { public static void main(String[] args) { MyThread t = new MyThread(); // New state t.start(); // Runnable → Running } }

Important Methods
  • start() → starts thread
  • run() → contains execution code
  • sleep() → pauses thread
  • join() → waits for another thread
  • yield() → gives chance to other threads

Key Points for Exam
  • 5 states: New, Runnable, Running, Waiting/Blocked, Terminated
  • start() method begins execution
  • Thread cannot restart after termination
  • Life cycle controlled by JVM scheduler
5. Concepts of Exception Handling in Java

Definition

Exception handling is a mechanism in Java used to handle runtime errors so that the normal flow of the program can be maintained without termination.


Exception Handling Flow

Key Concepts of Exception Handling
1. Exception
  • An unwanted event that occurs during program execution
  • Disrupts normal flow of program
  • Example: division by zero, null reference

2. Types of Exceptions
  • Checked Exceptions → occur at compile time (e.g., IOException)
  • Unchecked Exceptions → occur at runtime (e.g., ArithmeticException)

3. Try Block
  • Contains code that may cause exception
  • Must be followed by catch or finally
try { int a = 10/0; }

4. Catch Block
  • Handles the exception thrown in try block
  • Multiple catch blocks can be used
catch(ArithmeticException e) { System.out.println("Error"); }

5. Finally Block
  • Executes always, whether exception occurs or not
  • Used for cleanup operations
finally { System.out.println("Executed always"); }

6. Throw Keyword
  • Used to explicitly throw an exception
throw new ArithmeticException("Error");

7. Throws Keyword
  • Declares exceptions in method signature
  • Passes exception handling responsibility to caller
void test() throws IOException { }

8. Multiple Catch Block
  • Allows handling different exceptions separately
  • Order should be from specific to general

9. User-Defined Exception
  • Custom exception created by extending Exception class
  • Used for specific application needs

Example Program
class Demo { public static void main(String[] args) { try { int a = 10/0; } catch(ArithmeticException e) { System.out.println("Exception handled"); } finally { System.out.println("Program continues"); } } }

Advantages of Exception Handling
  • Prevents program crash
  • Maintains normal program flow
  • Improves reliability and robustness
  • Helps in debugging and error tracking

Key Points for Exam
  • Core keywords: try, catch, finally, throw, throws
  • Two types: checked and unchecked
  • Multiple catch improves handling
  • User-defined exceptions extend Exception class
6. String & String Functions in Java

Definition

A String in Java is a sequence of characters represented by the String class in java.lang, used to store and manipulate textual data.


String Representation

Creation of String
1. Using String Literal
String s1 = "Java";
2. Using new Keyword
String s2 = new String("Programming");

Properties of String
  • Immutable (cannot be changed after creation)
  • Stored in String pool (memory efficient)
  • Provides many built-in methods

Common String Functions (Methods)
1. length()

Returns number of characters

s.length();
2. charAt()

Returns character at given index

s.charAt(2);
3. substring()

Extracts part of string

s.substring(1,4);
4. equals()

Compares two strings

s1.equals(s2);
5. equalsIgnoreCase()

Compares ignoring case

s1.equalsIgnoreCase(s2);
6. concat()

Joins two strings

s1.concat(s2);
7. toUpperCase() / toLowerCase()

Converts case

s.toUpperCase();
8. indexOf()

Finds position of character

s.indexOf('a');
9. replace()

Replaces characters

s.replace('a','b');
10. trim()

Removes extra spaces

s.trim();

Example Program
class StringDemo { public static void main(String[] args) { String s = "Java Programming"; System.out.println(s.length()); System.out.println(s.toUpperCase()); System.out.println(s.substring(0,4)); } }

String vs StringBuffer vs StringBuilder
Feature String StringBuffer StringBuilder
Nature Immutable Mutable Mutable
Thread Safety Yes Yes No
Performance Slow Moderate Fast

Key Points for Exam
  • String is immutable
  • Stored in String pool
  • Many built-in functions available
  • StringBuffer & StringBuilder used for modification
7. Inheritance & Its Types in Java

Definition

Inheritance is an OOP concept where one class (subclass) acquires the properties and methods of another class (superclass) using the extends keyword, promoting code reuse.


Basic Structure of Inheritance

Key Terms
  • Superclass (Base Class) → Class whose properties are inherited
  • Subclass (Derived Class) → Class that inherits properties
  • extends keyword → Used to implement inheritance

Syntax
class A { void display() { System.out.println("Superclass"); } } class B extends A { void show() { System.out.println("Subclass"); } }

Types of Inheritance in Java
1. Single Inheritance

One subclass inherits from one superclass

class Animal { void eat() { System.out.println("Eating"); } } class Dog extends Animal { void bark() { System.out.println("Barking"); } }

2. Multilevel Inheritance

A class inherits from another class, forming a chain

class Animal { void eat() { } } class Mammal extends Animal { void breathe() { } } class Dog extends Mammal { void bark() { } }

3. Hierarchical Inheritance

Multiple subclasses inherit from one superclass

class Animal { void eat() { } } class Dog extends Animal { } class Cat extends Animal { }

4. Multiple Inheritance (Using Interfaces)

Java does not support multiple inheritance using classes

Achieved using interfaces

interface A { void displayA(); } interface B { void displayB(); } class C implements A, B { public void displayA() { } public void displayB() { } }

Advantages of Inheritance
  • Code reusability
  • Reduces redundancy
  • Improves readability
  • Supports polymorphism

Key Points for Exam
  • Inheritance uses extends keyword
  • Promotes reuse and hierarchy
  • Types: Single, Multilevel, Hierarchical, Multiple (via interface)
  • Java avoids multiple inheritance with classes to prevent ambiguity
8. Control Statements in Java
Screenshot-2026-03-26-20-24-14-63-96b26121e545231a3c569311a54cda96
Definition

Control statements are used to control the flow of execution of a program based on conditions, loops, and branching.


Types of Control Statements
Control Statements Diagram
1. Conditional (Decision-Making) Statements
a) if Statement

Executes block if condition is true

if(x > 0) { System.out.println("Positive"); }

b) if-else Statement

Chooses between two conditions

if(x > 0) { System.out.println("Positive"); } else { System.out.println("Negative"); }

c) else-if Ladder

Multiple conditions checked sequentially

if(x > 0) { System.out.println("Positive"); } else if(x == 0) { System.out.println("Zero"); } else { System.out.println("Negative"); }

d) switch Statement

Selects one case from many options

switch(day) { case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; default: System.out.println("Invalid"); }

2. Looping Statements
a) while Loop

Executes while condition is true

int i = 0; while(i < 5) { System.out.println(i); i++; }

b) do-while Loop

Executes at least once

int i = 0; do { System.out.println(i); i++; } while(i < 5);

c) for Loop

Used when number of iterations is known

for(int i = 0; i < 5; i++) { System.out.println(i); }

3. Jumping (Branching) Statements
a) break

Terminates loop or switch

break;

b) continue

Skips current iteration

continue;

c) return

Exits from method

return;

Key Points for Exam
  • Control statements guide program execution
  • Three types: Conditional, Looping, Jumping
  • Used for decision-making and repetition
  • Essential for logic building in programs
9. Operators in Java

Definition

Operators in Java are special symbols used to perform operations on variables and values such as arithmetic, comparison, and logical operations.


Types of Operators

1. Arithmetic Operators

Used for mathematical calculations

OperatorOperation
+Addition
-Subtraction
*Multiplication
/Division
%Modulus

Example:

int a = 10, b = 5; System.out.println(a + b); // 15

2. Relational Operators

Used to compare two values (returns boolean)

OperatorMeaning
==Equal to
!=Not equal
>Greater than
<Less than
>=Greater than or equal
<=Less than or equal

3. Logical Operators

Used to combine conditions

OperatorMeaning
&&Logical AND
||Logical OR
!Logical NOT

4. Assignment Operators

Used to assign values

OperatorExample
=a = 10
+=a += 5
-=a -= 2
*=a *= 3
/=a /= 2

5. Unary Operators

Operate on single operand

OperatorOperation
++Increment
--Decrement
!Logical NOT

6. Bitwise Operators

Operate on bits

OperatorMeaning
&AND
|OR
^XOR
~Complement

7. Ternary Operator

Shortcut for if-else

int result = (a > b) ? a : b;

Example Program
class OperatorDemo { public static void main(String[] args) { int a = 10, b = 5; System.out.println(a + b); // Arithmetic System.out.println(a > b); // Relational System.out.println(a > 0 && b > 0); // Logical } }

Key Points for Exam
  • Operators perform operations on data
  • Types: Arithmetic, Relational, Logical, Assignment, Unary, Bitwise, Ternary
  • Used in calculations and decision-making
  • Important for building program logic
10. Features of Java

Key Features of Java

1. Simple
  • Easy to learn and use
  • Syntax is similar to C++
  • Avoids complex features like pointers and operator overloading

2. Object-Oriented
  • Based on OOP concepts: encapsulation, inheritance, polymorphism
  • Everything is treated as an object

3. Platform Independent
  • Follows Write Once, Run Anywhere (WORA)
  • Java code is compiled into bytecode that runs on any JVM

4. Portable
  • Java programs can run on different platforms without modification
  • Fixed size of data types ensures portability

5. Secure
  • No direct memory access (no pointers)
  • Uses bytecode verification and security manager
  • Provides safe execution environment

6. Robust
  • Strong memory management
  • Automatic garbage collection
  • Exception handling reduces errors

7. Architecture Neutral
  • Not dependent on hardware architecture
  • Bytecode can run on any machine with JVM

8. Interpreted
  • Java bytecode is interpreted by JVM
  • Supports dynamic execution

9. High Performance
  • Uses Just-In-Time (JIT) compiler
  • Optimizes execution speed

10. Multithreaded
  • Supports multiple threads running simultaneously
  • Improves efficiency and performance

11. Distributed
  • Supports network-based applications
  • Provides APIs like RMI and networking packages

12. Dynamic
  • Supports dynamic class loading at runtime
  • Allows flexible and extensible programs
11. Difference between Method Overloading and Method Overriding
Screenshot-2026-03-26-20-29-59-12-96b26121e545231a3c569311a54cda96
Definition

Method Overloading: Defining multiple methods with the same name but different parameters in the same class.

Method Overriding: Redefining a method of a superclass in a subclass with the same method signature.


Comparison Diagram

Difference Table
Feature Method Overloading Method Overriding
Definition Same method name with different parameters Same method name and parameters in subclass
Polymorphism Compile-time polymorphism Runtime polymorphism
Class Requirement Occurs within same class Requires inheritance
Parameters Must be different (number/type/order) Must be same
Return Type Can be same or different Must be same or covariant
Method Signature Must differ Must be identical
Binding Early binding (static binding) Late binding (dynamic binding)
Access Modifier No restriction Cannot reduce access level
Keyword No special keyword @Override annotation used
Execution Time Decided at compile time Decided at runtime

Method Overloading Example
class Calculator { int add(int a, int b) { return a + b; } int add(int a, int b, int c) { return a + b + c; } }

Method Overriding Example
class Animal { void sound() { System.out.println("Animal makes sound"); } } class Dog extends Animal { @Override void sound() { System.out.println("Dog barks"); } }

Rules of Method Overloading
  • Method name must be same
  • Parameters must be different
  • Return type alone is not sufficient
  • Can occur in same class

Rules of Method Overriding
  • Method name and parameters must be same
  • Requires inheritance (extends)
  • Cannot override static, final, or private methods
  • Access modifier cannot be more restrictive
  • Runtime decision (dynamic binding)

Key Points for Exam
  • Overloading → compile-time, same class, different parameters
  • Overriding → runtime, subclass, same method signature
  • Overloading increases readability
  • Overriding enables runtime polymorphism
12. Java Swing

Definition

Java Swing is a GUI (Graphical User Interface) toolkit in Java used to build window-based desktop applications and is part of the javax.swing package.


Swing Architecture

Features of Java Swing
  • Platform independent (runs on any system with JVM)
  • Rich set of components (JButton, JLabel, JTextField, JTable)
  • Lightweight components (not dependent on OS)
  • Highly customizable (color, font, size)
  • Event-driven programming support
  • Follows MVC architecture

Hierarchy of Swing Components
  • Top-level containers → JFrame, JDialog, JApplet
  • Intermediate containers → JPanel, JScrollPane
  • Components → JButton, JLabel, JTextField, JTextArea

Common Swing Components
1. JFrame
  • Main window container
  • Used to hold other components

2. JButton
  • Represents a clickable button
  • Generates action events

3. JLabel
  • Displays text or images

4. JTextField
  • Single-line text input

5. JTextArea
  • Multi-line text input

6. JPanel
  • Container to group components

Layout Managers
  • FlowLayout → arranges components in a row
  • BorderLayout → divides into North, South, East, West, Center
  • GridLayout → arranges in grid form
  • BoxLayout → arranges in row/column

Event Handling in Swing
  • Handles user actions like button clicks
  • Uses listeners such as ActionListener
  • Event → Action → Response mechanism

Example Program
import javax.swing.*; public class SwingExample { public static void main(String[] args) { JFrame frame = new JFrame("Swing Example"); JButton button = new JButton("Click Me"); button.setBounds(100, 100, 100, 30); frame.add(button); frame.setSize(400, 300); frame.setLayout(null); frame.setVisible(true); } }

Applications of Java Swing
  • Desktop applications
  • Banking systems
  • Text editors
  • Management systems
  • GUI-based tools

Key Points for Exam
  • Swing is part of javax.swing
  • Used for GUI development
  • Contains rich components and layouts
  • Event-driven and platform independent