Basic Java Knowledge

Source: Internet
Author: User
Tags comparable export class semaphore

One, Java exceptions

1, runtime exception (generally do not need to capture, divisor is 0)

2, checked exception (null pointer), throws and throw

Ii. generics (public static <t extend comparable & serializable> t min (T t))

1. Virtual machines do not have generic type objects-all objects are normal classes. When a program invokes a generic method, if the return type is erased, the compiler inserts a forced type conversion.

1 ImportJava.util.*; 2  Public classErasedtypeequivalence {3      Public Static voidMain (string[] args) {4Class C1 =NewArraylist<string>(). GetClass ();5Class C2 =NewArraylist<integer>(). GetClass ();6SYSTEM.OUT.PRINTLN (C1 = = C2);//Generic Erase7     } 8}/*Output:9 trueTen *///:~

2. Troubleshoot generic erase

1) wildcard characters

<? Super T> inversion indicates that the generic class holds the base class of T, then T must be put into

<? Extends t> indicates that the generic class holds the export class of T, the return value must be returned as a covariant type of t

2) Define the interface implementation

Third, reflection

In a running state, all of its properties and methods can be obtained for any class, and its methods can be called for any object (the function of dynamically invoking object methods)

Clazz.getclass ()

Iv. class Loading

1. Class loading mechanism

(1) Loading: Find and import class files;

(2) Link: Merges the binary data of the class into the JRE;

(a) Verification: check the correctness of loading class file data;

(b) Preparation: Allocating storage space to static variables of the class;

(c) Parsing: Transferring symbolic references to direct references;

(3) Initialize: Static variable for class, static code block to initialize operation

2. Three ways of class loading

1) New Date ()

2) Class.forName ("")-->class.forname (ClassName, true, This.getclass (). getClassLoader ()). The second parameter is whether the class must be initialized after being loading. Class.forName (Com.mysql.cj.jdbc.Driver);

3) Classloader.loadclass (className) actually calls Classloader.loadclass (name, false), and the second parameter refers to whether the class is being link.

3. Class loader and parental delegation model

1) Bootstrap ClassLoader: Will be stored in the <java_home>\lib directory, only the matching class library will be loaded.

2) Extension ClassLoader: Load the <java_home>\lib\ext directory or all class libraries in the path specified by the Java.ext.dirs system variable. Developers can use the extension class loader directly.

3) Application ClassLoader: Responsible for loading the class library specified on the User class path (ClassPath), which can be used directly by the developer. It is responsible for loading the class libraries in the directory under the system classpath Java-classpath or-djava.class.path variables into memory.

Five, set

1, Collection (implements the Iterable interface)

2, the list of each object is stored in a separate node, each node also holds a reference to the next node in the sequence, add delete fast, the array is added to delete slow, need to copy the array.

3, array list ArrayList, the underlying array, random Find Fast.

4, hash set HashSet bottom HashMap

5, Tree set TreeSet red and black tree

6, object comparison comparable interface, to achieve this interface to compare, CompareTo (T); Comparator Compare (T1, T2)

7, queue and double-ended queue arraydeque (non-thread-safe, access fast), Stack (Extend Vector)

8, the mapping table HashMap initial 16 size is 2^n,jdk7 the underlying array, the array each item is a Entry,hash collision resolution is the zipper------------bucket + linked list; JDK8 underlying array, each item of the array is a Node,hash collision resolution--bucket + list/ Red and black Trees

Six, multi-threaded

1, inherit thread, realize runnable

2, in the disconnection process

3, the state of the thread

1) NEW

2) after RUNNABLE start ()

3) after BLOCKED locked

4) Waiting Wait (), join ()

5) TIMED waiting Wait (time)

6) TERMINAL

4, thread priority, and daemon thread (ends when no other thread executes)

5. Volatile

6, ThreadLocal

7. Communication between threads

1) Use of the most basic synchronized , notifywait

2) Use Lock andCondition

3) Semaphore A, cyclicbarrier (after the number of scheduled threads reached) B, countdownlatch (counter minus 0) C, Semaphore (number of threads allowed access to restricted resources)

8. Actuator

1) Newsinglethreadexecutor:

2) Newfixedthreadpool:

3) Newcachedthreadpool:

4) Newscheduledthreadpool:

5) Threadpoolexecutor:

V. Database

1. Business

1) transaction characteristics (ACID) atomacity, consistency, isolation, durability

2) Transaction ISOLATION level (dirty read, non-repeatable read, fantasy read, lost modification)-uncommitted read, Read committed, Repeatable read, serial read

3) Lock share lock, update lock, exclusive lock

4) Index: created directly (created at table creation) and indirectly created (created after the table is built)

Basic Java Knowledge

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.