Group A — Short answer Questions (1 mark)
OOP is a paradigm based on 'objects' containing data and methods. Unlike Procedural Programming, which focuses on functions and top-down logic, OOP emphasizes data security (encapsulation) and reusability.
A Class is a blueprint or template that defines variables and methods. An Object is a runtime instance of a class containing actual values.
Encapsulation is wrapping data (variables) and code (methods) into a single unit. Data Hiding restricts direct access to internal data, usually achieved via private access modifiers.
Abstraction hides complex implementation details and shows only the essential features. In Java, it is implemented using abstract classes and interfaces.
Inheritance is a mechanism where a new class inherits properties and behaviors of an existing class. Its primary benefit is code reusability.
Polymorphism allows entities to take multiple forms. Compile-time (method overloading) is resolved during compilation, while Run-time (method overriding) is resolved dynamically at execution.
A Constructor is a special method used to initialize objects. Characteristics: it has the same name as the class, has no return type, and is called automatically during object creation.
Constructor overloading is defining multiple constructors in a class with different parameter lists (different number or types of arguments) to initialize objects in various ways.
The 'this' keyword is a reference variable in Java that refers to the current object. It is used to resolve naming conflicts between instance variables and parameters.
The 'super' keyword refers to the immediate parent class object. It is used to call parent class constructors, methods, and access hidden parent fields.
Overloading occurs in the same class with same method name but different parameters (compile-time). Overriding occurs in a subclass with the exact same signature as the parent method (run-time).
Java doesn't support multiple inheritance with classes to avoid the Diamond Problem (ambiguity when multiple parent classes have a method with the same signature).
A class can implement multiple interfaces simultaneously because interfaces only contain abstract methods (prior to Java 8), so there is no ambiguity in method implementation.
An Abstract Class can have both abstract and concrete methods with state, while an Interface historically has only abstract methods and static final constants, and a class can implement multiple interfaces.
- public: Accessible everywhere.
- private: Accessible only within the same class.
- protected: Accessible within the package and subclasses.
- default: Accessible only within the same package.
A static variable belongs to the class rather than instances, shared among all objects. A static method can be called without creating an object and can only directly access static data.
- Variables: Creates a constant.
- Methods: Prevents overriding.
- Classes: Prevents inheritance.
Garbage Collection automatically frees memory by destroying unreachable objects. System.gc() requests a garbage collection run, and finalize() is a method called just before an object is destroyed for cleanup.
A Package is a namespace that organizes a set of related classes and interfaces. It is created using the package keyword at the top of the file and imported using the import keyword.
Exception Handling manages runtime errors to maintain normal flow. Checked exceptions are verified at compile-time (e.g., IOException), while Unchecked exceptions occur at runtime (e.g., NullPointerException).
- try: Wraps risky code.
- catch: Handles exceptions.
- finally: Executes crucial cleanup code.
- throw: Manually triggers an exception.
- throws: Declares exceptions a method might throw.
A user-defined exception is a custom exception class created by a developer (usually by extending the Exception or RuntimeException class) to handle application-specific errors.
Multithreading is the concurrent execution of multiple threads to maximize CPU utilization. A Thread is the smallest lightweight unit of processing or execution within a program.
Process-based involves heavyweight independent programs with separate memory spaces. Thread-based involves lightweight concurrent paths of execution that share the same memory space within one process.
A thread can be created either by extending the Thread class and overriding run(), or by implementing the Runnable interface and passing it to a Thread constructor.
Thread priorities dictate the order in which threads are scheduled. In Java, priorities range from 1 (MIN_PRIORITY) to 10 (MAX_PRIORITY), with 5 being the default (NORM_PRIORITY).
Thread Synchronization restricts multiple threads from accessing shared resources concurrently to prevent data inconsistency. The synchronized keyword locks the object or class during execution.
Inter-Thread Communication allows synchronized threads to communicate. wait() pauses a thread, while notify() and notifyAll() wake up one or all waiting threads on that monitor.
Deadlock is a situation where two or more threads are blocked forever, each waiting for a lock held by the other, bringing the program to a halt.
The String class represents a sequence of characters. Strings are immutable (unchangeable) for security, synchronization, caching, and to optimize the String Pool memory management.
String is immutable. StringBuilder is mutable and not thread-safe (faster). StringBuffer is mutable and thread-safe (synchronized, slower).
A Wrapper Class encapsulates a primitive type into an object. Autoboxing is automatic conversion of primitive to wrapper object; Unboxing is the reverse conversion.
The JCF is a unified architecture providing ready-to-use classes and interfaces (like List, Set, Map) for storing, manipulating, and searching groups of objects.
- List: Ordered collection that allows duplicates.
- Set: Unordered collection with no duplicates.
- Map: Collection of Key-Value pairs, keys must be unique.
ArrayList uses a dynamic array (better for searching/random access). LinkedList uses a doubly linked list (better for frequent insertions/deletions).
HashMap is a Map implementation that stores key-value pairs using a hash table. It uses a hashing algorithm on keys to compute indices for bucketing values.
Generics allow types (classes and interfaces) to be parameters when defining classes, interfaces, and methods. Their main advantage is compile-time type safety and avoiding explicit casting.
File I/O handles reading and writing to files. Byte Streams (e.g., FileInputStream) read/write 8-bit bytes (for binary data). Character Streams (e.g., FileReader) read/write 16-bit Unicode characters.
Serialization converts an object's state into a byte stream for saving or networking. Deserialization reconstructs the object from the byte stream.
The transient keyword marks a variable so that it is ignored during serialization; its value will not be saved or transmitted.
A Lambda Expression provides a concise syntax to write anonymous methods, typically used to implement the single abstract method of a functional interface.
A Functional Interface has exactly one abstract method. Examples include Runnable and Callable (or Predicate and Function from java.util.function).
The Stream API provides a functional and declarative approach to process collections of objects (filtering, mapping, reducing) allowing for easy parallel execution.
Design Patterns are proven solutions to common software design problems. Creational deals with object creation, Structural with object composition, and Behavioral with object communication.
The Singleton pattern ensures that a class has only one single instance throughout the application lifecycle and provides a global point of access to it.
The Factory Method is a creational pattern that defines an interface for creating objects, but lets subclasses decide which class to instantiate.
SOLID stands for Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion—five principles for maintainable object-oriented design.
UML is a standard visual modeling language used in software engineering to document, specify, construct, and visualize the artifacts of a software system.
Association is a general relationship. Aggregation is a "has-a" relationship (weak ownership). Composition is a strict "part-of" relationship (strong ownership, part dies with whole).
A Class Diagram is a structural UML diagram that shows the system's static structure by detailing classes, their attributes, methods, and relationships.
A Virtual Function allows derived classes to override a method for runtime polymorphism. A Pure Virtual Function (assigned = 0) forces derived classes to implement it, making the base class abstract.
A Friend Function/Class in C++ is granted access to the private and protected members of the class in which it is declared as a friend.