GVKun编程网logo

JVM第三天 Java Class File structure(jvm classpath)

19

在本文中,我们将为您详细介绍JVM第三天JavaClassFilestructure的相关知识,并且为您解答关于jvmclasspath的疑问,此外,我们还会提供一些关于ASMClassReaderf

在本文中,我们将为您详细介绍JVM第三天 Java Class File structure的相关知识,并且为您解答关于jvm classpath的疑问,此外,我们还会提供一些关于ASM ClassReader failed to parse class file - probably due to a new Java class file version that i...、ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn''、Category Theory: 01 One Structured Family of Structures、class /classloader getResourceAsStream()与FileInputStream的有用信息。

本文目录一览:

JVM第三天 Java Class File structure(jvm classpath)

JVM第三天 Java Class File structure(jvm classpath)

Reference:  http://viralpatel.net/blogs/tutorial-java-class-file-format-revealed/

A Java class file is consist of 10 basic sections:


1.Magic Number: 0xCAFEBABE

2.Version of Class File Format: the minor and major versions of the class file

3.Constant Pool: Pool of constants for the class

4.Access Flags: for example whether the class is abstract, static, etc.

5.This Class: The name of the current class

6.Super Class: The name of the super class

7.Interfaces: Any interfaces in the class

8.Fields: Any fields in the class

9.Methods: Any methods in the class

10.Attributes: Any attributes of the class (for example the name of the sourcefile, etc.)

You can remember the 10 sections with some funny mnemonic: My Very Cute Animal Turns Savage In Full Moon Areas.


java-class-file-internal-structure

1. Javap Testing 查看字节码工具

Create JavapTest class as below:

public class JavapTip {
  public static void main(String []args) {
  }
  private static String withStrings(int count) {
    String s ="";
    for (int i = 0; i < count; i++) {
      s += i;
    }
    return s;
  }
  private static String withStringBuffer(int count) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < count; i++) {
      sb.append(i);
    }
    return sb.toString();
   }
}

Complie:
C:\Program Files\Java\JavaTip>javac JavapTip.java

1.1 javap


C:\Program Files\Java\JavaTip>javap  JavapTip
Compiled from "JavapTip.java"
public class JavapTip extends java.lang.Object{
    public JavapTip();
    public static void main(java.lang.String[]);
}


1.2 javap -c 


C:\Program Files\Java\JavaTip>javap  -c JavapTip
Compiled from "JavapTip.java"
public class JavapTip extends java.lang.Object{
public JavapTip();
  Code:
   0:   aload_0
   1:   invokespecial   #1; //Method java/lang/Object."<init>":()V
   4:   return


public static void main(java.lang.String[]);
  Code:
   0:   return


}


1.3 javap -c -private


C:\Program Files\Java\JavaTip>javap -c -private  JavapTip
Compiled from "JavapTip.java"
public class JavapTip extends java.lang.Object{
public JavapTip();
  Code:
   0:   aload_0
   1:   invokespecial   #1; //Method java/lang/Object."<init>":()V
   4:   return


public static void main(java.lang.String[]);
  Code:
   0:   return


private static java.lang.String withStrings(int);
  Code:
   0:   ldc     #2; //String
   2:   astore_1
   3:   iconst_0
   4:   istore_2
   5:   iload_2
   6:   iload_0
   7:   if_icmpge       35
   10:  new     #3; //class java/lang/StringBuilder
   13:  dup
   14:  invokespecial   #4; //Method java/lang/StringBuilder."<init>":()V
   17:  aload_1
   18:  invokevirtual   #5; //Method java/lang/StringBuilder.append:(Ljava/lang/
String;)Ljava/lang/StringBuilder;
   21:  iload_2
   22:  invokevirtual   #6; //Method java/lang/StringBuilder.append:(I)Ljava/lan
g/StringBuilder;
   25:  invokevirtual   #7; //Method java/lang/StringBuilder.toString:()Ljava/la
ng/String;
   28:  astore_1
   29:  iinc    2, 1
   32:  goto    5
   35:  aload_1
   36:  areturn


private static java.lang.String withStringBuffer(int);
  Code:
   0:   new     #8; //class java/lang/StringBuffer
   3:   dup
   4:   invokespecial   #9; //Method java/lang/StringBuffer."<init>":()V
   7:   astore_1
   8:   iconst_0
   9:   istore_2
   10:  iload_2
   11:  iload_0
   12:  if_icmpge       27
   15:  aload_1
   16:  iload_2
   17:  invokevirtual   #10; //Method java/lang/StringBuffer.append:(I)Ljava/lan
g/StringBuffer;
   20:  pop
   21:  iinc    2, 1
   24:  goto    10
   27:  aload_1
   28:  invokevirtual   #11; //Method java/lang/StringBuffer.toString:()Ljava/la
ng/String;
   31:  areturn


}

1.4 利用javap -verbose 

C:\Program Files\Java\JavaTip>javap  -verbose  JavapTip
Compiled from "JavapTip.java"
public class JavapTip extends java.lang.Object
  SourceFile: "JavapTip.java"
  minor version: 0
  major version: 50
  Constant pool:
const #1 = Method       #13.#28;        //  java/lang/Object."<init>":()V
const #2 = String       #29;    //
const #3 = class        #30;    //  java/lang/StringBuilder
const #4 = Method       #3.#28; //  java/lang/StringBuilder."<init>":()V
const #5 = Method       #3.#31; //  java/lang/StringBuilder.append:(Ljava/lang/S
tring;)Ljava/lang/StringBuilder;
const #6 = Method       #3.#32; //  java/lang/StringBuilder.append:(I)Ljava/lang
/StringBuilder;
const #7 = Method       #3.#33; //  java/lang/StringBuilder.toString:()Ljava/lan
g/String;
const #8 = class        #34;    //  java/lang/StringBuffer
const #9 = Method       #8.#28; //  java/lang/StringBuffer."<init>":()V
const #10 = Method      #8.#35; //  java/lang/StringBuffer.append:(I)Ljava/lang/
StringBuffer;
const #11 = Method      #8.#33; //  java/lang/StringBuffer.toString:()Ljava/lang
/String;
const #12 = class       #36;    //  JavapTip
const #13 = class       #37;    //  java/lang/Object
const #14 = Asciz       <init>;
const #15 = Asciz       ()V;
const #16 = Asciz       Code;
const #17 = Asciz       LineNumberTable;
const #18 = Asciz       main;
const #19 = Asciz       ([Ljava/lang/String;)V;
const #20 = Asciz       withStrings;
const #21 = Asciz       (I)Ljava/lang/String;;
const #22 = Asciz       StackMapTable;
const #23 = class       #38;    //  java/lang/String
const #24 = Asciz       withStringBuffer;
const #25 = class       #34;    //  java/lang/StringBuffer
const #26 = Asciz       SourceFile;
const #27 = Asciz       JavapTip.java;
const #28 = NameAndType #14:#15;//  "<init>":()V
const #29 = Asciz       ;
const #30 = Asciz       java/lang/StringBuilder;
const #31 = NameAndType #39:#40;//  append:(Ljava/lang/String;)Ljava/lang/String
Builder;
const #32 = NameAndType #39:#41;//  append:(I)Ljava/lang/StringBuilder;
const #33 = NameAndType #42:#43;//  toString:()Ljava/lang/String;
const #34 = Asciz       java/lang/StringBuffer;
const #35 = NameAndType #39:#44;//  append:(I)Ljava/lang/StringBuffer;
const #36 = Asciz       JavapTip;
const #37 = Asciz       java/lang/Object;
const #38 = Asciz       java/lang/String;
const #39 = Asciz       append;
const #40 = Asciz       (Ljava/lang/String;)Ljava/lang/StringBuilder;;
const #41 = Asciz       (I)Ljava/lang/StringBuilder;;
const #42 = Asciz       toString;
const #43 = Asciz       ()Ljava/lang/String;;
const #44 = Asciz       (I)Ljava/lang/StringBuffer;;


