0% found this document useful (0 votes)
1 views2 pages

Java Notes

The document provides notes on key Java concepts including OOP and inheritance, static vs non-static methods, JVM and memory management, string handling, and exception handling. It highlights the differences between method overriding and overloading, the immutability of strings, and the importance of equals() and hashCode() methods. Additionally, it covers exception hierarchy and handling mechanisms in Java.

Uploaded by

Arshita Marwaha
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)
1 views2 pages

Java Notes

The document provides notes on key Java concepts including OOP and inheritance, static vs non-static methods, JVM and memory management, string handling, and exception handling. It highlights the differences between method overriding and overloading, the immutability of strings, and the importance of equals() and hashCode() methods. Additionally, it covers exception hierarchy and handling mechanisms in Java.

Uploaded by

Arshita Marwaha
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

Java Interview Notes (Up to Exception Handling)

1. OOP & Inheritance

Child classes can have additional methods not present in parent.

A a = new B(); is valid (upcasting). Access depends on reference type, execution depends on
object.

Method overriding: same signature, runtime polymorphism.

Method overloading: same name, different parameters.

Final method cannot be overridden.

2. Static vs Non-static

Static methods belong to class, resolved at compile time.

Non-static methods belong to object, resolved at runtime.

Static methods cannot be overridden, only hidden.

3. JVM & Memory

Java code -> compiled to bytecode (.class).

JVM loads classes, verifies, links, and executes.

Objects are stored in heap, references in stack.

Class loading is lazy (on first use).

4. Strings

String is immutable.

String Constant Pool (SCP) avoids duplicate literals.

new String() creates object in heap.

StringBuilder: mutable, not thread-safe.

StringBuffer: mutable, thread-safe.

5. equals() and hashCode()

Default equals() compares references.

Override equals() for logical equality.

hashCode() used in hashing structures.

Contract: if equals() is true, hashCode() must be same.

6. Exception Handling

Exception disrupts normal flow.


Hierarchy: Throwable -> Exception / Error.

Checked exceptions (compile-time), Runtime exceptions (runtime).

try-catch-finally used to handle exceptions.

finally always executes unless JVM exits.

throw: explicitly throw exception.

throws: declare exception in method signature.

You might also like