JAVA Assignment 1
Submitted By :- Saransh Gupta (23BCE11652)
Ans1:-
Java is a high-level, class-based, object-oriented programming language. Key features include:
- Platform Independence
- Object-oriented: Supports OOP principles like inheritance, encapsulation, and polymorphism.
- Robust: Provides exception handling and memory management through garbage collection.
- Secure to use
- Multithreaded: Allows concurrent execution of multiple threads.
- High Performance: Uses Just-In-Time (JIT) compiler for optimization
Ans2:-
1) Classloader
Classloader is a subsystem of JVM which is used to load class files. Whenever we run the java
program, it is loaded first by the classloader. There are three built-in classloaders in Java.
2) Class(Method) Area
Class(Method) Area stores per-class structures such as the runtime constant pool, field and
method data, the code for methods.
3) Heap
It is the runtime data area in which objects are allocated.
4) Stack
Java Stack stores frames. It holds local variables and partial results, and plays a part in method
invocation and return.
5) Program Counter Register
PC (program counter) register contains the address of the Java virtual machine instruction
currently being executed.
6) Native Method Stack
It contains all the native methods used in the application.
7) Execution Engine
It contains:
1. A virtual processor
2. Interpreter
3. Just-In-Time(JIT) compiler
8) Java Native Interface
Ans3:-
public class GreatestNumber {
public static void main(String[ ] args) {
if (args.length == 0) {
System.out.println("Please provide numbers as command-line arguments.");
return;
}
int greatest = Integer.MIN_VALUE;
for (String arg : args) {
try {
int number = Integer.parseInt(arg);
if (number > greatest) {
greatest = number;
}
} catch (NumberFormatException e) {
System.out.println("Invalid input: " + arg);
}
}
System.out.println("The greatest number is: " + greatest);
}
}
Ans4:-
Java supports the following data types:
- Primitive Data Types:
- byte
- short
- int
- long
- float
- double
- char
- boolean
- Non-Primitive Data Types:
- String, Arrays, Classes, Interfaces, etc.
Ans5:-
Java supports the following types of operators:
1. Arithmetic Operators: +, -, *, /, %
Example: int sum = 5 + 3;
2. Relational Operators: >, <, >=, <=, ==, !=
Example: boolean isEqual = (5 == 3);
3. Logical Operators: &&, ||, !
Example: boolean result = (5 > 3) && (3 > 2);
4. Bitwise Operators: &, |, ^, ~, <<, >>
Example: int bitwiseAnd = 5 & 3;
5. Assignment Operators: =, +=, -=, *=, /=
Example: int num = 5; num += 3;
6. Unary Operators: +, -, ++, --, !
Example: int increment = 5; increment++;
7. Ternary Operator: condition value1 : value2
Example: int max = (5 > 3) ? 5 : 3;