{
public JavapTip();
  Code:
   Stack=1, Locals=1, Args_size=1
   0:   aload_0
   1:   invokespecial   #1; //Method java/lang/Object."<init>":()V
   4:   return
  LineNumberTable:
   line 1: 0




public static void main(java.lang.String[]);
  Code:
   Stack=0, Locals=1, Args_size=1
   0:   return
  LineNumberTable:
   line 3: 0




}

2. Magic number 

Magic number is used to uniquely identify the format and to distinguish it from other formats. The first four bytes of the Class file are 0xCAFEBABE.

java-class-file-magic-word-cafebabe

3. Version of class file

The next four byte of the class file contains major and minor version numbers. This number allows the JVM to verify and identify the class file. If the number is greater than what JVM can load, the class file will be rejected with error java.lang.UnsupportedClassVersionError.

You can find class version of any Java class file using javap command line utility. For example

javap -verbose  JavaTip

Compiled from "JavapTip.java"
public class JavapTip extends java.lang.Object
  SourceFile: "JavapTip.java"
  minor version: 0
  major version: 50
Below is the list of Major versions and corresponding JDK version of class file.
Major Version Hex JDK version
51 0×33 J2SE 7
50 0×32 J2SE 6.0
49 0×31 J2SE 5.0
48 0×30 JDK 1.4
47 0x2F JDK 1.3
46 0x2E JDK 1.2
45 0x2D JDK 1.1

4 Constant pool

All the constants related to the Class or an Interface will get stored in the Constant Pool.The constants includes class names, variable names, interface names, method names and signature, final variable values, string literals etc.

java-class-file-constant-pool-structure




The constants are stored as a variable length array element in the Constant pool. The arrays of constants are preceded by its array size, hence JVM knows how many constants it will expect while loading the class file. In above diagram, the portion represented in green contains the size of the array.


Within each array elements first byte represents a tag specifying the type of constant at that position in the array. In above diagram the portion in orange represent the one-byte tag. JVM identifies the type of the constant by reading one-byte tag. Hence if one-byte tag represents a String literal then JVM knows that next 2 bytes represents length of the String literal and rest of the entry is string literal itself.


You can analyse the Constant Pool of any class file using javap command. Executing javap on above Main class, we get following symbol table.


C:\>javap -verbose Main
Compiled from "Main.java"
public class Main extends java.lang.Object
  SourceFile: "Main.java"
  minor version: 0
  major version: 50
  Constant pool:
const #1 = Method       #4.#13; //  java/lang/Object."<init>":()V
const #2 = int  16707053;
const #3 = class        #14;    //  Main
const #4 = class        #15;    //  java/lang/Object
const #5 = Asciz        <init>;
const #6 = Asciz        ()V;
const #7 = Asciz        Code;
const #8 = Asciz        LineNumberTable;
const #9 = Asciz        main;
const #10 = Asciz       ([Ljava/lang/String;)V;
const #11 = Asciz       SourceFile;
const #12 = Asciz       Main.java;
const #13 = NameAndType #5:#6;//  "<init>":()V
const #14 = Asciz       Main;
const #15 = Asciz       java/lang/Object;
The constant pool has 15 entries in total. Entry #1 is Method public static void main; #2 is for integer value 0xFEEDED (decimal 16707053). Also we have two entries #3 and #4 which corresponds to this class and super class. Rest is the symbol table storing string literals.


5 Access flags

Access flags follows the Constant Pool. It is a two byte entry that indicates whether the file defines a class or an interface, whether it is public or abstract or final in case it is a class. Below is a list of some of the access flags and their interpretation.


Flag Name Value Interpretation
ACC_PUBLIC 0x0001 Declared public; may be accessed from outside its package.
ACC_FINAL 0x0010 Declared final; no subclasses allowed.
ACC_SUPER 0x0020 Treat superclass methods specially when invoked by the invokespecial instruction.
ACC_INTERFACE 0x0200 Is an interface, not a class.
ACC_ABSTRACT 0x0400 Declared abstract; may not be instantiated.

6 This class

This Class is a two byte entry that points to an index in Constant Pool. In above diagram, this class has a value 0x0007 which is an index in Constant Pool. The corresponding entry that is pointed by this class Constant_pool[this_class] in Constant pool has two parts, first part is the one-byte tag that represents the type of entry in constant pool, in this case it is Class or Interface. In above diagram this is shown inorange color. And second entry is two-byte having index again in Constant pool. This above diagram, two byte contain value 0x0004. Thus it points to Constant_poo [0x0004] which is the String literal having name of the interface or class

7 super Class

Next 2 bytes after This Class is of Super Class. Similar to this class, value of two bytes is a pointer that points to Constant pool which has entry for super class of the class.


8 Interfaces

All the interfaces that are implemented by the class (or interface) defined in the file goes in Interface section of a class file. Starting two byte of the Interface section is the count that provides information about total number of interfaces being implemented. Immediately following is an array that contains one index into the constant pool for each interface implemented by class.


9 Fields

A field is an instance or a class level variable (property) of the class or interface. Fields section contains only those fields that are defined by the class or an interface of the file and not those fields which are inherited from the super class or super interface.


First two bytes in Fields section represents count: that is the total number of fields in Fields Section. Following the count is an array of variable length structure one for each field. Each element in this array represent one field. Some information is stored in this structure where as some information like name of the fields are stored in Constant pool.


10 Methods

The Methods component host the methods that are explicitly defined by this class, not any other methods that may be inherited from super class.


First two byte is the count of the number of methods in the class or interface. The rest is again a variable length array which holds each method structure. Method structure contains several pieces of information about the method like method argument list, its return type, the number of stack words required for the method''s local variables, stack words required for method''s operand stack, a table for exceptions, byte code sequence etc.


11 Attributes

Attribute section contains several attribute about the class file, e.g. one of the attribute is the source code attribute which reveals the name of the source file from which this class file was compiled.


First two bytes in Attribute section is count of the number of attributes, followed by the attributes themselves. The JVMs will ignore any attributes they don''t understand.


为了让大家深入理解基于Java字节码的应用,大家可以研究如下Java字节码的开源库(这些开源库都是在充分理解Java字节码类文件格式的基础上编写的):


□ BCEL,http://jakarta.apache.org/bcel/ 
□ ASM,http://asm.ow2.org/
□ CGLib,http://cglib.sourceforge.net/ 

ASM ClassReader failed to parse class file - probably due to a new Java class file version that i...

ASM ClassReader failed to parse class file - probably due to a new Java class file version that i...

在照着这里例子学习ssm时,在部署阶段遇到了这个问题“ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn''t supported yet

结合例子里的博主说java的版本不要用太高的,怕兼容不了,猜到应该是java版本不符的问题,于是修改了一下项目运行的java版本。在eclipse下的操作步骤如下:

1.右键项目,Properties,然后按图操作

 

修改一下java的version就好了!

 

 

ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn''

ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn''

项目比较老,使用的是 spring3 的版本。 在 jdk7 下没问题,如果是 jdk8 就有问题了。。。

版本不兼容

http://blog.csdn.net/blueheart20/article/details/50150529

