程序员必知的技术官网系列--java篇

在我们的工作中我们会用到各种工具和技术,学习这些技术和工具是我们工作的必要的前提条件, 如何学习其中的知识, 有很多方式, 其中查阅官网资料是一个效率极高的学习方式. 本系列目标就想通过官网资料来达到快速学习和掌握的目的, 对这些技术的整体架构和模块功能有个整体性的把握.
关于java的学习资源有很多种:书籍,网络博客,java官网,java源码和开源项目等.

书籍
在这些资源中书籍的优势是知识点覆盖全面,知识讲述的比较透彻,但是缺点一是对于大部分人来说不够方便,二是需要一定技术基础,可能还需要一点读书的技巧(推荐一本书《如何阅读一本书》);
网络博客
网络博客的优势是获取方便, 博客中的代码例子和图示更为详细, 上手和理解都比较快, 缺点是知识点比较零散;
java官网
java 官网, 涉及的java学习资料和java相关的开发资源最全面,有各种技术原理和java的架构的描述, 还有java api 和工具的使用说明. 很多关于java的出版书籍里面很多内容都参考了官网. 另外包含了java最新的技术介绍, 如果想了解java的某个技术变迁和最新状况,那么官网应该是最好的资源了, 缺点是大部分文档都是英文, 需要有一定的英语能力, 不过配合各种翻译工具和在线英语教程,学习英语也不是难事了;
java源码和开源项目
java 源码和开源项目学习,这个难度更大, 但是对于那些对java整个体系有了一定掌握的程序员来说, 通过源码来研究和验证java所使用的技术的实现原理, 这对自身的技术能力和在工作编码时会有很大的帮助.

在上面资源中, 本文选择介绍下大部分java程序员都应该知道但是却不知道的java文档和资源--java官网.
java官网全面涵盖了java的学习资源和各种生产工具与资源, 下面就以官网的导航地图来介绍这些资源,这些资源主要分为两个大的子站:

  1. jdk 的下载和使用
    有jdk的各版本下载链接还有jdk的安装使用文档, 这个子站也有指向java文档某个具体子项的链接, 由于这个子站内容相对比较少, 所以本文只做简单的导航链接介绍

  2. java 文档
    java的开发指导文档,java语言规范,java虚拟机规范,api文档等等,这个子站的包含的java几乎所有的描述性文档资料, 所以除了会做导航介绍外,还会介绍几个比较重要的文档子项.

下面我们进入本文的主题

站点地图导航篇

1.oracle 官网

https://www.oracle.com/index.html

程序员必知的技术官网系列--java篇_第1张图片
oracle 官网导航栏

点击 [oracle 官网导航栏] 图中的 2.1, 进入https://www.oracle.com/java/

进入后往下拉到 Java SE

程序员必知的技术官网系列--java篇_第2张图片
java产品站点

2. java 资源站点

随后会进入 https://www.oracle.com/technetwork/java/javase/overview/index.html
可以看到如下图

程序员必知的技术官网系列--java篇_第3张图片
java资源导航站点

点击download页签会进入下载界面, 里面有各个版本的jdk下载链接,不过有一些比较旧的版本没有直接列在页面中
程序员必知的技术官网系列--java篇_第4张图片
java jdk下载界面

如果想下载比较旧的jdk, 可以拉到最下面, 看到已经jdk归档下载链接

程序员必知的技术官网系列--java篇_第5张图片
java jdk最下面的归档jdk链接,点击download

点击上图的download,进入历史版本jdk下载界面, 往下拉, 就可以看到历史版本的下载链接. (曾经有一个工作了3年的java程序员, 想下载jdk 7, 去官网居然没有找到下载入口, 被我嘲讽了, 不知道有没有类似的读者, 不过以后有同事问你们怎么找各个版本的jdk下载链接, 你们就可以秀一把了,嘿嘿嘿)
程序员必知的技术官网系列--java篇_第6张图片
历史版本的jdk下载

好了java资源站点先讲到这里,有兴趣的小伙伴可以点进去逛一逛.下面进入java 文档子站

3. java 文档子站

点击图片 oracle 官网导航栏 中的2.2可以进入到下面页面, 这里面包含了oracle各种产品的文档说明,很全面,其中那个带有一个咖啡杯和java文本的图标就是java文档的子站https://docs.oracle.com/en/

程序员必知的技术官网系列--java篇_第7张图片
oracle 文档导航

点击上图中的java文档连接,进入java文档子站, 可以看到下图.https://docs.oracle.com/en/java/index.html

程序员必知的技术官网系列--java篇_第8张图片
java 文档导航

点击 java se document 可以进入最新版java 13 的文档界面https://docs.oracle.com/en/java/javase/13/

程序员必知的技术官网系列--java篇_第9张图片
java 最新版文档

点击层级导航中的 Java SE, 可以进入历史版本的文档导航页 https://docs.oracle.com/en/java/javase/index.html

程序员必知的技术官网系列--java篇_第10张图片
java 历史版本文档导航

下面真正进入本文的重点, 以jdk 8 为例, 点击后进入 https://docs.oracle.com/javase/8/index.html, 如下图所示
程序员必知的技术官网系列--java篇_第11张图片
java 8文档导航说明

