Abnormal
Exceptions can be divided into two categories:
1. Check for exceptions (checking for exceptions is usually a user error or a problem that cannot be foreseen by the programmer.) ;
2. Run-time exceptions (run-time exceptions are usually the types of exceptions that can occur during a program's run, and may be avoided).
Exception handling
1. Catch the exception and not let it continue down the call stack;
2. Catch the exception and let it continue to throw downward;
3. Do not capture it, let him throw it to the following method (if there is no way to handle these exceptions, throw it to the JVM, and if the JVM cannot handle it, the JVM will crash.)
The exception mechanism is as follows:
try/catch/finally statement block
Try { // code for possible exception /// If an exception occurs, the code after the exception will not be executed catch// exception handling code Finally// If an exception occurs, the finally statement block is executed}
Multiple catch
a try can be followed by multiple catch, but no matter how many, only one catch block will be executed at most
When catching an exception, catch the child exception before capturing the exception class exception.
The error class is the parent of all Java class error classes;
The exception class is the parent class of all exception classes;
Thowable is the parent class of the error class and the exception class.
Common classes
system Class
Returns the current time in milliseconds
Long Start=system.currenttimemillis ();
Terminating a currently running JVM virtual machine
System.exit (0);
Garbage collection
System.GC ();
string-related class
String StringBuffer StringBuilder
Difference
String test1= "abc";
StringBuffer test2=new StringBuffer ("abc");
StringBuilder test3=new StringBuilder ("abc");
Date Class
Many methods in the date class are obsolete and replaced by calender
Regular expressions
For validating formats
String stu= "ABC";
Pattern pattern=pattern.compily ("validation Rules");
Matcher Matcher=pattern.matcher (STU);
System.out.println (Matcher.matches ());
If the rule is met, Matcher.matches () is true;
Reflection (Runtime explores and uses classes that are not known at compile time)
There are three types of loaders: root Loader extension ClassLoader System class loader
When a class is loaded into the JVM, the same class is not loaded.
Connection
Merge binary into JRE during connection phase
Java Collection Framework
Set, list, and map can be seen as the three main classes of collections.
The list collection is an ordered collection, and the elements in the collection can be repeated, and accessing the elements in the collection can be accessed based on the index of the element.
The set collection is an unordered collection, and the elements in the collection cannot be duplicated, and access to the elements in the collection can only be accessed based on the element itself (and the reason that the elements in the collection are not allowed to be duplicated).
The map collection holds elements of the key-value pair form, which can only be accessed by the key of each element when accessing its value.
Collection interface:
Set interface:
HashSet specific Class (no order, no duplicate data, can be null)
Linkedhashset Concrete Class
TreeSet Concrete Class
List interface: ArrayList specific class
LinkedList Concrete Class
Vector class vectors specific classes
Stack Concrete Class
Map Interface: HashMap class
Linkedhashmap class
TreeMap class
ArrayList: The method of array is implemented, the query efficiency is high, and the efficiency is low.
LinkedList: By the way of the chain list, adding and deleting the efficiency is high;
Generic type
Pros: 1. Ensure data security
2. Data types do not need to be converted
Map interface (key-value pair, key--value one by one, key cannot be duplicated, value can be duplicated)
Java Basic Three