Category Theory: 01 One Structured Family of Structures

Category Theory: 01 One Structured Family of Structures

Category Theory: 01 One Structured Family of Structures

这次看来要放弃了。看了大概三分之一。似乎不能够让注意力集中了。先更新吧。

群的定义

$G = {G, +, e}$,一个数据集 $G$,一个二元操作符 $+$,和一个幺元 $e$。

满足结合律:$(a + b) + c = a + (b + c)$ 满足封闭性。 存在单位元:$e + a = a = a + e$ 存在逆元:对于每一个 a,存在一个逆元 a'': $a + a'' = e$ 如果满足交换律,则是一个交换群,也就是阿尔贝群。

群的同态 (homomorphism) 和同构 (isomorphism)

  • 定义:同态 (homomorphism) 群同态是一个函数 f,应用于源群 $(G, *, e)$ 和目标群 $(G'', *'', e'')$,满足:

    1. $f(x * y) = f(x) *'' f(y)$
    2. $f(e) = e''$ e.g. $f(x) = e^x, e^{x + y} = e^x e^y$
  • 定理:

    1. 群 $(G, *, e)$,总有一个单位同态,$1_G : G \to G$.
    2. 给定两个同态 $f: G \to H, g: H \to J$,存在一个组合同态 $g \circ f : G \to J$.
    3. 同态的组合满足结合律 (associative),$j \circ (g \circ f) = (j \circ g) \circ f$
  • 定义:同构 (isomorphism) 群同构 $(f : G \simeq H)$ 是一个同态,如果其对应的函数是一个双射。

  • 定理: 一个群同态 $f: G \to H$ 是一个同构,当且仅当它有一个双边的逆,也就是说,有一个同态 $f'': H \to G$,有 $f'' \circ f = 1_G, f \circ f'' = 1_H$。

  • 定理 在群之间的同构是一个群之间的等价关系。

02 范畴的定义

一个范畴是一个带标签的有向图,其节点为对象 (object),带有标签的有向边为箭头 (arrow or morphism)。

一个范畴 C 包含 2 个数学实体:

  • 对象集合:ob (C) 每个元素都是一个对象,一个对象又可以认为是一个集合。

  • 态射集合: hom (C) 态射集合的每个元素是一个态射,$f: a \to b$,每个态射 f 有一个源对象 (source object) a 和目标对象 (target object) b。 $hom (a, b)$ 表示从 a 到 b 的所有态射。 每个态射 $f: A \to B$ 有 src () 和 tgt (),两个属性,可以获得源对象和目标对象,i.e. $A = src (f), B = tgt (f)$。

  • 性质:

    • 二元操作:态射结合 (composition of morphisms): $\circ$ $f: a \to b, g: b \to c$ 的结合是 $g \circ f$。
  • 公理

    • 满足结合律 (Associativity): $ h \circ ( g \circ f ) = ( h \circ g ) \circ f $ 结合律意味着操作执行的次序不影响其总体结果,是等价的。但是操作元素的次序不能改变(不满足交换律)。
    • 存在恒等态射 (identity): 对于每个对象 x,存在一个恒等态射 (identity morphism) $1_x: x \to x$, 其性质为,对于任何态射 $f: a \to b$,有 $1_b \circ f = f = f \circ 1_a$ 恒等态射的含义是:定义了相同关系 (equality relation A = B)。 可以简单的认为是;$f (x) = x$。
  • 定理:一个对象的单位箭头是唯一的;不同对象的单位箭头是不同的。

范畴的理解

  • 对象 从编程语言的角度来说,一个类(范畴)并不需要一个对象集合。 一个类的对象集合是由这个类的属性和方法决定的,是编程语言的各种数据类型和类的各种各样的组合形式。 我们往往用元类型来描述范畴里的对象

  • 态射 态射就是一个类的方法。 一个方法有多个输入或者输出,可以简单地认为其源对象或者目标对象是一个对象组合。 如何理解一个没有输入的静态方法。

态射的种类

单态射 (monomorphism) $\simeq$ 单射 (injective) 满态射 (epimorphism) $\simeq$ 满射 (surjective) 双态射 (bimorphism) = 单态射 (monomorphism) + 满态射 (epimorphism) 同构 (isomorphism) = 双态射 (bimorphism) + 存在逆态射 自态射 (endomorphism) = (src (f) = tgt (f)) 自同构 (automorphism) = 自态射 (endomorphism) + 同构 (isomorphism) 撤回射 (retraction) = 存在右逆 部分射 (section) = 存在左逆 同态 = 两个数据结构之间满足分配律。$f (x * y) = f (x) *'' f (y)$

半幺群和预次序集合

  • 幺半群 (monoid) 没有逆元限制的群。 $(M, \dot, e_M)$,$\dot$ 是一个二元函数,$e_M$ 是一个显著对象。

    1. $\dot$ 是满足结合律:$(a \dot b) \dot c = a \dot (b \dot c), \forall a, b, c \in M$
    2. $e_M \dot a = a = a \dot e_M$ 例如:$(\mathbb {N}, +, 0)$ 是一个幺半群。
  • 预次序集合 (pre-ordered collection) $(M, \leqslant)$,具有:

    1. $a \leqslant b, b \leqslant c \implies a \leqslant c$,
    2. $a \leqslant a$
  • 单调映射 (monotone map) 作用于次序集合上的单调映射 $f: (M, \leqslant) \to (N, \sqsubseteq)$,具有:如果 $a \leqslant b, \forall a, b \in M$, 则 $f (a) \sqsubseteq f (b)$。

范畴的例子

  • Mon Mon 是对象为所有幺半群,箭头为幺半群同态。

  • Ord Ord 是对象为所有预序组,箭头为他们之间的单调映射。

  • Set Set 是对象为所有 set,箭头为他们之间的任意集合函数。

  • Grp Grp 是对象为所有 group,箭头为 group 的同态。

  • Ab Ab 是对象为所有 abelian group,箭头为 group 的同态。

  • Rng Rng 是对象为所有 ring,箭头为 ring 的同态。

  • 任取一个幺半群 $(M, \dot, e_M)$,定义范畴 $\mathcal {M}$ 如下:

    1. $\mathcal {M}$ 的唯一的对象是任何实体(不一定是 M 中的对象),我们称其为 $\star$
    2. $\mathcal {M}$ 的箭头 $a : \star \to \star$ 就是幺半群中的一个对象 a;
    3. 箭头的组合 $a \circ b$ 定义为幺半群对象的积 $a \dot b$;
    4. 单位箭头 1 定义为幺半群的单位元 $e_M$。

