Java Outline Solution (3rd B - 2025)
By Sakib-58
Blue mark = previous question a ashcilo.
1) Inheritance - types - (Multiple, Multilevel, Hierarchical), Importance.
Ans => Inheritance in Java is a mechanism where one class
(child/subclass) can acquire the properties and behaviors (fields and
methods) of another class (parent/superclass).
Types of Inheritance in Java :
1)Single Inheritance : One class inherits from one parent class.
2) Multilevel Inheritance : A class is derived from a class which is also
derived from another class.
3) Hierarchical Inheritance : Multiple classes inherit from the same base
class.
4) Multiple Inheritance : It is when a class inherits from more than one
class or interface.
Importance of Inheritance :
● Code Reusability: Reuse existing code easily.
● Method Overriding: Supports polymorphism.
● Organized Code: Keeps classes structured.
● Easy Extending: Add new features without changing old code.
● Data Protection: Controls access to data.
2) Why doesn’t Java support multiple inheritance? How can it be
implemented?
=> Why Java doesn’t support multiple inheritance?
To avoid ambiguity and the “diamond problem” where a class inherits
conflicting methods from multiple parent classes.
=> How can it be implemented?
By using interfaces, since a class can implement multiple interfaces in Java.
3) Polymorphism (Definition, Types (Compile Time, Run Time
Polymorphism)). Importance of Polymorphism?
Definition:
Polymorphism means “many forms.” In Java, it allows a single method or
object to take multiple forms based on how it is used.
Types of Polymorphism
1. Compile-Time Polymorphism (Method Overloading):
Same method name but different parameters within the same class. The
decision is made at compile time.
2. Run-Time Polymorphism (Method Overriding):
A subclass provides a specific implementation of a method declared in its
superclass. The decision is made at runtime.
=> Importance of Polymorphism
● Flexibility: Allows one interface to be used for a general class of actions.
● Scalability: Easier to add new classes with specific behavior without
changing existing code.
● Code Reusability: Methods can work with different types of objects.
● Simplifies Maintenance: Makes code more modular and easier to
manage.
4) Difference between method overloading & method overriding?
5) What is the difference between compile-time and run-time
polymorphism?
6) Encapsulation – Definition, Importance, Coding example.
Definition:
Encapsulation is the process of wrapping data (variables) and methods that
operate on the data into a single unit (class) and restricting direct access to some
of the object's components.
Importance:
● Protects data from unauthorized access.
● Improves code maintainability and flexibility.
● Helps hide implementation details.
● Controls how data is accessed or modified.
7) Abstraction – Definition, Importance, Coding example.
Definition:
Abstraction is hiding the complex implementation details and showing only the
essential features of an object.
Importance:
● Simplifies code by hiding unnecessary details.
● Helps focus on what an object does, not how it does it.
● Improves code maintainability and security.
8) Abstract class vs interface :
9) Uses of final, static, extends & implements keywords.
final:
Prevents modification. Used with variables (constant), methods (no override),
and classes (no inheritance).
Example: final int MAX = 100;
static:
Belongs to the class, not instances. Used for variables and methods shared by
all objects.
Example: static int count;
extends:
Used for class inheritance (a class inherits another class).
Example: class Dog extends Animal { }
implements:
Used when a class implements one or more interfaces.
Example: class Dog implements Runnable { }.
10) Differences between public, private, protected & default access
modifiers .
11) String, String Buffer, String Builder & String Tokenizer
String: Immutable sequence of characters.
String s = "Hello";
StringBuffer: Mutable and thread-safe string class.
StringBuffer sb = new StringBuffer("Hello");
[Link](" World");
StringBuilder: Mutable but not thread-safe, faster than StringBuffer.
StringBuilder sb = new StringBuilder("Hello");
[Link](" World");
StringTokenizer: Used to split a string into tokens.
StringTokenizer st = new StringTokenizer("Java is
fun");
while([Link]()) {
[Link]([Link]());
}
12) July-Dec 2024 --> 2 (a, b), 3 (a,b) .
2(a,b) => StringBuffer in Java
What is StringBuffer?
A mutable class for strings, unlike String which is immutable. StringBuffer
allows modifying the string without creating new objects, so it's efficient for
frequent changes.
Difference from String:
String is immutable; StringBuffer is mutable and thread-safe.
Key methods:
● Convert to String: [Link]();
● Insert: [Link](index, "text");
● Delete: [Link](start, end);
● Append: [Link]("text");
● Reverse: [Link]();
● Replace: [Link](start, end, "newText");
3(a) => StringTokenizer
● What is StringTokenizer?
A class to break a string into tokens (parts) using delimiters.
● Difference from split():
StringTokenizer returns tokens one by one.
split() returns an array of all tokens at once.
( b) Join array:
String joined = [Link](" ", arr);
● Count substring:
int count = 0, i = 0;
while ((i = [Link](sub, i)) != -1) {
count++; i += [Link]();
● Check equality:
[Link](s2); // case-sensitive
[Link](s2); // case-insensitive
13) Thread - Definition, Importance, States, Multithreading vs
Multitasking
Thread:
A thread is a lightweight unit of a process that can run independently.
Importance:
● Allows simultaneous execution of tasks.
● Improves performance and resource use.
States of a Thread:
1. New — Created but not started.
2. Runnable — Ready to run.
3. Running — Executing.
4. Blocked/Waiting — Paused, waiting for resources or event.
5. Terminated — Finished execution.
=> Multithreading vs Multitasking :
14) Exception handling - (try-catch-finally, Types of exception) | Several
Exception - examples
try-catch-finally:
15) Why is exception handling important? How to create a custom
exception?
Why Exception Handling is Important:
● Prevents program crashes by managing errors gracefully.
● Helps maintain normal program flow.
● Makes debugging easier by identifying error sources.
Example : class MyException extends Exception {
MyException(String msg) {
super(msg);
17) File Handling- (file input stream, file output stream, bufferedreader,
bufferedwriter). How does it work?
FileInputStream: Reads bytes from a file (for binary data).
FileOutputStream: Writes bytes to a file (for binary data).
BufferedReader: Reads text efficiently from a file (character data).
BufferedWriter: Writes text efficiently to a file (character data).
How it works: Streams connect to the file and read/write bytes
(FileInputStream/OutputStream) or characters (BufferedReader/Writer).
Buffered classes speed up by using a buffer. Always close streams to free
resources.
Java Graphical User Interface (GUI)
22-05-2025
1) Why is GUI important in Java?
GUI is important in Java because it lets users interact with programs
using buttons, windows, and forms instead of text commands. It makes
applications user-friendly and easy to use.
2) What is swing in Java? How is it different from AWT & JavaFX?
=> Swing is a GUI toolkit that provides rich, flexible components like
JButton, JFrame, etc., for building desktop apps.
3) How do you create a simple GUI Application in Java Swing?
5 and 6 )
● 1. JFrame – Main window
● JFrame frame = new JFrame("Main Window");
● [Link](300, 200);
● [Link](true);
● ✅ 2. JDialog – Popup window
● JDialog dialog = new JDialog();
● [Link]("Popup");
● [Link](200, 100);
● [Link](true);
● ✅ 3. JLabel – Displays text
● JLabel label = new JLabel("Hello, User!");
● [Link](label);
● ✅ 4. JButton – Clickable button
● JButton btn = new JButton("Click Me");
● [Link](btn);
● ✅ 5. JCheckBox – Selectable box
● JCheckBox cb = new JCheckBox("I Agree");
● [Link](cb);
● ✅ 6. JRadioButton – Select one option
● JRadioButton r1 = new JRadioButton("Male");
● JRadioButton r2 = new JRadioButton("Female");
● ButtonGroup bg = new ButtonGroup();
● [Link](r1); [Link](r2);
● [Link](r1); [Link](r2);
● ✅ 7. JComboBox – Drop-down menu
● String[] options = {"Java", "C++", "Python"};
● JComboBox cb = new JComboBox(options);
● [Link](cb);
● ✅ 8. JList – List of items
● String[] items = {"Apple", "Banana", "Cherry"};
● JList list = new JList(items);
● [Link](list);
● ✅ 9. JTextField – Single-line input
● JTextField tf = new JTextField();
● [Link](50, 50, 100, 30);
● [Link](tf);
● ✅ 10. JPasswordField – Hidden text input
● JPasswordField pf = new JPasswordField();
● [Link](pf);
● ✅ 11. JTextArea – Multi-line input
● JTextArea ta = new JTextArea("Type here...");
● [Link](ta);
● ✅ 12. JPanel – Holds components
● JPanel panel = new JPanel();
● [Link](new JLabel("Inside Panel"));
● [Link](panel);
● ✅ 13. JTable – Displays tabular data
● String[][] data = {{"1", "Sakib"}, {"2",
"Sakib-again"}};
● String[] cols = {"ID", "Name"};
● JTable table = new JTable(data, cols);
● [Link](new JScrollPane(table));
8) What is Layout Manager? Types of layout manager?(FlowLayout,
BorderLayout, GridLayout) -> Explain with a Figure.
9) What is an event handler? How is it important?
Event Handler:
It’s code that responds to user actions like clicks, typing, etc.
Importance:
● Makes GUI interactive.
● Detects and handles events like button clicks, key presses, etc.
● Connects user actions to program logic.
10) What is an Action Listener? How does it work?
10 marks for log in or sign up page design 👍
Sign up o same code just :
login page er motoi email ar confirm password er moto extra field add
korte hobe. Ar button ta hobe “Sign Up” just like uporer layout e.
Registration form :