MindMap Gallery JavaSE Advanced
Dark Horse Programmer Course, mainly includes object-oriented advanced, Collection, Stream, Miscellaneous, High-tech, IO flow, Multi-threading etc.
Edited at 2024-03-21 20:54:44This Valentine's Day brand marketing handbook provides businesses with five practical models, covering everything from creating offline experiences to driving online engagement. Whether you're a shopping mall, restaurant, or online brand, you'll find a suitable strategy: each model includes clear objectives and industry-specific guidelines, helping brands transform traffic into real sales and lasting emotional connections during this romantic season.
This Valentine's Day map illustrates love through 30 romantic possibilities, from the vintage charm of "handwritten love letters" to the urban landscape of "rooftop sunsets," from the tactile experience of a "pottery workshop" to the leisurely moments of "wine tasting at a vineyard"—offering a unique sense of occasion for every couple. Whether it's cozy, experiential, or luxurious, love always finds the most fitting expression. May you all find the perfect atmosphere for your love story.
The ice hockey schedule for the Milano Cortina 2026 Winter Olympics, featuring preliminary rounds, quarterfinals, and medal matches for both men's and women's tournaments from February 5–22. All game times are listed in Eastern Standard Time (EST).
This Valentine's Day brand marketing handbook provides businesses with five practical models, covering everything from creating offline experiences to driving online engagement. Whether you're a shopping mall, restaurant, or online brand, you'll find a suitable strategy: each model includes clear objectives and industry-specific guidelines, helping brands transform traffic into real sales and lasting emotional connections during this romantic season.
This Valentine's Day map illustrates love through 30 romantic possibilities, from the vintage charm of "handwritten love letters" to the urban landscape of "rooftop sunsets," from the tactile experience of a "pottery workshop" to the leisurely moments of "wine tasting at a vineyard"—offering a unique sense of occasion for every couple. Whether it's cozy, experiential, or luxurious, love always finds the most fitting expression. May you all find the perfect atmosphere for your love story.
The ice hockey schedule for the Milano Cortina 2026 Winter Olympics, featuring preliminary rounds, quarterfinals, and medal matches for both men's and women's tournaments from February 5–22. All game times are listed in Eastern Standard Time (EST).
JavaSE Advanced
Object-oriented advanced
static
static modified member variables
Class variables (static member variables): belong to the class, have only one copy in the memory, and are called with the class name Instance variables (object variables): belong to objects, each object has a copy, and are called with objects
Application scenarios of static class variables
If you only need one copy of a certain data and want it to be shared (accessed, modified), the data can be defined as a class variable to remember.
static modified member method
Class method (static method): static modified method It can be called by the class name because it is loaded when the class is loaded; Therefore, the static modified method can be found directly in the class name; It belongs to a class and can be called with a class name or an object. However, it is not recommended to call it with an object because calling an object will increase memory overhead.
staic application scenario-tool class
Notes on staic
In instance methods, you can directly access class members and instances.
Class methods can directly access class methods, but they cannot directly access instance methods.
This keyword can appear in instance methods
The this keyword cannot appear in class methods
code block
Static code block, automatically executed when the class is loaded, only executed once
Instance code block, executed once each time an object is created
Design Patterns
Singleton design pattern
Hungry Chinese singleton
When you get the object, the object has already been created.
Lazy Singleton
Create objects only when you get them
Template method design pattern
inherit
Features
Subclasses can inherit non-private members (member variables, member methods) of the parent class
Java is single inheritance and can have multiple levels of inheritance.
permission modifier
Method override @Override
subclass access
When accessing other members (member variables, member methods) in subclass methods, follow the proximity principle
subclass constructor
All constructors of subclasses will first call the constructor of the parent class and then execute themselves.
By default, the first line of code in all constructors of a subclass is super() (either written or not), which will call the parameterless constructor of the parent class. If the parent class does not have a parameterless constructor, we must hand-write super(….) on the first line of the subclass constructor to specify to call the parent class’s parameterized constructor.
You can specify access to members of the parent class through the super keyword: super. Parent class member variables/parent class member methods
sibling constructor
Features: 1. Both this(…) and super(…) must be placed in the first line of the constructor, otherwise an error will be reported
2. All constructors in subclasses must first call the constructor of the parent class and then execute themselves
3. A common application of super(...) to call the parameterized constructor of the parent class is to assign values to the member variables of the object containing the parent class.
4.this(…) is generally used to call other constructors of this class in the constructor
Polymorphism
Polymorphism is a phenomenon in the context of inheritance/implementation, manifested as: object polymorphism and behavior polymorphism.
Prerequisites for polymorphism: there is an inheritance/implementation relationship; there is a parent class referencing a subclass object; there is method overriding
Note: Polymorphism is the polymorphism of objects and behaviors. The properties (member variables) in Java are not polymorphic.
Benefits: Can be decoupled and more scalable; when using variables of the parent class type as formal parameters of methods, all subclass objects can be received
Problem: Unique methods of subclasses cannot be directly called under polymorphism
Before force transfer, Java recommends using the instanceof keyword to determine the true type of the current object and then perform the force transfer.
final keyword
Modified class: This class is called the final class, and its characteristic is that it cannot be inherited. Modified method: This method is called the final method, and its characteristic is that it cannot be overridden. Modified variable: This variable can only be assigned once.
constant
Member variables modified with static final are called constants
abstract class
The most important features: 1. Abstract classes cannot create objects, but only serve as a special parent class for subclasses to inherit and implement. 2. Abstract classes are designed to better support polymorphism.
abstract modifies the class, this class is an abstract class; Abstract modifies the method and cannot write the method body. This method is an abstract method.
1. Abstract classes do not necessarily have abstract methods. A class with abstract methods must be an abstract class. 2. Abstract classes can have all the members (member variables, methods, constructors) that a class should have. 3. If a class inherits an abstract class, it must rewrite all abstract methods of the abstract class, otherwise the class must also be defined as an abstract class. 4. The main feature of abstract classes: Abstract classes cannot create objects. They only serve as a special parent class for subclasses to inherit and implement.
Benefits: 1. Supports polymorphism to improve code flexibility 2. Allows subclasses to inherit and implement implementations to facilitate system expansion
interface
Note: Interfaces cannot create objects; interfaces are used to be implemented by classes. Classes that implement interfaces are called implementation classes.
A class can implement multiple interfaces (interfaces can be understood as godfathers). If an implementation class implements multiple interfaces, all abstract methods of all interfaces must be rewritten. Otherwise, the implementation class needs to be defined as an abstract class.
Benefits: 1. It makes up for the shortcomings of single class inheritance. A class can implement multiple interfaces at the same time. 2. Let the program be programmed for the interface, so that programmers can switch various business implementations flexibly and conveniently (more conducive to the decoupling of the program)
Newly added after JDK8
Default method: Use the default modification and call it using the object of the implementation class. Static method: static modification, must be called with the current interface name Private method: private modification, only available since jdk9, can only be called within the interface. They will all be modified by public by default.
Function: Enhanced interface capabilities to make project expansion and maintenance easier
Other things to note
1. An interface inherits multiple interfaces. If there are method signature conflicts in multiple interfaces, multiple inheritance is not supported at this time. 2. A class implements multiple interfaces. If there are method signature conflicts in multiple interfaces, multiple implementations are not supported at this time. 3. A class inherits a parent class and implements an interface at the same time. If there are default methods with the same name in the parent class and in the interface, the implementation class will give priority to the parent class. 4. A class implements multiple interfaces. There are default methods with the same name in multiple interfaces. There is no need for conflict. This class can just override the method.
inner class
member inner class
Can directly access instance members and static members of external classes
You can get the current external class object in the format: external class name.this
static inner class
static modification, you can directly access the static members of the external class, but you cannot directly access the instance members of the external class.
anonymous inner class
Used to create a subclass object more conveniently
Usually passed as a parameter to a method
enum class
The first line of the enumeration class can only list some names. These names are all constants, and each constant remembers an object of the enumeration class.
It can be more restrictive and practical, Lei Ge’s code
The enumeration class constructor is private, so objects cannot be created externally.
A final class cannot be inherited
Starting from the second line, you can define various other members of the class
Use enumeration classes to design singleton patterns
Generics
When defining a class, interface, or method, one or more type variables (such as: <E>) are declared at the same time, which are called generic classes, generic interfaces, and generic methods. They are collectively called generics.
The essence is to pass the specific data type as a parameter to the type variable
Generic class
Generic interface
Generic methods, generic wildcards, upper and lower bounds
Common API
Object
StringBuilder
StringBuilder is more suitable for string modification operations than String. It will be more efficient and the code will be simpler.
For string-related operations, such as frequent splicing, modification, etc., it is recommended to use StringBuidler, which is more efficient!
The usage of StringBuffer is exactly the same as StringBuilder But StringBuilder is thread-unsafe StringBuffer is thread-safe
StringJoiner
A mutable, string-operating container that appears in JDK8
Not only can it improve the efficiency of string operations, but in some scenarios, using it to operate strings will make the code more concise.
Math
The tool class provides some static methods for operating on data, such as absolute value, rounding up and down, rounding, obtaining the larger value, and returning b power, random number between 0 and 1.
System
Tools
currentTimeMillies(), returns the millisecond value since 1970.01.01, the birth of C language.
exit() terminates the virtual machine
Runtime
Related to virtual machines, you can start and terminate a program
BigDecimal
Used to solve the problem of result distortion when floating point operations
time
LocalDate
year month day
LocalTime
Minutes and seconds
LocalDateTime
Year, month, day, hour, minute, second
ZoneId
Time zone
ZonedDateTime
Time with time zone
DateTimeFormatter
For formatting and parsing of time
Instant
Timestamp
Period
time interval (year, month, day)
Duration
Time interval (hours, minutes, seconds, nanoseconds)
Arrays
Method 1 of custom sorting rules: Let the class where the object is located implement the comparison rule interface Comparable, and override the compareTo method to specify the comparison rules.
Method 2 of custom sorting rules: sort has an overloaded method and supports the built-in Comparator object to directly specify the comparison rules.
Lambda
Role: Simplify anonymous inner classes of functional interfaces
An interface with only one abstract method is a functional interface
Note: Lambda expressions can only simplify anonymous inner classes of functional interfaces!!!@FunctionalInterface
The parameter type can be omitted. If there is only one parameter, the parameter type can be omitted, and () can also be omitted. If the method body code in the Lambda expression has only one line of code, you can omit the curly braces and omit the semicolon! At this time, if this line of code is a return statement, the return must be removed and not written.
Static method reference
Class name::static method
Usage scenarios: If a Lambda expression only calls a static method, and the parameters before and after are in the same form, you can use static method references.
instance method reference
ObjectName::InstanceMethod
Usage scenario: If a Lambda expression only calls an instance method, and the parameters before and after are in the same form, you can use the instance method reference.
Method reference of a specific type
type::method
If a Lambda expression only calls an instance method, and the first parameter in the previous parameter list is used as the main call of the method, and all subsequent parameters are used as input parameters of the instance method, then you can Use a method reference of a specific type.
Constructor reference
Class name::new
If a Lambda expression is only creating an object, and the parameters before and after are consistent, you can use a constructor reference.
algorithm
Bubble Sort
Selection sorting and optimization
Binary search (halve search)
Prerequisite: The data in the array must be ordered
Implementation steps: Define variables to record the left and right positions. Use a while loop to control binary query (the condition is that the left position <= the right position) Get the middle element index inside the loop Determine if the element you are currently looking for is greater than the middle element, the left position = middle index 1 Determine if the element you are currently looking for is smaller than the middle element, the right position = middle index -1 Determine if the current element you are looking for is equal to the middle element, and return the current middle element index.
regular expression
Those enclosed in square brackets can only match one
Note that \ is an escape character in Java
replaceAll(String regex, String newStr) Replace according to the content matched by the regular expression
split(String regex) splits the string according to the content matched by the regular expression and returns a string array.
Collection, Stream
Note on concurrent modification exceptions for List series collections
The underlying principle of HashSet/HashMap collection
The value generated by the hashCode method is calculated with the table length to obtain the storage location of the element.
Before JDK8: array linked list
After JDK8: array, linked list, red-black tree
Data addition process
Create an array with a default length of 16, the default loading factor is 0.75, and the array name is table Use the hash value of the element to calculate the remainder of the length of the array to calculate the position where it should be stored. Determine whether the current position is null. If it is null, store it directly. If it is not null, it means there is an element. Then call the equals method to compare if they are equal. If they are not equal, they will not be stored. If they are not equal, they will be stored in the array. Before JDK8, new elements were stored in the array, occupying the position of the old elements, and the old elements were hung below. After the start of JDK8, new elements are directly hung under the old elements.
Collections collection tool class
Comprehensive case: Landlord Fighting
map series collection
1.HashMap: Unordered, non-repeating, no index
2.LinkedHashMap: ordered, non-duplicate, no index
3.TreeMap: sortable, non-repeating, no index
Key value traversal, key value pair traversal, Lambda traversal
Stream
1. Used to simplify collection operations and used with Lambda expressions
2.Three stages
1. Get the stream
1. For collections
2. For arrays
2. Operation flow
1.filter(): filter data
2.sorted(): sorting
3.distince(): remove duplicates
4.limit(): Get the previously specified number
5.skip(): ignore the previous multiple
6.map(): mapping
7.concat(): concatenate streams
3. Collection flow
1.count(): count
2.max() and min(): maximum and minimum
3.forEach(): Traverse the elements in the stream
4.collect(): collect stream
Miscellaneous
File
1. Used to operate files and folders
2. Specific use
1. Determine file information and obtain file information
2. Create files and delete files
3. Traverse folders
1.list: Return String[], loaded with names
2.listFiles: return File[]
Comprehensive case: recursive file search
High-tech
Junit unit testing
reflection
annotation
dynamic proxy
Multithreading
Create thread method 1: Inherit the Thread class, override the run method, create a thread object, and start it in the main function
Disadvantages: poor scalability, cannot inherit other classes, and cannot return the results of thread execution
Create thread method 2: implement the Runnable interface, rewrite the run method, create new Thread (an object that implements the Runnable interface) in the main function, and then start
Disadvantages: Programming is relatively complex and cannot return the results of thread execution.
Create thread method 3: implement the Callable interface, rewrite the call method to encapsulate the things to be done and the returned data, encapsulate the Callable type object into a FutureTask (thread task object), hand the thread task object to the Thread object for processing, and then start , and finally obtain the result of the thread task execution through the get method of the FutureTask object
Disadvantages: Programming is relatively complex
Thread common methods:
The sleep method allows the current thread to sleep for a certain period of time before continuing to execute the task. The join method is a thread scheduling method that allows the current thread to be executed first. It is generally used in scenarios that require sequential execution of tasks.
Solving thread safety issues
Method 1: Synchronized code blocks
It is recommended that instance methods use this as the object
Static methods recommend using bytecode (class name.class) objects as lock objects
Method 2: Synchronization method
Method 3: Lock
Thread communication
1.wait: Let the thread wait for the state
2.notify: wake up a waiting thread
3.notifyAll: wake up all waiting threads
Thread Pool
1. Concept: Store the content of threads, manage threads, avoid frequently creating and destroying threads, and wasting resources
2. Creation method
1.ThreadPoolExcutor: recommended
1. Execute Runable tasks
2. Execute Callable tasks
2.Executors tool class
Thread status
New
ready
lock blocking
wait
timer wait
termination
IO stream
character set
GBK, UTF-8 (default encoding), ASCII, ios-8859-1
Encoding: Convert the string into a byte array: "".getBytes()
Decoding: Convert byte array into string: new String(bytes[])
byte stream
FileInputStream
1. Read a single byte at a time: read()
2. Read multiple bytes at one time: read(byte[])
3. Read all bytes at once: read(byte[]) or readAllBytes()
FileOutputStream
1. Write a byte: write()
2. Write multiple bytes: write(byte[])
3. Write bytes of specified length: write(byte[],offset,len)
Application case: copy files
character stream
Used to read characters and operate files based on character units FileReader & FileWriter The units of operation are characters, which is more suitable for operating text file contents.
buffered stream
1. Pack the byte stream or character stream
2. Specific use
1. Byte stream: BufferedReader, BufferedWriter
2. Character stream: BufferInputStream, BufferedOutputStream
3. Reading and writing performance has been improved
Conversion flow
1. Convert the byte stream into a character stream and set the character set. Textile reading Chinese data appears garbled
Specific use
1.InputStreamReader
2.OutputStreamWriter
print stream
1. It can achieve the effect of outputting whatever is printed.
2.PrintStream, PrintWriter
data flow
1. When writing data, you can also write out the type: DtaOutputStream
2. You can directly read data of the specified type: DataInputStream, such as readUTF()
2.writeInt(), readInt()
object stream
Serialization: Save objects in memory to hard disk files, serialization stream: ObjectOutputStream
Deserialization: Read the contents of the hard disk file into memory and use an object to receive it: ObjectInputStream
Requirements: JavaBean class, must implement the interface Serializable
IO framework
1.commons-io
2.FileUtils and IOUtils
Special files and log technology
Read Properties configuration file
Key-value pair format, keys cannot be repeated
To parse and generate properties files, you can directly use the properties object to operate.
Parse XML files
Function: Used to make project and system configuration files
Parse XML: dom4j
Generate XML: Do not use dom4j API, just use I/O operations directly
Logback log
Implementation classes: JUL, log4j, logback
Interface: jcl, slf4j
Add three jar packages: logback-core, logback-classic, and slf4j; Construct a Logger object and call trace() debug() info() warn() error(); logback.cml is placed under src