4: 范畴生范畴

  • 对偶 (duality) 对于一个范畴 $\mathcal {C}$ 的对偶 (dual)$\mathcal {C}^{op}$,也称为逆范畴、反向范畴 (opposite)。满足:

    1. $ob(\mathcal{C}^{op}) = ob(\mathcal{C})$
    2. 对于 $\mathcal {C}, f : A \to B$,存在 $\mathcal {C}^{op}, f : B \to $
    3. 单位箭头保持不变: $1_A^{op} = 1_A$
    4. $\mathcal {C}^{op}$ 的复合定义: $f \circ^{op} g = g \circ f$
  • 子范畴 (subcategory) $\mathcal {C}$ subcategory $\mathcal {S}$:

    1. objects: some or all of the $ob(C)$,
    2. arrows: some or all of the $hom(C)$,
    3. for each $o \in ob(S)$, the arrow $1_o \in hom(S)$
    4. for any arrow $f: C \in D, g: D \to E$, the arrow $g \circ f: C \to E \in hom(S)$
  • 全子范畴 (full subcategory) $\mathcal {C}$ subcategory $\mathcal {S}$ is a full subcategory, when: $\forall A, B \in ob (S), hom_S (A, B) = hom_C (A, B)$

  • 积范畴 (product category)

  • 等价关系 (congruence relation)

  • 商范畴 (quotient category) 商范畴 $\mathcal {C}/\sim = (ob (C), hom (hom (X \to Y)\to \sim class)$ 是对一个范畴,按照某种属性进行分类。 商范畴的态射,我的理解是:C 的态射 -> 一个具体的分类属性。 还有一个理解是:$A \to B, A \sim B$ 一个例子: If X is the set of all cars, and ~ is the equivalence relation "has the same color as", then one particular equivalence class consists of all green cars. X/~ could be naturally identified with the set of all car colors.

  • 箭范畴 (Arrow categories) 一个范畴 $\mathcal {C}$ 的派生箭范畴 $\mathcal {C}^{\to}$, $ob (C)$ 是范畴 $\mathcal {C}$ 的所有箭头 $hom (C)$。 给定一个 $\mathcal {C}^{\to}$ 的对象 $f_1, f_2 | f_1 : X_1 \to Y_1, f_2 : X_2 \to Y_2$, 可以派生一个 $\mathcal {C}^{\to}$ 的箭头 $f_1 \to f_2$ 是一个匹配 $(j, k) | j : X_1 \to Y_1, K : X_2 \to Y_2 \in hom (C)$,

  • 切片范畴 (Slice categories) 一个范畴 $\mathcal {C}$ 的派生切片范畴 $\mathcal {C}/I, I \in ob (C)$, $(A, f) \in ob (C/I) | A \in ob (C), f : A \to I \in hom (C)$, $j'' : (A, f) \to (B, g) \in hom (C/I) | j : A \to B, g \circ j = f, j \in hom (C)$, $1_{(A, f)} = 1_A : A \to A | 1_A \in hom (C)$ $j : (A, f) \to (B, g), k : (B, g) \to (C, h), k \circ j : (A, f) \to (C, h) | k \circ j \in hom (C)$

5: Kinds of arrows

Monomorphism vs Injective

  • definition: monomorphism An arrow $f : C\to D$ in the category $\mathcal {C}$ is a monomorphism (monic) if and only if it is left-cancellable.. left-cancellable - 左可消除。 i.e. for $g : B \to C$ and $h : B \to C$, if $f \circ g = f \circ h \implies g = h$

  • Theorem : the monomorphisms in Set are exactly the injective functions 意味着不是所有的范畴的单射都是单射方法。

  • Theorem : the monomorphisms in Grp are exactly the injective group homomorphisms

Epimorphism vs Surjective

  • definition: epimorphism An arrow $f : C\to D$ in the category $\mathcal {C}$ is a epimorphism (epic) if and only if it is right-cancellable.. right-cancellable - 右可消除。 i.e. for $g : B \to C$ and $h : B \to C$, if $g \circ f = h \circ f \implies g = h$

  • Theorem : the epimorphisms in Set are exactly the surjective functions 意味着不是所有的范畴的满射都是满射方法。

  • Theorem : the epimorphisms in Grp are exactly the surjective group epimorphisms

  • Theorem :

    1. 单位箭头总是单射,并且也是满射。
    2. 如果 f, g 是单射,$f \circ g$ 也是单射。
    3. 如果 f, g 是满射,$f \circ g$ 也是满射。
    4. 如果 $f \circ g$ 也是单射,则 g 是单射。
    5. 如果 $f \circ g$ 也是满射,则 f 是满射。

逆态射 (Inverses)

  • 定义:在范畴 $\mathcal {C}$ 中给定一个箭头 $f : C \to D$,
    1. $g: D \to C$ 是 f 的一个 right inverse,$\iff f \circ g = 1_D$.
    2. $g: D \to C$ 是 f 的一个 left inverse,$\iff f \circ g = 1_C$.
    3. $g: D \to C$ 是 f 的一个逆,如果 g 是 f 的左逆和右逆.

right 和 left 只是一个记号,没有方向性的含义。 可以这样想象:$C \to D$ C 在左边,D 在右边。 右逆:是从 D 出发,逆回到 D,$f \circ g = 1_D$; 左逆:是从 C 出发,逆回到 C,$g \circ f = 1_C$;

  • 定理:如果一个箭头有左逆和右逆,那么左逆和右逆是同一个,也是原箭头的逆。 $r = 1_C \circ r = (s \circ f) \circ r = s \circ (f \circ r) = s \circ 1_D = s$

  • 定理:

    1. 通常,不是每一个单态射都是右逆;(可能存在元素 $c | c \in C$ 在 D 中没有对应的元素。)
    2. 同样,不是每一个满态射都是左逆。(可能存在元素 $d_1, d_2 | d_1, d_2 \in D$ 同时指向 $c | c \in C$。)
    3. 但是,每一个右逆都是单态射,每一个左逆都是满态射。
  • 定理: 在 Set 中,每一个单态射是一个右逆,除了 $\emptyset \to D$。 同理,在 Set 中,推论 “每一个满态射是一个左逆” 是一个选择公理 (Axiom of Choice) 的一个版本。

  • 定义:section and retraction 如果 $g \circ f = 1_C$,f 也称为是 g 的一个部分态射 (section);g 称为是 f 的一个撤回态射 (retraction)。

  • 定义:split monomorphism and split spimonomorphism 如果 f 有一个左逆,那么 f 是一个拆分单态射; 如果 g 有一个右逆,那么 g 是一个拆分满态射。

同构 (Isomorphisms)

  • 同构 (isomorphism) 在范畴里的一个同构是一个有逆箭头。一般用 $\sim \over \longrightarrow$。

  • 定理

    1. 单位箭头是同构。
    2. 一个同构 $f: C \sim \over \longrightarrow D$,有一个唯一的逆,记为 $f^{-1} : D \sim \over \longrightarrow C$,存在以下性质:
    • $f^{-1} \circ f = 1_C$
    • $f \circ f^{-1} = 1_D$
    • (f^{-1})^{-1} = f
    • f^{-1} 是一个同构
    1. 如果 f 和 g 是同构,那么如果 $g \circ f$ 如果存在,也是一个同构。它的逆是 $f^{-1} \circ g^{-1}$。 比如:双射是一个同构。
  • 定理 如果 f 同时是单态射 (monic) 和拆分满态射 (split epic)(或者同时是满态射 (epic) 和拆分单态射),那么 f 是一个同构。

  • 定理 15 如果 f 和 g 是具有相同目标对象的单态射箭头。并且存在 i,j,有 $f = g \circ i, g = f \circ j$,那么因子 i 和 j 是同构态射,并且互为逆。

  • 定义:平衡的 (balanced) 范畴 $\mathcal {C}$ 是平衡的,当且仅当每一个箭头都是一个同构。

同构的对象 (Isomorphic objects)

  • 定义:同构的对象 (Isomorphic objects) 在范畴 $\mathcal {C}$ 中,一个同构 $f : C \sim \over \longrightarrow D$,那么对象 $C, D$ 称为在范畴 $\mathcal {C}$ 中被同构化,记做 $fC \sim \over \longrightarrow D$。

  • 定理 16 在范畴 $\mathcal {C}$ 中,一个对象之间的同构是一个等价关系。

  • 定理 17 在范畴 $\mathcal {C}$ 中,如果 $f : C \sim \over \longrightarrow D$,那么对于所有的对象 $X \in \matchcal {C}$,在箭头 $C \to X$ 和箭头 $C \to \Y$ 之间有一对一的对应。同样,存在一对一的对应在箭头 $X \to C$ 和箭头 $Y \to C$ 之间。

6 起点和终点对象 (Initial and terminal objects)

  • 定义:起点对象 (initial object) 在范畴 $\mathcal {C}$ 中,对象 $I$ 是起点对象,如果,对于每一个范畴中的对象 X,都有一个唯一的箭头 $! : I \to X$,可以记做 $!_x$。

  • 定义:终点对象 (terminal object) 在范畴 $\mathcal {C}$ 中,对象 $T$ 是终点对象,如果,对于每一个范畴中的对象 X,都有一个唯一的箭头 $! : X \to T$,可以记做 $!_x$。

  • 定义:空对象 (null object) 在范畴 $\mathcal {C}$ 中的空对象 $O$,如果,对于 $O$ 即是起点对象也是终点对象。

从唯一性到唯一性同构 (Uniqueness up to unique isomorphism)

  • 定理:起点对象之间是 “从唯一性到唯一性同构”。 在范畴 $\mathcal {C}$ 中,$I, J$ 是起点对象,则存在一个唯一的同构 $f : I \sim \over \longrightarrow J$。 对终点对象,亦然。 如果 $I$ 是一个起点对象,有 $f : I \sim \over \longrightarrow J$,则 $J$ 也是一个起点对象。

  • 定义:将起点对象记为 $0$,将终点对象记为 $1$

元素和通用化的元素 (Elements and generalized elements)

  • 定义:元素 在一个带有终点对象 $1$ 范畴 $\mathcal {C}$ 中,对象 X 的一个元素 (或者对象 X 的一个点) 是一个箭头 $f: 1 \to X$。

  • 定义: well-pointed 假设范畴 $\mathcal {C}$ 有一个终点对象,并且假设范畴 $\mathcal {C}$ 中的任意对象 $X, Y$,平行箭头 $f, g : X \to Y$,$f = g$ 如果 $f \circ x = g \circ x, \forall x : 1 \to X$,那么范畴 $\mathcal {C}$ 被称为 (well-pointed)。

  • 定理:拿出两个终点对象 $1$ 和 $1''$,定义两个不同类型的 X 的元素 $f_1 : 1 \to X$ 和 $f_2 : 1'' \to X$。范畴 $\mathcal {C}$ 对于第一个元素是 well-pointed,当且仅当范畴 $\mathcal {C}$ 对于第二个元素也是 well-pointed。

  • 定义:通用化的元素 (generalized elements) 在范畴 $\mathcal {C}$ 中,一个 $X$ 对象的(shape S 的)通用化元素 (generalized element) 是一个箭头 $e: S \to X$

  • 定理:在范畴 $\mathcal {C}$ 中,平行箭头是相同的,当且仅当它们在所有的通用化元素上都是相同的。

  • 定理:在范畴 $\mathcal {C}$ 中,点元素 $x: 1 \to X$ 都是单态射。

    每一个生命都是神圣不可侵犯的。 每一个生命都只是一粒尘埃。 我们既可以尊重每个生命,又可以对其随心所欲。就是这么矛盾。

7 乘积 (products)

结对模式

  • 定义: pairing schema, pair-objects, pairing function, un-pairing (projection) function 假设 X, Y, O 是对象的集合(它们可以是相同的或者是不同的)。 有 $pr: X, Y \to O$ 是一个二元函数 (tow-place function), 同时有 $\pi_1 : O \to X$ 和 $\pi_2 : O \to Y$ 是 one-place function。 这样 $[O, pr, \pi_1, \pi_2]$ 形成一个对 X、Y 的结对模式,当且仅当满足条件: a:π1(pr(x,y))=x&π2(pr(x,y))=y,xX,yY b:pr(π1(o),π2(o))=o,oO

    这样,O 被称为这个结对模式的结对对象 (pair-objects), $pr$ 为关联的结对函数 (pairing function), $\pi_1$ 和 $\pi_2$ 是反结对函数 (映射函数)(un-pairing or projection functions)

  • 定理:如果 $[O, pr, \pi_1, \pi_2]$ 是一个结对模式,那么:

    1. $pr$ 不同的输入对生成不同的结对对象。
    2. $pr, \pi_1, \pi_2$ 都是满射。
  • 定理: 如果 $[O, pr, \pi_1, \pi_2]$ 和 $[O, pr, \pi''_1, \pi''_2]$ 都是 X 和 Y 的结对模式,则 $\pi_1 = \pi''_1, \pi_2 = \pi''_2$。 如果 $[O, pr, \pi_1, \pi_2]$ 和 $[O, pr'', \pi_1, \pi_2]$ 都是 X 和 Y 的结对模式,则 $\pr = \pr''$。

  • 定理: 如果 $[O, pr, \pi_1, \pi_2]$ 和 $[O'', pr'', \pi''_1, \pi''_2]$ 都是 X 和 Y 的结对模式,则存在一个唯一的双射 (bijection)$f : O \to O''$,有 $pr''(x, y) = f (pr (x, y)), \forall x \in X, \forall y \in Y$。

  • 定理 假设 X, Y, O 是对象集合,和函数 $\pi_1 : O \to X, \pi_2 : O \to Y$,如果有一个唯一的 two-place 函数 $pr: X, Y \to O$,满足条件 (a): a:π1(pr(x,y))=x&π2(pr(x,y))=y,xX,yY

    则,$[O, pr, \pi_1, \pi_2]$ 满足条件 (b),从而形成一个结对模式。

  • 定义:乘积 如果 X, Y 是集合,那么 $[O, \pi_1, \pi_2]$ 形成一个 X 和 Y 的乘积, 这里面: O 是一个集合, $\pi_1 : O \to X$ 是一个函数, $\pi_2 : O \to Y$ 是一个函数, 有一个唯一的 two-place 函数:$pr : X, Y \to O$,有 $\pi_1 (pr (x, y)) = x \And \pi_2 (pr (x, y)) = y, \forall x \in X, \forall y \in Y$。

二元乘积

  • 定义:二元乘积 (binary product) 在任何一个范畴中,一个对于 X 和 Y 的二元乘积 $[O, \pi_1, \pi_2]$ 是一个对象 O 和映射箭头 $\pi_1 : O \to X, \pi_2 : O \to Y$ 的组合。 这样对于任何对象 $S$ 和箭头 $f_1 : S \to X, f_2 : S \to Y$,总有一个协调箭头 (mediating arrow)$u : S \to O$ 形成一个交换图。

  • 定义:楔子 (wedge) 对于 X 和 Y 的一个楔子是一个对象 S 和一对儿箭头 $f_1 : S \to X, f_2 : S \to Y$。 一个楔子 $[O, \pi_1, \pi_2]$ 是 X 和 Y 的乘积,当且仅当,对于 X 和 Y 的任何其它楔子 $[S, f_1, f_2]$,存在一个唯一的态射 $u : S \to O$ 形成一个交换图。

  • 定义:衍生楔子范畴 (derived wedge category) 给定一个范畴 $\mathcal {C}, X, Y \in Ob (\mathcal {C})$,衍生楔子范畴 (derived wedge category)$\mathcal {C}_{W (XY)}$ 是: 对象数据是 X 和 Y 的所有楔子 $[O, f_1, f_2]$; $[O, f_1, f_2]$ 和 $[O'', f''_1, f''_2]$ 的箭头是范畴 $\mathcal {C} 的箭头 $g : O \to O''$; $[O, f_1, f_2]$ 单位箭头是 $1_O$; 箭头组合相同于范畴 $\mathcal {C}$ 的箭头组合。

  • 定义:在 $\mathcal {C}$ 中,一个 X 和 Y 的乘积是衍生范畴 $\mathcal {C}_{W (XY)}$ 一个终点对象。

唯一同构

范畴 $\mathcal {C}$ 中,对于任意的对象 X 和 Y,乘积不一定存在;如果存在,也不一定唯一。

  • 定义:Uniqueness up to unique isomorphism 如果 $[O, \pi_1, \pi_2]$ 和 $[O'', \pi_1'', \pi_2'']$ 是对象 X 和 Y 的乘积, 那么存在一个唯一的同构 $f: O \sim \over \longrightarrow O''$ 联系与影射箭头 (有:$\pi_1'' \circ f = \pi_1, \pi_2'' \circ f = \pi_2$)。

协乘积 (co-product)

  • 定义:范畴化定义楔子的对偶 (the duals) 通常被称为协楔子。这样一个范畴 C 的协楔子是协范畴 $C^{op}$ 的一个楔子。

  • 定义:协乘积 (co-product) 范畴 $\mathcal {C}$ 中,对于任意的对象 X 和 Y,一个二元协乘积 $[O, l_1, l_2]$ 是: 一个对象 O, 两个影射箭头:$l1: X \to O, l2: Y \to O$。 这样,对于任何 S 和箭头 $f_1: X \to S, f_2 : Y \to S$,有一个唯一的协调箭头:$v : O \to S$ 形成一个交换图。 协乘积记为: $X \oplus Y$

8 探索乘积

  • 定理:在有一个终点对象的范畴中

    1. 存在乘积 $1 \times X$ 和 $X \times 1$,并且有 $1 \times X \simeq X \simeq X \times 1$。
    2. $X \times Y \simeq Y \times X$
    3. $X \times ( Y \times Z ) \simeq ( X \times Y ) \times Z$
  • 定理:有这样的范畴,其中总是存在乘积 $0 \times X$ 或者 $X \times 0$,但是这个乘积通常不同构与 0。

  • 定理 如果 $1 \overset {!_{1 \times X}}{\longleftarrow} 1 \times X \overset {i}{\longrightarrow} X$ 是一个乘积 则:$i$ 是一个同构。

  • 定义:调解箭头 (mediating arrow) 的一种表示 假设 $[O, \pi_1, \pi_2]$ 是一个对象 X 和 Y 的二元乘积,假设有一个楔子 $X \overset {f_1}{\Longleftarrow} S \overset {f_2}{\longrightarrow} Y$, 通过一个调解箭头 $u : S \to O$,形成一个交换图。 这个调解箭头 $u : S \to O$ 科表示为 $<f_1, f_2>$。

  • 定理: $<f_1, f_2> = <g_1, g_2> \implies f_1 = g_1, f_2 = g_2$。

  • 定理 对于乘积 $[X \times Y, \pi_1, \pi_2]$ 和箭头 $u: S \to X \times Y, v: S \to X \times Y$, 如果有 $\pi_1 \circ u = \pi_1 \circ v, \pi_2 \circ u = \pi_2 \circ v \implies u = v$。

  • 定义:对角态射 (diagonal morphism) 对于乘积 $[X \times X, \pi_1, \pi_2]$ 和箭头 $\pi_1: X \times X \to X, \pi_2: X \times X \to X$, 楔子 $X \overset {1_X}{\Longleftarrow} X \overset {1_X}{\longrightarrow} X$, 它们对应的调解箭头 $<1_X, 1_X>$ 为对角态射,记做 $\delta_x$。

  • 定理: $q: S \to X \implies \delta_x \circ q = <q, q>$。

  • 定理: $<f, g> \circ e = <f \circ e, g \circ e>$

  • 定理: 给定平行箭头 $f_1: S \to X, f_2 : S \to X, f_1 \neq f_2$,那么至少有 4 个箭头 $S \to X \times X$。

两个乘积之间的匹配

  • 定义:两个乘积之间的匹配: $f \times g$

f:XX g:YY [X×Y,π1,pi2] [X×Y,π1,π2] f×g:X×YX×Y π1f×g=fπ1 π2f×g=gπ2

  • 定理: 假设 $f: X \to X, g: Y \to Y, o: X \times Y \to Y \times X {(x, y) \to (y, x)}$, 得出:$(f \times g) \cirs o = (g \times f) \circ o$。

  • 定理: 存在双箭头 $f, g: X \to Y$,和乘积 $X \times X, Y \times Y$, 则:楔子 $<f, g> = (f \times g) \circ \theta_x$。

  • 定理 37 有平行箭头 $f: X \to X'', j: X'' \to X", g: Y \to Y'', k: Y'' \to Y"$, 和乘积 $[X \times Y, \pi_1, \pi_2], [X'' \times Y'', \pi''_1, \pi''_2], [X"\times Y", \pi"_1, \pi"_2]$, 则:$(j \times k) \circ (f \times g) = (j \circ f) \times (k \circ g)$。

有限元乘积

  • 定义 44:有限元乘积 对于 $X_1, \cdots, X_n$ 的乘积 $O, \pi_1, \cdots, \pi_n$, 对于任意的 S 和箭头 $f_i : S \to X_i$,存在一个唯一的协调箭头 $u: S \to O$,$f_i = \pi_i \circ u$

  • 定理 38 在一个范畴里,对于 $X_1, X_2, X_3$, 如果有三元乘积 $[O, \pi_1, \pi_2, \pi_3]$ 和 $O, \pi''_1, \pi''_2, \pi''_3$, 那么存在一个唯一的同构 $u: O \simeq O''$

  • 定理 39 $(X_1 \times X_2) \times X_3$ 形成一个 $X_1, X_2, X_3$ 的三元乘积。

  • 定义 45: 范畴 $\mathcal {C}$ 有所有的二元乘积,$\iff$ 对于任意的两个对象,这个范畴都有乘积。 范畴 $\mathcal {C}$ 有所有的有限元乘积,$\iff$ 对于任意的 n 个对象,这个范畴都有 n 元乘积,$n \geqslant 0$。

  • 定理 40 范畴 $\mathcal {C}$ 有所有的有限元乘积,$\iff$ 这个范畴有一个终点对象,并且有所有的二元乘积。

无限乘积

  • 定义 46:无限乘积 (infinite products) 假设范畴 $\mathcal {C}$ 中,对象 $X_j$ 可以在一套索引 $J$ 中通过 j 索引,$J$ 是一个无限的。 如果,对于每个 $X_j$ 的乘积 $O$,有 $\pi_j : O \to X_j$, 同时需要对于任意的对象 $S$ 和箭头族 $f_j : S \to X_j$,有 $u : S \to O, \And f_j = \pi_j \circ u, \forall j$。

  • 定义 47: 范畴 $\mathcal {C}$ 有所有的乘积,$\iff$ 对于任意的对象 $X_j | j \in J$,这个范畴都有乘积,记做 $\prod_{j \in J}{X_j}$。

均衡器 (Equalizers)

  • 定义 48: 叉子 (fork) 一个叉子 (从 S 通过 X 到 Y),包含箭头 $k: S \to X, f: X \to Y, g: X \to Y, f \circ k = g \circ k$,是一个交换图。

  • 定义 49 均衡器 (Equalizer) 在一个范畴中,有平行箭头 $f, g : X \to Y$,一个均衡器:$E, e: E \to X$,需要满足以下条件:

    1. $f \circ e = g \cire e$,也就是说 E,X,Y 形成一个叉子。
    2. 任意的其它叉子 $S, X, Y, s: S \to X$,存在一个唯一的协调箭头 (mediating arrow)$u: S \to E$。

均衡器是一个约束 (limiting case)

  • 定义 50:叉子范畴 在范畴 $\mathcal {C}$ 中,$f,g:X \to Y$ 形成的叉子 $k: S \to X; g, f: X \to Y$, 可以得到一个衍生叉子范畴 $\mathcal {C_{F (fg)}}$,如下: 对象:每个 $S \to X; g, f: X \to Y$ 为一个对象; 箭头:$u: (S \to \cdots) \to (S'' \to \cdots)$ 是范畴 $\mathcal {C}$ 中的 $u : S \to S''$; 显而易见有交换图:$k = k'' \circ u$; 单位箭头:$1_{(S \to \cdots)} = 1_S$; 结合律:就是范畴 $\mathcal {C}$ 中的结合律。

  • 定义 51:叉子范畴的终点对象 在一个范畴中,平行箭头 $f, g : X \to Y$ 的均衡器:$E, e: E \to X$,其对应在衍生叉子范畴的对象是一个终点对象。

唯一性

  • 定理 41:均衡器之间存在唯一的同构 在范畴 $\mathcal {C}$ 中,$f,g:X \to Y$ 的均衡器 $[E, e], [E'', e'']$ 存在唯一的同构:$j: E \to E''$, 形成交换图:$e = e'' \circ j$。

  • 定理 42: 如果 $[E, e]$ 构成一个均衡器,那么 $e$ 是一个单态射 (monomorphism).

  • 定理 43: 一个满态射的均衡器是一个同构态射。

协均衡器 (co-equalizers)

  • 定义 52: 协叉子 (co-fork) 一个协叉子 (从 X 通过 Y 到 S),包含箭头 $f, g: X \to Y; k: S \to X,; \And k \circ f = k \circ g$。

  • 定义 53 协均衡器 (Co-Equalizer) 在一个范畴中,有平行箭头 $f, g : X \to Y$,一个协均衡器:$C, c: Y \to C$,需要满足以下条件:

    1. $c \circ f = c \cire g$,也就是说 C,X,Y 形成一个协叉子。
    2. 任意的其它协叉子 $S, X, Y, s: Y \to S$,存在一个唯一的协调箭头 (mediating arrow)$u: C \to S$。
  • 定义 R 对于平行箭头 $f,g: X \to Y$,可以引出一个对于对象 Y 的元素之间的关系 R (或者记做 $R_{fg}$)。 $yRy''$ 意味着 $f (x) = y \And g (x)= y'', \exists x \in X$。 在一个协叉子中,意味着 $yR_{fg} y''\implies k (y) = k (y'')$,有记做 $y \equiv_k y''$。

  • 定义 R 的最小等价关系 (the smallest equivalence relation R) $R~$ $R^~$ 需要包括一个箭头 $c: Y \to C, c (y) = c (y'') \iff yRy''$,或者说 $\equiv_c = R~$。

  • 定理 44 $C = Y/R~; c: Y \to C$,c 映射 y 到包含 y 的 C 元素上。$[C, c]$ 构成一个 $f, g$ 的协均衡器。 举例: $Y = [a, a'', b, b'', d, d''], aRa'', bRb'', dRd''$ $C = Y/R~ = [[a, a''], [b, b''], [d, d'']]$ $c (a) = [a, a'']$

10 限制和协限制 (limits and co-limits defined)

锥 (cone)

  • 定义 图表 (diagram) 一个基于范畴中的 diagram,是一些(或者没有)对象 $D_j$,这些对象可以按照索引 $J$ 通过序号 $j$ 来定位,和一些 (或者没有)$D_j$ 之间的箭头。

  • 定义 54 图表的锥 (cone) 对于一个图表 D 的锥 (cone over a diagram),其构成为 $[C, c_j: C \to D_j] | j \in J]$, 并且对于图表中的任意箭头 $d: D_i \to D_j$,有交换关系 $c_j = d \circ c_i$。

  • 定义 55 图表的闭包 (closure) 对于一个 ** 图表 D 的闭包 (closure)** 是一个最小的图表,并包含:

    1. D 的所有对象和箭头
    2. D 所有对象的单位箭头
    3. 如果有两个箭头的可组合的 (compos-able),那么要包含它们的组合箭头。
  • 定理 45 一个闭包是一个子范畴。

  • 定理 46 如果,$[C, c_j]$ 是图表 D 的锥,则也是图表 D 的闭包的锥。

