视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
java基础功能介绍外文翻译
2025-09-24 06:35:20 责编:小OO
文档
外文原文

Java Fundamentals

The rise of the Internet and the World Wide Web have fundamentally reshaped computing. Only a few short years ago, the cyber landscape was dominated by stand-alone PCs. Today, nearly all PCs are connected to the Internet. The Internet, itself, was transformed—originally offering a convenient way to share files and information, today it is a vast, distributed computing universe. These changes have been as rapid as they have been profound, and in their wake, they gave rise to a new way to program: Java. Java is the preeminent language of the Internet, but it is more than that. Java has revolutionized programming, changing the way that we think about both the form and the function of a program. To be a professional programmer today implies the ability to program in Java—it has become that important. In the course of this book, you will learn the skills needed to master it. The purpose of this module is to introduce you to Java, including its history, its design philosophy, and several of its most important features. By far, the hardest thing about learning a programming language is the fact that no element exists in isolation. Instead, the components of the language work in conjunction with each other. This interrelatedness is especially pronounced in Java. In fact, it is difficult to discuss one aspect of Java without involving others. To help overcome this problem, this module provides a brief overview of several Java features, including the general form of a Java program, some basic control structures, and operators. It does not go into too many details but, rather, concentrates on the general concepts common to any Java program.

1.1 The Origins of Java

Computer language innovation is driven forward by two factors: improvements in the art of programming and changes in the computing environment. Java is no exception. Building upon the rich legacy inherited from C and C++, Java adds refinements and features that reflect the current state of the art in programming. Responding to the rise of the online environment, Java offers features that streamline programming for a highly distributed architecture.

Java was conceived by James Gosling, Patrick Naughton, Chris Warth, Ed Frank, and Mike Sheridan at Sun Microsystems in 1991. This language was initially called “Oak” but was renamed “Java” in 1995. Somewhat surprisingly, the original impetus for Java was not the Internet! Instead, the primary motivation was the need for a platform-independent language that could be used to create software to be embedded in various consumer electronic devices, such as toasters, microwave ovens, and remote controls. As you can probably guess, many different types of CPUs are used as controllers. The trouble was that most computer languages are designed to be compiled for a specific target. For example, consider C++.       

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, however, is that compilers are expensive and time-consuming to create. In an attempt to find a better solution, Gosling Java Fundamentals and others worked on a portable, cross-platform language that could produce code that would run on a variety of CPUs under differing environments. This effort ultimately led to the creation of Java.

About the time that the details of Java were being worked out, a second, and ultimately more important, factor emerged 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 Web, Java was propelled to the forefront of computer language design, because the Web, too, demanded portable programs.

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. 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.What was once an irritating but a low-priority problem had become a high-profile necessity.

By 1993 it became obvious to members of the Java design team that the problems of portability frequently encountered when creating code for embedded controllers are also found when attempting to create code for the Internet. This realization caused the focus of Java to switch from consumer electronics to Internet programming. So, while it was the desire for an architecture-neutral programming language that provided the initial spark, it was the Internet that ultimately led to Java’s large-scale success.

How Java Relates to C and C++

Java is directly related to both C and C++. Java inherits its syntax from C. Its object model is adapted from C++. Java’s relationship with C and C++ is important for several reasons. First, many programmers are familiar with the C/C++ syntax. This makes it easy for a C/C++ programmer to learn Java and, conversely, for a Java programmer to learn C/C++. 

Second, Java’s designers did not “reinvent the wheel.” Instead, they further refined an already highly successful programming paradigm. The modern age of programming began with C. It moved to C++, and now to Java. By inheriting and building upon that rich heritage, Java provides a powerful, logically consistent programming environment that takes the best of the past and adds new features required by the online environment. Perhaps most important, because of their similarities, C, C++, and Java define a common, conceptual framework for the professional programmer. Programmers do not face major rifts when switching from one language to another. 

One of the central design philosophies of both C and C++ is that the programmer is in charge! Java also inherits this philosophy. Except for those constraints imposed by the Internet environment, Java gives you, the programmer, full control. If you program well, your programs reflect it. If you program poorly, your programs reflect that, too. Put differently, Java is not a language with training wheels. It is a language for professional programmers. 

Java has one other attribute in common with C and C++: it was designed, tested, and refined by real, working programmers. It is a language grounded in the needs and experiences of the people who devised it. There is no better way to produce a top-flight professional programming language.

