AbstractList

1
public abstract class AbstractList<E> extends AbstractCollection<E> implements List<E>
阅读全文 »

List

简述,具体参见

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Interface: List(public interface List<E> extends Collection<E> )
The <tt>List</tt> interface provides two methods to search for a specified object.
From a performance standpoint, these methods should be used with caution.
In many implementations they will perform costly linear searches.

Abstract class: AbstractList(public abstract class AbstractList<E> extends AbstractCollection<E> implements List<E>)
To implement an unmodifiable list, the programmer needs only to extend this class and provide implementations for the {@link #get(int)} and {@link List#size() size()} methods.

To implement a modifiable list, the programmer must additionally override the {@link #set(int, Object) set(int, E)} method (which otherwise throws an {@code UnsupportedOperationException}). If the list is variable-size the programmer must additionally override the {@link #add(int, Object) add(int, E)} and {@link #remove(int)} methods.


about---> Itr, ListItr, RandomAccessSubList <---------


class: ArrayList(public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, java.io.Serializable)
transient Object[] elementData; // non-private to simplify nested class access
阅读全文 »

String

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
public final class String
implements java.io.Serializable, Comparable<String>, CharSequence {
/** The value is used for character storage. */
private final char value[];

/** Cache the hash code for the string */
private int hash; // Default to 0

public int hashCode() {
int h = hash;
if (h == 0 && value.length > 0) {
char val[] = value;

for (int i = 0; i < value.length; i++) {
h = 31 * h + val[i];//32=2^5 左移5位减去自身+字符ASCII码值
}
hash = h;
}
return h;
}
public boolean equals(Object anObject) {
if (this == anObject) {//同一个引用
return true;
}
if (anObject instanceof String) {
String anotherString = (String)anObject;
int n = value.length;
if (n == anotherString.value.length) {//长度相同(减少比较次数)
char v1[] = value;
char v2[] = anotherString.value;
int i = 0;
while (n-- != 0) {//。。。
if (v1[i] != v2[i])
return false;
i++;
}
return true;
}
}
return false;
}
}
阅读全文 »

Unsafe–Java 指针(操作内存)

java 8: rt.jar\sun.misc
java 9: jdk.unsupported\sun.misc java.base\jdk.internal.misc

阅读全文 »

AsyncTask

Abstract

1
public abstract class AsyncTask<Params, Progress, Result> {...}

AsyncTask is designed to be a helper class around {@link Thread} and {@link Handler} and does not constitute a generic threading framework.
AsyncTasks should ideally be used for short operations (a few seconds at the most.)
If you need to keep threads running for long periods of time, it is highly recommended you use the various APIs provided by the java.util.concurrent package such as {@link Executor}, {@link ThreadPoolExecutor} and {@link FutureTask}.

阅读全文 »

ClassLoader

类加载器
file: ClassLoader.txt
参考:探秘Java9之类加载

1.8 and earlier version

code: java [1.8]

BootstrapClassLoader,ExtClassLoader,AppClassLoader

1
2
static class AppClassLoader extends URLClassLoader
static class ExtClassLoader extends URLClassLoader

ClassLoader

1
2
3
4
5
6
7
8
<tt>Class</tt> objects for array classes are not created by class loaders, but are created automatically as required by the Java runtime.    
The class loader for an array class, as returned by {@link Class#getClassLoader()} is the same as the class loader for its element type; if the element type is a primitive type, then the array class has no class loader.

<p> The <tt>ClassLoader</tt> class uses a delegation model to search for classes and resources.
Each instance of <tt>ClassLoader</tt> has an associated parent class loader.
When requested to find a class or resource, a <tt>ClassLoader</tt> instance will delegate the search for the class or resource to its parent class loader
before attempting to find the class or resource itself.
The virtual machine's built-in class loader, called the "bootstrap class loader", does not itself have a parent but may serve as the parent of a <tt>ClassLoader</tt> instance.
  • Bootstrap ClassLoader 最顶层的加载类,主要加载核心类库,%JRE_HOME%\lib下的rt.jar、resources.jar、charsets.jar和class等。另外需要注意的是可以通过启动jvm时指定-Xbootclasspath和路径来改变Bootstrap ClassLoader的加载目录。比如java -Xbootclasspath/a:path被指定的文件追加到默认的bootstrap路径中。我们可以打开我的电脑,在上面的目录下查看,看看这些jar包是不是存在于这个目录。

  • Extention ClassLoader 扩展的类加载器,加载目录%JRE_HOME%\lib\ext目录下的jar包和class文件。还可以加载-D java.ext.dirs选项指定的目录。

  • AppClass Loader ClassLoader.getSystemClassLoader() 也称为SystemAppClass 加载当前应用的classpath的所有类。

ExtClassLoader与AppClassLoader代码见:lib\rt.jar!\sun\misc\Launcher.class

阅读全文 »

哈希算法-MD5,SHA

Hash,就是把任意长度的输入(又叫做预映射pre-image)通过散列算法变换成固定长度的输出,该输出就是散列值。这种转换是一种压缩映射,也就是,散列值的空间通常远小于输入的空间。简单的说就是一种将任意长度的消息压缩到某一固定长度的消息摘要的函数。

阅读全文 »
0%