Please enable JavaScript.
Coggle requires JavaScript to display documents.
Java core - Coggle Diagram
Java core
OOP
Abstraction
Define: Abstraction is the process of hiding the implementation details of a system and showing only the essential features to the user.
Purpose: It reduces complexity by allowing the user to interact with the object through a simplified interface.
-
Encapsulation
Define: Encapsulation is the practice of bundling the data (variables) and methods that operate on that data into a single unit (class). It restricts direct access to an object’s data, ensuring that it can only be modified or accessed through methods (getters/setters).
-
Implementation: Use of private access modifiers for variables and public methods to access and modify them
Inheritance
Define: Inheritance allows a class (subclass) to inherit properties and behavior (methods) from another class (superclass). It promotes code reuse and establishes a parent-child relationship.
Purpose: Enables the creation of hierarchical relationships between classes and reduces code duplication.
-
Polymorphism
Define: Polymorphism allows one entity (method or object) to take many forms. It comes in two forms:
- Compile-time (Method Overloading): Allows multiple methods in the same class to have the same name but different parameter types.
- Runtime (Method Overriding): Allows a subclass to provide a specific implementation of a method that is already defined in its superclass.
Purpose: It enhances flexibility and reusability by allowing methods to behave differently based on the object invoking them.
Collection
List Interface
Define: A List is an ordered collection that allows duplicate elements. You can access elements by their index positions.
Type
ArrayList: A resizable array that provides fast random access but slower insertion/removal (except at the end).
-
Vector: A synchronized version of ArrayList, making it thread-safe, but generally slower due to synchronization overhead.
Set Interface
Define: A Set is a collection that does not allow duplicate elements. It is useful when you need to maintain a collection of unique items.
Type
HashSet: Backed by a hash table, allows constant-time performance for basic operations like add, remove, and contains.
-
TreeSet: Implements a sorted set using a red-black tree, guaranteeing that elements are sorted.
Map interface
Define: A Map stores key-value pairs, where each key is unique. Unlike the Collection interface, Map does not extend Collection.
Type
HashMap: Stores key-value pairs and allows null keys and values, but does not maintain any specific order.
-
-
Java String
-
-
StringBuffer
-
Thread safety: is synchronized, meaning it is thread-safe. It ensures that only one thread can modify the string at a time.
-
-
Exception
Define: an exception is an event that disrupts the normal flow of a program's execution. All exceptions in Java are subclasses of the Throwable class.
- Exceptions (Exception): Represents conditions that a program might want to catch and handle (e.g., invalid input, file not found).
- Errors (Error): Represents serious problems that a program should not catch (e.g., out of memory, stack overflow).
Type
Checked exceptions: These exceptions must be either caught or declared in the method using throws. If not handled properly, the code will not compile. Eg: IOException, SQLException,...
Unchecked exceptions (Runtime exceptions): These exceptions are not checked at compile time and can occur during the execution of the program. They usually indicate programming errors, such as logical mistakes, and you can choose whether to handle them or not. Eg: NullPointerException, ArrayIndexOutOfBoundsException,...
Java Architecture
Heap & Stack
Heap
Define: Where all objects in Java stored. Larger than stack and shared by all threads. Is managed by Garbage Collector
-
Stack
Define: Used for Method execution and local variables. Store state of each method (method parameters, local variables, return address). Every thread has its own stack, and data stored in it is only accessible to that specific thread (thread-safe)
Properties:
LIFO: when a method is called, block is created for it on the stack. When method finish execution, stack frame is removed
-
-
Garbage Collection(GC)
-
Process
Heap memory
Properties
Young generation: stores short-lived objects. It's further divided into:
- Eden Space: Where newly created objects start.
- Survivor Space: Holds objects that survived at least one garbage collection.
-
Phases
Mark Phase: The garbage collector marks all reachable objects starting from the "roots" (usually the stack, static variables, etc.). Unreachable objects are considered garbage.
-
-
Type
Serial Garbage Collector: Uses a single thread to perform GC. Suitable for single-threaded applications.
Parallel Garbage Collector (Throughput Collector): Uses multiple threads to speed up GC. It's good for multi-threaded environments.
CMS (Concurrent Mark-Sweep) Garbage Collector: Aims for low pause times by running GC concurrently with the application.
G1 (Garbage First) Collector: A modern GC designed to replace CMS. It divides the heap into regions and works in parallel, focusing on areas of memory with the most garbage first.
-