0% found this document useful (0 votes)
9 views3 pages

Java Object-Oriented Concepts Explained

The document contains a series of questions related to Java programming concepts, including object-oriented principles, memory management, class structures, exception handling, and specific Java features like Singleton classes and String initialization. It addresses fundamental differences between various Java components and functionalities, such as heap vs. stack memory, method overloading, and exception types. Additionally, it explores the implications of Java's design choices, such as the absence of pointers and the handling of exceptions.

Uploaded by

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

Java Object-Oriented Concepts Explained

The document contains a series of questions related to Java programming concepts, including object-oriented principles, memory management, class structures, exception handling, and specific Java features like Singleton classes and String initialization. It addresses fundamental differences between various Java components and functionalities, such as heap vs. stack memory, method overloading, and exception types. Additionally, it explores the implications of Java's design choices, such as the absence of pointers and the handling of exceptions.

Uploaded by

Deepi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1) Is java a pure Object Oriented Language?

2) What is the difference between Heap and Stack Memory in java. And how java utilizes
this?

3) What is the difference between reference and object?

4) What is an instance and an instance variable?

5) What is a Class variable?

6) What is Autoboxing and Unboxing?

7) Why does Java not make use of pointers?

8) What are the ways to initialize a String? Explain

9) Can the main method be overloaded and overrided?

10) Can static methods be overloaded and overrided?

11) What is a ClassLoader in java?

12) Where String literal and String Object is stored and how are they referenced?

13) What is a Singleton class?

class Singleton {
private static Singleton instance;
private Singleton() {
// private constructor prevents external object creation
}

public static Singleton getInstance() {


if (instance == null) {
instance = new Singleton(); // only one object created
}
return instance;
}
}

14) What is the difference between [Link], [Link] and [Link]?

15) What is the difference between print, println and printf?

16) What is a Jagged Array?

17) What is the difference between Shallow Copy and Deep Copy?

18) Is Multiple Inheritance supported by Java? Why?


19) Can we override a private method?

20) What is the difference between == and equals()?


Questions on Exceptions:

1. What is the difference between final, finally, and finalize?

2. Difference between Checked and Unchecked Exceptions.

3. What is the difference between throw and throws in Java?

4. Can we have multiple catch blocks in Java? In which order are they executed?

5. What is the difference between Comparable and Comparator?

6. Is try without a catch is allowed?

7. Can finally block can be avoided?

8. What is the difference between error and exception?

9. Is try without catch and finally allowed?

10. What is the output of this program?

try {
int a = 10 / 0;
} catch (ArithmeticException e) {
[Link]("Error: Division by zero");
} finally {
[Link]("End of program");
}

Common questions

Powered by AI

Shallow copy in Java means copying an object and its references to other objects, which means changes to the objects referenced could impact the copied object. Deep copy involves copying an object along with the objects it references, creating completely independent objects. Shallow copy may be used in scenarios involving immutable objects, while deep copy is preferred when copies should be independent, such as in serialization processes or when working with complex object graphs where changes in one object should not affect the others .

A ClassLoader in Java is a part of the Java Runtime Environment that loads classes into memory after compilation. It is responsible for dynamically loading Java classes into the Java Virtual Machine. This flexibility allows Java applications to load classes as needed at runtime, which is crucial for dynamic linkings, such as loading classes from different sources and utilizing dynamic class features .

Java avoids using pointers to increase security and reduce complexity. Pointers can introduce vulnerabilities such as unauthorized memory access and reduce code safety. By not exposing pointers, Java ensures memory safety and simplicity in programming models, which decreases the likelihood of memory corruption and makes managing memory in programs less error-prone .

In Java, '==' is a reference comparison operator used to determine if two references point to the same memory location, implying the exact same object. The equals() method is used to check object equality based on the object's properties rather than its reference. This method needs to be overridden in a class if logical equality based on properties other than reference is required. Not understanding or using these operators appropriately can lead to logical errors in the program .

In Java, the main method can be overloaded, meaning you can have multiple main methods with different parameters. However, it cannot be overridden because it is static. Overriding is related to the dynamic method dispatching of instance methods, but since static methods belong to the class and not the instance, they cannot be overridden .

Autoboxing in Java is the automatic conversion that the Java compiler makes between primitive types and their corresponding object wrapper classes. Unboxing is the reverse process where the object wrapper is converted back to a primitive type. This feature simplifies code writing by allowing primitives to be used as objects when necessary without manual conversion, enhancing flexibility and reducing code errors .

Java is not considered a pure object-oriented language because it uses primitive data types, such as int, char, etc., which are not objects. In purely object-oriented programming languages, everything should be represented as objects; however, Java provides these primitive types for performance reasons .

In Java, stack memory is used for static memory allocation and the execution of threads. It stores primitive variables and references to objects in the heap. Heap memory, on the other hand, is used for dynamic memory allocation and contains actual objects. Stack memory follows LIFO (Last In First Out) order, while heap memory is unordered and managed by the garbage collector to free up unreferenced objects . Java utilizes stack memory for methods, local variables, and pointers, whereas heap memory stores objects created during runtime.

In Java, String literals are stored in the String pool, a special area in heap memory for caching strings. When a new String literal is created, the JVM checks this pool to see if an identical String already exists; if so, it returns a reference to the existing String. This improves memory efficiency. In contrast, String objects created using the 'new' keyword are stored in heap memory, with each instance being a distinct object, even if they contain the same text .

The Singleton design pattern ensures that a class has only one instance and provides a global point of access to it. This is accomplished by maintaining a static variable that holds the single instance of the class and a static method to return that instance. The constructor is made private to prevent the direct creation of instances through the constructor, ensuring only one object is created in the entire application .

You might also like