上图总共4个页签, 主要内容都在首页这一块, 其他三个页签是一些附属文档说明,客户端技术主要讲PC桌面应用的开发文档;嵌入式主要讲一些终端设备的开发,比如atm,路由器,视频会议终端等;所有书籍里面是前三个页签中的链接的清单.

首页页签下面总共有9块内容,上图已经给出了中文翻译,其中相关引用这块的内容是java的核心原理和架构说明, 其中包含了api,工具,开发者指南,java语言和虚拟机规范. api 和工具本次不做详细讲解, api链接里面描述的是java各大模块api列表, 可以看下各模块api所提供的功能.工具链接里面讲了编译,运行,监控,错误定位等工具的详细描述, 比如java, javac,jps, jstat,jmap,jstack等等工具.

我们重点看下 开发者指南 和 java语言和虚拟机规范 这两个链接的内容

4. 开发者指南 developer guide

点击 developer guide https://docs.oracle.com/javase/8/docs/index.html 可以可看到一个关于jdk和jre功能范围描述,下面的文本包含了官方英文原文和中文翻译.

4.1 jdk产品模块

Oracle has two products that implement Java Platform Standard Edition (Java SE) 8: Java SE Development Kit (JDK) 8 and Java SE Runtime Environment (JRE) 8.
oracle有两个产品实现了java平台标准版8:java 标准版开发包(JDK) 8和java标准版运行时环境(JRE) 8.
JDK 8 is a superset of JRE 8, and contains everything that is in JRE 8, plus tools such as the compilers and debuggers necessary for developing applets and applications.
jdk 8 是 jre的超集, 包含了jre的所有东西, 附加了一些开发插件和应用的必要的工具比如编译器和debug工具.
JRE 8 provides the libraries, the Java Virtual Machine (JVM), and other components to run applets and applications written in the Java programming language.
jre 8 提供了类库, java 虚拟机,和其他用来运行java语言编写的插件和应用的组件
Note that the JRE includes components not required by the Java SE specification, including both standard and non-standard Java components.
注意jre包含的组件并不是java 标准版本规范要求的, jre同时包含了标准和非标准的组件.
The following conceptual diagram illustrates the components of Oracle's Java SE products:
下面的概念图介绍了oracle的java 标准版本的产品

程序员必知的技术官网系列--java篇_第12张图片
oracle 实现的java 平台功能模块图

上图按职责范围来进行集合分类的图, 少了各部分依赖关系和交互关系, 我按照我的理解基于上图重新整理一张图. 其中增加了java 标准版本规范.

程序员必知的技术官网系列--java篇_第13张图片
oracle 实现的java 平台各模块依赖和交互图

原图中的各个模块中的文本是一个链接, 链接的页面包含该模块的详细介绍, 此处, 介绍一个模块 Java HotSpot Client and Server VM : https://docs.oracle.com/javase/8/docs/technotes/guides/vm/index.html

这个页面里面有一大段文字描述, 介绍了HotSpot虚拟机用到一些关键技术,下面是这段文字的翻译:

Java Virtual Machine Technology

java虚拟机技术

The JDK provides one or more implementations of the Java virtual machine (VM):

jdk 提供了一个或者多个java虚拟机实现

On platforms typically used for client applications, the JDK comes with a VM implementation called the Java HotSpot Client VM (client VM). The client VM is tuned for reducing start-up time and memory footprint. It can be invoked by using the -client command-line option when launching an application.
平台通常被客户端应用所使用, jdk 自带了一个虚拟机实现:java HotSpot client vm,简称 client VM. client VM 主要致力于减少启动时间和内存占用大小.可以在启动应用的时候使用命令行选项 -client来使用client VM.

On all platforms, the JDK comes with an implementation of the Java virtual machine called the Java HotSpot Server VM (server VM). The server VM is designed for maximum program execution speed. It can be invoked by using the -server command-line option when launching an application.
在所有平台上, jdk自带了一个java虚拟机实现叫作 Java HotSpot Server,简称(server VM). server VM被设计成最大化程序的执行速度. 可以在启动应用的时候使用命令行选项 -server 来使用 server VM.

Some features of Java HotSpot technology, common to both VM implementations, are the following.

java HotSpot 的一些技术特性,上面两个虚拟机实现都具备这些特性,下面就是这些特性.

Adaptive compiler - Applications are launched using a standard interpreter, but the code is then analyzed as it runs to detect performance bottlenecks, or "hot spots". The Java HotSpot VMs compile those portions of the code for a boost in performance, while avoiding unnecessary compilation of seldom-used code (most of the program). The Java HotSpot VMs also use the adaptive compiler to decide, on the fly, how best to optimize compiled code with techniques such as in-lining. The runtime analysis performed by the compiler allows it to eliminate guesswork in determining which optimizations will yield the largest performance benefit.
适应性编译器 - 使用一个标准解释器加载标准应用程序,相反代码在运行时会进行性能瓶颈或代码执行热点检测的代码分析.java HotSpot 虚拟机 编译这部分有性能临界的代码以提升性能, 相反避免编译那些大部分很少用到的代码. java hotspot 虚拟机动态的决定使用适应性编译器,使用各种技术比如代码嵌入以达到最好的优化编译后的代码.编译器允许运行时分析决定哪中优化方式产生最大化的性能收益来消除猜测执行.

