Unit2 - Subjective Questions

CSE310 • Practice Questions with Detailed Answers

1

Differentiate between the while loop and the do-while loop in Java with syntax and examples.

2

Explain the concept of the Enhanced for-loop (for-each loop) in Java. Provide its syntax and discuss its advantages and limitations.

3

Define an Array in Java. Explain how to declare, instantiate, and initialize a one-dimensional array.

4

What are Multi-dimensional Arrays in Java? How are they stored in memory? Write a code snippet to print a 2D array in matrix format.

5

Explain the concept of Variable Arguments (Varargs) in Java. How is it defined in a method signature?

6

What is an Enumeration (Enum) in Java? How does it differ from a standard class? Provide an example of an Enum used in a switch statement.

7

Define Class and Object. Explain the relationship between them and how an object is created in Java.

8

What is a Constructor? How does it differ from a regular method? Explain Default and Parameterized constructors.

9

Explain Method Overloading with an example. What are the rules for overloading a method?

10

Describe the usage of the this keyword in Java with appropriate examples for each use case.

11

What are Initializer Blocks? Distinguish between Static Initializer Blocks and Instance Initializer Blocks regarding their execution time.

12

Explain Constructor Overloading. How can one constructor call another constructor within the same class?

13

Discuss the String class in Java. Why are Strings called Immutable? Explain the concept of the String Constant Pool.

14

Compare String and StringBuilder classes. When should you use StringBuilder over String?

15

List and explain any five important methods of the String class with examples.

16

Write a Java program to define a class Rectangle with fields length and width. Include a constructor to initialize these fields and a method area() to return the area. Instantiate the class and print the area.

17

How does the StringBuilder class handle capacity? Explain the append() and insert() methods.

18

What is a Jagged Array? How do you declare and initialize a jagged array in Java? Provide a diagrammatic representation description or code.

19

Explain the mechanics of the for loop flow. How can you create an Infinite Loop using the for syntax?

20

Discuss Anonymous Arrays in Java. When are they useful? Give an example.