极限锥 (limit cone)

  • 定义 56 图表的极限锥 (limit cone) 图表 D 的极限锥 (limit cone)$[L, \lambda_j]$ 的满足条件: 对于图表 D 的任意一个锥 C,都存在一个唯一的协调箭头 $k: C \to L, \lambda_j \circ k = c_j | \forall j \in J$。

  • 定理 47 一个给定图表的所有极限锥之间,一对一之间都存在唯一的同构,这个同构与锥箭头之间形成了交换。

  • 定义 56 派生范畴:图表的锥范畴 一个范畴 $\mathcal {C}$ 中,对于图表 D,可以派生含有图表 D 上所有锥的范畴,记做 $\mathcal {C}_{C (D)}$:

    1. 对象:所有锥 $[C, c]$
    2. 箭头:任意 C 之间的箭头 $k: C \to C''$,并满足 $c''_j \circ k = c_j, j \in J$
    3. 单位对象:$1_C$
    4. 组合关系:箭头的原组合关系。
  • 定理 58 一个范畴 $\mathcal {C}$ 中,图表 D 的极限锥是图表的锥范畴 $\mathcal {C}_{C (D)}$ 的终点对象。

  • 定理 48 一个范畴 $\mathcal {C}$ 中,$[L, \lambda]$ 是图表 D 的极限锥, $[L'', \lambda'']$ 是图表 D 的锥,并且通过 $f: L'' \to L$ 构成一个同构, 则:$[L'', \lambda'']$ 是图表 D 的极限锥。

  • 定理 49 TBD

  • 定理 50 一个范畴 $\mathcal {C}$ 有一个起点对象,当且仅当范畴 $\mathcal {C}$ 作为一个图表有一个极限锥。

  • 定义 59 极限对象 对于一个图表 D 的一个极限锥,我们将位于这个极限锥的顶点的极限对象,自作 $\lim_{\rightarrow j} D_j$。