Rapid memory allocation and garbage collection - Java HotSpot technology provides for rapid memory allocation for objects, and it offers a choice of fast, efficient, state-of-the-art garbage collectors.
快速内存分配和垃圾回收--java HotSpot 技术给对象提供了快速内存分配,还提供了快速的,有效率的,最先进的垃圾回收器的选择

Thread synchronization - The Java programming language allows for use of multiple, concurrent paths of program execution (called "threads"). Java HotSpot technology provides a thread-handling capability that is designed to scale readily for use in large, shared-memory multiprocessor servers.
线程同步 -- java 编程语言支持使用多个,并发的程序执行路径(也就是线程).java HotSpot 技术提供了一个在大容量共享内存多处理器服务器上方便扩展的线程处理能力

Tools

工具

Some operating characteristics of the Java HotSpot VM can be controlled by the use of command-line flags. See the documentation for the Java application launcher for Microsoft Windows or Solaris, Linux, or OS X.
java HotSpot 的一些运行特性可以通过使用命令行参数来控制. java 应用程序启动器文档中有用于windows ,linux,Os X等操作系统的参数描述.

Java HotSpot Virtual Machine Garbage Collection Tuning Guide describes the garbage collectors included with the Java HotSpot VM and helps you decide which garbage collector can best optimize the performance of your application, especially if it handles large amounts of data (multiple gigabytes), has many threads, and has high transaction rates.
java HotSpot 虚拟机垃圾回收调整引导手册描述了 Java HotSpot 虚拟机中的一些垃圾回收器和帮助你决定使用哪一个垃圾回收器得到最好的性能优化给你的应用程序,尤其是如果在应用程序处理大量的数据,多线程,高事务处理率的情况下.

上面这段文字描述了oracle 虚拟机所使用的技术.这里讲到的 适应性编译器,内存分配和垃圾回收,和线程同步 技术, 并不属于 java标准版本规范(java语言规范java虚拟机规范)所要求的, 是规范实现厂商自己添加的技术特性.
除了这些描述性的文字, 这个页面下面还描述了jdk的一些增强特性.我们下一节就来介绍下这些官网声明的规范.

5. java语言和虚拟机规范

点击 图片 java 8文档导航说明 中的 java 语言和虚拟机规范 :https://docs.oracle.com/javase/specs/index.html, 如下图所示, 可以看到各个版本的java 语言和虚拟机规范, 每一个规范都提供了html和pdf两种查阅方式, 不过两者的内容是一样.

程序员必知的技术官网系列--java篇_第14张图片
java语言和虚拟机规范导航

5.1 java语言规范

在这里我们介绍这个规范目录所讲的大致内容, 挑了 章节一 中的引言中的章节介绍翻译一下 https://docs.oracle.com/javase/specs/jls/se8/html/jls-1.html
, 这样大家就能对语言规范有个大致的了解.

Introduction

引言

Table of Contents

内容列表

The Java® programming language is a general-purpose, concurrent, class-based, object-oriented language.
java程序语言是一个通用的,并发的,基于类继承的面向对象的语言.
It is designed to be simple enough that many programmers can achieve fluency in the language.
java程序语言设计的足够简单,这样大多数程序员就可以达到熟练使用这门语言.

The Java programming language is related to C and C++ but is organized rather differently,
java程序语言和c语言,c++语言属于同一个种类,但是java程序语言被组织成的结构是完全不同

with a number of aspects of C and C++ omitted and a few ideas from other languages included.
其中删去c语言和c++语言中的一些观点,另外从其他语言引进了一些新的观点

It is intended to be a production language, not a research language, and so, as C. A. R. Hoare suggested in his classic paper on language design, the design has avoided including new and untested features.
java 是一中倾向于工业生产的语言, 而不是一个用于研究工作的语言,正如发明快速排序的托尼·霍尔在他关于语言设计上的经典论文中建议的那样, 语言设计应该避免新的而且没有测试过的特性.

The Java programming language is strongly and statically typed.
java 程序语言是严格且静态类型的.

This specification clearly distinguishes between the compile-time errors that can and must be detected at compile time, and those that occur at run time.
本规范明确了必须在编译期检测到的编译时错误和运行时错误的不同.

Compile time normally consists of translating programs into a machine-independent byte code representation.
编译时通常包括将程序代码翻译为不依赖于操作系统的字节码形式.

Run-time activities include loading and linking of the classes needed to execute a program, optional machine code generation and dynamic optimization of the program, and actual program execution.
运行时的活动包括:程序运行时必要类的加载和链接;非必要的机器码生成和程序的动态优化;真正的程序运行.

The Java programming language is a relatively high-level language, in that details of the machine representation are not available through the language.
java 程序语言是一个相对的高级语言, 从语言层面是遮盖了机器展现形式的细节

It includes automatic storage management, typically using a garbage collector, to avoid the safety problems of explicit deallocation (as in C's free or C++'s delete).
它包含了自动化内存管理,典型的是使用一个垃圾收集器,避免了显示手动垃圾回收的安全问题.

High-performance garbage-collected implementations can have bounded pauses to support systems programming and real-time applications.
高性能的垃圾回收实现可以通过有限的暂停来支持系统编程和实时的应用程序

