Java Programming Assignment (Detailed Answers)
Unit I: Fundamentals of Java and Loops
1) What is Object-Oriented Programming? Explain any five Features/Characteristics of
Object-Oriented Programming Languages.
Object-Oriented Programming (OOP) organizes code using objects and classes. It emphasizes
reusability, modularity, and data encapsulation.
Features:
1. Encapsulation - Wrapping data and code into a single unit.
2. Inheritance - One class can inherit from another.
3. Polymorphism - Using the same method name with different implementations.
4. Abstraction - Hiding implementation details.
5. Class & Object - A blueprint and its instance.
2) List and Explain Primitive & Non-Primitive Data Types Available in Java.
Primitive types store simple values (byte, int, float, boolean, etc.). Non-primitive types store complex
structures (Strings, Arrays, Objects).
3) Explain All Types of Loops in Java with a Suitable Program Example.
Java supports For, While, and Do-While loops for iterative execution.
4) Java Program to Find Maximum & Minimum Value in an Array.
Code Example:
```java
int[] a = {24, 47, 2, 6, 72, 60, 19, 34};
int max = a[0], min = a[0];
for (int num : a) {
if (num > max) max = num;
if (num < min) min = num;
}
```
5) Java Program for Linear Search & Binary Search.
Linear Search iterates, Binary Search divides array into halves.
Unit II: Classes, Objects, and Constructors
1) Differentiate Between Class and Object.
Class - A blueprint; Object - An instance of a class.
2) How to Define a Constructor? Explain with Examples.
Constructors initialize objects. Types: Default, Parameterized, Copy Constructor.
3) What is Constructor Overloading? Explain with an Example.
Multiple constructors with different parameters in the same class.
4) What is an Abstract Class? Explain Key Features.
Abstract class cannot be instantiated and contains abstract methods.
5) Method Overloading in Java
Using the same method name with different parameters in the same class.