协极限 (colimits)

  • 定义 60: 协锥 (co-cone) 一个图表 D 的协锥 C,有:
    1. $c_j: D_j \to C, j \in J$
    2. $c_k = c_l \circ d, \forall d: D_k \to D_l$

撤回 (Pullbacks)

  • 定义 61:撤回,撤回正方形 (pullback square) 对于一个角图 (corner diagram) 的一个极限 (limit)$[L, \lambda_1: L \to D_1, \lambda_2: L \to D_2]$ 是一个撤回。 一个角图和极限组成一个撤回正方形 (pullback square)。 corner diagram: $D_1, D_2, D_3, d: D_1 \to D_3, e: D_2 \to D_3$。

  • 定理 51 撤回一个单态射,产生一个单态射。

  • 定理 52 $f: X \to Y$ 是一个单态射,当且仅当下面是一个撤回正方形: $1_X: X \to X, f: X \to Y$ $1_X: X \to X, f: X \to Y$

  • 定理 53 一个顶点为 Z 的角的撤回是商范畴 $\mathcal {C}/Z$ 的一个乘积。

推出 (pushout)

  • 定义 62:一个楔子图的极限是一个推出 (pushout)

11 极限的存在性

  • 定义 63:一个包含所有有限极限的范畴,被称为有限地完整。 有限极限:对于有限图 D(任意图包含 D,并拥有有限的索引 J)。