The language does not include any unsafe constructs, such as array accesses without index checking, since such unsafe constructs would cause a program to behave in an unspecified way.
java 语言不包含任何不安全的构造,比如无下标检查的数组访问, 因为这种不安全的构造会导致程序产生意想不到的行为.

The Java programming language is normally compiled to the bytecode instruction set and binary format defined in The Java Virtual Machine Specification, Java SE 8 Edition.
java 程序语言通常被编译成java 虚拟机规范中定义的二进制的格式的字节码指令集.

Organization of the Specification

规范的内容组织结构

Chapter 2 describes grammars and the notation used to present the lexical and syntactic grammars for the language.
章节2, 描述了java程序语言的语法和被用来组成词法和句法性语法的符号

Chapter 3 describes the lexical structure of the Java programming language, which is based on C and C++. The language is written in the Unicode character set. It supports the writing of Unicode characters on systems that support only ASCII.
章节3, 描述了java程序语言的词法结构,这种词法结构是基于c语言和c++语言的词法结构. java语言使用了unicode字符集进行编程. java语言也支持在仅支持ascii编码的系统上使用unicode字符.

Chapter 4 describes types, values, and variables. Types are subdivided into primitive types and reference types.
章节4 描述了类型,值,变量.类型分为原始类型和引用类型.

The primitive types are defined to be the same on all machines and in all implementations, and are various sizes of two's-complement integers, single- and double-precision IEEE 754 standard floating-point numbers, a boolean type, and a Unicode character char type. Values of the primitive types do not share state.
原始类型在所有机器和其具体实现的定义是相同,原始类型中整型(int),单精度浮点数(single)和双精度浮点数(double),布尔类型(bool),unicode字符类型(bool)的二进制补码是不一样的.原始类型的值是独享的.
Reference types are the class types, the interface types, and the array types. The reference types are implemented by dynamically created objects that are either instances of classes or arrays. Many references to each object can exist. All objects (including arrays) support the methods of the class Object, which is the (single) root of the class hierarchy. A predefined String class supports Unicode character strings. Classes exist for wrapping primitive values inside of objects. In many cases, wrapping and unwrapping is performed automatically by the compiler (in which case, wrapping is called boxing, and unwrapping is called unboxing). Class and interface declarations may be generic, that is, they may be parameterized by other reference types. Such declarations may then be invoked with specific type arguments.
引用类型是类(class)类型,接口类型,数组类型. 引用类型中的类类型和数组类型被实现成动态创建对象,对象要么是类类型的实例,要么是数组的实例.一个对象可以被多次引用.所有对象都支持在对象上使用Object类上的方法, Object类是所有类类型层次结构的根节点.预定义String类型支持unicode字符的字符串.有一些类类型是用来使用其对象来装箱原始类型值.很多情况下,装箱和拆箱是有编译器自动完成的.类和接口的声明定义可以是泛型的, 这意味着,其他引用类型可以作为泛型类类型和泛型接口类型的参数.这些泛型的声明定义在使用时需要传递具体的引用类型作为参数.
Variables are typed storage locations. A variable of a primitive type holds a value of that exact primitive type. A variable of a class type can hold a null reference or a reference to an object whose type is that class type or any subclass of that class type. A variable of an interface type can hold a null reference or a reference to an instance of any class that implements the interface. A variable of an array type can hold a null reference or a reference to an array. A variable of class type Object can hold a null reference or a reference to any object, whether class instance or array.
变量是带有类型的内存地址.原始类型的变量持有的是对应原始类型的值.一个类类型变量可以持有指向null引用地址,或者是其对应类型和其对应类型的子类的对象的引用地址.一个接口类型变量可以持有指向null的引用地址,或者是一个任何实现其接口类型的实例的引用地址.一个数组类型的变量可以持有指向null的引用地址,或者是一个数组的引用地址.Object类型的变量可以持有指向null引用地址或者其他任何对象的引用地址,无论是类的实例引用地址还是数组实例的引用地址.

Chapter 5 describes conversions and numeric promotions. Conversions change the compile-time type and, sometimes, the value of an expression. These conversions include the boxing and unboxing conversions between primitive types and reference types. Numeric promotions are used to convert the operands of a numeric operator to a common type where an operation can be performed. There are no loopholes in the language; casts on reference types are checked at run time to ensure type safety.
章节5 描述了类型转换和数值类型自动提升,类型转换改变的是编译时的类型,或者改变的一个表达式的值.这些转换包括原始类型和引用类型之间的装箱和拆箱转换.数值类型提升用来将一个能被执行到的运算符左右的操作数转换成相同的类型.为了保证语言没有漏洞;引用类型的转换会在运行时被检查,以保证类型安全.

