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

Java Notes Final

This notes provides the detailed information about some of the topics of java programming language which is useful for interview Preparation
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)
4 views3 pages

Java Notes Final

This notes provides the detailed information about some of the topics of java programming language which is useful for interview Preparation
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/ 3

Java Notes

Difference b/w Finally & Final

- Final is used to make variables/constants unchangeable. It may be a final variable or final class.

- Finally block always runs after try-catch block. In finally block, the specific code should always run

whether an exception occurs or not.

Finalize()

- This finalize method is a special method in Java that is called by garbage collection before an

object is being garbage collected.

ArrayList & LinkedList difference

- ArrayList & LinkedList are both classes in Java used to store a list of elements, but they work

differently.

- ArrayList uses a dynamic array to store elements. It's faster when you want to access elements

using an index like list.get(2).

- LinkedList elements are connected by links. It is faster when you want to add or remove elements

from the middle or beginning of list.

2) HashMap & Hashtable difference

- Both HashMap & Hashtable are used to store data in key-value pairs, but they have key

differences.

- HashMap is not synchronized, which means it is not thread-safe, but it performs better in
Java Notes

single-threaded applications.

- Hashtable is synchronized, so it is thread-safe and is used in multi-threaded environments.

- Hashtable does not allow any null key or value, while HashMap allows null values.

3) Declare a HashMap & iterate

- First, I create a HashMap using: HashMap<Integer, String> map = new HashMap<>();

- Then I add key-value pairs using put() method.

- To iterate, I use a for-each loop with entrySet() to get both key & value.

4) ArrayList vs LinkedList vs Vector

- ArrayList is best when you need fast access to elements.

- LinkedList is used when frequent insertions & deletions are required, especially in the middle of the

list.

- Vector is similar to ArrayList but it is synchronized. It is thread-safe but slower in performance.

5) HashSet vs LinkedHashSet & TreeSet

- HashSet only stores values (not key) in an unordered manner.

- LinkedHashSet maintains the insertion order.


Java Notes

- TreeSet stores elements in sorted (ascending) order because it uses tree structure.

6) HashMap vs LinkedHashMap vs TreeMap

- HashMap stores data in key-value pairs but in unordered manner.

- LinkedHashMap stores in insertion order, so keys are returned in the order they were added.

- TreeMap stores keys in sorted (ascending) order using Red-Black tree structure.

7) Iterator vs ListIterator

- Iterator works with all types of collections like Set, List, Map, but it can only move forward.

- ListIterator works only with List types & can move both forward & backward.

You might also like