12 子对象 (sub-object)

13 指数 (Exponential)

14 组对象,自然数对象

15 函子 (Functor)

16 范畴的范畴 (Categories of categories)

17 函子和极限 (functors and limits)

18 同态函子 (Hom-functors)

19 函子和逗号范畴

20 自然的同构 (Natural isomorphisms)

21 自然的变形 (Natural transformations)

22 函子范畴 (Functor categories)

23 范畴的等价性 (Equivalent categories)

24 Yoneda 植入 (The Yoneda embedding)

25 Yoneda 推论 (The Yoneda Lemma)

26 可表达和统一元素 (Representables and universal elements)

27 Galois 连接 (Galois connections)

28 伴随的介绍 (Adjoints introduced)

  • 定义 125 伴随 (adjoint) 范畴 $\mathcal {A}, \mathcal {B}$,和函子 $F: \mathcal {B} \to B, G: \mathcal {B} \to \mathcal {A}$。 则 $F$ 是 $G$ 的左伴随,则 $G$ 是 $F$ 的右伴随,记做:$F \dashv G$。 前提条件: $\mathcal {B}(F (A), B) \simeq \mathcal {A}(A, G (B))$。

29 伴随的更多探索 (Adjoints further explored)

30 伴随函子和极限 (Adjoints functors and limits)