Because of the similarities between Java and C++, especially their support for objectoriented programming, it is tempting to think of Java as simply the “Internet version of C++.” However, to do so would be a mistake. Java has significant practical and philosophical differences. Although Java was influenced by C++, it is not an enhanced version of C++. For example, it is neither upwardly nor downwardly compatible with C++. Of course, the similarities with C++ are significant, and if you are a C++ programmer, you will feel right at home with Java. Another point: Java was not designed to replace C++. Java was designed to solve a certain set of problems. C++ was designed to solve a different set of problems. Both will coexist for many years to come.

How Java Relates to C#

Recently a new language called C# has come on the scene. Created by Microsoft to support its .NET Framework, C# is closely reated to Java. In fact, many of C#’s features were directly adapted from Java. Both Java and C# share the same general C++-style syntax, support distributed programming, and utilize the same object model. There are, of course, differences between Java and C#, but the overall “look and feel” of these languages is very similar. This means that if you already know C#, then learning Java will be especially easy. Conversely, if C# is in your future, then your knowledge of Java will come in handy. Given the similarity between Java and C#, one might naturally ask, “Will C# replace Java?” The answer is No. Java and C# are optimized for two different types of computing environments. Just as C++ and Java will co-exist for a long time to come, so will C# and Java.

1.2 Java’s Contribution to the Internet

The Internet helped catapult Java to the forefront of programming, and Java, in turn, has had a profound effect on the Internet. The reason for this is quite simple: Java expands the universe of objects that can move about freely in cyberspace. In a network, there are two very broad categories of objects that are transmitted between the server and your personal computer: passive information and dynamic, active programs. For example, when you read your e-mail, you are viewing passive data. Even when you download a program, the program’s code is still only passive data until you execute it. However, a second type of object can be transmitted to your computer: a dynamic, self-executing program. Such a program is an active agent on the client computer, yet it is initiated by the server. For example, a program might be provided by the server to properly display the data that it is sending. 

As desirable as dynamic, networked programs are, they also present serious problems in the areas of security and portability. Prior to Java, cyberspace was effectively closed to half of the entities that now live there. As you will see, Java addresses those concerns and, in doing so, has defined a new form of program: the applet.

Java Applets and Applications

Java can be used to create two types of programs: applications and applets. An application is a program that runs on your computer, under the operating system of that computer. An application created by Java is more or less like one created using any other type of computer language, such as Visual Basic or C++. When used to create applications, Java is not much different from any other computer language. Rather, it is Java’s ability to create applets that makes it important. An applet is an application designed to be transmitted over the Internet and executed by a Java-compatible Web browser. Although any computer language can be used to create an application, only Java can be used to create an applet. The reason is that Java solves two of the thorniest problems associated with applets: security and portability. Before continuing, let’s define what these two terms mean relative to the Internet.

Security

As you are almost certainly aware, every time you download a “normal” program, you are risking a viral infection. Prior to Java, most users did not download executable programs frequently, and those that did, scanned them for viruses prior to execution. Even so, most users still worried about the possibility of infecting their systems with a virus or allowing a malicious program to run wild in their systems. (A malicious program might gather private information, such as credit card numbers, bank account balances, and passwords by searching the contents of your computer’s local file system.) Java answers these concerns by providing a firewall between a networked application and your computer.

When using a Java-compatible web browser, it is possible to safely download Java applets without fear of viral infection. The way that Java achieves this is by confining a Java program to the Java execution environment and not allowing it access to other parts of the computer. (You will see how this is accomplished, shortly.) Frankly, the ability to download applets with confidence that no harm will be done to the client computer is the single most important aspect of Java.

Portability

As discussed earlier, many types of computers and operating systems are connected to the Internet. For programs to be dynamically downloaded to all of the various types of platforms, some means of generating portable executable code is needed. As you will soon see, the same mechanism that helps ensure security also helps create portability. Indeed, Java’s solution to these two problems is both elegant and efficient.

外文翻译

JAVA的基础

互联网和万维网的崛起已经从根本上重塑了计算。仅短短几年前,网络景观的主导力量还是的个人电脑。而今天,几乎所有的电脑都连接到互联网。互联网本身也得到转化,原本提供一个方便的途径来共享文件和信息,而今天它是一个巨大的,分布式计算宇宙。因特网就像它本身的深度一样迅速的变化,因为在因特网之后,产生了一种新的语言进行编程:Java语言。

Java是互联网的杰出的语言,但它不止于此。 Java具有性编程,改变了我们思考程序形式和功能的方式。今天要成为一名专业程序员今日意味着在Java的能力,它已成为这一重要计划。在这本书的过程中,你将学习掌握它需要的技能。

