JAVA编程思想的翻译
- 格式:pdf
- 大小:150.79 KB
- 文档页数:5
文档从互联网中收集,已重新修正排版,word格式支持编辑,如有帮助欢迎下载支持。
外文翻译原文及译文学院计算机学院专业计算机科学与技术班级学号姓名指导教师负责教师Java(programming language)Java is a general-purpose, concurrent, class-based, object-oriented computer program- -ming language that is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere" (WORA), meaning that code that runs on one platform does not need to be recompiled to run on another. Java applications are typically compiled to byte code (class file) that can run on any Java virtual machine(JVM) regardless of computer architecture. Java is, as of 2012, one of the most popular programming languages in use, particularly for client-server web applications, with a reported 10 million users. Java was originally developed by James Gosling at Sun Microsystems (which has since merged into Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++, but it has fewer low-level facilities than either of them.The original and reference implementation Java compilers, virtual machines, and class libraries were developed by Sun from 1991 and first released in 1995. As of May 2007, in compliance with the specifications of the Java Community Process, Sun relicensed most of its Java technologies under the GNU General Public License. Others have also developed alternative implementations of these Sun technologies, such as the GNU Compiler for Java and GNU Classpath.Java is a set of several computer software products and specifications from Sun Microsystems (which has since merged with Oracle Corporation), that together provide a system for developing application software and deploying it in across-platform computing environment. Java is used in a wide variety of computing platforms from embedded devices and mobile phones on the low end, to enterprise servers and supercomputers on the high end. While less common, Java appletsare sometimes used to provide improved and secure functions while browsing the World Wide Web on desktop computers.Writing in the Java programming language is the primary way to produce code that will be deployed as Java bytecode. There are, however, byte code compilers available forother languages such as Ada, JavaScript, Python, and Ruby. Several new languages have been designed to run natively on the Java Virtual Machine (JVM), such as Scala, Clojure and Groovy.Java syntax borrows heavily from C and C++, but object-oriented features are modeled after Smalltalk and Objective-C. Java eliminates certain low-level constructs such as pointers and has a very simple memory model where every object is allocated on the heap and all variables of object types are references. Memory management is handled through integrated automatic garbage collection performed by the JVM.An edition of the Java platform is the name for a bundle of related programs from Sun that allow for developing and running programs written in the Java programming language. The platform is not specific to any one processor or operating system, but rather an execution engine (called a virtual machine) and a compiler with a set of libraries that are implemented for various hardware and operating systems so that Java programs can run identically on all of them. The Java platform consists of several programs, each of which provides a portion of its overall capabilities. For example, the Java compiler, which converts Java source code into Java byte code (an intermediate language for the JVM), is provided as part of the Java Development Kit (JDK). The Java Runtime Environment(JRE), complementing the JVM with a just-in-time (JIT) compiler, converts intermediate byte code into native machine code on the fly. An extensive set of libraries are also part of the Java platform.The essential components in the platform are the Java language compiler, the libraries, and the runtime environment in which Java intermediate byte code "executes" according to the rules laid out in the virtual machine specification.In most modern operating systems (OSs), a large body of reusable code is provided to simplify the programmer's job. This code is typically provided as a set of dynamically loadable libraries that applications can call at runtime. Because the Java platform is not dependent on any specific operating system, applications cannot rely on any of the pre-existing OS libraries. Instead, the Java platform provides a comprehensive set of its own standard class libraries containing much of the same reusable functions commonly found in modern operating systems. Most of the system library is also written in Java. For instance, Swing library paints the user interface and handles the events itself, eliminatingmany subtle differences between how different platforms handle even similar components.The Java class libraries serve three purposes within the Java platform. First, like other standard code libraries, the Java libraries provide the programmer a well-known set of functions to perform common tasks, such as maintaining lists of items or performing complex string parsing. Second, the class libraries provide an abstract interface to tasks that would normally depend heavily on the hardware and operating system. Tasks such as network access and file access are often heavily intertwined with the distinctive implementations of each platform. The and java.io libraries implement an abstraction layer in native OS code, then provide a standard interface for the Java applications to perform those tasks. Finally, when some underlying platform does not support all of the features a Java application expects, the class libraries work to gracefully handle the absent components, either by emulation to provide a substitute, or at least by providing a consistent way to check for the presence of a specific feature.The success of Java and its write once, run anywhere concept has led to other similar efforts, notably the .NET Framework, appearing since 2002, which incorporates many of the successful aspects of Java. .NET in its complete form (Microsoft's implementation) is currently only fully available on Windows platforms, whereas Java is fully available on many platforms. .NET was built from the ground-up to support multiple programming languages, while the Java platform was initially built to support only the Java language, although many other languages have been made for JVM since..NET includes a Java-like language called Visual J# (formerly named J++) that is incompatible with the Java specification, and the associated class library mostly dates to the old JDK 1.1 version of the language. For these reasons, it is more a transitional language to switch from Java to the .NET platform, than a first class .NET language. Visual J# was discontinued with the release of Microsoft Visual Studio 2008. The existing version shipping with Visual Studio 2005will be supported until 2015 as per the product life-cycle strategy.In June and July 1994, after three days of brainstorming with John Gage, the Director of Science for Sun, Gosling, Joy, Naughton, Wayne Rosing, and Eric Schmidt, the team re-targeted the platform for the World Wide Web. They felt that with the advent of graphical web browsers like Mosaic, the Internet was on its way to evolving into the samehighly interactive medium that they had envisioned for cable TV. As a prototype, Naughton wrote a small browser, Web Runner (named after the movie Blade Runner), later renamed Hot Java.That year, the language was renamed Java after a trademark search revealed that Oak was used by Oak Technology. Although Java 1.0a was available for download in 1994, the first public release of Java was 1.0a2 with the Hot Java browser on May 23, 1995, announced by Gage at the Sun World conference. His announcement was accompanied by a surprise announcement by Marc Andreessen, Executive Vice President of Netscape Communications Corporation, that Netscape browsers would be including Java support. On January 9, 1996, the Java Soft group was formed by Sun Microsystems to develop the technology.Java编程语言Java是一种通用的,并发的,基于类的并且是面向对象的计算机编程语言,它是为实现尽可能地减少执行的依赖关系而特别设计的。
1. 《Java编程思想(第4版)》基本信息原书名:Thinking in Java (4th Edition)原出版社:Prentice Hall PTR作者:(美)Bruce Eckel [作译者介绍]译者:陈昊鹏丛书名:计算机科学丛书出版社:机械工业出版社ISBN:9787111213826上架时间:2007-6-19出版日期:2007年6月推荐语本书是全球程序员必备图书《Java编程思想》的最新版本(《Java编程思想(英文影印版.第4版)》)本书曾获:·被china-pub会员评为“2007年我最喜爱的十大技术图书”之一·2003年《Software Development》杂志最佳书籍Jolt大奖·2003年《Java Developer’s Journal》读者选择最佳书籍奖·2001年《Java World》编辑选择最佳书籍奖·2000年《Java World》读者选择最佳书籍奖·1999年《Software Development》杂志最佳产品奖·1998年《Java Developer’s Journal》编辑选择最佳书籍奖内容简介本书赢得了全球程序员的广泛赞誉,即使是最晦涩的概念,在bruce eckel的文字亲和力和小而直接的编程示例面前也会化解于无形。
从java的基础语法到最高级特性(深入的面向对象概念、多线程、自动项目构建、单元测试和调试等),本书都能逐步指导你轻松掌握。
从本书获得的各项大奖以及来自世界各地的读者评论中,不难看出这是一本经典之作。
本书的作者拥有多年教学经验,对c、c++以及java语言都有独到、深入的见解,以通俗易懂及小而直接的示例解释了一个个晦涩抽象的概念。
本书共22章,包括操作符、控制执行流程、访问权限控制、复用类、多态、接口、通过异常处理错误、字符串、泛型、数组、容器深入研究、java i/o系统、枚举类型、并发以及图形化用户界面等内容。
java英汉互译Java是一种广泛使用的编程语言,它是一种面向对象的语言,最初由Sun Microsystems开发。
Java的设计目标是让开发者编写一次代码,然后可以在不同的平台上运行,这种特性被称为“一次编写,到处运行”。
Java的语法与C++类似,但是Java具有更强的安全性和可移植性。
Java的英汉互译是Java English-Chinese Translation,它是指将Java程序中的英文单词翻译成中文,或将中文翻译成英文。
Java英汉互译在软件开发中非常重要,因为Java程序中的注释、变量名、方法名等都需要进行翻译,以便程序员能够更好地理解和维护代码。
Java英汉互译的实现方式有多种,其中最常用的是使用翻译工具或翻译软件。
这些工具可以自动将Java程序中的英文单词翻译成中文,或将中文翻译成英文。
翻译工具的优点是速度快、准确度高,但是由于语言的复杂性,翻译工具有时会出现错误或不准确的翻译结果。
除了翻译工具,Java程序员还可以使用在线翻译网站或翻译软件进行英汉互译。
这些工具可以帮助程序员快速翻译Java程序中的英文单词,但是需要注意的是,翻译结果需要进行人工校对,以确保翻译的准确性和可读性。
在进行Java英汉互译时,程序员需要注意以下几点:1. 翻译结果需要符合语法规范,以便程序能够正常运行。
2. 翻译结果需要准确无误,以避免程序出现错误或漏洞。
3. 翻译结果需要易于理解和维护,以便程序员能够快速定位和修复问题。
总之,Java英汉互译是Java程序员必备的技能之一,它可以帮助程序员更好地理解和维护代码,提高程序的可读性和可维护性。
在进行翻译时,程序员需要注意翻译结果的准确性和可读性,以确保程序的正常运行和稳定性。
Java语言与面向对象思想翻译(中英文)Java语言与面向对象思想Java,是由Sun Microsystems公司于1995年5月推出的Java程序设计语言和Java的总称。
用Java实现的Hot Java 浏览器(支持Java applet)显示了Java的魅力:跨平台、动态的Web、Internet计算。
从此,Java被广泛接受并推动了Web的迅速发展,常用的浏览器现在均支持Java applet。
1 Java语言的特点Java语言适用于Internet环境,是一种被广泛使用的网络编程语言,它具有如下的一些特点: 简单Java语言的语法规则和C++类似,但Java语言取消了指针和多重继承,统一使用引用来指示对象(C++中有两种形式,实际上是两种产生对象的途径,而Java 中只有一种),通过自动垃圾收集免去了程序设计人员对于内存块的释放工作。
面向对象(近于完全)Java语言为了提高效率,定义了几个基本的数据类型以非类的方式实现,余下的所有数据类型都以类的形式进行封装,程序系统的构成单位也是类。
因而几乎可以认为是完全面向对象。
平台无关性(可移植、跨平台)Java虚拟机(JVM)是在各种体系结构真实机器中用软件模拟实现的一种想象机器,必要时候可以用硬件实现。
当然,这些虚拟机内部实现各异,但其功能是一致的——执行统一的Java虚拟机指令。
Java编译器将Java 应用程序的源代码文件(.java)翻译成Java字节码文件(.class),它是由Java虚拟机指令构成的。
由于是虚拟机器,因而Java虚拟机执行Java程序的过程一般称为解释。
依赖于虚拟机技术,Java语言具有与机器体系结构无关的特性,即Java程序一旦编写好之后,不需进行修改就可以移植到任何一台体系结构不同的机器上。
从操作系统的角度看,执行一次Java程序的过程就是执行一次Java 虚拟机进程的过程。
面向网络编程Java语言产生之初就面向网络,在JDK中包括了支持TCP/IP、HTTP和FTP等协议的类库。
ThinkinginJava系列⽂档+代码+简评声明:本⼈⽆意侵犯原作者的版权,这⾥可下载的⽂档都属于作者⾃⾏开放下载的,统⼀放置在这⾥是因为不可预测的原因使得原⽂档和代码不⽅便下载,故将我所收集的内容统⼀在这⾥,如果这⾥的内容侵犯了别⼈,请告知我会第⼀时间删除,谢谢理解。
Java编程思想(英⽂第4版) , +Java编程思想是不是⼀本好书呢?当然,在书中作者详细解释了Java的起源和语⾔的特点,通过学习这本书可以知其(Java)然也可以知其所以然。
读懂这本书后,你不仅仅是个会写程序的编码⼯⼈,⽽是成为⼀个专业的程序员。
这本书可否作为⼊门书籍呢?其实,作为Java的⼊门也未尝不可,只是因为其庞⼤的块头和相对艰涩的内容会使⼤部分初学者半途⽽废。
如果完全没有编程功底的⼈,当然就不要以此⼊门了,这绝对是⾃虐。
如何快速学习这本书呢?直接看Java编程思想第3版,跳过第1章,从第2章开始所有理论知识都跳过,⼿⼯输⼊所有代码,调试成功,然后再回过头看相关理论知识,能看懂多少看多少,看不懂的留下来,等以后在实践中碰到了再回头学习。
如何深⼊学习这套书呢?有强⼤意志⼒的可以从第1版开始往后看,看到第4版就可以对Java语⾔的发展史有个深刻的理解,甚⾄对于程序设计语⾔的发展历史也会有所了解(这个很重要),因为所有的语⾔其实都是相通的。
⼀门语⾔理解以后,再学其他语⾔(如:C++、Python 等)都会明⽩这个语⾔的特点在哪⾥,为何要这样设计语⾔,⽤在什么场合下效果最好。
如果这个语⾔因为设计的需要缺少某些特性的时候,可以通过什么⽅法来解决。
例如:Java 1.4以前是没有泛型的,那么第3版就没有介绍泛型的使⽤,⽽第4版才引⼊了泛型,那么通过对⽐第3版和第4版,既可以深⼊理解泛型的好处,也可以知道如何通过其他⼿段来解决这个问题。
java中文翻译-回复Java中文翻译Java作为一种广泛使用的编程语言,其独特性和强大的功能使其成为开发人员和企业的首选。
然而,对于初学者来说,理解和掌握Java可能并不容易。
本文将以中括号内的内容为主题,为您一步一步回答有关Java中文翻译的问题,帮助您更好地掌握这门语言。
Java中文翻译的第一步是了解Java程序中各种元素的中文名称。
下面是一些常见的Java关键词和常用术语的中文对照表:1. 源代码(source code):程序员编写的Java代码。
2. 编译(compile):将源代码翻译成可以被计算机执行的机器语言代码。
3. 编译器(compiler):用于将源代码转换成可执行文件的软件工具。
4. 运行时(runtime):程序在计算机上执行的时期。
5. 类(class):Java程序的基本单元,包含了数据和方法。
6. 对象(object):具体的实例,是类的实体化。
7. 方法(method):类中定义的用于执行特定任务的函数。
8. 变量(variable):用于存储数据的内存区域。
9. 参数(parameter):方法接收的输入值。
10. 返回值(return value):方法执行后返回给调用方的值。
在掌握了Java编程中常见术语的中文对照后,可以开始编写代码并进行中文翻译。
Java中文翻译的第二步是翻译代码中的注释和标识符。
注释是对代码的解释和说明,通常用于提高代码的可读性。
标识符是用于标识变量、方法和类等元素的名称。
以下是一些常见的注释和标识符的中文译名建议:1. 单行注释(single line comment):对单行代码进行注释,使用“”符号表示。
2. 多行注释(multi-line comment):对多行代码进行注释,使用“/* ...*/”符号包裹注释内容。
3. 标识符规则(identifier rules):Java中标识符的命名规则,例如变量命名应以字母开头,后续可以是字母、数字或下划线。
Java基础60个常见英语词汇Java是一种可以撰写跨平台应用程序的面向对象的程序设计语言。
Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于PC、数据中心、游戏控制台、科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群。
学习Java对英语没有要求,但是代码和英语单词很像,并且一些的用法也很相同,因此掌握一些必要的英语词汇也很重要。
【1】object-oriented ,面向对象【2】object-oriented programming,面向对象编程【3】JDK:Java development kit, java开发工具包【4】JVM:java virtual machine ,java虚拟机【5】Compile:编绎【6】Run:运行【7】Class:类【8】Object:对象【9】 System:系统【10】out:输出【11】print:打印【12】line:行【13】variable:变量【14】type:类型【15】operation:操作,运算【16】array:数组【17】parameter:参数【18】method:方法【19】function:函数【20】member-variable:成员变量【21】member-function:成员函数【22】get:得到【23】set:设置【24】public:公有的【25】private:私有的【26】protected:受保护的【27】default:默认【28】access:访问【29】package:包【30】import:导入【31】static:静态的【32】void:无(返回类型)【33】extends:继承【34】parent class:父类【35】base class:基类【36】super class:超类【37】child class:子类【38】derived class:派生类【39】override:重写,覆盖【40】overload:重载【41】abstract:抽象【42】interface:接口【43】implements:实现【44】exception:异常【45】Runtime:运行时【46】ArithmeticException:算术异常【47】ArrayIndexOutOfBoundsException:数组下标越界异常【48】 NullPointerException:空引用异常【49】ClassNotFoundException:类没有发现异常【50】NumberFormatException:数字格式异常(字符串不能转化为数字) 【51】Try:尝试【52】Throws: (投掷)表示强制异常处理【53】Throwable:(可抛出的)表示所有异常类的祖先类【54】Lang:language,语言【55】Jdbc:java database connectivity,java数据库连接【56】DriverManager:驱动管理器【57】Connection:连接【58】Statement:表示执行对象【59】Preparedstatement:表示预执行对象【60】Resultset:结果集翡翠教育专注IT教育培训,以创新的教学方式和完善的就业服务享誉业内,已覆盖全国30多个城市,拥有70家教学中心。
java面向对象的理解
面向对象(Object-Oriented)是计算机编程的一种编程思想,它利用种
类和对象之间的关系,在这种方式下开发软件系统,它把一组功能相
关的数据 (或者信息)和功能或者行为封装在一个“对象” 里面。
这种思
想主要表现在编程语言的三个特征:封装、继承与多态。
以下是具体
的内容:
一、封装:
封装是指将数据和操作他的函数结合在一起,限制外界对这些数据的
访问,简而言之就是将对象的状态和行为封装在一起,形成独立的类,这样在程序执行和调试时,可以更加灵活、清晰,也便于复用。
二、继承:
继承是指当一个类(称作父类)的功能太多或者太过复杂时,可以将
其中一部分功能以被独立的类的形式复制出来(称作子类),子类获
得父类的全部功能,并且还可以有自己的独立功能,这样不仅简化了
程序实现(减少重复编程),还保持了代码可读性非常高。
三、多态:
多态是指一个类具有多个功能(例如,一类可以实现多种功能),这
个类可以根据不同的输入参数(例如,不同的输入参数可能导致不同
的输出),以不同的方式来实现多种功能,这样可以有效地实现程序
的功能扩展,提高程序的可维护性。
四、总结:
总的来说,面向对象的编程思想将一组相关的数据和功能封装在一起,并利用继承和多态的原理来简化程序的实现、提高代码的可维护性,
以此达到可复用的目的。
Java基础常见英语词汇(共70个) ['ɔbdʒekt]['ɔ:rientid]导向的['prəʊɡræmɪŋ]编程OO: object-oriented ,面向对象OOP: object-oriented programming,面向对象编程[dɪ'veləpmənt][kɪt]工具箱['vɜːtjʊəl]虚拟的JDK:Java development kit, java开发工具包JVM:java virtual machine ,java虚拟机['dʒɑːvə][mə'ʃiːn]机器[kəm'paɪl]Compile:编绎Run:运行['veərɪəb(ə)l] [ɒpə'reɪʃ(ə)n] [pə'ræmɪtə]variable:变量operation:操作,运算parameter:参数['fʌŋ(k)ʃ(ə)n]function:函数member-variable:成员变量member-function:成员函数[dɪ'fɔːlt] ['ækses] ['pækɪdʒ] [ɪm'pɔːt] ['stætɪk]default:默认access:访问package:包import:导入static:静态的[vɔid] ['peər(ə)nt] [beɪs] ['sjuːpə]void:无(返回类型) parent class:父类base class:基类super class:超类[tʃaɪld] [di'raivd] [əʊvə'raɪd] [əʊvə'ləʊd] child class:子类derived class:派生类override:重写,覆盖overload:重载['faɪn(ə)l] ['ɪmplɪm(ə)nts]final:最终的,不能改变的implements:实现[rʌn'taim] [æriθ'metik][ik'sepʃən]Runtime:运行时ArithmeticException:算术异常[ə'rei]['indeks] [baundz][ik'sepʃən] [nʌl] ['pɔintə]指针ArrayIndexOutOfBoundsException:数组下标越界异常Null Pointer Exception:空引用异常ClassNotFoundException:类没有发现异常['nʌmbə]['fɔ:mæt]NumberFormatException:数字格式异常(字符串不能转化为数字)[θrəuz]Throws: (投掷)表示强制异常处理Throwable:(可抛出的)表示所有异常类的祖先类[læŋ]['læŋɡwidʒ][ju'til] [,dis'plei] [ə'rei] [list]Lang:language,语言Util:工具Display:显示ArrayList:(数组列表)表示动态数组[hæʃ][mæp]HashMap: 散列表,哈希表[swiŋ] ['æbstrækt] ['windəu] ['tu:lkit]Swing:轻巧的Awt:abstract window toolkit:抽象窗口工具包[freim] ['pænl] ['leiaut] [skrəul] ['və:tikəl] Frame:窗体Panel:面板Layout:布局Scroll:滚动Vertical:垂直['hɔri'zɔntəl] ['leibl] [tekst] ['fi:ld]Horizontal:水平Label:标签TextField:文本框['εəriə] ['bʌtən] [tʃek] [bɔks]TextArea:文本域Button:按钮Checkbox:复选框['reidiəu] ['kɔmbəu] ['lisənə]Radiobutton:单选按钮Combobox:复选框Listener:监听['bɔ:də] [fləu] [ɡrid] ['menju:] [bɑ:]Border:边界Flow:流Grid:网格MenuBar:菜单栏['menju:] ['aitəm] ['pɔpʌp]Menu:菜单MenuItem:菜单项PopupMenu:弹出菜单['daiəlɔɡ] ['mesidʒ] ['aikɔn] [nəud]Dialog:对话框Message:消息Icon:图标Node:节点['dʒa:və]['deitəbeis] [,kɔnek'tivəti]Jdbc:java database connectivity :java数据库连接[draivə] ['mænidʒə] [kə'nekʃən] ['steitmənt]DriverManager:驱动管理器Connection:连接Statement:表示执行对象[pri'peəd] [ri'zʌlt]Preparedstatement:表示预执行对象Resultset:结果集['eksikju:t] ['kwiəri]executeQuery:执行查询Jbuilder中常用英文(共33个)[kləuz] [ik'sept] [peinz]Close all except…:除了..全部关闭Panes:面板组[bi:n] ['prɔpətiz] [meik] [bild] [,ri:'bild]Bean:豆子Properties:属性Make:编绎Build:编绎Rebuild:重编绎[ri'freʃ] ['prɔdʒekt] [di'fɔ:lt]Refresh:刷新Project properties:项目属性Default project properties:默认的项目属性[di:'bʌɡ] ['prefərənsiz] [kən'fiɡə] ['laibrəriz] Debug:调试Preferences:参数配置Configure:配置Libraries:库JSP中常用英文[,ju:ni'və:səl] [ri'sɔ:s] [ləu'keiʃən]URL: Universal Resource Location:统一资源定位符['intənet] [ik'splɔ:rə] ['dʒa:və] ['sə:və] [peidʒ]IE: Internet Explorer 因特网浏览器JSP: java server page:java服务器页面['mɔdəl] [kən'trəulə] ['tɔmkæt]Model:模型C:controller:控制器Tomcat:一种jsp的web服务器['mɔdju:l] ['sə:vlet][i'niʃəlaiz] ['sta:tʌp] WebModule:web模块Servlet:小服务程序Init: initialize,初始化Startup:启动['mæpiŋ][pə'ræmitə] ['seʃən] [,æpli'keiʃən] Mapping:映射Getparameter:获取参数Session:会话Application:应用程序['kɔntekst] [,ri:di'rekt] [dis'pætʃ] ['fɔ:wəd]Context:上下文redirect:重定向dispatch:分发forward:转交['ætribju:t] ['kɔntent] [taip]setattribute:设置属性getattribute:获取属性contentType:内容类型[tʃɑ:] [in'klu:d] [tæɡ][lib]charset:字符集include:包含tag:标签taglib:标签库[ik'spreʃən] ['læŋɡwidʒ][skəup] ['empti] EL:expression language,表达式语言Scope:作用域Empty:空['stændəd][tæɡ] ['laibrəri]JSTL:java standard tag library :java标准标签库[di'skripʃən] [kɔ:]TLD:taglib description,标签库描述符Core:核心Foreach:表示循环[va:(r)] ['vεəriəbl] ['steitəs] ['aitəm]Var:variable,变量Status:状态Items:项目集合['fɔ:mæt] [filtə]Fmt:format,格式化Filter:过滤器(报错英文['strʌktʃəz]Data Structures 基本数据结构['dikʃənəriz]Dictionaries 字典[prai'ɔrəti] [kju:z]Priority Queues 堆[ɡrɑ:f] ['deɪtə] ['strʌktʃəz]Graph Data Structures 图[set] ['deɪtə]['strʌktʃəz]Set Data Structures 集合[tri:s]Kd-Trees 线段树[nju:'merikəl] ['prɔ:bləms]Numerical Problems 数值问题[sɔlviŋ] ['liniə] [i'kweiʃənz]Solving Linear Equations 线性方程组['bændwidθ] [ri'dʌkʃən]Bandwidth Reduction 带宽压缩['meitriks] [,mʌltipli'keiʃən]Matrix Multiplication 矩阵乘法[di'tə:minənt] ['pə:mənənt]Determinants and Permanents 行列式[kən'streind] [ʌnkən'streɪnd] [,ɔptimai'zeiʃən]Constrained and Unconstrained Optimization 最值问题['liniə] ['prəuɡræmiŋ]Linear Programming 线性规划['rændəm] ['nʌmbə] [,dʒenə'reiʃən]Random Number Generation 随机数生成['fæktərɪŋ] [prai'mæləti] ['testɪŋ]Factoring and Primality Testing 因子分解/质数判定['ɑːbɪtrərɪ][prɪ'sɪʒən][ə'rɪθmətɪk]Arbitrary Precision Arithmetic 高精度计算['næpsæk] ['prɒbləm]Knapsack Problem 背包问题[dɪ'skriːt] ['fʊriər][træns'fɔːm]Discrete Fourier Transform 离散Fourier变换Combinatorial Problems 组合问题Median and Selection 中位数Generating Permutations 排列生成Generating Subsets 子集生成Generating Partitions 划分生成Generating Graphs 图的生成Calendrical Calculations 日期Job Scheduling 工程安排Satisfiability 可满足性Graph Problems -- polynomial 图论-多项式算法Connected Components 连通分支Topological Sorting 拓扑排序Minimum Spanning Tree 最小生成树Shortest Path 最短路径Transitive Closure and Reduction 传递闭包Matching 匹配Eulerian Cycle / Chinese Postman Euler回路/中国邮路Edge and Vertex Connectivity 割边/割点Network Flow 网络流Drawing Graphs Nicely 图的描绘Drawing Trees 树的描绘Planarity Detection and Embedding 平面性检测和嵌入Graph Problems -- hard 图论-NP问题Clique 最大团Independent Set 独立集Vertex Cover 点覆盖Traveling Salesman Problem 旅行商问题Hamiltonian Cycle Hamilton回路Graph Partition 图的划分Vertex Coloring 点染色Edge Coloring 边染色Graph Isomorphism 同构Steiner Tree Steiner树Feedback Edge/Vertex Set 最大无环子图Computational Geometry 计算几何Convex Hull 凸包Triangulation 三角剖分V oronoi Diagrams V oronoi图Nearest Neighbor Search 最近点对查询Range Search 范围查询Point Location 位置查询Intersection Detection 碰撞测试Bin Packing 装箱问题Medial-Axis Transformation 中轴变换Polygon Partitioning 多边形分割Simplifying Polygons 多边形化简Shape Similarity 相似多边形Motion Planning 运动规划Maintaining Line Arrangements 平面分割Minkowski Sum Minkowski和Set and String Problems 集合与串的问题Set Cover 集合覆盖Set Packing 集合配置String Matching 模式匹配Approximate String Matching 模糊匹配Text Compression 压缩Cryptography 密码Finite State Machine Minimization 有穷自动机简化Longest Common Substring 最长公共子串Shortest Common Superstring 最短公共父串DP——Dynamic Programming——动态规划recursion ——递归)报错英文第一章:JDK(Java Development Kit) java开发工具包JVM(Java Virtual Machine) java虚拟机Javac 编译命令java 解释命令Javadoc 生成java文档命令classpath 类路径Version 版本static 静态的String 字符串类JIT(just-in-time) 及时处理第二章:第三章:OOP object oriented programming 面向对象编程Object 对象Class 类Class member 类成员Class method 类方法Class variable 类变量Constructor 构造方法Package 包Import package 导入包第四章:Base class 基类Super class 超类Overloaded method 重载方法Overridden method 重写方法Public 公有Private 私有Protected 保护Static 静态Abstract 抽象Interface 接口Implements interface 实现接口第五章:RuntimeExcepiton 运行时异常ArithmeticException 算术异常IllegalArgumentException 非法数据异常ArrayIndexOutOfBoundsException 数组索引越界异常NullPointerException 空指针异常ClassNotFoundException 类无法加载异常(类不能找到)NumberFormatException 字符串到float类型转换异常(数字格式异常)IOException 输入输出异常FileNotFoundException 找不到文件异常EOFException 文件结束异常InterruptedException (线程)中断异常throws 投、掷、抛print Stack Trace() 打印堆栈信息get Message()获得错误消息get Cause()获得异常原因method 方法able 能够instance 实例Byte (字节类)Character (字符类)Integer(整型类)Long (长整型类)Float(浮点型类)Double (双精度类)Boolean(布尔类)Short (短整型类)Digit (数字)Letter (字母)Lower (小写)Upper (大写)Space (空格)Identifier (标识符)Start (开始)String (字符串)length (值)equals (等于)Ignore (忽略)compare (比较)sub (提取)concat (连接)trim (整理)Buffer (缓冲器)reverse (颠倒)delete (删除)append (添加)Interrupted (中断的)第七章:toString 转换为字符串GetInstance 获得实例Util 工具,龙套Components 成分,组成Next Int 下一个整数Gaussian 高斯ArrayList 对列LinkedList 链表Hash 无用信息,杂乱信号Map 地图Vector 向量,矢量Collection 收集Shuffle 混乱,洗牌RemoveFirst 移动至开头RemoveLast 移动至最后lastElement 最后的元素Capacity 容量,生产量Contains 包含,容纳InsertElementAt 插入元素在某一位置第八章:io->in out 输入/输出File 文件isFile 是文件isDirectory 是目录getPath 获取路径getAbsolutePath 获取绝对路径lastModified 最后修改日期Unicode 统一的字符编码标准, 采用双字节对字符进行编码FileInputStream 文件输入流FileOutputStream文件输出流IOException 输入输出异常fileobject 文件对象available 可获取的BufferedReader 缓冲区读取FileReader 文本文件读取BufferedWriter 缓冲区输出FileWriter 文本文件写出flush 清空close 关闭DataInputStream 二进制文件读取DataOutputStream二进制文件写出EOF 最后encoding 编码Remote 远程release 释放第九章:JBuider Java 集成开发环境(IDE)Enterprise 企业版Developer 开发版Foundation 基础版Messages 消息格Structure 结构窗格Project 工程Files 文件Source 源代码Design 设计History 历史Doc 文档File 文件Edit 编辑Search 查找Refactor 要素View 视图Run 运行Tools 工具Window 窗口Help 帮助Vector 矢量addElement 添加内容Project Winzard 工程向导Step 步骤Title 标题Description 描述Copyright 版权Company 公司Aptech Limited Aptech有限公司author 作者Back 后退Finish 完成version 版本Debug 调试New 新建ErrorInsight 调试第十章:JFrame 窗口框架JPanel 面板JScrollPane 滚动面板title 标题Dimension 尺寸Component 组件Swing JA V A轻量级组件getContentPane 得到内容面板LayoutManager 布局管理器setVerticalScrollBarPolicy 设置垂直滚动条策略AWT(Abstract Window Toolkit)抽象窗口工具包GUI (Graphical User Interface)图形用户界面VERTICAL_SCROLLEARAS_NEEDED 当内容大大面板出现滚动条VERTICAL_SOROLLEARAS_ALWAYS 显示滚动条VERTICAL_SOROLLEARAS_NEVER 不显示滚动条JLabel 标签Icon 图标image 图象LEFT 左对齐RIGHT 右对齐JTextField 单行文本getColumns 得到列数setLayout 设置布局BorderLayout 边框布局CENTER 居中对齐JTextArea 多行文本setFont 设置字体setHorizontalAlignment 设置文本水平对齐方式setDefaultCloseOperation 设置默认的关闭操作add 增加JButton 按钮JCheckBox 复选框JRadioButton单选按钮addItem 增加列表项getItemAt 得到位置的列表项getItemCount 得到列表项个数setRolloverIcon 当鼠标经过的图标setSelectedIcon 当选择按钮的图标getSelectedItem 得到选择的列表项getSelectedIndex 得到选择的索引ActionListener 按钮监听ActionEvent 按钮事件actionPerformed 按钮单击方法(编程词汇A2A integration A2A整合abstract 抽象的abstract base class (ABC)抽象基类abstract class 抽象类abstraction 抽象、抽象物、抽象性access 存取、访问access level访问级别access function 访问函数account 账户action 动作activate 激活active 活动的actual parameter 实参adapter 适配器add-in 插件address 地址address space 地址空间address-of operator 取地址操作符ADL (argument-dependent lookup)ADO(ActiveX Data Object)ActiveX数据对象advanced 高级的aggregation 聚合、聚集algorithm 算法alias 别名align 排列、对齐allocate 分配、配置allocator分配器、配置器angle bracket 尖括号annotation 注解、评注API (Application Programming Interface) 应用(程序)编程接口app domain (application domain)应用域application 应用、应用程序application framework 应用程序框架appearance 外观append 附加architecture 架构、体系结构archive file 归档文件、存档文件argument引数(传给函式的值)。
Java编程思想外文翻译文献(文档含中英文对照即英文原文和中文翻译)原文:Thinking in JavaAlthough it is based on C++, Java is more of a “pure” object-oriented language.Both C++ and Java are hybrid languages, but in Java the designers felt that the hybridization was not as important as it was in C++. A hybrid language allows multiple programming styles; the reason C++ is hybrid is to support backward compatibility with the C language. Because C++ is a superset of the C language, it includes many of that language’s undesirable features, which can make some aspects of C++ overly complicated. The Java language assumes that you want to do only object-oriented programming. This means that before you can begin you must shift yourmindset into an object-oriented world (unless it’s already there). The benefit of this initial effort is the ability to program in a language that is simpler to learn and to use than many other OOP languages. In this chapter we’ll see the basic components of a Java program and we’ll lea rn that everything in Java is an object, even a Java program.Each programming language has its own means of manipulating data. Sometimes the programmer must be constantly aware of what type of manipulation is going on. Are you manipulating the object directly, or are you dealing with some kind of indirect representation (a pointer in C or C++) that must be treated with a special syntax?All this is simplified in Java. You treat everything as an object, using a single consistent syntax. Although you treat everything as an object, the identifier you manipulate is actually a “reference” to an object. You might imagine this scene as a television (the object) with your remote control (the reference). As long as you’re holding this reference, you have a connecti on to the television, but when someone says “change the channel” or “lower the volume,” what you’re manipulating is the reference, which in turn modifies the object. If you want to move around the room and still control the television, you take the remote/reference with you, not the television.Also, the remote control can stand on its own, with no television. That is, just because you have a reference doesn’t mean there’s necessarily an object connected to it. So if you want to hold a word or sentence, you create a String reference:But here you’ve created only the reference, not an object. If you decided to send a message to s at this point, you’ll get an error (at run time) because s isn’t actually attached to anything (there’s no television). A safer p ractice, then, is always to initialize a reference when you create it.However, this uses a special Java feature: strings can be initialized with quoted text. Normally, you must use a more general type of initialization for objectsWhen you create a reference, you want to connect it with a new object. You do so, in general, with the new keyword. The keyword new says, “Make me a new one of these objects.” So in the preceding example, you can say:Not only does this mean “Make me a new String,” but it also g ives information about how to make the String by supplying an initial character string.Of course, String is not the only type that exists. Java comes with a plethora of ready-made types. What’s more important is that you can create your own types. In fact, that’s the fundamental activity in Java programming, and it’s what you’ll be learning about in the rest of this bookIt’s useful to visualize some aspects of how things are laid out while the program is running—in particular how memory is arranged. There are six different places to store data: Registers. This is the fastest storage because it exists in a place different from that of other storage: inside the processor. However, the number of registers is severely limited, so registers are allocated by t he compiler according to its needs. You don’t have direct control, nor do you see any evidence in your programs that registers even exist.The stack. This lives in the general random-access memory (RAM) area, but has direct support from the processor via its stack pointer. The stack pointer is moved down to create new memory and moved up to release that memory. This is an extremely fast and efficient way to allocate storage, second only to registers. The Java compiler must know, while it is creating the program, the exact size and lifetime of all the data that is stored on the stack, because it must generate the code to move the stack pointer up and down. This constraint places limits on the flexibility of your programs, so while some Java storage exists on the stack—in particular, object references—Java objects themselves are not placed on the stack.The heap. This is a general-purpose pool of memory (also in the RAM area) where all Java objects live. The nice thing about the heap is that, unlike the stack, the compiler doesn’t need to know how much storage it needs to allocate from the heap or how long that storage must stay on the heap. Thus, there’s a great deal of flexibility in using storage on the heap. Whenever you need to create an object, you simply write the code to create it by using new,and the storage is allocated on the heap when that code is executed. Of course there’s a price you pay for this flexibility. It takes more time to allocate heap storage than it does to allocate stack storage (if you even could create objects on the stack in Java, as you can in C++).Static storage. “Static” is used here in the sense of “in a fixed location” (although it’s also in RAM). Static storage contains data that is available for the entire time a program is running. You can use the static keyword to specify that a particular element of an object is static, but Java objects themselves are never placed in static storage.Constant storage. Constant values are often placed directly in the program code, which is safe since they can never change. Sometimes constants are cordoned off by themselves so that they can be optionally placed in read-only memory (ROM), in embedded systems.Non-RAM storage. If data lives completely outside a program, it can exist while the program is not running, outside the control of the program. The two primary examples of this are streamed objects, in which objects are turned into streams of bytes, generally to be sent to another machine, and persistent objects, in which the objects are placed on disk so they will hold their state even when the program is terminated. The trick with these types of storage is turning theobjects into something that can exist on the other medium, and yet can be resurrected into a regular RAM-based object when necessary. Java provides support for lightweight persistence, and future versions of Java might provide more complete solutions for persistence One group of types, which you’ll use quite often in your programming, gets special treatment. You can think of these as “primitive” types. The reason for the special treatment is that to create an object with new—especially a small, simple variable—isn’t very efficient, because new places objects on the heap. For these types Java falls back on the approach taken by C and C++. That is, instead of creating the variable by using new, an “automatic” variable is created that is not a reference. The variable holds the value, and it’s placed on the stack, so it’s much more efficient.Java determines the size of each p rimitive type. These sizes don’t change from one machine architecture to another as they do in most languages. This size invariance is one reason Java programs are portableAll numeric types are signed, so don’t look for unsigned types.The size of the boolean type is not explicitly specified; it is only defined to be able to take the literal values true or false.The “wrapper” classes for the primitive data types allow you to make a nonprimitive object on the heap to represent that primitive type. For example:char c = 'x';Character C = new Character(c);Or you could also use:Character C = new Character('x');The reasons for doing this will be shown in a later chapter.Java includes two classes for performing high-precision arithmetic: Big Integer and BigDecimal. Although these approximately fit into the same category as the “wrapper” classes, neither one has a primitive analogue.Both classes have methods that provide analogues for the operations that you perform on primitive types. That is, you can do anything with a BigInteger or BigDecimal that you can with an int or float, it’s just that you must use method calls instead of operators. Also, since there’s more involved, the operations will be slower. You’re exchanging speed for accuracy. BigInteger supports arbitrary-precision integers. This means that you can accurately represent integral values of any size without losing any information during operations.BigDecimal is for arbitrary-precision fixed-point numbers; you can use these for accurate monetary calculations, for example.Consult the JDK documentation for details about the constructors and methods you can call for these two classesVirtually all programming languages support arrays. Using arrays in C and C++ is perilous because those arrays are only blocks of memory. If a program accesses the array outside of its memory block or uses the memory before initialization (common programming errors), there will be unpredictable results.One of the primary goals of Java is safety, so many of the problems that plague programmers in C and C++ are not repeated in Java. A Java array is guaranteed to be initialized and cannot be accessed outside of its range. The range checking comes at the price of having a small amount of memory overhead on each array as well as verifying the index at run time, but the assumption is that the safety and increased productivity is worth the expense.When you create an array of objects, you are really creating an array of references, and each of those references is automatically initialized to a special value with its own keyword: null. When Java sees null, it recognizes that the reference in question isn’t pointing to an object. You must assign an object to each reference before you use it, and if you try to use a reference that’s still null,the problem will be reported at run time. Thus, typical array errors are prevented in Java.You can also create an array of primitives. Again, the compiler guarantees initialization because it zeroes the memory for that array.Arrays will be covered in detail in later chapters.In most programming languages, the concept of the lifetime of a variable occupies a significant portion of the programming effort. How long does the variable last? If you are supposed to destroy it, when should you? Confusion over variable lifetimes can lead to a lot of bugs, and this section shows how Java greatly simplifies the issue by doing all the cleanup work for you.Most procedural languages have the concept of scope. This determines both the visibility and lifetime of the names defined within that scope. In C, C++, and Java, scope is determined by the placement of curly braces {}. So for example:{int x = 12;// Only x available{int q = 96;// Both x & q available}// Only x available// q “out of scope”}A variable defined within a scope is available only to the end of that scope.Any text after a ‘//’ to the end of a line is a comment.Indentation makes Java code easier to read. Since Java is a free-form language, the extra spaces, tabs, and carriage returns do not affect the resulting program.Note that you cannot do the following, even though it is legal in C and C++:{int x = 12;{int x = 96; // Illegal}}The compiler will announce that the variable x has already been defined. Thus the C and C++ ability to “hide” a variable in a larger scope is not allowed, because the Java designers thought that it led to confusing programs.Java objects do not have the same lifetimes as primitives. When you create a Java object using new, it hangs around past the end of the scope. Thus if you use:{String s = new String("a string");} // End of scopethe reference s vanishes at the end of the scope. However, the String object that s was pointing to is still occupying memory. In this bit of code, there is no way to access the object, because the only reference to it is out of scope. In later chapters you’ll see how the reference to the object can be passed around and duplicated during the course of a program.It turns out that because objects created with new stay around for as long as you want them, a whole slew ofC++ programming problems simply vanish in Java. The hardest problems seem to occur in C++ because you don’t get any help from t he language in making sure that the objects are available when they’re needed. And more important, in C++ you must make sure that you destroy the objects when you’re done with them.That brings up an interesting question. If Java leaves the objects lying around, what keeps them from filling up memory and halting your program? This is exactly the kind of problem that would occur in C++. This is where a bit of magic happens. Java has a garbage collector, which looks at all the objects that were created with new and figures out which ones are not being referenced anymore. Then it releases the memory for those objects, so the memory can be used for new objects. This means that you never need to worry about reclaiming memory yourself. You simply create objects, and when you no longer need them, they will go away by themselves. This eliminates a certain class of programming problem: the so-called “memory leak,” in which a programmer forgets to release memory.If everything is an object, what determines how a particular class of object looks and behaves?Put another way, what establishes the type of an object? You might expect there to be a keyword called “type,” and that certainly would have made sense. Historically, however, most object-oriented languages have used the keyword class to mean “I’m about to tell you what a new type of object looks like.” The class keyword (which is so common that it will not be bold-faced throughout this book) is followed by the name of the new type. For example:class ATypeName { /* Class body goes here */ }This introduces a new type, although the class body consists only of a comment (the stars and slashes and what is inside, which will be discussed later in this chapter), so there is not too much that you can do with it. However, you can create an object of this type using new: ATypeName a = new ATypeName();But you cannot tell it to do much of anything (that is, you cannot send it any interesting messages) until you define some methods for it.When you define a class (and all you do in Java is define classes, make objects of those classes, and send messages to those objects), you can put two types of elements in your class: fields (sometimes called data members), and methods (sometimes called member functions). A field is an object of any type that you can communicate with via its reference. It can also be one of the primitive types (which isn’t a reference). If it is a reference to an object, you must initialize that reference to connect it to an actual object (using new, as seen earlier) in a special method called a constructor (described fully in Chapter 4).If it is a primitive type, you can initialize it directly at the point of definition in the class. (As you’ll see later, references can also be initialized at the poi nt of definition.) Each object keeps its own storage for its fields; the fields are not shared among objects. Here is an example of a class with some fields:class DataOnly {int i;float f;boolean b;}This class doesn’t do anything, but you can create an object:DataOnly d = new DataOnly();You can assign values to the fields, but you must first know how to refer to a member ofan object. This is accomplished by stating the name of the object reference, followed by a period (dot), followed by the name of the member inside the object:objectReference.memberFor example:d.i = 47;d.f = 1.1f; // ‘f’ after number indicates float constantd.b = false;It is also possible that your object might contain other objects that contain data you’d like to modify. For this, you just keep “connecting the dots.” For example:myPlane.leftTank.capacity = 100;The DataOnly class cannot do much of anything except hold data, because it has no methods. To understand how those work, you must first understand arguments and return values, which will be described shortly.译文:Java编程思想“尽管以C++为基础,但Java是一种更纯粹的面向对象程序设计语言”。
Java英汉互译一、引言Java是一种高级编程语言,其特点是面向对象、跨平台、安全性高等。
它广泛应用于软件开发、网络编程、移动应用等领域。
在Java的学习过程中,掌握英汉互译是十分重要的,因为程序中常常会涉及到英文单词、术语等。
本文将以Java英汉互译为主题,深入探讨各种常见的Java词汇及其对应的中文翻译,帮助读者更好地理解和应用Java编程语言。
二、Java基础词汇2.1 类(Class)类是Java中最基本的组成单位,用于描述具有相同属性和行为的一类对象。
在Java中,我们通过定义类来创建对象。
类由属性和方法组成,属性描述对象的状态,方法描述对象的行为。
2.2 对象(Object)对象是类的实例化结果,它具有类所描述的属性和行为。
在Java中,通过使用关键字new来创建一个对象,并通过对象来调用类中定义的方法。
2.3 方法(Method)方法是类中用于实现某种功能的代码块。
Java是一种面向对象的编程语言,在Java中,方法用于封装一个行为。
方法有输入和输出,输入为参数,输出为返回值。
2.4 参数(Parameter)参数是方法定义时的一种占位符,用于接收调用该方法时传递的数据。
Java中的方法可以有多个参数,可以是基本数据类型或者对象类型。
三、Java面向对象编程术语3.1 继承(Inheritance)继承是面向对象编程中的一个重要概念,它允许一个类继承另一个类的属性和方法。
被继承的类称为父类或超类,继承的类称为子类。
子类可以重写父类的方法,也可以新增自己的属性和方法。
3.2 多态(Polymorphism)多态是一种对象的多种形态展示方式。
在Java中,多态通过方法的重写和重载来实现。
方法重写是指子类重新定义父类中已有的方法,方法重载是指在一个类中定义多个同名的方法,但参数类型或个数不同。
3.3 封装(Encapsulation)封装是面向对象编程中的一种重要特性,它将数据和操作数据的方法封装在一个类中,通过访问修饰符来控制对数据的访问权限。
abstract (关键字) 抽象['æbstrækt]access vt.访问,存取['ækses]'(n.入口,使用权)algorithm n.算法['ælgәriðm]Annotation [java] 代码注释[ænәu'teiʃәn]anonymous adj.匿名的[ә'nɒnimәs]'(反义:directly adv.直接地,立即[di'rektli, dai'rektli]) apply v.应用,适用[ә'plai]application n.应用,应用程序[,æpli'keiʃәn]' (application crash 程序崩溃)arbitrary a.任意的['ɑ:bitrәri]argument n.参数;争论,论据['ɑ:gjumәnt]'(缩写args)assert (关键字) 断言[ә'sә:t] ' (java 1.4 之后成为关键字)associate n.关联(同伴,伙伴) [ә'sәuʃieit]attribute n.属性(品质,特征) [ә'tribju:t]boolean (关键字) 逻辑的, 布尔型call n.v.调用; 呼叫; [kɒ:l]circumstance n.事件(环境,状况) ['sә:kәmstәns]crash n.崩溃,破碎[kræʃ]cohesion 内聚,黏聚,结合[kәu'hi:ʒәn](a class is designed with a single, well-focoused purpose. 应该不止这点) command n. 命令,指令[kә'mɑ:nd](指挥, 控制) (command-line 命令行) Comments [java] 文本注释['kɒments]compile [java] v.编译[kәm'pail]' Compilation n.编辑[,kɒmpi'leiʃәn]const (保留字)constant n. 常量, 常数, 恒量['kɒnstәnt]continue (关键字)coupling 耦合,联结['kʌpliŋ]making sure that classes know about other classes only through their APIs. declare [java] 声明[di'klєә]default (关键字) 默认值; 缺省值[di'fɒ:lt]delimiter 定义符; 定界符Encapsulation[java] 封装(hiding implementation details)Exception [java] 例外; 异常[ik'sepʃәn]entry n.登录项, 输入项, 条目['entri]enum (关键字)execute vt.执行['eksikju:t]exhibit v.显示, 陈列[ig'zibit]exist 存在, 发生[ig'zist] '(SQL关键字exists)extends (关键字) 继承、扩展[ik'stend]false (关键字)final (关键字) finally (关键字)fragments 段落; 代码块['frægmәnt]FrameWork [java] 结构,框架['freimwә:k]Generic [java] 泛型[dʒi'nerik]goto (保留字) 跳转heap n.堆[hi:p]implements (关键字) 实现['implimәnt]import (关键字) 引入(进口,输入)Info n.信息(information [,infә'meiʃәn] )Inheritance [java] 继承[in'heritәns] (遗传,遗产)initialize 预置初始化[i'niʃәlaiz]instanceof (关键字) 运算符,用于引用变量,以检查这个对象是否是某种类型。
毕业设计(论文)外文文献翻译文献、资料中文题目:Java编程思想 (Java和因特网)文献、资料英文题目:Thingking in Java(Java and the Internet)文献、资料来源:文献、资料发表(出版)日期:院(部):专业:班级:姓名:学号:指导教师:翻译日期: 2017.02.14文献来源:Bruce Eckel.Thinking in Java [J]. Pearson Higher Isia Education,2006-2-20.Java编程思想 (Java和因特网)既然Java不过另一种类型的程序设计语言,大家可能会奇怪它为什么值得如此重视,为什么还有这么多的人认为它是计算机程序设计的一个里程碑呢?如果您来自一个传统的程序设计背景,那么答案在刚开始的时候并不是很明显。
Java除了可解决传统的程序设计问题以外,还能解决World Wide Web(万维网)上的编程问题。
1、客户端编程Web最初采用的“服务器-浏览器”方案可提供交互式内容,但这种交互能力完全由服务器提供,为服务器和因特网带来了不小的负担。
服务器一般为客户浏览器产生静态网页,由后者简单地解释并显示出来。
基本HTML语言提供了简单的数据收集机制:文字输入框、复选框、单选钮、列表以及下拉列表等,另外还有一个按钮,只能由程序规定重新设置表单中的数据,以便回传给服务器。
用户提交的信息通过所有Web服务器均能支持的“通用网关接口”(CGI)回传到服务器。
包含在提交数据中的文字指示CGI该如何操作。
最常见的行动是运行位于服务器的一个程序。
那个程序一般保存在一个名为“cgi-bin”的目录中(按下Web页内的一个按钮时,请注意一下浏览器顶部的地址窗,经常都能发现“cgi-bin”的字样)。
大多数语言都可用来编制这些程序,但其中最常见的是Perl。
这是由于Perl是专为文字的处理及解释而设计的,所以能在任何服务器上安装和使用,无论采用的处理器或操作系统是什么。
**********************<JA V A编程术语英语翻译>**********************abstract 抽象的抽象的abstraction 抽象体、抽象物、抽象性抽象体、抽象物、抽象性access 存取、取用存取、访问access level 存取级别访问级别access function 存取函式访问函数activate 活化激活active 作用中的adapter 配接器适配器address 位址地址address space 位址空间,定址空间address-of operator 取址运算子取地址操作符aggregation 聚合algorithm 演算法算法allocate 配置分配allocator (空间)配置器分配器application 应用程式应用、应用程序application framework 应用程式框架、应用框架应用程序框架architecture 架构、系统架构体系结构argument 引数(传给函式的值)。
叁见parameter 叁数、实质叁数、实叁、自变量array 阵列数组arrow operator arrow(箭头)运算子箭头操作符assembly 装配件assembly language 组合语言汇编语言assert(ion) 断言assign 指派、指定、设值、赋值赋值assignment 指派、指定赋值、分配assignment operator 指派(赋值)运算子= 赋值操作符associated 相应的、相关的相关的、关联、相应的associative container 关联式容器(对应sequential container)关联式容器atomic 不可分割的原子的attribute 属性属性、特性audio 音讯音频A.I. 人工智慧人工智能background 背景背景(用於图形着色)後台(用於行程)backward compatible 回溯相容向下兼容bandwidth 频宽带宽base class 基础类别基类base type 基础型别(等同於base class)batch 批次(意思是整批作业)批处理benefit 利益收益best viable function 最佳可行函式最佳可行函式(从viable functions 中挑出的最佳吻合者)binary search 二分搜寻法二分查找binary tree 二元树二叉树binary function 二元函式双叁函数binary operator 二元运算子二元操作符binding 系结绑定bit 位元位bit field 位元栏位域bitmap 位元图位图bitwise 以bit 为单元逐一┅bitwise copy 以bit 为单元进行复制;位元逐一复制位拷贝block 区块,区段块、区块、语句块boolean 布林值(真假值,true 或false)布尔值border 边框、框线边框brace(curly brace) 大括弧、大括号花括弧、花括号bracket(square brakcet) 中括弧、中括号方括弧、方括号breakpoint 中断点断点build 建造、构筑、建置(MS 用语)build-in 内建内置bus 汇流排总线business 商务,业务业务buttons 按钮按钮byte 位元组(由8 bits 组成)字节cache 快取高速缓存call 呼叫、叫用调用callback 回呼回调call operator call(函式呼叫)运算子调用操作符(同function call operator)candidate function 候选函式候选函数(在函式多载决议程序中出现的候选函式)chain 串链(例chain of function calls)链character 字元字符check box 核取方块(i.e. check button) 复选框checked exception 可控式异常(Java)check button 方钮(i.e. check box) 复选按钮child class 子类别(或称为derived class, subtype)子类class 类别类class body 类别本体类体class declaration 类别宣告、类别宣告式类声明class definition 类别定义、类别定义式类定义class derivation list 类别衍化列类继承列表class head 类别表头类头class hierarchy 类别继承体系, 类别阶层类层次体系class library 类别程式库、类别库类库class template 类别模板、类别范本类模板class template partial specializations类别模板偏特化类模板部分特化class template specializations类别模板特化类模板特化cleanup 清理、善後清理、清除client 客端、客户端、客户客户client-server 主从架构客户/服务器clipboard 剪贴簿剪贴板clone 复制克隆collection 群集集合combo box 复合方块、复合框组合框command line 命令列命令行(系统文字模式下的整行执行命令)communication 通讯通讯compatible 相容兼容compile time 编译期编译期、编译时compiler 编译器编译器component 组件组件composition 复合、合成、组合组合computer 电脑、计算机计算机、电脑concept 概念概念concrete 具象的实在的concurrent 并行并发configuration 组态配置connection 连接,连线(网络,资料库)连接constraint 约束(条件)construct 构件构件container 容器容器(存放资料的某种结构如list, vector...)containment 内含包容context 背景关系、周遭环境、上下脉络环境、上下文control 控制元件、控件控件console 主控台控制台const 常数(constant 的缩写,C++ 关键字)constant 常数(相对於variable)常量constructor(ctor)建构式构造函数(与class 同名的一种member functions)copy (v) 复制、拷贝拷贝copy (n) 复件, 副本cover 涵盖覆盖create 创建、建立、产生、生成创建creation 产生、生成创建cursor 游标光标custom 订制、自定定制data 资料数据database 资料库数据库database schema 数据库结构纲目data member 资料成员、成员变数数据成员、成员变量data structure 资料结构数据结构datagram 资料元数据报文dead lock 死结死锁debug 除错调试debugger 除错器调试器declaration 宣告、宣告式声明deduction 推导(例:template argument deduction)推导、推断default 预设缺省、默认defer 延缓推迟define 定义预定义definition 定义、定义区、定义式定义delegate 委派、委托、委任委托delegation (同上)demarshal 反编列散集dereference 提领(取出指标所指物体的内容)解叁考dereference operator dereference(提领)运算子* 解叁考操作符derived class 衍生类别派生类design by contract 契约式设计design pattern 设计范式、设计样式设计模式※最近我比较喜欢「设计范式」一词destroy 摧毁、销毁destructor 解构式析构函数device 装置、设备设备dialog 对话窗、对话盒对话框directive 指令(例:using directive)(编译)指示符directory 目录目录disk 碟盘dispatch 分派分派distributed computing 分布式计算(分布式电算) 分布式计算分散式计算(分散式电算)document 文件文档dot operator dot(句点)运算子. (圆)点操作符driver 驱动程式驱动(程序)dynamic binding 动态系结动态绑定efficiency 效率效率efficient 高效高效end user 终端用户entity 物体实体、物体encapsulation 封装封装enclosing class 外围类别(与巢状类别nested class 有关)外围类enum (enumeration) 列举(一种C++ 资料型别)枚举enumerators 列举元(enum 型别中的成员)枚举成员、枚举器equal 相等相等equality 相等性相等性equality operator equality(等号)运算子== 等号操作符equivalence 等价性、等同性、对等性等价性equivalent 等价、等同、对等等价escape code 转义码转义码evaluate 评估、求值、核定评估event 事件事件event driven 事件驱动的事件驱动的exception 异常情况异常exception declaration 异常宣告(ref. C++ Primer 3/e, 11.3)异常声明exception handling 异常处理、异常处理机制异常处理、异常处理机制exception specification 异常规格(ref. C++ Primer 3/e, 11.4)异常规范exit 退离(指离开函式时的那一个执行点)退出explicit 明白的、明显的、显式显式export 汇出引出、导出expression 运算式、算式表达式facility 设施、设备设施、设备feature 特性field 栏位,资料栏(Java)字段, 值域(Java)file 档案文件firmware 韧体固件flag 旗标标记flash memory 快闪记忆体闪存flexibility 弹性灵活性flush 清理、扫清刷新font 字型字体form 表单(programming 用语)窗体formal parameter 形式叁数形式叁数forward declaration 前置宣告前置声明forwarding 转呼叫,转发转发forwarding function 转呼叫函式,转发函式转发函数fractal 碎形分形framework 框架框架full specialization 全特化(ref. partial specialization)function 函式、函数函数function call operator 同call operatorfunction object 函式物件(ref. C++ Primer 3/e, 12.3)函数对象function overloaded resolution函式多载决议程序函数重载解决(方案)functionality 功能、机能功能function template 函式模板、函式范本函数模板functor 仿函式仿函式、函子game 游戏游戏generate 生成generic 泛型、一般化的一般化的、通用的、泛化generic algorithm 泛型演算法通用算法getter (相对於setter) 取值函式global 全域的(对应於local)全局的global object 全域物件全局对象global scope resolution operator全域生存空间(范围决议)运算子:: 全局范围解析操作符group 群组group box 群组方块分组框guard clause 卫述句(Refactoring, p250) 卫语句GUI 图形介面图形界面hand shaking 握手协商handle 识别码、识别号、号码牌、权柄句柄handler 处理常式处理函数hard-coded 编死的硬编码的hard-copy 硬拷图屏幕截图hard disk 硬碟硬盘hardware 硬体硬件hash table 杂凑表哈希表、散列表header file 表头档、标头档头文件heap 堆积堆hierarchy 阶层体系层次结构(体系)hook 挂钩钩子hyperlink 超链结超链接icon 图示、图标图标IDE 整合开发环境集成开发环境identifier 识别字、识别符号标识符if and only if 若且唯若当且仅当Illinois 伊利诺伊利诺斯image 影像图象immediate base 直接的(紧临的)上层base class。
JAVA编程思想第2章一切都是对象尽管以C++为基础,但Java是一种更纯粹的面向对象程序设计语言”。
无论C++还是Java都属于杂合语言。
但在Java中,设计者觉得这种杂合并不象在C++里那么重要。
杂合语言允许采用多种编程风格;之所以说C++是一种杂合语言,是因为它支持与C语言的向后兼容能力。
由于C++是C的一个超集,所以包含的许多特性都是后者不具备的,这些特性使C++在某些地方显得过于复杂。
Java语言首先便假定了我们只希望进行面向对象的程序设计。
也就是说,正式用它设计之前,必须先将自己的思想转入一个面向对象的世界(除非早已习惯了这个世界的思维方式)。
只有做好这个准备工作,与其他OOP语言相比,才能体会到Java的易学易用。
第6章类再生“Java引人注目的一项特性是代码的重复使用或者再生。
但最具革命意义的是,除代码的复制和修改以外,我们还能做多得多的其他事情。
”在象C那样的程序化语言里,代码的重复使用早已可行,但效果不是特别显著。
与Java 的其他地方一样,这个方案解决的也是与类有关的问题。
我们通过创建新类来重复使用代码,但却用不着重新创建,可以直接使用别人已建好并调试好的现成类。
但这样做必须保证不会干扰原有的代码。
在这一章里,我们将介绍两个达到这一目标的方法。
第一个最简单:在新类里简单地创建原有类的对象。
我们把这种方法叫作“合成”,因为新类由现有类的对象合并而成。
我们只是简单地重复利用代码的功能,而不是采用它的形式。
第二种方法则显得稍微有些技巧。
它创建一个新类,将其作为现有类的一个“类型”。
我们可以原样采取现有类的形式,并在其中加入新代码,同时不会对现有的类产生影响。
这种魔术般的行为叫作“继承”(Inheritance),涉及的大多数工作都是由编译器完成的。
对于面向对象的程序设计,“继承”是最重要的基础概念之一。
第14章多线程利用对象,可将一个程序分割成相互独立的区域。
我们通常也需要将一个程序转换成多个独立运行的子任务。
**********************<JAVA编程术语英语翻译>**********************abstract 抽象的抽象的abstraction 抽象体、抽象物、抽象性抽象体、抽象物、抽象性access 存取、取用存取、访问access level 存取级别访问级别access function 存取函式访问函数activate 活化激活active 作用中的adapter 配接器适配器address 位址地址address space 位址空间,定址空间address-of operator 取址运算子取地址操作符aggregation 聚合algorithm 演算法算法allocate 配置分配allocator (空间)配置器分配器application 应用程式应用、应用程序application framework 应用程式框架、应用框架应用程序框架architecture 架构、系统架构体系结构argument 引数(传给函式的值)。
叁见 parameter 叁数、实质叁数、实叁、自变量array 阵列数组arrow operator arrow(箭头)运算子箭头操作符assembly 装配件assembly language 组合语言汇编语言assert(ion) 断言assign 指派、指定、设值、赋值赋值assignment 指派、指定赋值、分配assignment operator 指派(赋值)运算子 = 赋值操作符associated 相应的、相关的相关的、关联、相应的associative container 关联式容器(对应sequential container)关联式容器atomic 不可分割的原子的attribute 属性属性、特性audio 音讯音频A.I. 人工智慧人工智能background 背景背景(用於图形着色)後台(用於行程)backward compatible 回溯相容向下兼容bandwidth 频宽带宽base class 基础类别基类base type 基础型别 (等同於 base class)batch 批次(意思是整批作业)批处理benefit 利益收益best viable function 最佳可行函式最佳可行函式(从 viable functions 中挑出的最佳吻合者)binary search 二分搜寻法二分查找binary tree 二元树二叉树binary function 二元函式双叁函数binary operator 二元运算子二元操作符binding 系结绑定bit 位元位bit field 位元栏位域bitmap 位元图位图bitwise 以 bit 为单元逐一┅bitwise copy 以 bit 为单元进行复制;位元逐一复制位拷贝block 区块,区段块、区块、语句块boolean 布林值(真假值,true 或 false)布尔值border 边框、框线边框brace(curly brace) 大括弧、大括号花括弧、花括号bracket(square brakcet) 中括弧、中括号方括弧、方括号breakpoint 中断点断点build 建造、构筑、建置(MS 用语)build-in 内建内置bus 汇流排总线business 商务,业务业务buttons 按钮按钮byte 位元组(由 8 bits 组成)字节cache 快取高速缓存call 呼叫、叫用调用callback 回呼回调call operator call(函式呼叫)运算子调用操作符(同 function call operator)candidate function 候选函式候选函数(在函式多载决议程序中出现的候选函式)chain 串链(例 chain of function calls)链character 字元字符check box 核取方块 (i.e. check button) 复选框checked exception 可控式异常(Java)check button 方钮 (i.e. check box) 复选按钮child class 子类别(或称为derived class, subtype)子类class 类别类class body 类别本体类体class declaration 类别宣告、类别宣告式类声明class definition 类别定义、类别定义式类定义class derivation list 类别衍化列类继承列表class head 类别表头类头class hierarchy 类别继承体系, 类别阶层类层次体系class library 类别程式库、类别库类库class template 类别模板、类别范本类模板class template partial specializations类别模板偏特化类模板部分特化class template specializations类别模板特化类模板特化cleanup 清理、善後清理、清除client 客端、客户端、客户客户client-server 主从架构客户/服务器clipboard 剪贴簿剪贴板clone 复制克隆collection 群集集合combo box 复合方块、复合框组合框command line 命令列命令行(系统文字模式下的整行执行命令)communication 通讯通讯compatible 相容兼容compile time 编译期编译期、编译时compiler 编译器编译器component 组件组件composition 复合、合成、组合组合computer 电脑、计算机计算机、电脑concept 概念概念concrete 具象的实在的concurrent 并行并发configuration 组态配置connection 连接,连线(网络,资料库)连接constraint 约束(条件)construct 构件构件container 容器容器(存放资料的某种结构如 list, vector...)containment 内含包容context 背景关系、周遭环境、上下脉络环境、上下文control 控制元件、控件控件console 主控台控制台const 常数(constant 的缩写,C++ 关键字)constant 常数(相对於 variable)常量constructor(ctor)建构式构造函数(与class 同名的一种 member functions)copy (v) 复制、拷贝拷贝copy (n) 复件, 副本cover 涵盖覆盖create 创建、建立、产生、生成创建creation 产生、生成创建cursor 游标光标custom 订制、自定定制data 资料数据database 资料库数据库database schema 数据库结构纲目data member 资料成员、成员变数数据成员、成员变量data structure 资料结构数据结构datagram 资料元数据报文dead lock 死结死锁debug 除错调试debugger 除错器调试器declaration 宣告、宣告式声明deduction 推导(例:template argument deduction)推导、推断default 预设缺省、默认defer 延缓推迟define 定义预定义definition 定义、定义区、定义式定义delegate 委派、委托、委任委托delegation (同上)demarshal 反编列散集dereference 提领(取出指标所指物体的内容)解叁考dereference operator dereference(提领)运算子 * 解叁考操作符derived class 衍生类别派生类design by contract 契约式设计design pattern 设计范式、设计样式设计模式※最近我比较喜欢「设计范式」一词destroy 摧毁、销毁destructor 解构式析构函数device 装置、设备设备dialog 对话窗、对话盒对话框directive 指令(例:using directive) (编译)指示符directory 目录目录disk 碟盘dispatch 分派分派distributed computing 分布式计算 (分布式电算) 分布式计算分散式计算 (分散式电算)document 文件文档dot operator dot(句点)运算子 . (圆)点操作符driver 驱动程式驱动(程序)dynamic binding 动态系结动态绑定efficiency 效率效率efficient 高效高效end user 终端用户entity 物体实体、物体encapsulation 封装封装enclosing class 外围类别(与巢状类别 nested class 有关)外围类enum (enumeration) 列举(一种 C++ 资料型别)枚举enumerators 列举元(enum 型别中的成员)枚举成员、枚举器equal 相等相等equality 相等性相等性equality operator equality(等号)运算子 == 等号操作符equivalence 等价性、等同性、对等性等价性equivalent 等价、等同、对等等价escape code 转义码转义码evaluate 评估、求值、核定评估event 事件事件event driven 事件驱动的事件驱动的exception 异常情况异常exception declaration 异常宣告(ref. C++ Primer 3/e, 11.3)异常声明exception handling 异常处理、异常处理机制异常处理、异常处理机制exception specification 异常规格(ref. C++ Primer 3/e, 11.4)异常规范exit 退离(指离开函式时的那一个执行点)退出explicit 明白的、明显的、显式显式export 汇出引出、导出expression 运算式、算式表达式facility 设施、设备设施、设备feature 特性field 栏位,资料栏(Java)字段, 值域(Java)file 档案文件firmware 韧体固件flag 旗标标记flash memory 快闪记忆体闪存flexibility 弹性灵活性flush 清理、扫清刷新font 字型字体form 表单(programming 用语)窗体formal parameter 形式叁数形式叁数forward declaration 前置宣告前置声明forwarding 转呼叫,转发转发forwarding function 转呼叫函式,转发函式转发函数fractal 碎形分形framework 框架框架full specialization 全特化(ref. partial specialization)function 函式、函数函数function call operator 同 call operatorfunction object 函式物件(ref. C++ Primer 3/e, 12.3)函数对象function overloaded resolution函式多载决议程序函数重载解决(方案)functionality 功能、机能功能function template 函式模板、函式范本函数模板functor 仿函式仿函式、函子game 游戏游戏generate 生成generic 泛型、一般化的一般化的、通用的、泛化generic algorithm 泛型演算法通用算法getter (相对於 setter) 取值函式global 全域的(对应於 local)全局的global object 全域物件全局对象global scope resolution operator全域生存空间(范围决议)运算子 :: 全局范围解析操作符group 群组group box 群组方块分组框guard clause 卫述句 (Refactoring, p250) 卫语句GUI 图形介面图形界面hand shaking 握手协商handle 识别码、识别号、号码牌、权柄句柄handler 处理常式处理函数hard-coded 编死的硬编码的hard-copy 硬拷图屏幕截图hard disk 硬碟硬盘hardware 硬体硬件hash table 杂凑表哈希表、散列表header file 表头档、标头档头文件heap 堆积堆hierarchy 阶层体系层次结构(体系)hook 挂钩钩子hyperlink 超链结超链接icon 图示、图标图标IDE 整合开发环境集成开发环境identifier 识别字、识别符号标识符if and only if 若且唯若当且仅当Illinois 伊利诺伊利诺斯image 影像图象immediate base 直接的(紧临的)上层 base class。
Java的面向对象编程思想引言面向对象编程(Object-Oriented Programming,简称OOP)是一种软件开发的方法论,它将现实世界的事物抽象成对象,并通过对象之间的交互来完成程序的设计和实现。
Java作为一种面向对象的编程语言,深受开发者的喜爱和广泛应用。
本文将介绍Java的面向对象编程思想,并讨论其特点、优势以及如何在实际开发中应用。
第一章:面向对象编程的基本概念1.1 对象和类对象是面向对象编程的核心概念之一,它是现实世界中的一个实体,具有属性和行为。
类则定义了对象的结构和行为模式,是对象的模板。
在Java中,使用关键字"class"来定义类,通过创建类的实例来生成对象。
1.2 封装、继承和多态封装(Encapsulation)、继承(Inheritance)和多态(Polymorphism)是面向对象编程的三大特性。
封装是将对象的属性和行为封装在一起,对外部隐藏内部实现细节。
通过使用访问修饰符(public、private、protected)来控制对象的访问权限。
继承是指一个类可以继承另一个类的属性和方法,使得代码的重用性大大增加。
通过使用关键字"extends"来实现类之间的继承关系。
多态是指同一个方法可以根据不同的对象调用出不同的实现结果。
它通过方法的重载和重写来实现,提高了代码的灵活性和可扩展性。
第二章:面向对象编程的优势2.1 代码重用性面向对象编程的一个重要优势是代码的重用性。
通过继承和多态的使用,可以避免重复编写相同的代码,提高了开发效率。
2.2 可维护性和扩展性面向对象编程将代码分解成多个独立的对象,使得每个对象都可以独立进行开发、测试和维护。
当需要修改或扩展功能时,只需修改或添加相应的对象,而不会对其他部分产生影响,大大提高了代码的可维护性和扩展性。
2.3 代码的可读性和可理解性面向对象编程使用对象来模拟现实世界的事物,使得代码更加易读和易理解。
Thinking in Java 3rd EditionႸ້ᪿ˖៥Ң2002ᑈ7᳜ᓔẝᴀˈᔧᰃৰѠDŽԚᰃҟˈchinapubˈ᪸Ո᪕DŽѢᰃ៥ЁњˈՈDŽ៥ᰃৰϔՈẝᴀˈԚᰃ៥༅њDŽ↨ৰϔˈ៥ඌẝᴀњˈԚᰃּ៥Ո8ˈᅗᰃᏂDŽ᠔Bruce Eckel ҪՈตՈৰϝՈᯊˈ៥އᴹDŽˈخDŽϔ1000ՈкᰃὧМՈDŽᳳ៥гˈԚᰃܼᴹњDŽҢҞᑈՈϸ᳜߱ˈࠄ7᳜ᑩˈ៥њ᠔ՈϮˈܼՈDŽᑨˈẝ-Ո▂њ៥ՈᛇDŽˈᪿᰃϸDŽᆵᰃϸՈ᪱ˈᕫᕜՈহˈ៤ЁњּDŽ᳝៥ᕫᅵˈ៥࿁ՈহDŽˈϔ᪡≵ˈᑊᢧᭈˈԚᴹ᪸ˈẝህњDŽˈẝᰃϔՈҎՈҎՈкˈ᠔☢ᆵՈᡔˈᅗϬˈহᮍ☦☢ᐌDŽᆵẝϔˈԚᰃᇍᴹ᪸ˈẝህᰃᯣњDŽˈBruce EckelẝḋՈˈݭњ1000ˈབˈҪᰃˈкₐẜĀࡉāՈহDŽ↨ὧহՈĀThegenesis of the computer revolution was in a machine. The genesis of our programming languages thus tends to look like that machine.ā៥ህDŽ៥ᛇˈ᪸Bruce ՈህᰃẝϾᬜDŽẝᰃϔՈৡˈᡔՈỤDŽ໐ˈ៥ՈේњᕜDŽݡՈẝѯˈՓᕫ៥ϡᕫϡՈDŽᔧ៥ₑՈᯊˈ៥থᬍՈഄᮍᅲњDŽˈ៥ϡህˈ៥াᬍẋՈᾬDŽϡẝϡᰃ᳔ՈČˈ៥ẜՈDŽᴹˈ៥ޚ10᳜ӑˈ៥ׂᬍᅠ7তПDŽԚᰃˈ៥থ៥জњˈ៥އႮᏅय़ˈɴህDŽҹˈ៥ᇚᬍᅠতህতˈ/shhgs/tij.htmlDŽᕫདˈ៥ˈԴՈۇᰃ៥ᎹՈᕫϡˈὧ៥њˈ៥ӮՈᛣᬍՈDŽ៥ẝᮍˈ᪕ᕫϞՈкDŽshhgs2003ᑈ9᳜8᮹Thinking in Java 3rd Edition8:ষϢݙᾬିষ(interface)ݙି(inner cl as )կњϔՈᬥՈᮍDŽᮍ᪸ˈC+ẝˈϡՈ࣏ᰃ࿁ẝDŽav aẝϾˈᰃ☢ᐌˈ᪱կᬃDŽৰ7তњabstractˈᅗିₐϾϾ≵ՈᮍüüњষˈԚᰃˈẝᾬՈණିᴹᅮDŽ໐in te rf aceњϔᬥՈˈկՈିDŽԴˈin te rf aceᰃϔᬥିՈˈᅗᰃϔᇚϾᇍᬥϾିՈˈկњିԐC+ՈĀ(m tip e inh eritance)āՈDŽᴹˈݙିᰃϔՈՈ˖ᰃᡞϾିϾିₐDŽԚᰃˈԴᇚˈݙିẝМüüି(s rro nd ing cl as )üüˈݙିˈԴᰃ࿁ՈDŽԴᕫẋݙିc DŽষ(interface)in te rf aceњabstractՈὖDŽԴ៤ĀՈāabstractିDŽᅗିՈ˖ᮍˈ᭄߫ˈՈିൟˈԚᰃᮍՈDŽin te rf ace ᭄៤ˈԚᰃᅗᰃstatic in alՈDŽin te rf aceկᔶˈDŽin te rf aceՈᛣᰃĀ᠔ẝϾষՈିẝϾḋDŽāˈাњẝϾin te rf ace ὧѯᮍկ᫇њˈDŽˈin te rf aceିՈĀ(p ro to co )āDŽ(ᬥՈ᪱ՈϬprotocolᴹẝDŽ)in te rf ace ˈাcl ass៤in te rf ace њDŽିˈԴin te rf acebl ic (ৠₐՈin te rf ace )ˈˈack ag eᴗ└ˈẝḋϾack ag eњDŽϾᅲњϾ()in te rf aceՈିˈህimp me tsin te rf aceThinking in Java 3rd EditionˈԚᰃɴ៥ᡅᰃᗢՈDŽāˈᅗDŽẜᰃҹˈՈњẝՈ˖Ңin BrassˈିњϾin te rf aceˈ៤њϔϾৃՈିњDŽin te rf ace ₐՈᮍ៤bl icՈˈԚᰃˈᅗᰃbl icՈDŽ᠔imp me tsϾin te rf ace ՈᯊˈԴẝϾin te rf ace Ոᮍ៤bl icՈDŽབẝМˈὧ៤ack ag eᴗ└ՈˈẝḋˈẝѯᮍՈᴗ└└ࠊˈ໐ẝᰃav aՈේՈDŽҢׂᬍৢՈstru me tẝϔDŽˈේin te rf aceₐ☦ᮍDŽℸˈstru me t Ոᮍ៤bl icՈˈԚᰃᅗႮᰃbl ic Ո˖//: c08:music5:Music5.java// Interfaces.package c08.music5;import com.bruceeckel.simpletest.*; import c07.music.Note;interface Instrument {// Compile-time constant:int I = 5; // static & final// Cannot have method definitions:void play(Note n); // Automatically publicString what();void adjust();}class Wind implements Instrument {public void play(Note n) {System.out.println("Wind.play() " + n);}public String what() { return"Wind"; }public void adjust() {}}class Percussion implements Instrument { public void play(Note n) {System.out.println("Percussion.play() " + n); }public String what() { return"Percussion"; } public void adjust() {}}class Stringed implements Instrument {public void play(Note n) {System.out.println("Stringed.play() " + n);}public String what() { return"Stringed"; }public void adjust() {}}class Brass extends Wind {public void play(Note n) {System.out.println("Brass.play() " + n);}public void adjust() {System.out.println("Brass.adjust()");}}class Woodwind extends Wind {public void play(Note n) {System.out.println("Woodwind.play() " + n);}public String what() { return"Woodwind"; }}public class Music5 {private static Test monitor = new Test();// Doesn't care about type, so new types// added to the system still work right:static void tune(Instrument i) {// ...i.play(Note.MIDDLE_C);}static void tuneAll(Instrument[] e) {for(int i = 0; i < e.length; i++)tune(e[i]);}public static void main(String[] args) {// Upcasting during addition to the array: Instrument[] orchestra = { new Wind(),new Percussion(), new Stringed(), new Brass(), new Woodwind() };tuneAll(orchestra);monitor.expect(new String[] { "Wind.play() Middle C","Percussion.play() Middle C", "Stringed.play() Middle C", "Brass.play() Middle C", "Woodwind.play() Middle C" }); }} ///:~ՈᎹᮍᓣDŽϡᰃᡞϾstru me tՈĀāିˈẜᰃϔϾstru me t ՈabstractିˈẜᰃϔϾstru me t Ոin te rf aceˈᅗՈᎹᮍᓣᰃϔՈDŽᅲˈԴҢtu )ᴹˈstru me tᰃĀāିˈẜᰃabstract ିˈin te rf aceDŽẝህᰃᅗՈᴀ˖ႮᏅὧϾᬥՈՓDŽJavaՈĀₑණᡓāin te rf aceᰃϔĀāՈabstractିDŽᅗՈՈDŽin te rf aceĀᅲāüüᰃ᪸in te rf aceݙüüin te rf ace ՈDŽẝϔ☢ᐌˈĀxᰃa ᰃbˈ໐ᰃcāՈDŽC+ˈẝĀᇚϾିՈষϔāՈĀ(lti ple i ri ta ce )āˈԚᰃϾିႮᏅՈᅲˈ໐ẝᴹᕜĀāՈDŽav aՈџˈԚᰃẝϾିˈav aষՈᯊˈህẝњ˖av aabstractᰃĀāՈି(ᰃϡabstract ᮍՈି)ˈԚᰃԴϾ☢in te rf aceՈିDŽ᠔Ոିܗ(b as e el em ents )ᰃin te rf aceDŽԴᕫᡞՈষimp me tsˈϬDŽԴˈᅲϾin te rf aceᇚẝϾିϾin te rf ace DŽẝњབᇚϾՈିϾin te rf aceᴹˈϾՈି˖//: c08:Adventure.java // Multiple interfaces.interface CanFight { void fight(); }interface CanSwim { void swim(); }interface CanFly { void fly(); }class ActionCharacter { public void fight() {} }class Hero extends ActionCharacterimplements CanFight, CanSwim, CanFly { public void swim() {} public void fly() {} }public class Adventure {public static void t(CanFight x) { x.fight(); } public static void u(CanSwim x) { x.swim(); } public static void v(CanFly x) { x.fly(); } public static void w(ActionCharacter x) { x.fight(); }public static void main(String[] args) { Hero h = new Hero();t(h); // Treat it as a CanFight u(h); // Treat it as a CanSwimv(h); // Treat it as a CanFlyw(h); // Treat it as an ActionCharacter }} ///:~ˈroњՈActio aracte r ିˈҹan ig t ˈan im an ষDŽᔧẝᮍᓣି(co ncrete cl as )ষՈᯊˈᇚିࠡˈᰃDŽ(DŽ)Actio aracte r ିՈig t( )ᮍDŽᅗՈin te rf ace an ig t Ոig t( )ᮍˈԚᰃroկig t( )ՈDŽin te rf aceՈᰃẝḋՈˈԴ()ˈԚᰃණᴹՈẜᰃin te rf ace DŽབϾିൟՈᇍᬥˈὧМẝϾିൟᰃିˈ໐ᕫկDŽroՈկig t( )ՈᅮˈԚᰃActio aracte rկњˈ᠔roႮᕫẝϾᮍˈᑊᬥњDŽAd tu re ିϾষᅲି᭄ՈᮍDŽᴹՈ roᬥϾᮍˈгᰃ᪸њϾin te rf aceDŽẝϾẋՈˈẝϔav a ՈDŽ៥ষՈՈ˖Ͼିൟ(b as e ty e)DŽˈՓষՈৰѠϾˊˈᅲᰃĀᡞabstractିିāᅠՈ˖ᰃᡅẝϾିՈᇍᬥˈᑊĀẝাᰃϔϾষāDŽẝህᴹњϔϾ˖ᰃϬin te rf aceˈẜᰃϬabstract ିin te rf aceњԴabstractିՈདˈজњԴin te rf aceՈདˈିՈₐ☦ᮍ៤ՈᅮˈԴin te rf aceDŽᅲˈẝḋᰃିՈ᪡ˈԴ៤in te rf ace ˈাϡᕫϡᮍ៤ՈˈԴᬍ៤abstractିˈᬍ៤ᅲିDŽড়ᑊষᯊՈৡᄫކॅϾষՈᯊDŽϞˈan ig tActio aracte rϾϔՈid f ig t( )ᮍDŽẝₐˈՈᰃৠϾᮍDŽԚᰃབᰃᰃϔϾ˖//: c08:InterfaceCollision.javainterface I1 { void f(); }interface I2 { int f(int i); }interface I3 { int f(); }class C { public int f() { return 1; } }class C2 implements I1, I2 { public void f() {}public int f(int i) { return 1; } // overloaded }class C3 extends C implements I2 {public int f(int i) { return 1; } // overloaded }class C4 extends C implements I3 { // Identical, no problem: public int f() { return 1; } }// Methods differ only by return type: //! class C5 extends C implements I1 {} //! interface I4 extends I1, I3 {} ///:~ẝϾ▂ₑՈϡˈҹĀϡᴹՈᮍāDŽབՈˈህՈ˖te rf ce olli on f ) i C ca ot i ple t f ) i I tte pti to u i com pa ti le re tu rn ty peou : i t re re v oite rf ce olli on i te rf ce I a I a recom pa ti le b oth d f ) b t w th d re t re tu rn ty peᡅՈষₐ☦ᮍˈՈৃDŽ᠔ẝМDŽණᡓᠽacˈin te rf aceₐ☦ՈᮍˈгϾin te rf ace៤ϔϾՈin te rf aceDŽẝϸˈԴᕫࠄՈᰃϔϾՈinterfaceˈህẝḋ˖//: c08:HorrorShow.java// Extending an interface with inheritance.interface Monster { void menace(); }interface DangerousMonster extends Monster { void destroy(); }interface Lethal { void kill(); }class DragonZilla implements DangerousMonster { public void menace() {} public void destroy() {} }interface Vampire extends DangerousMonster, Lethal { void drinkBlood(); }class VeryBadVampire implements Vampire { public void menace() {} public void destroy() {} public void kill() {}public void drinkBlood() {} }public class HorrorShow {static void u(Monster b) { b.menace(); } static void v(DangerousMonster d) { d.menace(); d.destroy(); }static void w(Lethal l) { l.kill(); } public static void main(String[] args) {DangerousMonster barney = new DragonZilla(); u(barney); v(barney);Vampire vlad = new VeryBadVampire(); u(vlad); v(vlad); w(vlad); }} ///:~an ro sM ste r ᰃᇍste rњϔˈ៤ϔϾՈin te rf ace DŽrag il a њẝϾষDŽamp ireՈ᪱ᰃĀষ(inh eriting interfaces )ā᠔ՈDŽˈ e xte s ିˈԚᰃϾin te rf aceϾষ៤ˈՈin te rf ace Ոᯊxte sᴹϾĀষ(b as e interfaces )āDŽՈˈin te rf ace ՈৡDŽՈߚin te rf ace Ո᭄៤Ⴎᰃstatic in alՈˈin te rf ace ᰃϔ☢ᐌᮍՈˈՈᎹDŽẝ⚍CC+m//: c08:Months.java// Using interfaces to create groups of constants. package c08;public interface Months { intJANUARY = 1, FEBRUARY = 2, MARCH = 3, APRIL = 4, MAY = 5, JUNE = 6, JULY = 7, AUGUST = 8, SEPTEMBER = 9, OCTOBER = 10, NOVEMBER = 11, DECEMBER = 12; } ///:~ˈav aՈේᰃˈϬ(ϾₐՈϾ)ᴹˈϬՈstatic f in alDŽinterfaceՈ᭄៤ਬႮࡼህᰃicՈˈℸህϡᖙݡ⊼ᯢњDŽՈack ag eὧḋˈϬimp rt c0c0th sᴹˈẝḋẝϾack ag eՈth s.AN UAR ିՈᴹՓẝѯњDŽᔧˈԴᕫࠄՈᰃϔϾin tˈC+ՈmὧḋՈିൟˈԚᰃẝ(Ո)࣏ₐ☦᭄ᄫᕫDŽ(ẝᮍ៤ЎĀ᭄ᄫāˈᑊᕫՈමᡸᕫ☢ᐌೄDŽ)ՈିൟˈৃẝḋϾି˖//: c08:Month.java// A more robust enumeration system. package c08;import com.bruceeckel.simpletest.*;public final class Month {private static Test monitor = new Test(); private String name;private Month(String nm) { name = nm; } public String toString() { return name; } public static final MonthJAN = new Month("January"), FEB = new Month("February"), MAR = new Month("March"), APR = new Month("April"), MAY = new Month("May"), JUN = new Month("June"), JUL = new Month("July"), AUG = new Month("August"), SEP = new Month("September"), OCT = new Month("October"), NOV = new Month("November"), DEC = new Month("December");public static final Month[] month = { JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC };Thinking in Java 3rd Editionpublic static final Month number(int ord) { return month[ord - 1]; }public static void main(String[] args) { Month m = Month.JAN; System.out.println(m); m = Month.number(12); System.out.println(m);System.out.println(m == Month.DEC);System.out.println(m.equals(Month.DEC)); System.out.println(Month.month[3]); monitor.expect(new String[] { "January", "December", "true", "true", "April" }); }} ///:~thᰃϔϾriv ate ᭄Ոin alିˈˈՈᅲDŽ᠔ᰃିႮᏅՈˈᑊᰃin al staticՈ˖ANˈEBˈARˈDŽẝѯᬥmo th᭄DŽẝᰃϔϾկՈthᬥՈ᭄ඈDŽԴϾ᭄ᄫmbe r( )ᮍˈҹ᳜ӑՈthᬥDŽҢmain )ˈẝМᰃିൟՈm ᰃϔϾthՈᇍᬥˈ᠔th DŽݡϾˈth av a ՈᰃϔϾin tՈˈẝϾ᳜ӑՈin tՈˈᰃ☢ᐌDŽmain )Ո᳔ՈˈẝₐԴal s( )DŽПẝМˈᰃthՈϾϾᅲDŽࠄৰতˈԴՈᅮିՈᮍˈϬẝି߯ՈᇍᬥDŽav a.til al arₐ☦ϾnthՈ៤DŽach eՈ J ak arta Co nsњϔିൟՈᎹˈᅗՈˈԚᰃϬᴹ≵ὧМDŽ/commons ՈĀangāˈẝϾᰃrg ap ach co mmo s.an mDŽẝϾ-ₐ☦Ոˈৃ☢ᐌՈିDŽ߱ྟ࣪ষЁՈ᭄៤ਬThinking in Java 3rd EditionষՈ᭄Ⴎᰃstaticin alՈDŽᅗᰃĀՈfinal᭄៤āˈԚᰃৃ☢ᐌՈᴹᇍDŽ˖//: c08:RandVals.java// Initializing interface fields with // non-constant initializers. import java.util.*;public interface RandVals { Random rand = new Random();int randomInt = rand.nextInt(10);long randomLong = rand.nextLong() * 10; float randomFloat = rand.nextLong() * 10;double randomDouble = rand.nextDouble() * 10; } ///:~᭄៤ᰃstaticՈˈିՈᯊˈгᰃৰϔẝ᭄៤ՈᯊDŽᰃϔϾՈ˖//: c08:TestRandVals.javaimport com.bruceeckel.simpletest.*;public class TestRandVals {private static Test monitor = new Test(); public static void main(String[] args) { System.out.println(RandVals.randomInt); System.out.println(RandVals.randomLong); System.out.println(RandVals.randomFloat); System.out.println(RandVals.randomDouble); monitor.expect(new String[] { "%% -?\\d+", "%% -?\\d+","%% -?\\d\\.\\d+E?-?\\d+", "%% -?\\d\\.\\d+E?-?\\d+" }); }} ///:~ˈẝѯ᭄ᰃষՈ៤ᾬˈּẝϾষՈݙDŽষՈጠষିₐˈгষₐ☦DŽẝϔњ☢ᐌՈ˖//: c08:nesting:NestingInterfaces.javapackage c08.nesting;class A {interface B {void f();}public class BImp implements B {public void f() {}}private class BImp2 implements B {public void f() {}}public interface C {void f();}class CImp implements C {public void f() {}}private class CImp2 implements C {public void f() {}}private interface D {void f();}private class DImp implements D {public void f() {}}public class DImp2 implements D {public void f() {}}public D getD() { return new DImp2(); }private D dRef;public void receiveD(D d) {dRef = d;dRef.f();}}interface E {interface G {void f();}// Redundant "public":public interface H {void f();}void g();// Cannot be private within an interface://! private interface I {}}public class NestingInterfaces {public class BImp implements A.B {public void f() {}}class CImp implements A.C {public void f() {}}// Cannot implement a private interface except // within that interface's defining class://! class DImp implements A.D {//! public void f() {}//! }class EImp implements E { public void g() {} }class EGImp implements E.G { public void f() {} }class EImp2 implements E { public void g() {}class EG implements E.G { public void f() {} } }public static void main(String[] args) { A a = new A();// Can't access A.D: //! A.D ad = a.getD();// Doesn't return anything but A.D: //! A.DImp2 di2 = a.getD();// Cannot access a member of the interface: //! a.getD().f();// Only another A can do anything with getD(): A a2 = new A();a2.receiveD(a.getD()); }} ///:~ିₐষՈ᪱ᰃ↨ՈDŽିₐՈষˈᰃbl icack ag eᴗ└ՈDŽ໐ˈbl ic ack ag eᴗ└Ոষ៤bl icˈack ag e ᴗ└ˈriv ateՈĀି(nes ted cl as es )āDŽA.ՈˈՈᡔˈষᰃriv ateՈ(ẝĀষnes ted interfacesāˈгĀିǍnes ted cl as esā)DŽὧМriv ate Ոষˈᅗ៤riv ateՈݙିˈህmpὧˈԚᰃA.mp ៥ˈᅗ៤bl icՈିDŽԚᰃA.mp ႮᏅՈିൟᴹϬDŽԴĀᅗњϾriv ateষāՈˈriv ateষ៤њϔĀὧϾষՈᮍˈԚᰃজିൟ(ᰃ᪸)āՈњDŽtD )ᮍњriv ate ষՈՈೄ๗˖ᰃϔϾbl icᮍˈԚϾriv ate ষՈreferenceDŽẝϾˈmain )њདˈẝϾˈԚᰃ῁њDŽᕫՈᰃˈᡞẝϾϾ᳝ᴗՈᬥüüẝህᰃAՈre ce iv )ᮍDŽThinking in Java 3rd EditionষEњˈষষDŽϡষՈüüĽᰃষՈ᠔ᰃbl icՈẝˈষՈষႮᰃbl icՈˈᅗᰃriv ateՈDŽstin te rf ace sњষՈDŽՈᰃˈᅲষՈᯊˈϡₐ☦ՈষDŽৠriv ateষᅮՈିₐᅲDŽᴹˈẝѯᰃЎĀ᪱ՈϔāՈˈԚᰃ៥ՈˈϔᢧњϔˈႮՈഄᮍDŽݙᾬିϔϾିₐᅮϾିᰃᅠՈDŽẝĀݙି(nnercl ass )āDŽݙିᰃϔ☢ᐌՈˈᅗᇚҢՈିඈᴹˈᑊିՈݙᴗ└DŽԚᰃˈݙି៤ᰃՈˈẝϔ☢ᐌDŽݙିˈԚDŽẝϔՈˈ៥ݙିՈ᪱᪱ˈԴĀ࿁ݙିāՈњDŽݙିՈᮍՈᅠüüᇚିՈᅮՈି(s rro nd ing cl as )˖//: c08:Parcel1.java// Creating inner classes.public class Parcel1 { class Contents {private int i = 11;public int value() { return i; } }class Destination {private String label;Destination(String whereTo) { label = whereTo; }String readLabel() { return label; } }// Using inner classes looks just like // using any other class, within Parcel1: public void ship(String dest) { Contents c = new Contents();Destination d = new Destination(dest); System.out.println(d.readLabel()); }public static void main(String[] args) { Parcel1 p = new Parcel1(); p.ship("Tanzania"); }Thinking in Java 3rd Edition } ///:~sh ip )ˈݙିՈϬିDŽᅲՈᰃˈିՈৡarceₐ☦њDŽϡˈẋˈẝᑊᰃՈDŽՈˈẜᰃᩭିᦤկϾӮݙିՈreferenceՈᮍˈህẝḋ˖//: c08:Parcel2.java// Returning a reference to an inner class.public class Parcel2 {class Contents {private int i = 11;public int value() { return i; }}class Destination {private String label;Destination(String whereTo) {label = whereTo;}String readLabel() { return label; }}public Destination to(String s) {return new Destination(s);}public Contents cont() {return new Contents();}public void ship(String dest) {Contents c = cont();Destination d = to(dest);System.out.println(d.readLabel());}public static void main(String[] args) {Parcel2 p = new Parcel2();p.ship("Tanzania");Parcel2 q = new Parcel2();// Defining references to inner classes:Parcel2.Contents c = q.cont();Parcel2.Destination d = q.to("Borneo");}} ///:~☢ᰃĀି(o ter cl as)āՈ☢staticᮍₐ☦ˈὧₐݙିՈᇍᬥˈ῁terC assN ame.I nnerC assN ame ՈᴹẝϾᇍᬥՈିൟˈህmain )ₐ☦ὧḋDŽThinking in Java 3rd Editionˈݙି☢ᐌՈDŽˈབՈাᰃˈὧМav a њüüିack ag eᴗ└(ack ag eݙ)њˈԩ៤ݙିDŽᰃˈᔧᇚିˈᰃin te rf aceՈᯊˈህˈݙିᰃ᳝ႮᏅՈՈDŽ(ˈᇚᬥՈষᇚିᰃᅠDŽ)ẝḋˈݙିњüüᰃin te rf aceՈᅲњˈѢᰃĀāህᕫњDŽԴᕫࠄՈˈাᰃϔϾିin te rf aceՈreference DŽˈᡅՈ᭛ᴹᅮষˈẝḋĀܼā˖//: c08:Destination.javapublic interface Destination { String readLabel(); } ///:~//: c08:Contents.javapublic interface Contents { int value(); } ///:~te tsstin atio ষњDŽ(ˈin te rf ace៤Ⴎᰃbl ic ՈDŽ)ିin te rf aceՈreference Ոᯊˈ᳝ՈିൟˈህՈ˖//: c08:TestParcel.java// Returning a reference to an inner class.class Parcel3 {private class PContents implements Contents { private int i = 11;public int value() { return i; } }protected class PDestination implements Destination {private String label;private PDestination(String whereTo) { label = whereTo; }public String readLabel() { return label; } }public Destination dest(String s) { return new PDestination(s); }public Contents cont() { return new PContents();Thinking in Java 3rd Edition} }public class TestParcel {public static void main(String[] args) { Parcel3 p = new Parcel3(); Contents c = p.cont();Destination d = p.dest("Tanzania");// Illegal -- can't access private class://! Parcel3.PContents pc = p.new PContents(); }} ///:~ẝϾₐˈmain )Ͼିₐˈẝḋݙିte tsᮍ☦ՈᬜDŽarce њ⚍˖ݙିte t ᰃriv ateՈˈ᠔њarce ˈDŽstin atio ᰃro te cte ˈњarce ˈৠẝϾack ag e Ոି(ro te cte ᴗ└)ˈҹarce Ոණିˈstin atio DŽẝህᰃˈẝѯ៤Ոњᢧᴗ└ᰃ᳝└ࠊՈDŽᅲˈԴᇚᬥϟriv ate Ոݙି(ᰃro te cte Ոݙିˈ☢ԴњẝϾି)ˈˈcl ass T stP arce ՈˈԴẝϾৡDŽˈĀriv ateՈݙିāЎିՈկњϔĀ࿁ିൟᴹේՈ(ty e-co ing d ep end encies )ˈᑊᇚᴹāՈᮍDŽℸˈҢՈᴹˈin te rf aceᰃՈˈbl ic in te rf aceՈᮍDŽẝгњav aϾՈDŽି(☢ݙି)ᰃϡ៤riv atero te cte Ոᰃbl ic ack ag ᴗ└ՈDŽՈݙˈԴњݙିՈDŽˈԴՈˈݙିՈ࣏ˈ῁ᰃѯՈĀᕜՈāݙିDŽԚᰃݙିՈᰃּՈˈẜՈˈϡՈϬկọݙିᮍݙˈᰃϾₐDŽẝМϾˊ˖1.ՈˈԴᅲϾষˈẝḋẝϾষՈDŽ.ϾՈˈ◄ϾିˈԚᰃজẝМϾିDŽThinking in Java 3rd EditionϟᴹՈˈ៥ẝḋᬍࠡՈ࣏˖1. ᮍՈݙϾି2. ᮍՈϾₐᅮϾି3. ϾᅲњϾষՈି4. ϾණњĀϾ᳝☢᭄āՈିՈି5. Ͼ᭄៤Ոି.Ͼ(ݙି᭄)ᴹՈିrap in ᰃϔϾ᳝ՈିˈԚᰃ݊ିՈĀষā˖//: c08:Wrapping.java public class Wrapping { private int i;public Wrapping(int x) { i = x; } public int value() { return i; } } ///:~ˈrap in Ͼ᭄Ո᭄ˈẝᰃЎњᩭᕫDŽৰϔϾњˈᮍՈₐ(ᰃϾିՈₐ)ϾᅠՈିDŽẝĀᴀݙି(ocal nner cl ass )ā˖//: c08:Parcel4.java// Nesting a class within a method.public class Parcel4 {public Destination dest(String s) {class PDestination implements Destination { private String label;private PDestination(String whereTo) { label = whereTo; }public String readLabel() { return label; } }return new PDestination(s); }public static void main(String[] args) { Parcel4 p = new Parcel4();Destination d = p.dest("Tanzania"); }} ///:~stin atio ିᰃarce Ո៤ᾬˈּᰃst( )Ո៤ᾬDŽ(ˈẜᕫˈৠϾᄤₐˈϾିϾstin atio ݙିˈẝМՈDŽ)ˈThinking in Java 3rd Editionњst( )ˈstin atio DŽˈϞüüst( )ᰃϾstin atioՈreference ˈᅗᰃstin atio ՈିDŽᔧˈᡞstin atio st( )ₐˈᑊst( )Ոstinatio ᰃϔϾ᳝ՈᇍᬥDŽՈњˈᗢϾₐݙି˖//: c08:Parcel5.java// Nesting a class within a scope.public class Parcel5 {private void internalTracking(boolean b) { if (b) {class TrackingSlip { private String id;TrackingSlip(String s) { id = s; }String getSlip() { return id; } }TrackingSlip ts = new TrackingSlip("slip"); String s = ts.getSlip(); }// Can't use it here! Out of scope://! TrackingSlip ts = new TrackingSlip("x"); }public void track() { internalTracking(true ); } public static void main(String[] args) { Parcel5 p = new Parcel5(); p.track(); }} ///:~rack in ipifₐ☦DŽẝᑊẝϾିՈᰃ᳝ՈüüՈDŽԚᰃˈẝϾିՈ└ՈὧϾDŽˈᅗՈିDŽẝ˖//: c08:Parcel6.java// A method that returns an anonymous inner class.public class Parcel6 {public Contents cont() { return new Contents() { private int i = 11;public int value() { return i; } }; // Semicolon required in this case }public static void main(String[] args) { Parcel6 p = new Parcel6(); Contents c = p.cont(); }} ///:~co t( )ᮍᇚẘՈĀẝϾՈāିՈᅮˈњϔDŽℸẝϾିᰃՈDŽՈᰃˈՈᰃϔϾte tsᬥ˖return new Contents()ᰃˈՈᯊˈԴˈĀ៥ᰃϡᰃњିՈᅮā˖return new Contents() {private int i = 11;public int value() { return i; } };ẝՈ᪱Ոᛣᰃ˖ĀϾණte tsՈିՈᇍᬥāDŽՈreferenceႮՈϞte tsDŽᅲẝݙିᰃབՈ˖class MyContents implements Contents {private int i = 11;public int value() { return i; } }return new MyContents();ẝϾݙିᰃ᭄ᴹte tsՈDŽẝњབĀିՈᰃϔϾ᭄Ո᭄āՈ᪡ˈὧজ˖//: c08:Parcel7.java// An anonymous inner class that calls // the base-class constructor.public class Parcel7 {public Wrapping wrap(int x) { // Base constructor call:return new Wrapping(x) { // Pass constructor argument.public int value() {return super .value() * 47; }}; // Semicolon required }public static void main(String[] args) { Parcel7 p = new Parcel7(); Wrapping w = p.wrap(10); }} ///:~ẝህᰃˈָᇚড়Ո᭄ӴିՈ᭄ˈህẝₐˈᇚxWrap in x)DŽݙିՈߚିՈՈ(ẝ⚍C+)DŽּˈᅗՈᛣᰃˈẝϾିՈњDŽˈẝϾߚՈ݊ᮍՈᰃᅠDŽᅮିՈ᭄៤Ոᯊ˖//: c08:Parcel8.java// An anonymous inner class that performs// initialization. A briefer version of Parcel4.java.public class Parcel8 {// Argument must be final to use inside // anonymous inner class:public Destination dest(final String dest) { return new Destination() {private String label = dest;public String readLabel() { return label; } }; }public static void main(String[] args) { Parcel8 p = new Parcel8();Destination d = p.dest("Tanzania"); }} ///:~ᅮݙିՈᯊˈẜՈᇍᬥˈὧේẝϾ᭄Ոreference៤in alՈˈህst( )Ո᭄ὧDŽབњˈේՈᯊDŽ᭄៤ˈὧМẝᰃᕜՈDŽԚᰃབĀିԐ᭄Ոāˈὧজݙିₐ᭄()ˈԚᰃ᳝њĀᅲ(nstance ni ti al ati on )āˈԴџϾݙିՈ᭄ˈህẝḋ˖//: c08:AnonymousConstructor.java// Creating a constructor for an anonymous innerclass.import com.bruceeckel.simpletest.*;abstract class Base {public Base(int i) {System.out.println("Base constructor, i = " + i);}public abstract void f();}public class AnonymousConstructor {private static Test monitor = new Test();public static Base getBase(int i) {return new Base(i) {{System.out.println("Inside instanceinitializer");}public void f() {System.out.println("In anonymous f()");}};}public static void main(String[] args) {Base base = getBase(47);base.f();monitor.expect(new String[] {"Base constructor, i = 47","Inside instance initializer","In anonymous f()"});}} ///:~ẝˈiᰃin alՈDŽiିՈିՈ᭄ˈିᰃՈDŽᴹₑĀarcelāẝϾ᪡DŽst( )Ո᭄ᰃin alՈˈିDŽ//: c08:Parcel9.java// Using "instance initialization" to perform// construction on an anonymous inner class.import com.bruceeckel.simpletest.*;public class Parcel9 {private static Test monitor = new Test();public Destinationdest(final String dest, final float price) {return new Destination() {private int cost;// Instance initialization for each object: {cost = Math.round(price);if(cost > 100)System.out.println("Over budget!");}private String label = dest;public String readLabel() { return label; } };}public static void main(String[] args) {Parcel9 p = new Parcel9();Destination d = p.dest("Tanzania", 101.395F);monitor.expect(new String[] {"Over budget!"});}} ///:~ĀᅲāᾬˈԴᰃҹĀᇍ᭄៤ՈāՈᵯᕫࠄՈ(ᰃif)DŽ᠔ˈᅲᰃݙିՈ᭄DŽᔧˈᅗՈᰃ᳝└ՈˈϾ᭄DŽՈ݇ẝₐˈݙିᰃϔՈᮍᓣˈẝгᰃ᳝ՈˈԚՈഄDŽԚᰃˈݙିDŽབњϔϾݙିˈὧМẝϾݙିՈՈᇍᬥˈህՈĀିՈᇍᬥ(encl ing o ect)āњˈẝḋିᬥՈ៤њüüՈᴗDŽℸˈݙିିՈ᠔DŽՈњẝϔ˖//: c08:Sequence.java// Holds a sequence of Objects.import com.bruceeckel.simpletest.*;interface Selector {boolean end();Object current();void next();}public class Sequence {private static Test monitor = new Test();private Object[] objects;private int next = 0;public Sequence(int size) { objects = newObject[size]; }public void add(Object x) {if(next < objects.length)objects[next++] = x;}private class SSelector implements Selector {private int i = 0;public boolean end() { return i ==objects.length; }public Object current() { return objects[i]; } public void next() { if (i < objects.length) i++; } }public Selector getSelector() { return new SSelector(); }public static void main(String[] args) { Sequence sequence = new Sequence(10); for (int i = 0; i < 10; i++)sequence.add(Integer.toString(i));Selector selector = sequence.getSelector(); while (!selector.end()) {System.out.println(selector.current()); selector.next(); }monitor.expect(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }); }} ///:~ce ᰃϔϾݙିՈˈՈbj ct᭄ඈDŽԴad )ᮍẝϾՈՈbj ct (Ո᪡)DŽℸcto r ষᴹceₐ☦ՈᇍᬥˈẝϾষˈᰃϡᰃࠄњ᭄ඈՈ )ᮍˈbj ct Ոcu rre t( )ᮍˈҹce ՈϾbj ct Ոxt( )ᮍDŽcto r ᰃϔϾin te rf aceˈϾିႮᏅՈᮍᴹᅲẝϾin te rf aceˈ໐ᮍẝϾin te rf ace ᭄Ā(g eneric co e)āDŽẝₐՈcto rᰃϔϾկњcto r Ոriv ateିDŽԴˈmain )њϔϾceˈₐ☦њϔtrin DŽˈݡtS cto r( )ᕫࠄњϔϾcto rˈᑊᴹce ՈᇍᬥDŽᴹˈcto rՈݙିDŽԚᰃˈԴˈᅗՈᮍüü )ˈcu rre t( )ˈҹxt( )üüՈbj ct ᰃcto rՈˈּᰃ݊ିՈriv ate៤DŽԚᰃݙିିՈᮍ᭄៤ˈህႮᏅՈDŽҢϞՈᴹˈẝᮍDŽThinking in Java 3rd EditionݙିႮᕫି៤Ոᴗ└DŽὧМᰃᗢẝՈݙିₐϾĀᡅՈāିᬥՈreference DŽẝḋˈᔧିՈ៤ՈᯊˈህὧϾ(Ո)referenceᴹ៤DŽᕫՈᰃˈේẝϔˈᰃԴᰃᑨˈݙିᬥՈᰃϢିᬥՈDŽݙିᬥՈࠡᰃˈᡅᕫିᬥՈreferenceˈབᕫϡẝϾreference ˈᅗDŽ᭄ᚙˈẝϾẋՈDŽẝĀݙିᬥିᬥՈāˈὧМݙି៤static ՈDŽẝĀି(nested cl ass )āDŽᢧstaticݙିՈᛣˈԴˈՈݙିᬥĀᅗՈିᬥˈгᰃՈὧϾᇍᬥՈāreference DŽԚᰃᔧݙିᰃstaticՈᯊˈᰃẝḋњDŽିՈᛣᰃ˖1. ିՈᇍᬥିՈᇍᬥDŽ.ିՈᇍᬥₐ☦☢staticՈିᬥDŽˈିՈݙିDŽݙିՈ៤᭄ᮍିՈẝϔˈՈݙିₐϡstatic᭄ˈstatic᭄៤ିDŽԚᰃˈẝѯିₐ῁˖//: c08:Parcel10.java// Nested classes (static inner classes).public class Parcel10 {private static class ParcelContents implements Contents {private int i = 11;public int value() { return i; } }protected static class ParcelDestination implements Destination { private String label;private ParcelDestination(String whereTo) { label = whereTo; }public String readLabel() { return label; } // Nested classes can contain other static elements:public static void f() {} static int x = 10;static class AnotherLevel { public static void f() {} static int x = 10; } }public static Destination dest(String s) { return new ParcelDestination(s);}public static Contents cont() { return new ParcelContents(); }public static void main(String[] args) { Contents c = cont();Destination d = dest("Tanzania"); }} ///:~main )ₐ☦ˈarce Ոᇍᬥᰃ≵ՈˈԴᕫՓՈˈstatic៤Ո᪱ᴹte tsstin atio ՈreferenceՈᮍDŽᇚᕫˈ(☢static )ՈݙିՈth isreference ᴹϢିᬥֱDŽ໐ିẝϾth isreference ˈẝህᕫᅗstaticᮍњDŽˈ in te rf aceₐ☦ᰃϡՈˈԚିैᰃin te rf aceՈϔDŽିᰃstaticՈˈẝᑊin te rf aceՈüüିষՈৡₐ˖//: c08:IInterface.java// Nested classes inside interfaces.public interface IInterface { static class Inner { int i, j, k;public Inner() {} void f() {} }} ///:~ᴀՈࠡˈ៥᳒Ͼିₐ῁ϾկՈmain )DŽẝϾˈህᰃේˈԴᕫDŽབẝՈᰃϔϾˈὧМିᴹ˖//: c08:TestBed.java// Putting test code in a nested class.public class TestBed { public TestBed() {}public void f() { System.out.println("f()"); } public static class Tester {public static void main(String[] args) { TestBed t = new TestBed(); t.f(); } }。
JAVA编程思想第2章一切都是对象尽管以C++为基础,但Java是一种更纯粹的面向对象程序设计语言”。
无论C++还是Java都属于杂合语言。
但在Java中,设计者觉得这种杂合并不象在C++里那么重要。
杂合语言允许采用多种编程风格;之所以说C++是一种杂合语言,是因为它支持与C语言的向后兼容能力。
由于C++是C的一个超集,所以包含的许多特性都是后者不具备的,这些特性使C++在某些地方显得过于复杂。
Java语言首先便假定了我们只希望进行面向对象的程序设计。
也就是说,正式用它设计之前,必须先将自己的思想转入一个面向对象的世界(除非早已习惯了这个世界的思维方式)。
只有做好这个准备工作,与其他OOP语言相比,才能体会到Java的易学易用。
第6章类再生“Java引人注目的一项特性是代码的重复使用或者再生。
但最具革命意义的是,除代码的复制和修改以外,我们还能做多得多的其他事情。
”在象C那样的程序化语言里,代码的重复使用早已可行,但效果不是特别显著。
与Java 的其他地方一样,这个方案解决的也是与类有关的问题。
我们通过创建新类来重复使用代码,但却用不着重新创建,可以直接使用别人已建好并调试好的现成类。
但这样做必须保证不会干扰原有的代码。
在这一章里,我们将介绍两个达到这一目标的方法。
第一个最简单:在新类里简单地创建原有类的对象。
我们把这种方法叫作“合成”,因为新类由现有类的对象合并而成。
我们只是简单地重复利用代码的功能,而不是采用它的形式。
第二种方法则显得稍微有些技巧。
它创建一个新类,将其作为现有类的一个“类型”。
我们可以原样采取现有类的形式,并在其中加入新代码,同时不会对现有的类产生影响。
这种魔术般的行为叫作“继承”(Inheritance),涉及的大多数工作都是由编译器完成的。
对于面向对象的程序设计,“继承”是最重要的基础概念之一。
第14章多线程利用对象,可将一个程序分割成相互独立的区域。
我们通常也需要将一个程序转换成多个独立运行的子任务。
象这样的每个子任务都叫作一个“线程”(Thread)。
编写程序时,可将每个线程都想象成独立运行,而且都有自己的专用CPU。
一些基础机制实际会为我们自动分割CPU的时间。
我们通常不必关心这些细节问题,所以多线程的代码编写是相当简便的。
这时理解一些定义对以后的学习狠有帮助。
“进程”是指一种“自包容”的运行程序,有自己的地址空间。
“多任务”操作系统能同时运行多个进程(程序)——但实际是由于CPU分时机制的作用,使每个进程都能循环获得自己的CPU时间片。
但由于轮换速度非常快,使得所有程序好象是在“同时”运行一样。
“线程”是进程内部单一的一个顺序控制流。
因此,一个进程可能容纳了多个同时执行的线程。
多线程的应用范围很广。
但在一般情况下,程序的一些部分同特定的事件或资源联系在一起,同时又不想为它而暂停程序其他部分的执行。
这样一来,就可考虑创建一个线程,令其与那个事件或资源关联到一起,并让它独立于主程序运行。
一个很好的例子便是“Quit”或“退出”按钮——我们并不希望在程序的每一部分代码中都轮询这个按钮,同时又希望该按钮能及时地作出响应(使程序看起来似乎经常都在轮询它)。
事实上,多线程最主要的一个用途就是构建一个“反应灵敏”的用户界面。
第15章网络编程历史上的网络编程都倾向于困难、复杂,而且极易出错。
程序员必须掌握与网络有关的大量细节,有时甚至要对硬件有深刻的认识。
一般地,我们需要理解连网协议中不同的“层”(Layer)。
而且对于每个连网库,一般都包含了数量众多的函数,分别涉及信息块的连接、打包和拆包;这些块的来回运输;以及握手等等。
这是一项令人痛苦的工作。
但是,连网本身的概念并不是很难。
我们想获得位于其他地方某台机器上的信息,并把它们移到这儿;或者相反。
这与读写文件非常相似,只是文件存在于远程机器上,而且远程机器有权决定如何处理我们请求或者发送的数据。
Java最出色的一个地方就是它的“无痛苦连网”概念。
有关连网的基层细节已被尽可能地提取出去,并隐藏在JVM以及Java的本机安装系统里进行控制。
我们使用的编程模型是一个文件的模型;事实上,网络连接(一个“套接字”)已被封装到系统对象里,所以可象对其他数据流那样采用同样的方法调用。
除此以外,在我们处理另一个连网问题——同时控制多个网络连接——的时候,Java内建的多线程机制也是十分方便的。
第16章设计范式在向面向对象程序设计的演化过程中,或许最重要的一步就是“设计范式”(Design Pattern)的问世。
它在由Gamma,Helm和Johnson编著的《Design Patterns》一书中被定义成一个“里程碑”(该书由Addison-Wesley于1995年出版,注释①)。
那本书列出了解决这个问题的23种不同的方法。
在最开始,可将范式想象成一种特别聪明、能够自我适应的手法,它可以解决特定类型的问题。
也就是说,它类似一些需要全面认识某个问题的人。
在了解了问题的方方面面以后,最后提出一套最通用、最灵活的解决方案。
具体问题或许是以前见到并解决过的。
然而,从前的方案也许并不是最完善的,大家会看到它如何在一个范式里具体表达出来。
尽管我们称之为“设计范式”,但它们实际上并不局限于设计领域。
思考“范式”时,应脱离传统意义上分析、设计以及实施的思考方式。
相反,“范式”是在一个程序里具体表达一套完整的思想,所以它有时可能出现在分析阶段或者高级设计阶段。
这一点是非常有趣的,因为范式具有以代码形式直接实现的形式,所以可能不希望它在低级设计或者具体实施以前显露出来(而且事实上,除非真正进入那些阶段,否则一般意识不到自己需要一个范式来解决问题)。
范式的基本概念亦可看成是程序设计的基本概念:添加一层新的抽象!只要我们抽象了某些东西,就相当于隔离了特定的细节。
而且这后面最引人注目的动机就是“将保持不变的东西身上发生的变化孤立出来”。
这样做的另一个原因是一旦发现程序的某部分由于这样或那样的原因可能发生变化,我们一般都想防止那些改变在代码内部繁衍出其他变化。
这样做不仅可以降低代码的维护代价,也更便于我们理解(结果同样是降低开销)。
为设计出功能强大且易于维护的应用项目,通常最困难的部分就是找出我称之为“领头变化”的东西。
这意味着需要找出造成系统改变的最重要的东西,或者换一个角度,找出付出代价最高、开销最大的那一部分。
一旦发现了“领头变化”,就可以为自己定下一个焦点,围绕它展开自己的设计。
所以设计范式的最终目标就是将代码中变化的内容隔离开。
如果从这个角度观察,就会发现本书实际已采用了一些设计范式。
举个例子来说,继承可以想象成一种设计范式(类似一个由编译器实现的)。
在都拥有同样接口(即保持不变的东西)的对象内部,它允许我们表达行为上的差异(即发生变化的东西)。
合成亦可想象成一种范式,因为它允许我们修改——动态或静态——用于实现类的对象,所以也能修改类的运作方式。
Thinking in JavaBruce EckelPresident,MindView Inc.2:Everything is an objectAlthough it is based on C++,Java is more of a“pure”object-oriented language.Both C++and Java are hybrid languages,but in Java the designers felt that the hybridization was not as important as it was in C++.A hybrid language allows multiple programming styles;the reason C++is hybrid is to support backward compatibility with the C language.Because C++is a superset of the C language,it includes many of that language’s undesirable features which can make some aspects of C++overly complicated.The Java language assumes that you want to do only object-oriented programming.This means that before you can begin you must shift your mindset into an object-oriented world (unless it’s already there).The benefit of this initial effort is the ability to program in a language that is simpler to learn and to use than many other OOP languages.6:Reusing classesOne of the most compelling features about Java is code reuse.But to be revolutionary,you’ve got to be able to do a lot more than copy code and change it.That’s the approach used in procedural languages like C,and it hasn’t worked very well. Like everything in Java,the solution revolves around the class.You reuse code by creating new classes,but instead of creating them from scratch,you use existing classes that someone has already built and debugged.The trick is to use the classes without soiling the existing code.In this chapter you’ll see two ways to accomplish this.The first is quite straightforward:You simply create objects of your existing class inside the new class.This is called composition because the new class is composed of objects of existing classes.You’re simply reusing the functionality of the code,not its form.The second approach is more subtle.It creates a new class as a type of an existing class.You literally take the form of the existing class and add code to it without modifying the existing class. This magical act is called inheritance,and the compiler does most of the work.Inheritance is one of the cornerstones of object-oriented programming.14:Multiple threadsObjects provide a way to divide a program up into independent sections.Often,you also need to turn a program into separate,independently-running subtasks.Each of these independent subtasks is called a thread,and you program as if each thread runs by itself and has the CPU to itself.Some underlying mechanism is actually dividing up the CPU time for you,but in general,you don’t have to think about it,which makes programming with multiple threads a much easier task.Some definitions are useful at this point.A process is a self-contained running program with its own address space.A multitasking operating system is capable of running more than one process(program)at a time,while making it look like each one is chugging along by periodically providing CPU cycles to each process.A thread is a single sequential flow of control within a process.A single process can thus have multiple concurrently executing threads.There are many possible uses for multithreading,but in general,you’ll have some part of your program tied to a particular event or resource,and you don’t want to hang up the rest of your program because of that.So you create a thread associated with that event or resource and let it run independently of the main program.A good example is a“quit”button–you don’t want to be forced to poll the quit button in every piece of code you write in your program and yet you want the quit button to be responsive,as if you were checking it regularly.In fact,one of the most immediately compelling reasons for multithreading is to produce a responsive userinterface.15:Network programmingHistorically,network programming has been error-prone,difficult,and complex.The programmer had to know many details about the network and sometimes even the hardware.You usually needed to understand the various“layers”of the networking protocol, and there were a lot of different functions in each different networking library concerned with connecting,packing,and unpacking blocks of information;shipping those blocks back and forth; and handshaking.It was a daunting task.However,the concept of networking is not so difficult.You want to get some information from that machine over there and move it to this machine here,or vice versa.It’s quite similar to reading and writing files,except that the file exists on a remote machine and the remote machine can decide exactly what it wants to do about the information you’re requesting or sending.One of Java’s great strengths is painless networking.As much as possible,the underlying details of networking have been abstracted away and taken care of within the JVM and local machine installation of Java.The programming model you use is that of a file;in fact,you actually wrap the network connection(a“socket”)with stream objects,so you end up using the same method calls as you do with all other streams.In addition,Java’s built-in multithreading is exceptionally handy when dealing with another networking issue:handling multiple connections at once.16:Design patternsProbably the most important step forward in object-oriented design is the“design patterns”movement,chronicled in Design Patterns,by Gamma,Helm,Johnson&Vlissides (Addison-Wesley1995).1That book shows23different solutions to particular classes of problems.Initially,you can think of a pattern as an especially clever and insightful way of solving a particular class of problems.That is,it looks like a lot of people have worked out all the angles of a problem and have come up with the most general,flexible solution for it.The problem could be one you have seen and solved before,but your solution probably didn’t have the kind of completeness you’ll see embodied in a pattern.Although they’re called“design patterns,”they really aren’t tied to the realm of design.A pattern seems to stand apart from the traditional way of thinking about analysis,design,and implementation.Instead,a pattern embodies a complete idea within a program,and thus it can sometimes appear at the analysis phase or high-level design phase.This is interesting because a pattern has a direct implementation in code and so you might not expect it to show up before low-level design or implementation(and in fact you might not realize that you need a particular pattern until you get to those phases).The basic concept of a pattern can also be seen as the basic concept of program design: adding a layer of abstraction.Whenever you abstract something you’re isolating particular details,and one of the most compelling motivations behind this is to separate things that change from things that stay the same.Another way to put this is that once you find some part of your program that’s likely to change for one reason or another,you’ll want to keep those changes from propagating other changes throughout your code.Not only does this make the code much cheaper to maintain,but it also turns out that it is usually simpler to understand(which results in lowered costs).Often,the most difficult part of developing an elegant and cheap-to-maintain design is in discovering what I call“the vector of change.”(Here,“vector”refers to the maximum gradient and not a collection class.)This means finding the most important thing that changes in your system,or put another way,discovering where your greatest cost is.Once you discover the vector of change,you have the focal point around which to structure your design.So the goal of design patterns is to isolate changes in your code.If you look at it this way, you’ve been seeing some design patterns already in this book.For example,inheritance can be thought of as a design pattern(albeit one implemented by the compiler).It allows you to express differences in behavior(that’s the thing that changes)in objects that all have the same interface (that’s what stays the same).Composition can also be considered a pattern,since it allows you to change–dynamically or statically–the objects that implement your class,and thus the way that class works.。