Each program that you have written consists of Java code that resides in a single .java file. For large programs, keeping all the code in a single file is restrictive and unnecessary. (不能把所有代码都放在一个文件中,也不可能) Fortunately, it is very easy in Java to refer to a method in one file that is defined in another. This ability has two important consequences on our style of programming:
It allows us to extend the Java language by developing libraries of static methods for use by any other program, keeping each library in its own file. (静态方法库)
It enables modular programming, where we divide a program up into static methods, grouped together in some logical way. (模块化编程)
Using static methods in other programs.
To refer(引用) to a static method in one class that is defined in another, you must make both classes accessible to Java (for example, by putting them both in the same directory in your computer). Then, to call a method, prepend its class name and a period separator. For example, SAT.java calls the cdf() method in Gaussian.java, which calls the pdf() method, which calls the exp() and sqrt() methods in Math.

We describe several details about the process.
The public keyword. The public modifier identifies the method as available for use by any other program. You can also identify methods as private, but you have no reason to do so at this point.
Each module is a class. We use the term module to refer to all the code that we keep in a single file. By convention, each module is a Java class that is kept in a file with the same name of the class but has a .java extension. In this chapter, each class is merely a set of static methods.
The .class file. When you compile the program, the Java compiler makes a file with the class name followed by a .class extension that has the code of your program in a language more suited to your computer.
Compile when necessary. When you compile a program, Java typically compiles everything that needs to be compiled in order to run the program. For example, when you type javac SAT.java, the compiler will also check whether you modified Gaussian.java since the last time it was compiled. If so, it will also compile Gaussian.
Multiple main() methods. Both SAT.java and Gaussian.java have their own main() method. When you type java followed by a class name, Java transfers control to the machine code corresponding to the main() method defined in that class. (有多个main函数执行哪个?)
Libraries.
We refer to a module whose methods are primarily intended for use by many other programs as a library.
Clients. We use the term client to refer to a program that calls a given library method.
APIs. Programmers normally think in terms of a contract between the client and the implementation that is a clear specification of what the method is to do.
Implementations. We use the term implementation to describe the Java code that implements the methods in an API. (结合上图理解三个名词)

As an example, Gaussian.java is an implementation of the following API:

高斯分布概率密度函数(PDF)和累积分布函数(CDF)
https://blog.csdn.net/renwudao24/article/details/44465407
Random numbers.
StdRandom.java is a library for generating random numbers from various distributions.

设置随机数种子、均匀分布、高斯分布、置乱(运行并阅读代码)
Input and output for arrays.
StdArrayIO.java is a library for reading arrays of primitive types from standard input and printing them to standard output.

Iterated function systems.
An Iterated function system (IFS迭代函数系统) is a general way to produce fractals(分形) like the Sierpinski triangle or Barnsley fern. As a first example, consider the following simple process: Start by plotting a point at one of the vertices of an equilateral triangle. Then pick one of the three vertices(顶点) at random and plot a new point halfway between the point just plotted and that vertex. Continue performing the same operation.

Sierpinski.java simulates this process. Below are snapshots after 1,000, 10,000, and 100,000 steps.
Standard statistics.
StdStats.java is a library for statistical calculations and basic visualizations.





