




已阅读5页,还剩18页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第1章 Java的起源23第1部分 Java语言第1章 Java的起源When the chronicle of computer languages is written, the following will be said: B led to C, C evolved into C+, and C+ set the stage for Java. To understand Java is to understand the reasons that drove its creation, the forces that shaped it, and the legacy that it inherits. Like the successful computer languages that came before, Java is a blend of the best elements of its rich heritage combined with the innovative concepts required by its unique environment. While the remaining chapters of this book describe the practical aspects of Javaincluding its syntax, libraries, and applicationsin this chapter, you will learn how and why Java came about, and what makes it so important.说起Page: 1对于对于计算机语言的发展史,业界一般大家一般Page: 1业界认为:B语言导致了C语言的诞生B语言促成了 C语言Page: 1B语言导致了 C语言的诞生 ,C语言演变出了C+语言,而C+语言将让位于Java语言。要想更好地了解Java语言,就必须了解它产生的原因、推动它发展的动力,以及它对其他语言的继承。像以前其他成功的计算机语言一样,Java继承了其他语言的先进原理,同时又因其独特的环境要求而提出了一些创新性的概念。在这本书的其他各章中,将从实用的角度,对Java语言、库及应用程序进行包括语法在内的详细介绍。在本章里,我们将介绍Java语言产生的背景、发展过程,以及使它变得如此重要的原因它为什么变得如此重要的原因Page: 1什么使它变得如此重要。Although Java has become inseparably linked with the online environment of the Internet, it is important to remember that Java is first and foremost a programming language. Computer language innovation and development occurs for two fundamental reasons:To adapt to changing environments and usesTo implement refinements and improvements in the art of programmingAs you will see, the creation of Java was driven by both elements in nearly equal measure.尽管Java语言已和Internet的在线环境密不可分,但首先应该注意到的最重要一点是:它是一种程序语言。计算机语言的革新和发展需要2个基本因素的驱动: 适应正在变化的环境和需求 实现编程艺术的完善与提高下面你将看到,Java也正是在这两个因素的驱动下产生的。Java is related to C+, which is a direct descendent of C. Much of the character of Java is inherited from these two languages. From C, Java derives its syntax. Many of Javas object-oriented features were influenced by C+. In fact, several of Javas defining characteristics come fromor are responses toits predecessors. Moreover, the creation of Java was deeply rooted in the process of refinement and adaptation that has been occurring in computer programming languages for the past three decades. For these reasons, this section reviews the sequence of events and forces that led up to Java. As you will see, each innovation in language design was driven by the need to solve a fundamental problem that the preceding languages could not solve. Java is no exception.1.1 Java的由来Java总是和C+联系在一起,而C+则是从C语言派生而来的,所以Java语言继承了这两种语言的大部分特性。Java的语法是从C继承的,Java许多的面向对象的特性受到C+的影响。事实上,Java中几个自定义的特性都来自于或可以追溯到它的前驱。而且,Java语言的产生与过去30年中计算机语言细致改进和适应Page: 2不断不断发展密切相关。基于这些原因,本节将按次序Page: 2顺序顺序回顾促使Java产生的事件和推动力。正如你将看到的一样,每一次语言设计的革新都是因为先前的语言不能解决目前遇到的的基本问题而引起。Java也不例外。1.1.1 现代的编程语言的诞生:C语言 The C language shook the computer world. Its impact should not be underestimated, because it fundamentally changed the way programming was approached and thought about. The creation of C was a direct result of the need for a structured, efficient, high-level language that could replace assembly code when creating systems programs. As you probably know, when a computer language is designed, trade-offs are often made, such as the following:Ease-of-use versus powerSafety versus efficiencyRigidity versus extensibilityC语言的产生震撼了整个计算机界。它的影响不应该被低估,因为它从根本上改变了编程的方法和思路。C语言的产生是人们追求结构化、高效率、高级语言的直接结果,可用它替代汇编语言开发系统程序。当设计一种计算机语言时,经常要从以下几方面进行权衡: 易用性与功能易用和功能强大 安全性和效率性 稳定性和可扩展性C语言出现以前,程序员们不得不经常在有一方面优点而另一方面不足Page: 3有优点而又有欠缺的语言之间做出选择程序员们不得不经常在有优点但在某些方面又有欠缺的语言之间做出选择。例如,尽管公认FORTRAN在科学计算应用方面可以编写出相当高效的程序,但它不适于编写系统程序。BASIC虽然容易学习,但功能不够强大,并且谈不上结构化,这使它应用到大程序的有效性受到怀疑。汇编语言虽能写出高效率的程序,但是学习或有效地使用它却是不容易的。而且,调试汇编程序也相当困难。Another compounding problem was that early computer languages such as BASIC, COBOL, and FORTRAN were not designed around structured principles. Instead, they relied upon the GOTO as a primary means of program control. As a result, programs written using these languages tended to produce “spaghetti code”a mass of tangled jumps and conditional branches that make a program virtually impossible to understand. While languages like Pascal are structured, they were not designed for efficiency, and failed to include certain features necessary to make them applicable to a wide range of programs. (Specifically, given the standard dialects of Pascal available at the time, it was not practical to consider using Pascal for systems-level code.)另一个复杂的问题是,早期设计的计算机语言(如BASIC,COBOL,FORTRAN等)没有考虑结构化设计原则,使用GOTO语句作为对程序控制的一中主要方法语句作为对程序进行控制的一种主要方法。这样做的结果是,用这些语言编写的程序往往成了“意大利面条式的程序代码”,一大堆混乱的跳转语句和条件分支语句使得程序几乎不可能被读懂。Pascal虽然是结构化语言,但它的设计效率比较低,而且缺少几个必需的特性,因而无法在大的编程范围内使用(特别是,给定的Pascal的标准语言在特定时间是可用的,但将Pascal作为系统级程序Page: 3语言考虑是不实际的作为系统级编码是不切实际的)。So, just prior to the invention of C, no one language had reconciled the conflicting attributes that had dogged earlier efforts. Yet the need for such a language was pressing. By the early 1970s, the computer revolution was beginning to take hold, and the demand for software was rapidly outpacing programmers ability to produce it. A great deal of effort was being expended in academic circles in an attempt to create a better computer language. But, and perhaps most importantly, a secondary force was beginning to be felt. Computer hardware was finally becoming common enough that a critical mass was being reached. No longer were computers kept behind locked doors. For the first time, programmers were gaining virtually unlimited access to their machines. This allowed the freedom to experiment. It also allowed programmers to begin to create their own tools. On the eve of Cs creation, the stage was set for a quantum leap forward in computer languages.因此,在C语言产生以前,没有任何一种语言能完全满足人们的需要,但人们对这样一种语言的需要却是迫切的。在20世纪70年代初期,计算机革命开始了,对软件的需求量日益增加,使用早期的计算机语言进行软件开发根本无法满足这种需要。学术界付出很多努力,尝试创造一种更好的计算机语言。但是,促使C语言诞生的另一个,也许是最重要的因素,是计算机硬件资源的富余带来了机遇。Page: 4计算机不再象以前一样,被紧锁在门里,程序员们第一次摆脱了访问他们机器的限制。计算机不再像以前那样被紧锁在门里,程序员们可以随意使用计算机,可以随意进行自由试验Page: 4尝试尝试,因而也就有了可以开发适合自己使用的工具的机会。所以,在C语言诞生的前夕,计算机语言向前飞跃的时机已经成熟。Invented and first implemented by Dennis Ritchie on a DEC PDP-11 running the UNIX operating system, C was the result of a development process that started with an older language called BCPL, developed by Martin Richards. BCPL influenced a language called B, invented by Ken Thompson, which led to the development of C in the 1970s. For many years, the de facto standard for C was the one supplied with the UNIX operating system and described in The C Programming Language by Brian Kernighan and Dennis Ritchie (Prentice-Hall, 1978). C was formally standardized in December 1989, when the American National Standards Institute (ANSI) standard for C was adopted.在Dennis Ritchie第一个发明并且Page: 4和实现和实现在DEC PDP-11上运行UNIX操作系统时,一种更古老的由Martin Richards发展Page: 4设计设计的BCPL语言发展的结果Page: 4导致导致了C语言的产生。受BBCPL语言的影响,由Ken Thompson发明的B语言,CPL 语言产生由Ken Thompson发明的B语言在20世纪70年代逐渐向C语言发展演变。在有此后的许多年里,由Brian Kernighan和Dennis Ritchie编写的The C Programming Language(Prentice-Hall,1978)被认为是事实上的C语言标准,该书认为C只是支持UNIX 操作系统的一种语言。1989年12月,美国国家标准化组织( ANSI )制定了C语言的标准,C语言被正式标准化。The creation of C is considered by many to have marked the beginning of the modern age of computer languages. It successfully synthesized the conflicting attributes that had so troubled earlier languages. The result was a powerful, efficient, structured language that was relatively easy to learn. It also included one other, nearly intangible aspect: it was a programmers language. Prior to the invention of C, computer languages were generally designed either as academic exercises or by bureaucratic committees. C is different. It was designed, implemented, and developed by real, working programmers, reflecting the way that they approached the job of programming. Its features were honed, tested, thought about, and rethought by the people who actually used the language. The result was a language that programmers liked to use. Indeed, C quickly attracted many followers who had a near-religious zeal for it. As such, it found wide and rapid acceptance in the programmer community. In short, C is a language designed by and for programmers. As you will see, Java has inherited this legacy.许多人认为C语言的产生标志着现代计算机语言时代的开始。它成功地综合处理了长期困扰早期语言的冲突Page: 4矛盾矛盾属性。C语言是功能强大的、高效的的结构化语言,简单易学,而且它还包括一个无形的方面:它是程序员自己的语言。在C 的语言出现以前,计算机语言要么被作为学术实验而设计,要么由官僚委员会设计。而C语境Page: 4语言语言不同。它的设计、实现、开发由真正的从事编程工作的程序员来完成,反映了接近Page: 4现实现实编程工作的方法。它的特性经由实际运用该语言的人们不断去提炼、测试、思考、再思考,使得C语言成为结果是C语言是Page: 5这使C语言成为程序员们喜欢使用的语言。确实,C语言迅速吸引了许多狂热的追随者,因而很快受到许多程序员的青睐。简言之,C语言是由程序员设计并由他们使用的一种语言。正如你将看到的,Java继承了这个思想。1.1.2 对C+的需要During the late 1970s and early 1980s, C became the dominant computer programming language, and it is still widely used today. Since C is a successful and useful language, you might ask why a need for something else existed. The answer is complexity. Throughout the history of programming, the increasing complexity of programs has driven the need for better ways to manage that complexity. C+ is a response to that need. To better understand why managing program complexity is fundamental to the creation of C+, consider the following.在20世纪70年代末和80年代初,C成为了主导Page: 5主流主流的计算机编程语言,至今仍被广泛使用。你也许会问,既然C是一种成功且有用的语言,为什么还需要新的计算机语言?答案是复杂性Page: 5复杂度 注:后同复杂性(complexity)。程序越来越复杂这一事实贯穿编程语言的历史。C+正是适应了这一需求。为了更好地理解为什么对程序复杂性的更好管理是下面介绍为什么对程序复杂性的更好管理是C+产生的基本条件。 Approaches to programming have changed dramatically since the invention of the computer. For example, when computers were first invented, programming was done by manually toggling in the binary machine instructions by use of the front panel. As long as programs were just a few hundred instructions long, this approach worked. As programs grew, assembly language was invented so that a programmer could deal with larger, increasingly complex programs by using symbolic representations of the machine instructions. As programs continued to grow, high-level languages were introduced that gave the programmer more tools with which to handle complexity.自从计算机发明以来,编程方法经历了戏剧性的变化。例如,当计算机刚发明出来时,编程是通过前面板触发器用人工打孔的办法输入二进制机器指令Page: 5来令来实现的。对于只有在几百行的程序,这种办法是可行的。随着程序不断增大,人们发明了汇编语言,它通过使用符号来代替机器指令,这样程序员就能处理更大、更复杂的程序。随着程序的进一步增大,高级语言产生了,它给程序员提供了更多的工具来处理复杂性问题。The first widespread language was, of course, FORTRAN. While FORTRAN was an impressive first step, it is hardly a language that encourages clear and easy-to- understand programs. The 1960s gave birth to structured programming. This is the method of programming championed by languages such as C. The use of structured languages enabled programmers to write, for the first time, moderately complex programs fairly easily. However, even with structured programming methods, once a project reaches a certain size, its complexity exceeds what a programmer can manage. By the early 1980s, many projects were pushing the structured approach past its limits. To solve this problem, a new way to program was invented, called object-oriented programming (OOP). Object-oriented programming is discussed in detail later in this book, but here is a brief definition: OOP is a programming methodology that helps organize complex programs through the use of inheritance, encapsulation, and polymorphism.第一个被广泛使用的高级语言当然是FORTRAN。尽管FORTRAN最初给人留下了深刻的印象,但它无法开发出条理清楚易于理解的程序。20世纪60年代提出了结构化编程方法。这种结构化的编程思想被像C这样的语言所应用,第一次使程序员可以相对轻松地编写适度复杂的程序。然而,当一个工程项目达到一定规模后,即使使用结构化编程方法,编程人员也无法对它的复杂性进行有效管理。20世纪80年代初期,许多工程项目的复杂性都超过了结构化方法的极限。为解决这个问题,面向对象的编程(object-oriented programming,OOP)新方法诞生了。面向对象的编程在这本书的后面详细讨论,但在这里给出一个简短的定义:面向对象的编程是通过使用继承性、封装性和多态性来帮助组织复杂程序的编程方法。In the final analysis, although C is one of the worlds great programming languages, there is a limit to its ability to handle complexity. Once a program exceeds somewhere between 25,000 and 100,000 lines of code, it becomes so complex that it is difficult to grasp as a totality. C+ allows this barrier to be broken, and helps the programmer comprehend and manage larger programs.总之,尽管C是世界上伟大的编程语言之一,但它处理复杂性的能力有限。一旦一个程序的代码超过25 000100 000行,就很难从总体上把握它的复杂性了。C+突破了这个限制,帮助程序员理解并且管理更大的程序。C+ was invented by Bjarne Stroustrup in 1979, while he was working at Bell Laboratories in Murray Hill, New Jersey. Stroustrup initially called the new language “C with Classes.” However, in 1983, the name was changed to C+. C+ extends C by adding object-oriented features. Because C+ is built upon the foundation of C, it includes all of Cs features, attributes, and benefits. This is a crucial reason for the success of C+ as a language. The invention of C+ was not an attempt to create a completely new programming language. Instead, it was an enhancement to an already highly successful one. C+ was standardized in November 1997, and an ANSI/ISO standard for C+ is now available.1979年,当Bjarne Stroustrup在新泽西州的Murray Hill实验室工作时,发明了C+。Stroustrup 最初把这种新语言称为“带类的C”。1983年,改名为C+。C+通过增加面向对象的特性扩充了C。因为C+产生在C的基础之上,因此它包括了C所有的特征、属性和优点。这是C+作为语言成功的一个关键原因。C+的发明不是企图创造一种完全新的编程语言,而是对一个已经高度成功的语言的改进。C+在1997年11月被标准化,目前的标准是ANSI/ISO。1.1.3 Java出现的时机已经到来By the end of the 1980s and the early 1990s, object-oriented programming using C+ took hold. Indeed, for a brief moment it seemed as if programmers had finally found the perfect language. Because C+ blended the high efficiency and stylistic elements of C with the object-oriented paradigm, it was a language that could be used to create a wide range of programs. However, just as in the past, forces were brewing that would, once again, drive computer language evolution forward. Within a few years, the World Wide Web and the Internet would reach critical mass. This event would precipitate another revolution in programming.在20世纪80年代末和20 世纪 90年代初,使用面向对象编程的C+语言占主导地位。的确,有一段时间程序员似乎都认为已经找到了一种完美的语言。因为C+有面向对象的特征,又有C语言高效和格式上的优点,因此它是一中种可以被广泛应用的编程语言。然而,就像过去一样,推动计算机语言进化的力量正在酝酿。在随后的几年里,万维网(WWW)和Internet达到临界状态物质。这个事件促成编程的另一场革命。1.2 Java的产生Java was conceived by James Gosling, Patrick Naughton, Chris Warth, Ed Frank, and Mike Sheridan at Sun Microsystems, Inc. in 1991. It took 18 months to develop the first working version. This language was initially called “Oak” but was renamed “Java” in 1995. Between the initial implementation of Oak in the fall of 1992 and the public announcement of Java in the spring of 1995, many more people contributed to the design and evolution of the language. Bill Joy, Arthur van Hoff, Jonathan Payne, Frank Yellin, and Tim Lindholm were key contributors to the maturing of the original prototype.Java是由James Gosling,Patrick Naughton,Chris Warth,Ed Frank和Mike Sheridan于1991年在Sun Microsystems公司设想Page: 8设计设计出来的。开发第一个版本花了18个月。该语言开始名叫“Oak”,于1995年更名为“Java”。从1992 的秋天Oak问世到1995的春天公开发布Java语言,许多人对Java语言的设计和改进做出了贡献。Bill Joy,Arthur van Hoff,Jonathan Payne,Frank Yellin和Tim Lindholm是主要的贡献者,正是他们的贡献使对最初原型的得以成熟是关键的贡献者。 Somewhat surprisingly, the original impetus for Java was not the Internet! Instead, the primary motivation was the need for a platform-independent (that is, architecture- neutral) language that could be used to create software to be embedded in various consumer electronic devices, such as microwave ovens and remote controls. As you can probably guess, many different types of CPUs are used as controllers. The trouble with C and C+ (and most other languages) is that they are designed to be compiled for a specific target. Although it is possible to compile a C+ program for just about any type of CPU, to do so requires a full C+ compiler targeted for that CPU. The problem is that compilers are expensive and time-consuming to create. An easierand more cost-efficientsolution was needed. In an attempt to find such a solution, Gosling and others began work on a portable, platform-independent language that could be used to produce code that would run on a variety of CPUs under differing environments. This effort ultimately led to the creation of Java.说起来多少有些令人吃惊,Java的最初推动力并不是因特网!而是源于对独立于平台(也就是体系结构中立)语言的需要,这种语言可创建能够嵌入微波炉、遥控器等各种家用电器设备的软件。用作控制器的CPU芯片是多种多样的,但C和C+以及其他绝大多数语言的缺点是只能对特定目标进行编译。尽管为任何类型的CPU芯片编译C+程序是可能的,但这样做需要一个完整的以该CPU为目标的C+编译器,而创建编译器是一项既耗资巨大又耗时较长的工作。因此需要一种简单且经济的解决方案。为了找到这样一种方案,Gosling 和其他人开始一起致力于开发一种可移植、跨平台的语言,该语言能够生成运行于不同环境、不同CPU芯片上的代码。他们的努力最终促成了Java的诞生。About the time that the details of Java were being worked out, a second, and ultimately more important, factor was emerging that would play a crucial role in the future of Java. This second force was, of course, the World Wide Web. Had the Web not taken shape at about the same time that Java was being implemented, Java might have remained a useful but obscure language for programming consumer electronics. However, with the emergence of the World Wide Web, Java was propelled to the forefront of computer language design, because the Web, too, demanded portable programs.在Java的一些细节被设计出来的同时,第二个并且也是最重要的因素出现了,该因素将对Java的未来起着至关重要的作用。这第二个因素当然就是万维网(WWW)。如果万维网(WWW)的成型和Java的实现不是同时发生的话,那么Java可能保持它有用、但默默无闻的用于电子消费品编程语言的状态。然而,随着万维网的出现,Java被推到计算机语言设计的最前沿,因为万维网也需要可移植的程序。Most programmers learn early in their careers that portable programs are as elusive as they are desirable. While the quest for a way to create efficient, portable (platform-independent) programs is nearly as old as the discipline of programming itself, it had taken a back seat to other, more pressing problems. Further, because much of the computer world had divided itself into the three competing camps of Intel, Macintosh, and UNIX, most programmers stayed within their fortified boundaries, and the urgent need for portable code was reduced. However, with the advent of the Internet and the Web, the old problem of portability returned with a vengeance. After all, the Internet consists of a diverse, distributed universe populated with many types of computers, operating systems, and CPUs. Even though many types of platforms are attached to the Internet, users would like them all to be able to run the same program. What was once an irritating but low-priority problem had become a high-profile necessity.绝大多数程序员在涉足编程领域时都就知道可移植的程序像他们的所理想的一样难以捉摸。尽管人
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 护理质量管理制度
- 安全教育夹手事故防范与应对
- 消化内科出科感悟
- 物业开放日活动方案
- 绿色农业技术推广存在的问题及对策探究
- 婚姻解除后彩礼及财产分割标准协议书
- 翻译保密协议旅游攻略笔译保密合同
- 茶园土地流转与农业循环经济发展合作合同
- 车贷保险兼担保服务合同
- 竞业限制保密协议模板金融行业
- GB/T 37234-2018文件鉴定通用规范
- 健康减肥调脂降糖
- LaTeX科技排版课件
- 2023年河北交通投资集团有限公司招聘笔试题库及答案解析
- 反向传播算法课件
- 企业质量安全主体责任
- 南模自招试卷-2012年自主招生
- 数据仓库开发规范
- 可下载打印的公司章程
- 固定资产报废申请单
- 小学美术人美五年级上册偶戏皮影研究课教案
评论
0/150
提交评论