Chapter 6 describes declarations and names, and how to determine what names mean (denote). The language does not require types or their members to be declared before they are used. Declaration order is significant only for local variables, local classes, and the order of initializers of fields in a class or interface.
章节6 描述了声明和命名,和如何确定名字的意义. 语言没有要求类型和其成员必须在使用前被声明. 声明的顺序只有对局部变量的声明和局部类的声明,还有类或者接口中的字段的初始化顺序来说很重要.
The Java programming language provides control over the scope of names and supports limitations on external access to members of packages, classes, and interfaces. This helps in writing large programs by distinguishing the implementation of a type from its users and those who extend it. Recommended naming conventions that make for more readable programs are described here.
java 程序语言提供了命名作用域的控制,而且支持对包成员,类成员,接口成员的外界访问限制.这对于大项目中区分类型的用户和谁能扩展类型提供了很大的帮助.同时这里也给出了更加具有可读性程序的命名习惯.

Chapter 7 describes the structure of a program, which is organized into packages similar to the modules of Modula. The members of a package are classes, interfaces, and subpackages. Packages are divided into compilation units. Compilation units contain type declarations and can import types from other packages to give them short names. Packages have names in a hierarchical name space, and the Internet domain name system can usually be used to form unique package names.
章节7 描述了程序的结构,程序的结构被组织成了各种包,这有点像模块化概念中的各种模块.包的成员是各种类,接口,还有子包. 每个包都是一个编译单元,每个编译单元包含了类型声明的短名称和从其他包里导入的类型的短名称.包是以一个层次性命名空间进行命名的,因特网域名系统通常被用来组成唯一的包名.

Chapter 8 describes classes. The members of classes are classes, interfaces, fields (variables) and methods. Class variables exist once per class. Class methods operate without reference to a specific object. Instance variables are dynamically created in objects that are instances of classes. Instance methods are invoked on instances of classes; such instances become the current object this during their execution, supporting the object-oriented programming style.
章节8 描述了类,类的成员包括类,接口,变量字段和方法.类变量只有一份存在类里面.类方法的调用可以不使用对象的引用.实例变量被动态的创建成对象,这些对象就是类的实例.实例方法需要在类的实例上进行调用,在方法的执行期间实例就成为了当前对象 this ,以此提供了面向对象编程的风格
Classes support single implementation inheritance, in which the implementation of each class is derived from that of a single superclass, and ultimately from the class Object. Variables of a class type can reference an instance of that class or of any subclass of that class, allowing new types to be used with existing methods, polymorphically.
类类型支持单实现继承,其中每一个实现类派生于单个父类,最终都派生于类Object.类类型的变量可以引用了那个类的实例或那个类的子类的实例,新类型可以使用已经存在的方法,而且这些都是多态的.
Classes support concurrent programming with synchronized methods. Methods declare the checked exceptions that can arise from their execution, which allows compile-time checking to ensure that exceptional conditions are handled. Objects can declare a finalize method that will be invoked before the objects are discarded by the garbage collector, allowing the objects to clean up their state.
类支持使用同步方法进行并发编程. 方法声明了在执行过程中可能抛出的受检异常, 这样做是为了保证异常状况在编译时期就能被处理到.
For simplicity, the language has neither declaration "headers" separate from the implementation of a class nor separate type and class hierarchies.
为了简单,java语言没有将声明头文件(C和C++用头文件提前声明类名,函数名)和类的实现分开,也没有分离类型和类类型的层次结构.
A special form of classes, enums, support the definition of small sets of values and their manipulation in a type safe manner. Unlike enumerations in other languages, enums are objects and may have their own methods.
一个特殊类类型:枚举, 支持定义少量的值集合和集合中的值上类型安全的操作.和其他语言中的枚举不一样的是,java中的枚举值也是object而且可以拥有自己的方法.

Chapter 9 describes interface types, which declare a set of abstract methods, member types, and constants. Classes that are otherwise unrelated can implement the same interface type. A variable of an interface type can contain a reference to any object that implements the interface. Multiple interface inheritance is supported.
章节9 描述了接口类型, 接口中声明了一系列的抽象方法,成员类型,常量.不相关的类可以实现相同的接口类型.一个接口变量可以引用任何一个实现了该接口的对象.支持多接口继承.
Annotation types are specialized interfaces used to annotate declarations. Such annotations are not permitted to affect the semantics of programs in the Java programming language in any way. However, they provide useful input to various tools.
注解类型属于特殊接口用来作注解声明.java程序语言中这种注解任何方面都不会影响程序的语义.然而,注解给各种工具提供了非常有用的输入.

Chapter 10 describes arrays. Array accesses include bounds checking. Arrays are dynamically created objects and may be assigned to variables of type Object. The language supports arrays of arrays, rather than multidimensional arrays.
章节10, 描述了数组, 数组访问包括了边界检查.数组是动态创建出来对象而且可以被赋值各种类型的对象变量.java程序语言提供数组的数组, 而不是多维数组.

Chapter 11 describes exceptions, which are nonresuming and fully integrated with the language semantics and concurrency mechanisms. There are three kinds of exceptions: checked exceptions, run-time exceptions, and errors. The compiler ensures that checked exceptions are properly handled by requiring that a method or constructor can result in a checked exception only if the method or constructor declares it. This provides compile-time checking that exception handlers exist, and aids programming in the large. Most user-defined exceptions should be checked exceptions. Invalid operations in the program detected by the Java Virtual Machine result in run-time exceptions, such as NullPointerException. Errors result from failures detected by the Java Virtual Machine, such as OutOfMemoryError. Most simple programs do not try to handle errors.
章节11 描述了异常,异常是不可恢复,完全整合了语言的语义和并发机制.java程序语言提供了三种类型的异常:受检异常,运行时异常,错误异常.编译器只保证方法和构造器上具有受检异常声明的那些异常会被合适的处理.这提供了编译时期检查异常处理器的存在,极大的保证了程序正常.大多数用户自定义异常应该被定义成受检异常.程序中的无效操作会在java 虚拟机的运行时被检测成运行时异常,比如NullPointerException. 错误异常来自于java 虚拟机的失败检查, 比如 OutOfMemoryError. 大多数简单的程序不会去处理错误异常.