本单元目的是向你介绍Java中,包括它的历史,其设计理念,其最重要的特征数。到目前为止,有关学习一种编程语言最难的事情是没有孤立存在的元素。相反,语言的组成部分之间相互关联。这在Java语言中尤为特别。事实上,很难讨论Java的一个方面而不卷入Java的另外一些方面。为了帮助解决这个问题,这个模块提供了一些Java特性,包括一个Java程序的一般形式简要概述,一些基本的控制结构和运算符。它不会进入太多的细节,而是集中在任何Java程序都会有的一些共性。

1.1 Java的起源

    计算机语言创新是由两个因素驱动着:在编程艺术的改进和计算环境的改变。 Java也没有例外。Java从C和C++继承传统的基础之上增加了丰富的改进和功能,反映在编程的艺术现状。为了响应在线环境的增长,Java提供了高度分布式架构的流线编程。

Java是1991年由James Gosling,Patrick Naughton,Chris Warth,Ed Frank 和 Mike Sheridan在Sun公司构想出来的。这种语言最初被称为“Oak”,但在1995年改名为“Java”。奇怪的是,构思Java的原始动力竟然不是互联网,相反,在主要的动机是一个平台无关的语言,可用于创建需要在各种消费电子设备的嵌入式程序例如烤面包机,微波炉,远程控制。正如你可能猜到,许多不同类型的CPU都被作为控制器。麻烦的是,大多数计算机语言的目的是为特定目标的编制。例如,C++就是。

虽然可以编译一个C++程序的几乎所有类型的CPU,但是这样需要一个完整的C++编译器来对应这个CPU。但问题是,创建编译器昂贵而且费时。James Gosling在试图找到更好的解决办法,他和他的同事们致力于一种便携的,跨平台的语言,它能产生在不同环境的cpu下都能运行的代码。这一努力最终导致了Java的产生。

正当Java的细节正在拟定的时候,第二个因素,并最终显得更重要的因素出现,并在在Java的未来中起着重要的角色作用。这第二个推动力量当然是万维网了。如果该网页没有和Java在同一时间出现并崭露头角,Java虽然仍然会是有用的编程语言但是不会作为为消费电子编程的语言而著名。然而,随着互联网的出现,Java推动对计算机语言设计的前沿,因为Web的出现,也要求便携的编程方式。

大多数程序员在其职业生涯早期的学习中知道可移植程序是多么难以实现,因为它们是理想的。虽然寻求创造高效,可移植(平台无关)程序的方式几乎和编程它自己一样古老了,但是这必须解决诸多问题。然而,随着互联网和Web的发展,老问题的出现就像是报复一样。毕竟,互联网由一个多样化的,分布式的计算机宇宙,包含了各种各样的电脑,操作系统和CPU.曾经非常棘手的问题现在不得不成为一个必须解决的问题了。

到了1993年,在可移植过程中经常遇到的问题,对于Java的可移植性设计团队成员已经能解决了。当创造的嵌入式控制器的代码的同时,也在试图创建互联网的代码。这一点认识把Java的重点从消费类电子的嵌入式开关过渡到互联网编程了。因此,尽管Java设计为结构中立的编程语言,提供最初的火花,但是这是最终导致Java在因特网大规模成功的原因。

Java与c和c++有何关联

Java是直接关系到C和C + +。 Java的继承了它从C语法的对象模型是从C + +改写。 Java的C和C + +的关系是很重要的几个原因。第一,许多程序员用C / C + +语法熟悉。这就需要一个C / C + +程序员容易学习Java,相反,为Java程序员学习C / C + +的。

其次,Java的设计者并没有“另起炉灶。”相反,他们进一步完善了已经非常成功的编程范例。当今时代的节目开始C.它移动到C + +,现在到Java。通过继承遗产,并呼吁富有建设,Java提供了一个强大的,在逻辑上一致的编程环境,把过去的最好的,并增加了在线环境所需的新功能。也许最重要的,因为他们的相似性定义,C语言,C + +和Java的一个共同的,为专业程序员的概念框架。程序员不从一种语言时所面临的切换到另一个重大分歧。

对C和C + +的核心设计理念之一是,程序员要负责! Java也继承这一理念。除通过互联网环境施加的,让你的Java,程序员,完全控制。如果你的方案好,它反映了你的方案。如果方案不好,您的程序反映这一点。把不同的,Java是不是一个轮子的语言培训。这是一个专业的程序员的语言。

Java有一个共同的C和C + +其他属性:它是设计,测试,以及真实的,精致的程序员工作。它是在需要和人民谁发明它的经验为基础的语言。有没有更好的方法来生产一流的专业的编程语言。

