JAVA编程思想的翻译
Java编程语言外文翻译、英汉互译、中英对照

文档从互联网中收集,已重新修正排版,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是一种通用的,并发的,基于类的并且是面向对象的计算机编程语言,它是为实现尽可能地减少执行的依赖关系而特别设计的。
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英汉互译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语言与面向对象思想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系列文档+代码+简评

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程序中各种元素的中文名称。
下面是一些常见的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基础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面向对象的理解

java面向对象的理解
面向对象(Object-Oriented)是计算机编程的一种编程思想,它利用种
类和对象之间的关系,在这种方式下开发软件系统,它把一组功能相
关的数据 (或者信息)和功能或者行为封装在一个“对象” 里面。
这种思
想主要表现在编程语言的三个特征:封装、继承与多态。
以下是具体
的内容:
一、封装:
封装是指将数据和操作他的函数结合在一起,限制外界对这些数据的
访问,简而言之就是将对象的状态和行为封装在一起,形成独立的类,这样在程序执行和调试时,可以更加灵活、清晰,也便于复用。
二、继承:
继承是指当一个类(称作父类)的功能太多或者太过复杂时,可以将
其中一部分功能以被独立的类的形式复制出来(称作子类),子类获
得父类的全部功能,并且还可以有自己的独立功能,这样不仅简化了
程序实现(减少重复编程),还保持了代码可读性非常高。
三、多态:
多态是指一个类具有多个功能(例如,一类可以实现多种功能),这
个类可以根据不同的输入参数(例如,不同的输入参数可能导致不同
的输出),以不同的方式来实现多种功能,这样可以有效地实现程序
的功能扩展,提高程序的可维护性。
四、总结:
总的来说,面向对象的编程思想将一组相关的数据和功能封装在一起,并利用继承和多态的原理来简化程序的实现、提高代码的可维护性,
以此达到可复用的目的。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
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.。