Chapter 12 describes activities that occur during execution of a program. A program is normally stored as binary files representing compiled classes and interfaces. These binary files can be loaded into a Java Virtual Machine, linked to other classes and interfaces, and initialized.
章节12 描述了程序执行期间的活动.一个程序通常以存储成编译后的二进制类和接口文件.这些二进制文件会被加载到java虚拟机中,链接其他类和接口,然后被初始化.
After initialization, class methods and class variables may be used. Some classes may be instantiated to create new objects of the class type. Objects that are class instances also contain an instance of each superclass of the class, and object creation involves recursive creation of these superclass instances.
完成初始化后, 类方法和类变量就可以被使用了.一些类可能被实例化来创建新类类型对象.对象是类的实例,实例中包含了该类的每一个父类的实例,而且对象的创建包含了递归创建父类实例
When an object is no longer referenced, it may be reclaimed by the garbage collector. If an object declares a finalizer, the finalizer is executed before the object is reclaimed to give the object a last chance to clean up resources that would not otherwise be released. When a class is no longer needed, it may be unloaded.
当一个对象不在被引用,它就可能被垃圾回收器回收.如果一个对象声明了终结器:finalizer,终结器是对象被回收之前最后一次机会用来清理对象引用的资源,否则那些资源无法被释放.当一个类不再被需要,它就可能被卸载.

Chapter 13 describes binary compatibility, specifying the impact of changes to types on other types that use the changed types but have not been recompiled. These considerations are of interest to developers of types that are to be widely distributed, in a continuing series of versions, often through the Internet. Good program development environments automatically recompile dependent code whenever a type is changed, so most programmers need not be concerned about these details.
章节13 描述了二进制兼容性,明确了对那些还没有重新编译但是引用了修改类的类的影响.这些考虑是为了广泛分布开发者,他们通过网络使用具有连续版本号.好的程序开发环境任何时候改变一个类型都会自动重新编译,所以大所数程序员不需要关心这些细节.

Chapter 14 describes blocks and statements, which are based on C and C++. The language has no goto statement, but includes labeled break and continue statements. Unlike C, the Java programming language requires boolean (or Boolean) expressions in control-flow statements, and does not convert types to boolean implicitly (except through unboxing), in the hope of catching more errors at compile time. A synchronized statement provides basic object-level monitor locking. A try statement can include catch and finally clauses to protect against non-local control transfers.
章节14 描述了代码块和语句, 这些概念都是从c和c++中引进的.java 程序语言没有goto 语句,但是有break和continue语句. java编程语言和c在对boolean表达式的处理上不一样,分支控制语句要求使用boolean表达式,而且在除了拆箱外不会隐式将其他类型转换为boolean类型,这么做是为了在编译期捕获更多的错误.同步语句提供了基础的对象级别monitor锁.try语句包括catch和finally子句来保护非本地的执行流程控制转让(内部Exception会直接打断当前代码执行的流程)

Chapter 15 describes expressions. This document fully specifies the (apparent) order of evaluation of expressions, for increased determinism and portability. Overloaded methods and constructors are resolved at compile time by picking the most specific method or constructor from those which are applicable.
章节15 描述了表达式,这个文档完全明确了表达式的算值顺序,为了提高准确性和可移植性.重载的成员方法和构造方法会在编译时被解析到合适的而且最具体的方法和构造方法上.

Chapter 16 describes the precise way in which the language ensures that local variables are definitely set before use. While all other variables are automatically initialized to a default value, the Java programming language does not automatically initialize local variables in order to avoid masking programming errors.
章节16 描述了一种准确的方法,这种方法使得程序语言可以确保局部变量在使用前被定义赋值.同时其他变量被自动赋值为默认值, java程序语言不会自动初始化局部变量,这样可以避免掩盖程序错误.

Chapter 17 describes the semantics of threads and locks, which are based on the monitor-based concurrency originally introduced with the Mesa programming language. The Java programming language specifies a memory model for shared-memory multiprocessors that supports high-performance implementations.
章节17 描述了线程和锁的含义, 这些都是基于源自 Mesa 程序语言提出的monitor-based 并发性.java程序语言明确了一个多处理器共享内存下的内存模型,这都是为了支持高性能的实现.

Chapter 18 describes a variety of type inference algorithms used to test applicability of generic methods and to infer types in a generic method invocation.
章节18 描述使用不同类型接口算法测试泛型方法的适用性和泛型方法调用时的类型推断

Chapter 19 presents a syntactic grammar for the language.
章节19 展示了语言的句法.

总结一下