符号

Isomorphism: $\simeq$ iff: $\iff$

各种理解

  • 结合律的理解 结合律意味着可以在任何一个计算点开始计算。

  • 如何证明单射 (injective) 通过假设两个元素 e, e'' 的射结果相同,既 $f (e) = f (e'')$,如果可以推导出 $e = e''$,则 $f$ 是一个单射。

  • 如何证明满射 (surjective) 对于任何 $b \in B$,$f (a) = b, \exists a \in A$。

  • 如何证明同构 $\simeq$(isomorphism) 对于任何 $b \in B$,存在 $f (a) = b, a \in A$。

  • 交换图 各种表达:commuting with arrows, form a diagram commuting, triangle commutes, etc. 其中的含义是:从对象 A 到对象 B 存在两个相等的路径。

  • 协调箭头 (mediate arrows) 一种常见的交换图形式。总是以这样的形式出现: 有一组源对象和一个目标对象,存在:$[S_j, s_j: S \to T], j \in J$, 有一个对象 $[M, m: M \to T]$,对于每个源对象,存在唯一的: $k: S_j \to M; \And m \circ k = s_j$。 $k$ 就是协调箭头。 这里,似乎说明了 $[M, m]$ 有一种特性,存在一个等价的交换路径。

冯诺依曼 (Von Neumann) 的自然数定义

0= 1= 2=, 3=,,,  n+1=nn

参照

  • Category Theory A Gentle Introduction by Peter Smith (University of Cambridge)
  • Wikipedia

class /classloader getResourceAsStream()与FileInputStream

class /classloader getResourceAsStream()与FileInputStream

https://cloud.tencent.com/developer/ask/28683

 

getResourceAsStream()通过classname的类加载器加载文件。如果类来自JAR文件,那么就会从JAR文件中加载资源。

FileInputStream用于从文件系统读取文件。

 

https://blog.csdn.net/buster2014/article/details/53787224

props.load(new FileInputStream("db.properties")); 是读取当前目录的db.properties文件

getClass.getResourceAsStream("db.properties"); 是读取当前类所在位置一起的db.properties文件

getClass.getResourceAsStream("/db.properties"); 是读取ClassPath的根的db.properties文件,注意ClassPath如果是多个路径或者jar文件的,只要在任意一个路径目录下或者jar文件里的根下都可以,如果存在于多个路径下的话,按照ClassPath中的先后顺序,使用先找到的,其余忽略.

 

 

彻底搞懂Class.getResource和ClassLoader.getResource的区别和底层原理

Class.getResource和ClassLoader.getResource 最终调用的是ClassLoader 类的getResource方法。只不过Class.getResource是先调用Class 的 getResource 方法,在这个getResource  方法中,再去调用ClassLoader 类的getResource方法

那么Class类中的getResource方法做了什么呢,主要的一句是 name = resolveName(name); 
---------------------
作者:张守康
来源:CSDN
原文:https://blog.csdn.net/zhangshk_/article/details/82704010
版权声明:本文为博主原创文章,转载请附上博文链接!

 

设class包完整名为a.b.c
class.getResource  获取当前类加载器及其父加载器下a.b.c/下的资源
classloader.getResource  获取当前类加载器及其父加载器下所有jar包内资源(取第一个)
 
 (而且会优先级为 父加载器——不一定本jar包(即执行代码的所在jar包)的子加载器所有jar包随机
——classloader getresource jar包资源冲突情况,父亲为大,兄弟之间,谁先加载谁牛逼)
 
class.getResource(“/“) = classloader.getResource(“”)
 
所以从包名限定的角度说,前者比后者保险,假设2个jar包resource下都有资源文件a,则运行期具体拿哪个未知,但如果a有个性的包名,则冲突的可能性就大大降低
 
System.out.println(FingerPrint.class.getResource(""));
        System.out.println(FingerPrint.class.getClassLoader().getResource(""));
        System.out.println(FingerPrint.class.getResource("/"));
        System.out.println(FingerPrint.class.getClassLoader().getResource("/"));

        System.out.println(FingerPrint.class.getResource(""));
        System.out.println(FingerPrint.class.getClassLoader().getResource("expire.png"));
        System.out.println(FingerPrint.class.getResource("/expire.png"));
        System.out.println(FingerPrint.class.getClassLoader().getResource("/"));

 

jar:file:/Users/sunyuming/.m2/repository/com/jds/fast/fid-common/1.0.2/fid-common-1.0.2.jar!/com/jds/fid/fid_common/
file:/Users/sunyuming/work/MyTest/target/classes/  证明有可能先从本jar包读,从而忽略FingerPrint所在jar包中的资源
file:/Users/sunyuming/work/MyTest/target/classes/
null
jar:file:/Users/sunyuming/.m2/repository/com/jds/fast/fid-common/1.0.2/fid-common-1.0.2.jar!/com/jds/fid/fid_common/
jar:file:/Users/sunyuming/.m2/repository/com/jds/fast/fid-common/1.0.2/fid-common-1.0.2.jar!/expire.png
jar:file:/Users/sunyuming/.m2/repository/com/jds/fast/fid-common/1.0.2/fid-common-1.0.2.jar!/expire.png
null

 

可以看到,classloader的getResource可能先在本jar包(即执行代码的所在jar包)内寻找,所以如果本jar包resource下也有一个expire.png,就会找错

具体来说,是从本jar包先,还是其它情况,请看:classloader getresource jar包资源冲突情况,父亲为大,兄弟之间,谁先加载谁牛逼

 

2020.1.7

并不是class.getresource所有场景都有用的,当src下放着你的resource,而不是resource目录下,你就要注意了

使用resource中的jar包资源作为UrlClassloader

关于JVM第三天 Java Class File structurejvm classpath的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于ASM ClassReader failed to parse class file - probably due to a new Java class file version that i...、ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn''、Category Theory: 01 One Structured Family of Structures、class /classloader getResourceAsStream()与FileInputStream等相关内容,可以在本站寻找。

本文标签: