0% found this document useful (0 votes)
38 views4 pages

Java Theory Exam Notes

Uploaded by

gansh8967
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views4 pages

Java Theory Exam Notes

Uploaded by

gansh8967
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

### Java Theory Exam Study Material (Detailed Theory with Examples)

---

#### Q1: Introduction to Java and Its Features

**Introduction:**

Java is a high-level, object-oriented programming language developed by Sun Microsystems in 1995. It is

platform-independent due to the Java Virtual Machine (JVM), meaning you can write code once and run it

anywhere. Java is widely used in desktop applications, web applications, mobile applications, and enterprise

systems.

**Features of Java:**

1. **Simple:** Easy syntax similar to C++, without complex features like pointers.

2. **Object-Oriented:** Everything in Java is based on objects.

3. **Platform-Independent:** Java programs are compiled into bytecode which can run on any platform.

4. **Secure:** It has runtime checking and avoids unsafe constructs.

5. **Robust:** Strong memory management, exception handling, and garbage collection.

6. **Multithreaded:** Built-in support for multithreaded programming.

7. **Architecture-Neutral:** Java bytecode is not dependent on processor architecture.

8. **High Performance:** Just-In-Time compilers enhance speed.

9. **Distributed:** Facilitates distributed computing through networking packages.

10. **Dynamic:** Loads classes at runtime.

**Example:**

public class HelloWorld {

public static void main(String[] args) {


System.out.println("Hello, Java!");

---

#### Q2: What are Operators? Discuss its Types.

**Operators** are symbols that perform operations on variables and values.

**Types of Operators in Java:**

1. **Arithmetic Operators** (`+`, `-`, `*`, `/`, `%`): Perform basic math.

int a = 10, b = 5;

System.out.println(a + b); // Output: 15

2. **Relational Operators** (`==`, `!=`, `>`, `<`, `>=`, `<=`): Compare values.

System.out.println(a > b); // Output: true

3. **Logical Operators** (`&&`, `||`, `!`): Combine boolean expressions.

System.out.println((a > b) && (a != b)); // Output: true

4. **Bitwise Operators** (`&`, `|`, `^`, `~`, `<<`, `>>`): Operate on bits.

System.out.println(a & b); // Output: 0

5. **Assignment Operators** (`=`, `+=`, `-=`, etc.): Assign values.

a += 2; // Same as a = a + 2;

6. **Unary Operators** (`+`, `-`, `++`, `--`): Perform operations on a single operand.
int x = 5;

System.out.println(++x); // Output: 6

7. **Ternary Operator:** Shortcut for if-else.

int result = (a > b) ? a : b;

8. **instanceof Operator:** Checks if an object is an instance of a specific class.

System.out.println("Hello" instanceof String); // Output: true

---

#### Q3: Explain the Data Types in Java. Discuss its Categories.

**Data Types:** Define the type and size of data that variables can store.

**Categories of Data Types:**

1. **Primitive Data Types:**

- **Integer Types:**

- `byte` (1 byte), `short` (2 bytes), `int` (4 bytes), `long` (8 bytes)

- **Floating-point Types:**

- `float` (4 bytes), `double` (8 bytes)

- **Character Type:**

- `char` (2 bytes): holds a single character

- **Boolean Type:**

- `boolean`: holds true or false

int age = 25;

float marks = 92.5f;


char grade = 'A';

boolean passed = true;

2. **Non-Primitive (Reference) Data Types:**

- Arrays, Strings, Classes, Interfaces

String name = "Ansh";

int[] scores = {90, 80, 85};

...

You might also like