语言规范重点从java语言抽象定义出来的数据结构和语法,讲解这些数据结构和语法之间的关系和使用方法, 以及如何使用这些数据结构和语法来形成语义和运行时的上下文.其中还明确了代码所使用的字符集. 除此之外, 还明确了java应用执行期间的加载,链接,初始化,实例创建,实例的终结,卸载,程序退出的流程关键节点.

可以看出来语言规范定义了更靠近人类自然语言观念中抽象概念和流程约定. 其中流程约定后面要讲的虚拟机规范息息相关. 因为这块内容是在虚拟机规范中有明确规定. 好的,现在我们进入下一个主题.

5.2 java虚拟机规范

java 虚拟机规范,我也挑选了章节一中的引言描述的内容, 这样可以对虚拟机规范中的内容先有个整体的结构认识.https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-1.html

A Bit of History

一小段历史

The Java® programming language is a general-purpose, concurrent, object-oriented language. Its syntax is similar to C and C++, but it omits many of the features that make C and C++ complex, confusing, and unsafe. The Java platform was initially developed to address the problems of building software for networked consumer devices. It was designed to support multiple host architectures and to allow secure delivery of software components. To meet these requirements, compiled code had to survive transport across networks, operate on any client, and assure the client that it was safe to run.
java程序语言是一个通用,并发,面向对象的语言. 他的语法和c,c++很像,但是他省略了那些使c和c++变得复杂,令人迷惑,和不安全的特性.java 语言一开始被开发出来是用于定位在造构建网络消费者终端软件过程中的问题.java 被设计出来支持多主机架构和准许可靠的软件组件传输.为了满足这些需求,编译后的代码可以通过网路进行传输,在任何一个客户端,而且保证客户端能安全的运行.

The popularization of the World Wide Web made these attributes much more interesting. Web browsers enabled millions of people to surf the Net and access media-rich content in simple ways. At last there was a medium where what you saw and heard was essentially the same regardless of the machine you were using and whether it was connected to a fast network or a slow modem.
万维网的推广使得这些属性更加有趣了. Web浏览器使得数以百万的人们在网络冲浪而且以简单的方式访问富媒体化的内容.最后你看到的和听到的本质上都是一样的的媒介, 无论你使用的机器连接的是快速的网络还是慢的调制解调器.

Web enthusiasts soon discovered that the content supported by the Web's HTML document format was too limited. HTML extensions, such as forms, only highlighted those limitations, while making it clear that no browser could include all the features users wanted. Extensibility was the answer.
web爱好者很快就发现了web html 文档格式支持的内容太受限了. html 扩展,作为一种形式,只强调了这些限制,然而需要澄清的是没有浏览器能包含所有的用户想要的特性.

The HotJava browser first showcased the interesting properties of the Java programming language and platform by making it possible to embed programs inside HTML pages. Programs are transparently downloaded into the browser along with the HTML pages in which they appear. Before being accepted by the browser, programs are carefully checked to make sure they are safe. Like HTML pages, compiled programs are network- and host-independent. The programs behave the same way regardless of where they come from or what kind of machine they are being loaded into and run on.
HotJava浏览器第一次展示了java程序语言和平台有意思特性,通过将程序嵌入到HTML页面里面使满足所有用户想要的特性成为可能.程序通过明文随着展现html页面下载到浏览器中.浏览器在接受程序前,程序会被仔细的检查来保证程序是安全的. 和HTML 页面相似,编译后的程序是独立于网络和机器. 程序的行为是一致的而无视程序的来源或者什么类型的机器来加载和运行它.

A Web browser incorporating the Java platform is no longer limited to a predetermined set of capabilities. Visitors to Web pages incorporating dynamic content can be assured that their machines cannot be damaged by that content. Programmers can write a program once, and it will run on any machine supplying a Java run-time environment.
一个包含了java平台web浏览器不再受限于预置的功能集.对于用户,可以保证含有动态内容的Web页面不会危害他们的机器.程序员只用写一次程序, 然后在任何提供了java运行时环境的机器上运行.

The Java Virtual Machine

java 虚拟机

The Java Virtual Machine is the cornerstone of the Java platform. It is the component of the technology responsible for its hardware- and operating system-independence, the small size of its compiled code, and its ability to protect users from malicious programs.
java 虚拟机是java平台的基石. 虚拟机是独立于硬件和操作系统,编译后的代码体积小, 具备保护用户远离恶意程序的软件技术.

The Java Virtual Machine is an abstract computing machine. Like a real computing machine, it has an instruction set and manipulates various memory areas at run time. It is reasonably common to implement a programming language using a virtual machine; the best-known virtual machine may be the P-Code machine of UCSD Pascal.
java 虚拟机是一个抽象的计算机器.类似一个真的具备计算能力的机器, 它有一套指令集和在运行时操作不同的内存区域.使用虚拟机实现一个程序语言再普通不过了;最有名的虚拟机可能是加州大学圣地亚哥分校的 pascal语言的P-Code机器

