Java Knowledge Flashcards
Interface vs. Abstract Class
Definition:
An interface is a contract of methods (implicitly abstract), while an abstract class can have both abstract and concrete methods.
- Interfaces in Java 8+ can have default and static methods.
- An abstract class can maintain state (fields) and shared behavior.
ArrayList vs. LinkedList
Definition:
ArrayList is backed by a dynamic array; LinkedList is a doubly linked list.
- ArrayList provides faster random access (O(1) for get).
- LinkedList offers faster insertion/deletion at known positions.
final, finally, finalize
Definition:
- final: keyword for constants or methods that cannot be overridden.
- finally: a block that always executes after try-catch.
- finalize(): (deprecated) called by GC before object removal.
- finalize() is seldom used; modern Java uses other cleanup strategies.
== vs. equals()
Definition:
“==” checks reference equality for objects, while equals() checks logical (content) equality.
- For primitives, == compares values directly.
- For objects, == compares references unless overridden by equals().
Java Streams
Definition:
A sequence of elements supporting functional-style operations (map, filter, reduce).
- Can be sequential or parallel.
- Encourages a more declarative approach to iteration.
ExecutorService
Definition:
Manages a pool of threads, simplifying concurrent execution of tasks.
- Allows creation of thread pools, scheduling, and concurrency control.
- Must be shut down to release resources.
JVM Memory Areas
Definition:
Java divides memory into multiple areas (Heap, Stack, Metaspace, etc.).
- Objects and class-level structures go on the heap/metaspace.
- Local variables and function calls use the stack.
Garbage Collection in Java
Definition:
Automatic memory management that frees unused objects.
- Various GC algorithms exist (Serial, Parallel, CMS, G1, ZGC…).
- Tuning GC can greatly impact performance.