由于Java与C + +的相似之处,特别是他们对面向对象编程支持,这是很有诱惑力的爪哇看成简单的“C + +的网络版。”然而,这样做将是一个错误。 Java具有重大现实和哲学的差异。虽然Java是由C + +的影响,它不是一个对C + +的增强版。例如,它既不向上也不向下兼容的C + +。当然,用C + +的相似性是重要的,如果你是一个C + +程序员,你会觉得在权利与Java的家。另外一点:Java是不是要取代C + +。 Java的目的是要解决的问题的某些设置。 C + +的目的是为了解决不同的问题。两者将共存多年来。

Java与c#有何关联

最近,一个新的语言称为C#对现场来。微软支持其创建的。NET框架,C#是Java的紧密reated。事实上,C#的许多功能是直接改编自爪哇。 Java和C#都共享相同的一般的C + +风格的语法,支持分布式程序设计,并使用相同的对象模型。当然有,Java和C之间的差异#,但总的“外观和感觉这些语言的”非常相似。这意味着,如果你已经知道C#,那么学习Java将特别容易。反之,如果C#是你的未来,那么你的Java知识能派上用场。由于在Java和C#相似,人们可能会自然地问:“请问C#中取代Java吗?”答案是Java和C#号是两个不同类型的计算环境优化。正如C + +和Java将合作很长一段时间来存在,因此将C#和Java。

1.2 Java对因特网的贡献

    互联网帮助弹射Java来的节目的前列,和Java,反过来,已在互联网上产生深远的影响。其原因是相当简单:扩大了的Java对象,可以在网络空间中自由走动宇宙的原因。在网络中,有两个非常广泛的是在服务器之间和个人电脑:被动的信息和动态,积极传播节目的各类文物。例如,当你读你的电子邮件,您正在查看的被动数据。即使当您下载一个程序,该程序的代码还只是被动的数据,直到你执行它。然而,第二种类型的对象可以传输到您的计算机:一个动态的,自动执行程序。这种方案是在客户端计算机活性剂,但它是由服务器发起的。例如,一个程序可能是由服务器提供正确显示数据,这是发送。

作为理想的,动态的,联网方案,他们也出席在安全性和便携性方面的严重问题。在此之前,到Java,网络空间得到了有效封闭的实体,现在生活在那里的一半。正如你将看到,Java的解决这些问题,并在这样做,已经确定了新形式的节目:小程序。

Java小程序和应用

Java可以被用于创建两种类型的程序:应用程序和applet。应用程序是一种程序,在您的计算机运行在该计算机的操作系统。 Java是由或多或少像一个创建使用如Visual Basic或C + +计算机语言的任何其他类型的应用软件。当用于创建应用程序,Java没有太大的任何其他计算机语言不同。相反,它是Java的创造能力,使小程序很重要。一个applet是一种应用程序设计为在互联网上传输和Java的兼容的Web浏览器执行。虽然任何计算机语言可以用来创建应用程序,只有Java可以被用于创建一个applet。原因是,Java的小程序解决了两个与有关的最棘手的问题:安全性和可移植性。在继续之前,让我们定义这两个词是什么意思相对于互联网。

安全

如你几乎可以肯定知道,每一次你下载一个“正常”的计划,你是冒着一种病毒感染。在此之前爪哇,大多数用户没有下载可执行程序频繁,那些没有,他们进行了病毒扫描之前执行。即便如此,大多数用户仍然担心的是感染了病毒或恶意程序,允许在其系统中运行他们的系统野生的可能性。 (恶意程序可能会收集私人信息,如信用卡号码,银行账户余额和密码通过搜索您的计算机的本地文件系统的内容。)渣的了一个网络应用程序之间和你的电脑防火墙这些问题。

当使用一个Java兼容的网络浏览器,它可以安全地下载不担心感染病毒的Java小程序。爪哇的方式实现这一禁锢Java程序的Java执行环境,不允许它访问计算机的其他部分。 (你会看到这是如何完成,不久)。坦率地说,能够下载满怀信心地说,这样做会不会伤害到客户端计算机小程序是一个最重要的Java方面。

可移植性

在之前的讨论中提到过,许多类型的计算机和操作系统连接到互联网。程序被动态的下载到多种多样的平台,因此生成可移植的执行代码是必要的。正如您将很快看到的,同样的机制,有助于确保安全也有利于创造可移植性。事实上,Java解决这两个问题的方式,既优雅又高效。下载本文

显示全文
专题