CHAPTER 1 Introduction to Java(TM) Technology
第一章 Java技术简介
The Next Stage of the Known,Or a Completely New Paradigm?
是现状的下一个阶段,还是一个全新的范式?
Taiichi Sakaiya-- The Knowledge-Value Revolution
长官界屋太一--知识价值革命
The Software Developer's Burden
软件开发人员的负担
Imagine you're a software application developer. Your programming language of choice (or the language that's been foisted on you) is C or C++. You've been at this for quite a while and your job doesn't seem to be getting any easier. These past few years you've seen the growth of multiple incompatible hardware architectures, each supporting multiple incompatible operating systems, with each platform operating with one or more incompatible graphical user interfaces. Now you're supposed to cope with all this and make your applications work in a distributed client-server environment. The growth of the Internet, the World-Wide Web, and "electronic commerce" have introduced new dimensions of complexity into the development process.
假设您是一名软件应用程序开发人员。您选择的编程语言(或强加给您的语言)是C或c++,你干这行已经有一段时间了,你的工作似乎一点也不轻松。在过去的几年里,您已经看到了多个不兼容硬件架构的发展,每个架构都支持多个不兼容的操作系统,每个平台都使用一个或多个不兼容的图形用户界面进行操作。现在您应该处理所有这些问题,并使您的应用程序在分布式客户机-服务器环境中工作。互联网、万维网和“电子商务”的发展给发展进程带来了新的复杂性。
The tools you use to develop applications don't seem to help you much. You're still coping with the same old problems; the fashionable new object-oriented techniques seem to have added new problems without solving the old ones. You say to yourself and your friends, "There has to be a better way"!
您用于开发应用程序的工具似乎对您帮助不大。你仍然在处理同样的老问题;流行的面向对象的新技术似乎在没有解决旧问题的情况下增加了新问题。你对自己和朋友说,“一定有更好的方法”!
The Better Way is Here Now
更好的方法就在这里
Now there is a better way -- the Java TM programming language platform from Sun Microsystems. Imagine, if you will, this development world...
现在有一种更好的方法——Sun Microsystems的Java编程语言平台。想象一下,如果你愿意,它能重构世界…
●Your programming language is object oriented, yet it's still dead simple.
您的编程语言是面向对象的,但它仍然非常简单。
●Your development cycle is much faster because Java technology is interpreted. The compile-link-load-test-crash-debug cycle is obsolete--now you just compile and run.
由于Java技术是解释执行的,所以开发周期要快得多。编译-链接-加载-测试-崩溃-调试的周期已经过时了,现在只需要编译和运行即可。
●Your applications are portable across multiple platforms. Write your applications once, and you never need to port them--they will run without modification on multiple operating systems and hardware architectures.
您的应用程序可以跨多个平台移植。编写应用程序一次,您就不需要移植它们——它们将在多个操作系统和硬件体系结构上运行,而无需修改。
●Your applications are robust because the Java runtime environment manages memory for you.
您的应用程序是健壮的,因为Java运行时环境为您管理内存。
●Your interactive graphical applications have high performance because multiple concurrent threads of activity in your application are supported by the multithreading built into the Java programming language and runtime platform.
交互式图形应用程序具有高性能,因为Java编程语言和运行时平台内置的多线程支持应用程序中的多个活动并发线程。
●Your applications are adaptable to changing environments because you can dynamically download code modules from anywhere on the network.
您的应用程序可以适应不断变化的环境,因为您可以从网络上的任何地方动态下载代码模块。
●Your end users can trust that your applications are secure, even though they're downloading code from all over the Internet; the Java runtime environment has built-in protection against viruses and tampering.
您的最终用户可以相信您的应用程序是安全的,即使他们正在从Internet上下载代码;Java运行时环境具有针对病毒和篡改的内置保护。
You don't need to dream about these features. They're here now. The Java programming language platform provides a portable, interpreted, high-performance, simple, object-oriented programming language and supporting run-time environment. This introductory chapter provides you with a brief look at the main design goals of the Java system; the remainder of this paper examines the features of Java in more detail.
您不需要幻想这些功能特性,他们现在就在这里。Java编程语言平台提供了一种可移植的、解释的、高性能的、简单的、面向对象的编程语言,并且支持运行时环境。本介绍性章节简要介绍了Java系统的主要设计目标;本文的其余部分将更详细地研究Java的特性。
The last chapter of this paper describes the HotJava TM Browser . The HotJava Browser is an innovative World-Wide Web browser, and the first major applications written using the Java platform. It is the first browser to dynamically download and execute Java code fragments from anywhere on the Internet, and can do so in a secure manner.
本文的最后一章描述了HotJava TM浏览器。HotJava浏览器是一种创新的全球Web浏览器,也是第一个使用Java平台编写的主要应用程序。它是第一个从Internet上的任何地方动态下载和执行Java代码片段的浏览器,并且可以以安全的方式这样做。
1.1 Beginnings of the Java(TM) Programming Language Project
Java编程语言项目的开始
The Java TM programming language is designed to meet the challenges of application development in the context of heterogeneous, network-wide distributed environments. Paramount among these challenges is secure delivery of applications that consume the minimum of system resources, can run on any hardware and software platform, and can be extended dynamically.
Java编程语言是为了在异构的、网络范围的分布式环境中满足应用程序开发的挑战而设计的。这些挑战中最重要的是安全交付的应用程序,这些应用程序消耗最少的系统资源,可以在任何硬件和软件平台上运行,并且可以动态扩展。
The Java programming language originated as part of a research project to develop advanced software for a wide variety of network devices and embedded systems. The goal was to develop a small, reliable, portable, distributed, real-time operating platform. When the project started, C++ was the language of choice. But over time the difficulties encountered with C++ grew to the point where the problems could best be addressed by creating an entirely new language platform. Design and architecture decisions drew from a variety of languages such as Eiffel, SmallTalk, Objective C, and Cedar/Mesa. The result is a language platform that has proven ideal for developing secure, distributed, network-based end-user applications in environments ranging from network-embedded devices to the World-Wide Web and the desktop.
Java编程语言最初是一个研究项目的一部分,目的是为各种网络设备和嵌入式系统开发高级软件。其目标是开发一个小型、可靠、可移植、分布式、实时的操作平台。当项目开始时,c++是首选语言。但是随着时间的推移,c++遇到的困难逐渐增长到可以通过创建一个全新的语言平台来最好地解决问题。设计和架构决策来自各种语言,如埃菲尔、SmallTalk、Objective C和Cedar/Mesa。其结果是一个语言平台,它已被证明是在从网络嵌入式设备到全球Web和桌面的各种环境中开发安全的、分布式的、基于网络的最终用户应用程序的理想选择。
1.2 Design Goals of the Java TM Programming Language
Java编程语言项目的设计目标
The design requirements of the Java TM programming language are driven by the nature of the computing environments in which software must be deployed.
Java编程语言的设计需求是由必须部署软件的计算环境的特性驱动的。
The massive growth of the Internet and the World-Wide Web leads us to a completely new way of looking at development and distribution of software. To live in the world of electronic commerce and distribution, Java technology must enable the development of secure, high performance, and highly robust applications on multiple platforms in heterogeneous, distributed networks.
因特网和万维网的迅速发展使我们以一种全新的方式看待软件的开发和发行。要生活在电子商务和分发的世界中,Java技术必须能够在异构、分布式网络的多个平台上开发安全、高性能和高度健壮的应用程序。
Operating on multiple platforms in heterogeneous networks invalidates the traditional schemes of binary distribution, release, upgrade, patch, and so on. To survive in this jungle, the Java programming language must be architecture neutral, portable, and dynamically adaptable.
在异构网络的多个平台上运行,使传统的二进制分发、发布、升级、补丁等方案失效。为了在这种丛林中生存,Java编程语言必须是架构中立、可移植和动态适应的。
The system that emerged to meet these needs is simple, so it can be easily programmed by most developers; familiar, so that current developers can easily learn the Java programming language; object oriented, to take advantage of modern software development methodologies and to fit into distributed client-server applications; multithreaded, for high performance in applications that need to perform multiple concurrent activities, such as multimedia; and interpreted, for maximum portability and dynamic capabilities.
为满足这些需求而出现的系统很简单,因此大多数开发人员可以很容易地对其进行编程;熟悉,使当前开发人员可以轻松学习Java编程语言;面向对象,利用现代软件开发方法,适应分布式客户机-服务器应用;多线程,用于需要执行多个并发活动(如多媒体)的应用程序的高性能;并进行了解释,以获得最大的可移植性和动态能力。
Together, the above requirements comprise quite a collection of buzzwords, so let's examine some of them and their respective benefits before going on.
综上所述,上述需求包含了相当多的流行语,所以在继续之前,让我们先来看看其中一些流行语及其各自的好处。
1.2.1 Simple, Object Oriented, and Familiar
简单、面向对象和亲切
Primary characteristics of the Java programming language include a simple language that can be programmed without extensive programmer training while being attuned to current software practices. The fundamental concepts of Java technology are grasped quickly; programmers can be productive from the very beginning.
Java编程语言的主要特征包括一种简单的语言,这种语言在适应当前软件实践的同时无需经过大量的程序员培训就可以进行编程。快速掌握Java技术的基本概念;程序员可以从一开始就富有成效。
The Java programming language is designed to be object oriented from the ground up. Object technology has finally found its way into the programming mainstream after a gestation period of thirty years. The needs of distributed, client-server based systems coincide with the encapsulated, message-passing paradigms of object-based software. To function within increasingly complex, network-based environments, programming systems must adopt object-oriented concepts. Java technology provides a clean and efficient object-based development platform.
Java编程语言从一开始就被设计成面向对象的。经过30年的孕育,对象技术终于进入了编程主流。分布式的、基于客户机-服务器的系统的需求与封装的、基于对象的软件的消息传递范式相一致。要在日益复杂的、基于网络的环境中工作,编程系统必须采用面向对象的概念。Java技术提供了一个干净高效的基于对象的开发平台。
Programmers using the Java programming language can access existing libraries of tested objects that provide functionality ranging from basic data types through I/O and network interfaces to graphical user interface toolkits. These libraries can be extended to provide new behavior.
使用Java编程语言的程序员可以访问测试对象的现有库,这些库提供从基本数据类型到I/O和网络接口到图形用户界面工具包的各种功能。这些库可以扩展以提供新的行为。
Even though C++ was rejected as an implementation language, keeping the Java programming language looking like C++ as far as possible results in it being a familiar language, while removing the unnecessary complexities of C++. Having the Java programming language retain many of the object-oriented features and the "look and feel" of C++ means that programmers can migrate easily to the Java platform and be productive quickly.
尽管c++被拒绝作为一种实现语言,但是尽可能使Java编程语言看起来像c++,会使它成为一种熟悉的语言,同时消除c++不必要的复杂性。Java编程语言保留了许多面向对象的特性,以及c++的“外观和感觉”,这意味着程序员可以轻松地迁移到Java平台,并快速提高生产率。
1.2.2 Robust and Secure
健壮的和安全的
The Java programming language is designed for creating highly reliable software. It provides extensive compile-time checking, followed by a second level of run-time checking. Language features guide programmers towards reliable programming habits.
Java编程语言是为创建高度可靠的软件而设计的。它提供了广泛的编译时检查,然后是第二级运行时检查。语言特性引导程序员养成可靠的编程习惯。
The memory management model is extremely simple: objects are created with a new operator. There are no explicit programmer-defined pointer data types, no pointer arithmetic, and automatic garbage collection. This simple memory management model eliminates entire classes of programming errors that bedevil C and C++ programmers. You can develop Java code with confidence that the system will find many errors quickly and that major problems won't lay dormant until after your production code has shipped.
内存管理模型非常简单:用一个新的操作符创建对象。没有明确的程序员定义的指针数据类型,没有指针算术,也没有自动垃圾收集。这个简单的内存管理模型消除了困扰C和c++程序员的所有编程错误。您可以满怀信心地开发Java代码,相信系统会很快发现许多错误,并且在您的产品代码发布之前,主要问题不会潜伏。
Java technology is designed to operate in distributed environments, which means that security is of paramount importance. With security features designed into the language and run-time system, Java technology lets you construct applications that can't be invaded from outside. In the network environment, applications written in the Java programming language are secure from intrusion by unauthorized code attempting to get behind the scenes and create viruses or invade file systems.
Java技术设计用于在分布式环境中操作,这意味着安全性是至关重要的。通过将安全特性设计到语言和运行时系统中,Java技术允许您构建不能被外部入侵的应用程序。在网络环境中,用Java编程语言编写的应用程序是安全的,不会受到试图进入后台并创建病毒或入侵文件系统的未授权代码的入侵。
1.2.3 Architecture Neutral and Portable
体系结构中立且可移植
Java technology is designed to support applications that will be deployed into heterogeneous network environments. In such environments, applications must be capable of executing on a variety of hardware architectures. Within this variety of hardware platforms, applications must execute atop a variety of operating systems and interoperate with multiple programming language interfaces. To accommodate the diversity of operating environments, the Java Compiler TM product generates bytecodes--an architecture neutral intermediate format designed to transport code efficiently to multiple hardware and software platforms. The interpreted nature of Java technology solves both the binary distribution problem and the version problem; the same Java programming language byte codes will run on any platform.
Java技术旨在支持将部署到异构网络环境中的应用程序。在这种环境中,应用程序必须能够在各种硬件架构上执行。在各种硬件平台中,应用程序必须在各种操作系统之上执行,并与多个编程语言接口互操作。为了适应操作环境的多样性,Java Compiler TM产品生成字节码——一种与体系结构无关的中间格式,旨在有效地将代码传输到多个硬件和软件平台。Java技术的解释性解决了二进制分布问题和版本问题;相同的Java编程语言字节码可以在任何平台上运行。
Architecture neutrality is just one part of a truly portable system. Java technology takes portability a stage further by being strict in its definition of the basic language. Java technology puts a stake in the ground and specifies the sizes of its basic data types and the behavior of its arithmetic operators. Your programs are the same on every platform--there are no data type incompatibilities across hardware and software architectures.
架构中立性只是真正可移植系统的一部分。Java技术通过严格定义基本语言将可移植性更进一步。Java技术将赌注压在地面上,并指定其基本数据类型的大小和算术操作符的行为。您的程序在每个平台上都是相同的——在硬件和软件架构之间不存在数据类型不兼容的问题。
The architecture-neutral and portable language platform of Java technology is known as the Java virtual machine. It's the specification of an abstract machine for which Java programming language compilers can generate code. Specific implementations of the Java virtual machine for specific hardware and software platforms then provide the concrete realization of the virtual machine. The Java virtual machine is based primarily on the POSIX interface specification--an industry-standard definition of a portable system interface. Implementing the Java virtual machine on new architectures is a relatively straightforward task as long as the target platform meets basic requirements such as support for multithreading.
Java技术中与体系结构无关且可移植的语言平台称为Java虚拟机。它是一个抽象机器的规范,Java编程语言编译器可以为它生成代码。Java虚拟机的具体实现为具体的软硬件平台提供了虚拟机的具体实现。Java虚拟机主要基于POSIX接口规范——可移植系统接口的行业标准定义。在新体系结构上实现Java虚拟机是一项相对简单的任务,只要目标平台满足基本需求(比如支持多线程)。
1.2.4 High Performance
高性能
Performance is always a consideration. The Java platform achieves superior performance by adopting a scheme by which the interpreter can run at full speed without needing to check the run-time environment. The automatic garbage collector runs as a low-priority background thread, ensuring a high probability that memory is available when required, leading to better performance. Applications requiring large amounts of compute power can be designed such that compute-intensive sections can be rewritten in native machine code as required and interfaced with the Java platform. In general, users perceive that interactive applications respond quickly even though they're interpreted.
性能始终是一个考虑因素。Java平台通过采用一种无需检查运行时环境就能使解释器全速运行的方案来实现卓越的性能。自动垃圾收集器作为低优先级的后台线程运行,确保在需要时内存可用的高概率,从而提高性能。需要大量计算能力的应用程序可以这样设计:计算密集型部分可以根据需要用本机机器码重写,并与Java平台交互。一般来说,用户认为交互式应用程序即使经过解释,也能快速响应。
1.2.5 Interpreted, Threaded, and Dynamic
解释执行、多线程和动态
The Java interpreter can execute Java bytecodes directly on any machine to which the interpreter and run-time system have been ported. In an interpreted platform such as Java technology-based system, the link phase of a program is simple, incremental, and lightweight. You benefit from much faster development cycles--prototyping, experimentation, and rapid development are the normal case, versus the traditional heavyweight compile, link, and test cycles.
Java解释器可以在解释器和运行时系统已经移植到的任何机器上直接执行Java字节码。在解释的平台(如基于Java技术的系统)中,程序的链接阶段是简单的、增量的和轻量级的。您可以从更快的开发周期中获益——与传统的重量级编译、链接和测试周期相比,原型化、实验和快速开发是正常的情况。
Modern network-based applications, such as the HotJava TM Browser for the World Wide Web, typically need to do several things at the same time. A user working with HotJava Browser can run several animations concurrently while downloading an image and scrolling the page. Java technology's multithreading capability provides the means to build applications with many concurrent threads of activity. Multithreading thus results in a high degree of interactivity for the end user.
现代基于网络的应用程序,例如用于万维网的HotJava TM浏览器,通常需要同时做几件事情。使用HotJava浏览器的用户可以同时运行多个动画,同时下载图像和滚动页面。Java技术的多线程功能提供了构建具有许多并发活动线程的应用程序的方法。因此,多线程为最终用户带来了高度的交互性。
The Java platform supports multithreading at the language level with the addition of sophisticated synchronization primitives: the language library provides the Thread class, and the run-time system provides monitor and condition lock primitives. At the library level, moreover, Java technology's high-level system libraries have been written to be thread safe: the functionality provided by the libraries is available without conflict to multiple concurrent threads of execution.
Java平台通过添加复杂的同步原语在语言级别上支持多线程:语言库提供线程类,运行时系统提供监视器和条件锁原语。此外,在库级别,Java技术的高级系统库被编写成线程安全的:库提供的功能可以在不与多个并发执行线程冲突的情况下使用。
While the Java Compiler is strict in its compile-time static checking, the language and run-time system are dynamic in their linking stages. Classes are linked only as needed. New code modules can be linked in on demand from a variety of sources, even from sources across a network. In the case of the HotJava Browser and similar applications, interactive executable code can be loaded from anywhere, which enables transparent updating of applications. The result is on-line services that constantly evolve; they can remain innovative and fresh, draw more customers, and spur the growth of electronic commerce on the Internet.
虽然Java编译器在编译时静态检查方面很严格,但是语言和运行时系统在链接阶段是动态的。只有在需要时才链接类。新的代码模块可以根据需要从各种来源链接进来,甚至可以从网络上的来源链接进来。对于HotJava浏览器和类似的应用程序,交互式可执行代码可以从任何地方加载,从而支持应用程序的透明更新。结果是在线服务不断发展;它们可以保持创新和新鲜,吸引更多的客户,并刺激互联网电子商务的增长。
1.3 The Java Platform--a New Approach to Distributed Computing
Java平台——一种新的分布式计算方法
Taken individually, the characteristics discussed above can be found in a variety of software development platforms. What's completely new is the manner in which Java technology and its runtime environment have combined them to produce a flexible and powerful programming system.
单独来看,上面讨论的特性可以在各种软件开发平台中找到。全新的是Java技术及其运行时环境将它们结合在一起,从而产生了一个灵活而强大的编程系统。
Developing your applications using the Java programming language results in software that is portable across multiple machine architectures, operating systems, and graphical user interfaces, secure, and high performance. With Java technology, your job as a software developer is much easier--you focus your full attention on the end goal of shipping innovative products on time, based on the solid foundation of the Java platform. The better way to develop software is here, now, brought to you by the Java platform.
使用Java编程语言开发应用程序会生成可跨多个机器体系结构、操作系统和图形用户界面移植的软件,安全且高性能。使用Java技术,您作为软件开发人员的工作要容易得多——您将全部精力集中在按时交付创新产品的最终目标上,这些目标基于Java平台的坚实基础。现在,开发软件的更好方法就在这里,由Java平台提供给您。