Java Programming Long Answers
13(a) Basic Principles of Object Oriented Programming (OOP)
1. Encapsulation – Wrapping data and methods together into a class.
2. Inheritance – Acquiring properties from one class to another.
3. Polymorphism – One method performing different tasks.
4. Abstraction – Hiding implementation details and showing functionality only.
13(b) Java Operators with Examples
Arithmetic Operators: +, -, *, /, %
Relational Operators: ==, !=, >, <, >=, <=
Logical Operators: &&, ||, !
Assignment Operators: =, +=, -=
Increment/Decrement Operators: ++, --
Conditional Operator: ?:
Example:
int a = 10, b = 5;
[Link](a + b);
13(c) Features of Java
1. Platform Independent
2. Object Oriented
3. Secure
4. Robust
5. Portable
6. Multithreaded
7. High Performance
8. Dynamic
13(d) Program Structure of Java
1. Documentation Section
2. Package Statement
3. Import Statement
4. Class Definition
5. Main Method
Example:
import [Link].*;
class Hello {
public static void main(String args[]) {
[Link]("Hello Java");
}
}
14(a) Class and Object
Class is a blueprint for objects.
Object is an instance of a class.
Example:
class Student {
int id;
String name;
}
14(b) Constructor and Types
Constructor initializes objects.
Types:
1. Default Constructor
2. Parameterized Constructor
14(c) Method Overloading
Using same method name with different parameters.
Example:
void add(int a, int b)
void add(int a, int b, int c)
14(d) 1-D and 2-D Arrays
1-D Array Example:
int a[] = {10,20,30};
2-D Array Example:
int a[][] = {{1,2},{3,4}};
15(a) Thread and Life Cycle
Thread is a lightweight process.
Life Cycle:
New → Runnable → Running → Waiting → Dead
15(b) Runnable Interface
Runnable interface is used to create threads.
Example:
class MyThread implements Runnable {
public void run() {
[Link]("Thread Running");
}
}
15(c) Exception and Try-Catch
Exception is an abnormal condition during execution.
Example:
try {
int a = 10/0;
}
catch(ArithmeticException e) {
[Link]("Division by zero");
}
15(d) Multithreading
Multithreading means executing multiple threads simultaneously.
16(a) Binary I/O Classes
InputStream, OutputStream, FileInputStream, FileOutputStream are binary I/O classes.
Hierarchy:
InputStream → FileInputStream
OutputStream → FileOutputStream
16(b) Event and Mouse Event Handling
Event is an action generated by user interaction.
Mouse events are handled using MouseListener.
16(c) FileInputStream and FileOutputStream
FileInputStream reads data from file.
FileOutputStream writes data into file.
16(d) AWT and AWT Hierarchy
AWT stands for Abstract Window Toolkit.
Used for GUI applications.
Hierarchy:
Component → Container → Window → Frame