Q1
a) javac is the Java compiler that converts Java source code into bytecode (.class files).
b) Two wrapper classes: Integer, Double.
c) 'implements' keyword is used when a class implements an interface.
d) Types of constructors: Default, Parameterized, Copy constructor.
e) Array is used to store multiple values in a single variable.
f) Two listeners: ActionListener, MouseListener.
g) Exception is an event that disrupts the normal flow of a program.
h) Syntax of endsWith(): string.endsWith("suffix")
i) Package is a namespace that organizes a set of related classes and interfaces.
j) 'new' operator is used to create objects in Java.
Q2
a) A constructor is called automatically when an object is created.
b) Command line arguments are passed to main() and stored in the String[] args array.
c) Frame is a top-level window with a title and border. Methods: setSize(), setVisible().
d) Overloading: same method name, different parameters. Overriding: same method, subclass modifies behavior.
e) Two access specifiers: public, private.
Q3
a) Interface and Class:
interface Shape { void area(); }
class Triangle implements Shape {
double b, h;
public void area() {
System.out.println("Area: " + (0.5 * b * h));
b) Swing GUI:
- Use JFrame for window
- Add JTextField for Roll No, Name, Percentage
- Add JButton for Display and Clear
- Display data in console on clicking Display
- Clear all fields on Clear
c) File Copy:
- Read input file character by character
- If char is digit, replace with '*'
- If letter, change case
- Write modified content to output file
Q4
a) AWT vs Swing:
AWT: Heavyweight, platform-dependent. Swing: Lightweight, platform-independent.
b) User-defined exception:
class ZeroNumberExc extends Exception {...}
If input is zero, throw exception. Else, extract and sum first and last digit.
c) Perfect numbers:
- Accept n numbers from user
- Check each number if perfect (sum of divisors equals number)
- Store and display perfect numbers
Q5
a) final keyword:
- final variable: cannot be changed
- final method: cannot be overridden
- final class: cannot be inherited
b) Inheritance example:
class Emp { int Eid; void display() {...} }
class EmpName extends Emp { String Ename; void display() { super.display(); ... } }