The first prototype implementation of the Java Virtual Machine, done at Sun Microsystems, Inc., emulated the Java Virtual Machine instruction set in software hosted by a handheld device that resembled a contemporary Personal Digital Assistant (PDA). Oracle's current implementations emulate the Java Virtual Machine on mobile, desktop and server devices, but the Java Virtual Machine does not assume any particular implementation technology, host hardware, or host operating system. It is not inherently interpreted, but can just as well be implemented by compiling its instruction set to that of a silicon CPU. It may also be implemented in microcode or directly in silicon.
第一个java虚拟机实现原型是由Sun公司完成的.通过在一个类似个人助手的掌上设备上部署软件来模拟java虚拟机指令集. oracle当前的java虚拟机实现在手机,个人电脑和服务器设备上都进行了模拟,但是java虚拟机不假设任何特殊实现的技术,主机硬件,或者是主机操作系统.它不是一成不变的理解,可以将它的指令集编译成具体的cpu指令.java虚拟机也可以实现成中间码或者具体的cpu指令.

The Java Virtual Machine knows nothing of the Java programming language, only of a particular binary format, the class file format. A class file contains Java Virtual Machine instructions (or bytecodes) and a symbol table, as well as other ancillary information.
java 虚拟机和java程序语言没有任何直接联系, 他们之间通过特殊的二进制的类文件格式进行交互. 一个类文件包含了java虚拟机指令集(或者说字节码)和符号表,还有其他的辅助信息.

For the sake of security, the Java Virtual Machine imposes strong syntactic and structural constraints on the code in a class file. However, any language with functionality that can be expressed in terms of a valid class file can be hosted by the Java Virtual Machine. Attracted by a generally available, machine-independent platform, implementors of other languages can turn to the Java Virtual Machine as a delivery vehicle for their languages.
出于安全的缘故, java虚拟机采用了对类文件中的代码进行强语义和结构化约束.然而, 任何具有功能的代码都可以表述成一个可以加载到java虚拟机的有效类文件中的多个条目.

The Java Virtual Machine specified here is compatible with the Java SE 8 platform, and supports the Java programming language specified in The Java Language Specification, Java SE 8 Edition.
这里符合规范的java虚拟机兼容java标准平台8,而且支持符合java语言规范的java程序语言,java标准版第8版.

Organization of the Specification

规范的组织结构

Chapter 2 gives an overview of the Java Virtual Machine architecture.
章节2 java虚拟机架构概览

Chapter 3 introduces compilation of code written in the Java programming language into the instruction set of the Java Virtual Machine.
章节3 介绍了将java代码编译成java虚拟机指令集的过程

Chapter 4 specifies the class file format, the hardware- and operating system-independent binary format used to represent compiled classes and interfaces.
章节4 明确了类文件格式:使用接近硬件和独立于操作系统的二进制格式用来表示编译后类和接口

Chapter 5 specifies the start-up of the Java Virtual Machine and the loading,linking, and initialization of classes and interfaces.
章节5 明确了java虚拟机的启动,加载,链接和类与接口的初始化过程.

Chapter 6 specifies the instruction set of the Java Virtual Machine, presenting the instructions in alphabetical order of opcode mnemonics.
章节6 明确了java虚拟机的指令集,指令集是由字母操作码助记符组成

Chapter 7 gives a table of Java Virtual Machine opcode mnemonics indexed by opcode value.
章节7 按照操作码助记符的值进行排序的java虚拟机操作码助记符

总结一下

章节2:描述了java虚拟机运行时的涉及到一些数据结构,这些数据结构主要是用来承载运行时从类文件中解析,加载类用到的,以及执行流程的上下文和对物理机资源的封装用到的.
章节3:如何将java源码编译成java虚拟机中间码,源码中的各种信息会转译成各种和中间码相关的数据结构,不过这里不包含将中间码转译成具体cpu的指令的内容,将中间码转译成具体cpu指令的功能由JIT提供. 有关中间码数据结构, 由于编译器需要将源码编译成虚拟机能理解的格式, 所以这个中间码数据结构, 编译器和虚拟机都肯定会用到. 编译器在这里就成为了java 语言规范和java虚拟机规范 之间的沟通桥梁. 另外这一章的中间码数据结构和上一章的数据结构是有一定联系, 上一章用到的数据结构实际包含了本章的数据结构, 不过上一章主要是对运行时非本章数据结构进行了讲述.
章节4:将章节3 中数据结构和其辅助描述信息以一种具体的结构格式序列化然后存储成文件(类文件).
章节5:读取章节4产生的类文件,然后解析成章节2和3的数据结构,以及程序运行过程中的类的加载,检查,解析,链接,初始化,卸载,退出等流程.
章节6:描述了指令集的功能, 以及使用方式.
章节7:指令集助记符列表.

实际上java语言和虚拟机规范是java平台的核心, jdk和jre实际上是oracle两款符合规范的产品, 这些内容通过刚才的官网资料描述我们也是能了解到的.

好了, 这就是本文要讲的内容, 通过官网的导航, 分别重点介绍了java资源站点的下载, 文档站点中的开发者指南与 java语言和虚拟机规范. 本文介绍的文档站点中的内容实际上可以对java的整体架构和功能模块有大致的了解. 其中还有很多细节本文没有讲, 不过这也不是本文的目的, 本文的目的就是让读者能对架构和功能有一个大致的了解, 引导读者对官网的资料有个整体的了解, 通过本文了解的内容能帮助读者通过官网资料进行学习时能够起到一个引导的作用.
本文完.

你可能感兴趣的:(程序员必知的技术官网系列--java篇)