OOPS Java Assignment Solutions
1. Basics of OOPS Feature
Object-Oriented Programming (OOPS) is a programming paradigm that is based on objects and classes. The
main features of OOPS are:
- Encapsulation
- Inheritance
- Polymorphism
- Abstraction
These principles help in code reusability, modularity, and maintainability.
2. Merits and Demerits of OOPS & Application of OOPS
Merits:
- Code Reusability
- Modularity
- Scalability
- Security
Demerits:
- Higher Complexity
- Requires more memory
- Slower Execution compared to procedural programming
Applications:
- Game Development
- Web Applications
- Banking Systems
3. What is JDK and JVM?
JDK (Java Development Kit) is a complete development environment that includes tools for writing,
compiling, and running Java programs.
JVM (Java Virtual Machine) is responsible for running Java bytecode and provides platform independence.
OOPS Java Assignment Solutions
4. Reserved Keywords in Java
Reserved keywords are predefined words that have special meaning in Java, like:
abstract, class, static, void, int, float, new, return, etc.
5. Command Line Arguments
Command Line Arguments are inputs given to the program during execution via the terminal.
Example:
```java
public class Test {
public static void main(String args[]) {
System.out.println(args[0]);
}
}
``
6. Data Types in Java
Java has two types of data types:
1. Primitive (int, float, char, boolean, double, etc.)
2. Non-Primitive (String, Arrays, Classes, Interfaces, etc.)
7. Type Casting with Example
Type casting is converting one data type into another.
Example:
```java
int num = 10;
double d = num; // Implicit casting
```
8. Switch Case Example
A switch case allows multiple conditional checks.
Example:
OOPS Java Assignment Solutions
```java
switch(day) {
case 1: System.out.println('Monday'); break;
default: System.out.println('Invalid');
}
```
9. Class and Object Concept
Class is a blueprint, and Object is an instance of a class.
Example:
```java
class Car {
String brand;
}
Car myCar = new Car();
```
10. Method Overloading Example
Method overloading allows multiple methods with the same name but different parameters.
Example:
```java
void sum(int a, int b) {}
void sum(double a, double b) {}
```
11. Constructors with Example
Constructors are special methods used to initialize objects.
Example:
```java
class Test {
Test() { System.out.println('Constructor Called'); }
}
```
OOPS Java Assignment Solutions
12. Static and Global Variable Concept
Static variables belong to the class, while global variables are declared outside functions.
13. Wrapper Class with Example
Wrapper classes convert primitive data types into objects.
Example:
```java
Integer num = new Integer(10);
```
14. For Loop and Do-While with Example
For loop:
```java
for(int i=0; i<5; i++) { System.out.println(i); }
```
Do-while loop:
```java
do { System.out.println(i); } while(i<5);
```
15. Infinite Loop in Java
An infinite loop runs indefinitely.
Example:
```java
while(true) { System.out.println('Infinite Loop'); }
```