外文翻译java

外文翻译java
外文翻译java

外文资料译文及原文

Java

Java I/O 系统

对编程语言的设计者来说,创建一套好的输入输出(I/O)系统,是一项难度极高的任务。

这一点可以从解决方案的数量之多上看出端倪。这个问题难就难在它要面对的可能性太多了。不仅是因为有那么多I/O的源和目地(文件,控制台,网络连接等等),而且还有很多方法(顺序的『sequential』,随机的『random-access』,缓存的『buffered』,二进制的『binary』,字符方式的『character』,行的『by lines』,字的『by words』,等等)。

Java类库的设计者们用"创建很多类"的办法来解决这个问题。坦率地说Java I/O系统的类实在是太多了,以至于初看起来会把人吓着(但是,具有讽刺意味的是,这种设计实际上是限制了类的爆炸性增长)。此外,Java在1.0版之后又对其I/O类库作了重大的修改,原先是面向byte的,现在又补充了面向Unicode字符的类库。为了提高性能,完善功能,JDK 1.4又加了一个nio(意思是"new I/O"。这个名字会用上很多年)。这么以来,如果你想对Java的I/O 类库有个全面了解,并且做到运用自如,你就得先学习大量的类。此外,了解

I/O类库的演化的历史也是相当重要的。可能你的第一反应是"别拿什么历史来烦我了,告诉我怎么用就可以了!"但问题是,如果你对这段历史一无所知,很快就会被一些有用或是没用的类给搞糊涂了。

本章会介绍Java标准类库中的各种I/O类,及其使用方法。

File 类

在介绍直接从流里读写数据的类之前,我们先介绍一下处理文件和目录的类。

File类有一个极具欺骗性的名字;或许你会认为这是一个关于文件的类,但它不是。你可以用它来表示某个文件的名字,也可以用它来表示目录里一组文件的名字。如果它表示的是一组文件,那么你还可以用list( )方法来进行查询,让它会返回String数组。由于元素数量是固定的,因此数组会比容器更好一些。如果你想要获取另一个目录的清单,再建一个File对象就是了。实际上,叫它"FilePath"可能会更好一些。下面我们举例说明怎样使用这个类及其相关的FilenameFilter接口。

目录列表器

假设你想看看这个目录。有两个办法。一是不带参数调用list( )。它返回的是File对象所含内容的完整清单。但是,如果你要的是一个"限制性列表(restricted list)"的话——比方说,你想看看所有扩展名为.java的文件——那么你就得使用"目录过滤器"了。这是一个专门负责挑选显示File对象的内容的类。

下面就是源代码。看看,用了java.utils.Arrays.sort( )和11章的AlphabeticComparator之后,我们没费吹灰之力就对结果作了排序(按字母顺序):

//: c12:DirList.java

// Displays directory listing using regular expressions.

// {Args: "D.*\.java"}

import java.io.*;

import java.util.*;

import java.util.regex.*;

import com.bruceeckel.util.*;

public class DirList {

public static void main(String[] args) {

File path = new File(".");

String[] list;

if(args.length == 0)

list = path.list();

else

list = path.list(new DirFilter(args[0]));

Arrays.sort(list, new AlphabeticComparator());

for(int i = 0; i < list.length; i++)

System.out.println(list[i]);

}

}

class DirFilter implements FilenameFilter {

private Pattern pattern;

public DirFilter(String regex) {

pattern = https://www.360docs.net/doc/08344026.html,pile(regex);

}

public boolean accept(File dir, String name) {

// Strip path information, search for regex:

return pattern.matcher(

new File(name).getName()).matches();

}

} ///:~

DirFilter实现了FilenameFilter接口。我们来看看FilenameFilter究竟有多简单:

public interface FilenameFilter {

boolean accept(File dir, String name);

}

也就是说,这类对象的任务就是提供一个accept( )的方法。之所以要创建这个类,就是要给list( )提供一个accept( )方法,这样当list( )判断该返回哪些文件名的时候,能够"回过头来调用"accept( )方法。因此,这种结构通常被称为回调(callback)。更准确地说,由于list( )实现了基本功能,而FilenameFilter提供了"对外服务所需的算法",因此这是一种"策略模式(Strategy Pattern)"。由于list( )拿FilenameFilter对象当参数,因此你可以将任何实现

FilenameFilter接口的对象传给它,并以此(甚至是在运行时)控制list( )的工作方式。回调能提高程序的灵活性。

DirFilter还告诉我们,interface只是包含了一些方法,它没说你只能写这些方法。(但是,你至少要定义接口里有的方法。) 这里我们还定义了DirFilter的构造函数。

accept( )方法需要两个参数,一个是File对象,表示这个文件是在哪个目录里面的;另一个是String,表示文件名。虽然你可以忽略它们中的一个,甚至两个都不管,但是你大概总得用一下文件名吧。记住,list( )会对目录里的每个文件调用accept( ),并以此判断是不是把它包括到返回值里;这个判断依据就是accept( )的返回值。

切记,文件名里不能有路径信息。为此你只要用一个String对象来创建File 对象,然后再调用这个File对象的getName( )就可以了。它会帮你剥离路径信息(以一种平台无关的方式)。然后再在accept( )里面用正则表达式(regular

expression)的matcher对象判断,regex是否与文件名相匹配。兜完这个圈子,list( )方法返回了一个数组。

匿名内部类

这是用匿名内部类(详见第八章)来重写程序的绝佳机会。下面我们先创建一个返回FilenameFilter的filter( )方法。

//: c12:DirList2.java

// Uses anonymous inner classes.

// {Args: "D.*\.java"}

import java.io.*;

import java.util.*;

import java.util.regex.*;

import com.bruceeckel.util.*;

public class DirList2 {

public static FilenameFilter filter(final String regex) { // Creation of anonymous inner class:

return new FilenameFilter() {

private Pattern pattern = https://www.360docs.net/doc/08344026.html,pile(regex);

public boolean accept(File dir, String name) {

return pattern.matcher(

new File(name).getName()).matches();

}

}; // End of anonymous inner class

}

public static void main(String[] args) {

File path = new File(".");

String[] list;

if(args.length == 0)

list = path.list();

else

list = path.list(filter(args[0]));

Arrays.sort(list, new AlphabeticComparator());

for(int i = 0; i < list.length; i++)

System.out.println(list[i]);

}

} ///:~

注意,filter( )的参数必须是final的。要想在匿名内部类里使用其作用域之外的对象,只能这么做。

这是对前面所讲的代码的改进,现在FilenameFilter类已经与DirList2

紧紧地绑在一起了。不过你还可以更进一步,把这个匿名内部类定义成list( )的参数,这样代码会变得更紧凑:

//: c12:DirList3.java

// Building the anonymous inner class "in-place."

// {Args: "D.*\.java"}

import java.io.*;

import java.util.*;

import java.util.regex.*;

import com.bruceeckel.util.*;

public class DirList3 {

public static void main(final String[] args) {

File path = new File(".");

String[] list;

if(args.length == 0)

list = path.list();

else

list = path.list(new FilenameFilter() {

private Pattern pattern = https://www.360docs.net/doc/08344026.html,pile(args[0]);

public boolean accept(File dir, String name) {

return pattern.matcher(

new File(name).getName()).matches();

}

});

Arrays.sort(list, new AlphabeticComparator());

for(int i = 0; i < list.length; i++)

System.out.println(list[i]);

}

} ///:~

现在该轮到main( )的参数成final了,因为匿名内部类要用它的arg[0]了。

这个例子告诉我们,可以用匿名内部类来创建专门供特定问题用的,一次性的类。这种做法的好处是,它能把解决某个问题的代码全都集中到一个地方。但是从另一角度来说,这样做会使代码的可读性变差,所以要慎重。

查看与创建目录

File类的功能不仅限于显示文件或目录。它还能帮你创建新的目录甚至是目录路径(directory path),如果目录不存在的话。此外它还能用来检查文件的属性(大小,上次修改的日期,读写权限等),判断File对象表示的是文件还是目录,以及删除文件。下面这段程序演示了File类的一些其他方法(请查阅JDK 文档,以了解其全部功能):

//: c12:MakeDirectories.java

// Demonstrates the use of the File class to

// create directories and manipulate files.

// {Args: MakeDirectoriesTest}

import com.bruceeckel.simpletest.*;

import java.io.*;

public class MakeDirectories {

private static Test monitor = new Test(); private static void usage() {

System.err.println(

"Usage:MakeDirectories path1 ...\n" +

"Creates each path\n" +

"Usage:MakeDirectories -d path1 ...\n" +

"Deletes each path\n" +

"Usage:MakeDirectories -r path1 path2\n" +

"Renames from path1 to path2");

System.exit(1);

}

private static void fileData(File f) {

System.out.println(

"Absolute path: " + f.getAbsolutePath() +

"\n Can read: " + f.canRead() +

"\n Can write: " + f.canWrite() +

"\n getName: " + f.getName() +

"\n getParent: " + f.getParent() +

"\n getPath: " + f.getPath() +

"\n length: " + f.length() +

"\n lastModified: " + https://www.360docs.net/doc/08344026.html,stModified());

if(f.isFile())

System.out.println("It's a file");

else if(f.isDirectory())

System.out.println("It's a directory");

}

public static void main(String[] args) { if(args.length < 1) usage();

if(args[0].equals("-r")) {

if(args.length != 3) usage();

File

old = new File(args[1]),

rname = new File(args[2]);

old.renameTo(rname);

fileData(old);

fileData(rname);

return; // Exit main

}

int count = 0;

boolean del = false;

if(args[0].equals("-d")) {

count++;

del = true;

}

count--;

while(++count < args.length) {

File f = new File(args[count]);

if(f.exists()) {

System.out.println(f + " exists");

if(del) {

System.out.println("deleting..." + f);

f.delete();

}

}

else { // Doesn't exist

if(!del) {

f.mkdirs();

System.out.println("created " + f);

}

}

fileData(f);

}

if(args.length == 1 &&

args[0].equals("MakeDirectoriesTest"))

monitor.expect(new String[] {

"%% (MakeDirectoriesTest exists"+

"|created MakeDirectoriesTest)",

"%% Absolute path: "

+ "\\S+MakeDirectoriesTest",

"%% Can read: (true|false)",

"%% Can write: (true|false)",

" getName: MakeDirectoriesTest",

" getParent: null",

" getPath: MakeDirectoriesTest",

"%% length: \\d+",

"%% lastModified: \\d+",

"It's a directory"

});

}

} ///:~

在fileData( )演示了全套查询文件和目录路径信息的方法。

main( )的第一条指令就是执行renameTo( )。它会把文件重命名成(或者说移动到)新的目录,也就是参数所给出的目录。而参数本身就是一个File对象。这个方法也适用于目录。

如果你试过上面那段程序,就会发现,你能用它创建任意复杂的目录路径,因为mkdirs( )已经帮你打理好了。

输入与输出

I/O类库常使用"流(stream)"这种抽象。所谓"流"是一种能生成或接受数据的,代表数据的源和目标的对象。流把I/O设备内部的具体操作给隐藏起来了。

正如JDK文档所显示的,Java的I/O类库分成输入和输出两大部分。所有InputStream和Reader的派生类都有一个基本的,继承下来的,能读取单个或byte数组的read( )方法。同理,所有OutputStream和Writer的派生类都有一个基本的,能写入单个或byte数组的write( )方法。但通常情况下,你是不会去用这些方法的;它们是给其它类用的——而后者会提供一些更实用的接口。因此,你很少会碰到只用一个类就能创建一个流的情形,实际上你得把多个对象叠起来,并以此来获取所需的功能。Java的流类库之所以会那么让人犯晕,最主要的原因就是"你必须为创建一个流而动用多个对象"。

我们最好还是根据其功能为这些class归个类。Java 1.0的类库设计者们是从决定"让所有与输入相关的类去继承InputStream"入手的。同理,所有与输出相关的类就该继承OutputStream了。

添加属性与适用的接口

使用"分层对象(layered objects)",为单个对象动态地,透明地添加功能的做法,被称为Decorator Pattern。(模式[61]是Thinking in Patterns (with Java)的主题。)Decorator模式要求所有包覆在原始对象之外的对象,都必须具有与之完全相同的接口。这使得decorator的用法变得非常的透明--无论对象是否被decorate过,传给它的消息总是相同的。这也是Java I/O类库要有"filter(过滤器)"类的原因:抽象的"filter"类是所有decorator的基类。(decorator必须具有与它要包装的对象的全部接口,但是decorator可以扩展这个接口,由此就衍生出了很多"filter"类)。

Decorator模式常用于如下的情形:如果用继承来解决各种需求的话,类的数量会多到不切实际的地步。Java的I/O类库需要提供很多功能的组合,于是decorator模式就有了用武之地。[62]但是decorator有个缺点,在提高编程的灵活性的同时(因为你能很容易地混合和匹配属性),也使代码变得更复杂了。Java的I/O类库之所以会这么怪,就是因为它"必须为一个I/O对象创建很多类",也就是为一个"核心"I/O类加上很多decorator。

为InputStream和OutputStream定义decorator类接口的类,分别是FilterInputStream和FilterOutputStream。这两个名字都起得不怎么样。FilterInputStream和FilterOutputStream都继承自I/O类库的基类InputStream和OutputStream,这是decorator模式的关键(惟有这样decorator 类的接口才能与它要服务的对象的完全相同)。

用FilterInputStream读取InputStream

FilterInputStream及其派生类有两项重要任务。DataInputStream可以读取各种primitive及String。(所有的方法都以"read"打头,比如readByte( ),readFloat( ))。它,以及它的搭档DataOutputStream,能让你通过流将primitive 数据从一个地方导到另一个地方。这些"地方"都列在表12-1里。

其它的类都是用来修改InputStream的内部行为的:是不是做缓冲,是不是知道它所读取的行信息(允许你读取行号或设定行号),是不是会弹出单个字符。后两个看上去更像是给编译器用的(也就是说,它们大概是为Java编译器设计的),所以通常情况下,你是不大会用到它们的。

不论你用哪种I/O设备,输入的时候,最好都做缓冲。所以对I/O类库来说,比较明智的做法还是把不缓冲当特例(或者去直接调用方法),而不是像现在这样把缓冲当作特例。

JAVA

The Java I/O System

Creating a good input/output (I/O) system is one of the more difficult tasks for the language designer.

This is evidenced by the number of different approaches. The challenge seems to be in covering all eventualities. Not only are there different sources and sinks of I/O that you want to communicate with (files, the console, network connections, etc.), but you need to talk to them in a wide variety of ways (sequential, random-access, buffered, binary, character, by lines, by words, etc.).

The Java library designers attacked this problem by creating lots of classes. In fact, there are so many classes for Java’s I/O system that it can be intimidating at first (ironically, the Java I/O design actually prevents an explosion of classes). There was also a significant change in the I/O library after Java 1.0, when the original byte-oriented library was supplemented with char-oriented, Unicode-based I/O classes. In JDK 1.4, the nio classes (for

“new I/O,” a name we’ll still be using years from now) were added for improved performance and functionality. As a result, there are a fair number of classes to learn before you understand enough of Java’s I/O picture that you can use it properly. In addition, it’s rather important to understand the evolution history of the I/O library, even if your first reaction is “don’t bother me with history, just show me how to use it!” The problem is that without the historical perspective, you will rapidly become confused with some of the classes and when you should and shouldn’t use them.

This chapter will give you an introduction to the variety of I/O classes in the standard Java library and how to use them.

The File class

Before getting into the classes that actually read and write data to streams, we’ll look at a utility provided with the library to assist you in handling f ile directory issues.

The File class has a deceiving name; you might think it refers to a file, but it doesn’t. It can represent either the name of a particular file or the names of a set of files in a directory. If it’s a set of files, you can ask for th at set using the list( ) method, which returns an array of String. It makes sense to return an array rather than one of the flexible container classes, because the number of elements is fixed, and if you want a different directory listing, you just create a different File object. In fact, “FilePath” would have been a better name for the class. This section shows an example of the use of this class, including the associated FilenameFilter interface.

A directory lister

Suppose you’d like to see a directory l isting. The File object can be listed in two ways. If you call list( )with no arguments, you’ll get the full list that the File object contains. However, if you want a restricted list—for example, if you want all of the files with an extension of .java—th en you use a “directory filter,” which is a class that tells how to select the File objects for display.

Here’s the code for the example. Note that the result has been effortlessly sorted (alphabetically) using the java.utils.Arrays.sort( ) method and the AlphabeticComparator defined in Chapter 11:

//: c12:DirList.java

// Displays directory listing using regular expressions.

// {Args: "D.*\.java"}

import java.io.*;

import java.util.*;

import java.util.regex.*;

import com.bruceeckel.util.*;

public class DirList {

public static void main(String[] args) {

File path = new File(".");

String[] list;

if(args.length == 0)

list = path.list();

else

list = path.list(new DirFilter(args[0]));

Arrays.sort(list, new AlphabeticComparator());

for(int i = 0; i < list.length; i++)

System.out.println(list[i]);

}

}

class DirFilter implements FilenameFilter {

private Pattern pattern;

public DirFilter(String regex) {

pattern = https://www.360docs.net/doc/08344026.html,pile(regex);

}

public boolean accept(File dir, String name) {

// Strip path information, search for regex:

return pattern.matcher(

new File(name).getName()).matches();

}

} ///:~

The DirFilter class “implements” the interface FilenameFilter. It’s useful to see how simple the FilenameFilter interface is:

public interface FilenameFilter {

boolean accept(File dir, String name);

}

It says all that this type of object does is provide a method called

accept( ). The whole reason behind the creation of this class is to provide the accept( ) method to the list( ) method so that list( )can “call back”

accept( ) to determine which file names should be included in the list. Thus,

this structure is often referred to as a callback. More specifically, this is an example of the Strategy Pattern, because list( ) implements basic functionality, and you provide the Strategy in the form of a FilenameFilter in order to complete the algorithm necessary for list( ) to provide its service. Because list( ) takes a FilenameFilter object as its argument, it means that you can pass an object of any class that implements FilenameFilter to choose (even at run time) how the list( ) method will behave. The purpose of a callback is to provide flexibility in the behavior of code.

DirFilter shows that just because an interface contains only a set of methods, you’re not restricted to writing only those methods. (You must at least provide definitions for all the methods in an interface, however.) In this case, the DirFilter constructor is also created.

The accept( ) method must accept a File object representing the directory that a particular file is found in, and a String containing the name of that file. You might choose to use or ignore either of these arguments, but you will probably at least use the file name. Remember that the list( ) method is calling accept( ) for each of the file names in the directory object to see which one should be included; this is indicated by the boolean result returned by accept( ).

To make sure the element you’re w orking with is only the file name and contains no path information, all you have to do is take the String object and create a File object out of it, then call getName( ), which strips away all the path information (in a platform-independent way). Then accept( ) uses a regular expression matcher object to see if the regular expression regex matches the name of the file. Using accept( ), the list( ) method returns an array.

Anonymous inner classes

This example is ideal for rewriting using an anonymous inner class (described in Chapter 8). As a first cut, a method filter( ) is created that returns a reference to a FilenameFilter:

//: c12:DirList2.java

// Uses anonymous inner classes.

// {Args: "D.*\.java"}

import java.io.*;

import java.util.*;

import java.util.regex.*;

import com.bruceeckel.util.*;

public class DirList2 {

public static FilenameFilter filter(final String regex) { // Creation of anonymous inner class:

return new FilenameFilter() {

private Pattern pattern = https://www.360docs.net/doc/08344026.html,pile(regex);

public boolean accept(File dir, String name) {

return pattern.matcher(

new File(name).getName()).matches();

}

}; // End of anonymous inner class

}

public static void main(String[] args) {

File path = new File(".");

String[] list;

if(args.length == 0)

list = path.list();

else

list = path.list(filter(args[0]));

Arrays.sort(list, new AlphabeticComparator());

for(int i = 0; i < list.length; i++)

System.out.println(list[i]);

}

} ///:~

Note that the argument to filter( ) must be final. This is required by the anonymous inner class so that it can use an object from outside its scope.

This design is an improvement because the FilenameFilter class is now tightly bound to DirList2. However, you can take this approach one step further and define the anonymous inner class as an argument to list( ), in which case it’s even smaller:

//: c12:DirList3.java

// Building the anonymous inner class "in-place."

// {Args: "D.*\.java"}

import java.io.*;

import java.util.*;

import java.util.regex.*;

import com.bruceeckel.util.*;

public class DirList3 {

public static void main(final String[] args) {

File path = new File(".");

String[] list;

if(args.length == 0)

list = path.list();

else

list = path.list(new FilenameFilter() {

private Pattern pattern = https://www.360docs.net/doc/08344026.html,pile(args[0]);

public boolean accept(File dir, String name) {

return pattern.matcher(

new File(name).getName()).matches();

}

});

Arrays.sort(list, new AlphabeticComparator());

for(int i = 0; i < list.length; i++)

System.out.println(list[i]);

}

} ///:~

The argument to main( ) is now final, since the anonymous inner class uses args[0] directly.

This shows you how anonymous inner classes allow the creation of specific, one-off classes to solve problems. One benefit of this approach is that it keeps the code that solves a particular problem isolated together in one spot. On the other hand, it is not always as easy to read, so you must use it judiciously.

Checking for and creating directories

The File class is more than just a representation for an existing file or directory. You can also use a File object to create a new directory or an entire directory path if it doesn’t exist. You can also look at the characteristics of files (size, last modification date, read/write), see whether a File object represents a file or a directory, and delete a file. This program shows some of the other methods available with the File class (see the HTML documentation from https://www.360docs.net/doc/08344026.html, for the full set):

//: c12:MakeDirectories.java

// Demonstrates the use of the File class to

// create directories and manipulate files.

// {Args: MakeDirectoriesTest}

import com.bruceeckel.simpletest.*;

import java.io.*;

public class MakeDirectories {

private static Test monitor = new Test(); private static void usage() {

System.err.println(

"Usage:MakeDirectories path1 ...\n" +

"Creates each path\n" +

"Usage:MakeDirectories -d path1 ...\n" +

"Deletes each path\n" +

"Usage:MakeDirectories -r path1 path2\n" +

"Renames from path1 to path2");

System.exit(1);

}

private static void fileData(File f) {

System.out.println(

"Absolute path: " + f.getAbsolutePath() +

"\n Can read: " + f.canRead() +

"\n Can write: " + f.canWrite() +

"\n getName: " + f.getName() +

"\n getParent: " + f.getParent() +

"\n getPath: " + f.getPath() +

"\n length: " + f.length() +

"\n lastModified: " + https://www.360docs.net/doc/08344026.html,stModified());

if(f.isFile())

System.out.println("It's a file");

else if(f.isDirectory())

System.out.println("It's a directory");

}

public static void main(String[] args) { if(args.length < 1) usage();

if(args[0].equals("-r")) {

if(args.length != 3) usage();

File

old = new File(args[1]),

rname = new File(args[2]);

old.renameTo(rname);

fileData(old);

fileData(rname);

return; // Exit main

}

int count = 0;

boolean del = false;

if(args[0].equals("-d")) {

count++;

del = true;

}

count--;

while(++count < args.length) {

File f = new File(args[count]);

if(f.exists()) {

System.out.println(f + " exists");

if(del) {

System.out.println("deleting..." + f);

f.delete();

}

}

else { // Doesn't exist

if(!del) {

f.mkdirs();

System.out.println("created " + f);

}

}

fileData(f);

}

if(args.length == 1 &&

args[0].equals("MakeDirectoriesTest"))

monitor.expect(new String[] {

"%% (MakeDirectoriesTest exists"+

"|created MakeDirectoriesTest)",

"%% Absolute path: "

+ "\\S+MakeDirectoriesTest",

"%% Can read: (true|false)",

"%% Can write: (true|false)",

" getName: MakeDirectoriesTest",

" getParent: null",

" getPath: MakeDirectoriesTest",

"%% length: \\d+",

"%% lastModified: \\d+",

"It's a directory"

});

}

} ///:~

In fileData( ) you can see various file investigation methods used to display information about the file or directory path.

The first method that’s exercised by main( ) is renameTo( ), which allows you to rename (or move) a file to an entirely new path represented by

the argument, which is another File object. This also works with directories of any length.

If you experiment with the preceding program, you’ll find that you can make a directory path of any complexity, because mkdirs( ) will do all the work for you.

Input and output

I/O libraries often use the abstraction of a stream, which represents any data source or sink as an object capable of producing or receiving pieces of data. The stream hides the details of what happens to the data inside the actual I/O device.

The Java library classes for I/O are divided by input and output, as you can see by looking at the class hierarchy in the JDK documentation. By inheritance, everything derived from the InputStream or Reader classes have basic methods called read( ) for reading a single byte or array of bytes. Likewise, everything derived from OutputStream or Writer classes have basic methods called write( ) for writing a single byte or array of bytes. However, you won’t generally use these methods; they exist so that other classes can use them—these other classes provide a more useful interface. Thus, you’ll rarely create your stream object by using a single class, but instead will layer multiple objects together to provide your desired functionality. The fact that you create more than one object to create a single resulting stream is the primary reason that Java’s stream library is confusing.

It’s helpful to categorize the classes by their functionality. In Java 1.0, the library designers started by deciding that all classes that had anything to do with input would be inherited from InputStream, and all classes that were associated with output would be inherited from OutputStream. Adding attributes

and useful interfaces

The use of layered objects to dynamically and transparently add responsibilities to individual objects is referred to as the Decorator pattern. (Patterns[61] are the subject of Thinking in Patterns (with Java) at

https://www.360docs.net/doc/08344026.html,.) The decorator pattern specifies that all objects that wrap around your initial object have the same interface. This makes the basic use of the decorators transparent—you send the same message to an object whether it has been decorated or not. This is the reason for the existence of

the “filter” classes in the Java I/O library: The abstract “filter” class is the base class for all the decorators. (A decorator must have the same interface as the object it decorates, but the decorator can also extend the interface, which occurs in several of the “filter” classes).

Decorators are often used when simple subclassing results in a large number of classes in order to satisfy every possible combination that is needed—so many classes that it becomes impractical. The Java I/O library requires many different combinations of features, and this is the justification for using the decorator pattern.[62] There is a drawback to the decorator pattern, however. Decorators give you much more flexibility whi le you’re writing a program (since you can easily mix and match attributes), but they add complexity to your code. The reason that the Java I/O library is awkward to use is that you must create many classes—the “core” I/O type plus all the decorators—in order to get the single I/O object that you want.

The classes that provide the decorator interface to control a particular InputStream or OutputStream are the FilterInputStream and FilterOutputStream, which don’t have very intuitive names. FilterInputStream and FilterOutputStream are derived from the base classes of the I/O library, InputStream and OutputStream, which is the key requirement of the decorator (so that it provides the common interface to all the objects that are being decorated).

Reading from an InputStream

with FilterInputStream

The FilterInputStream classes accomplish two significantly different things. DataInputStream allows you to read different types of primitive data as well as String objects. (All the methods start with “read,” such as readByte( ), readFloat( ), etc.) This, along with its companion DataOutputStream, allows you to move primitive data from one place to another via a stream. These “places” are determined by the classes in Table 12-1.

The remaining classes modify the way an InputStream behaves internally: whether it’s buffered or unbuffered, if it keeps track of the lines it’s reading (allowing you to ask for line numbers or set the line number), and whether you can push back a single character. The last two classes look a lot like support for building a compiler (that is, they were probably added to support the construction of the Java compiler), so you probably won’t use them in general programming.

You’ll need to buffer your input almost every time, regardless of the I/O device you’re connecting to, so it would have made more sense for the I/O

library to make a special case (or simply a method call) for unbuffered input rather than buffered input.

[此文档可自行编辑修改,如有侵权请告知删除,感谢您的支持,我们会努力把内容做得更好]

外文翻译java

外文资料译文及原文 Java Java I/O 系统 对编程语言的设计者来说,创建一套好的输入输出(I/O)系统,是一项难度极高的任务。 这一点可以从解决方案的数量之多上看出端倪。这个问题难就难在它要面对的可能性太多了。不仅是因为有那么多I/O的源和目地(文件,控制台,网络连接等等),而且还有很多方法(顺序的『sequential』,随机的『random-access』,缓存的『buffered』,二进制的『binary』,字符方式的『character』,行的『by lines』,字的『by words』,等等)。 Java类库的设计者们用"创建很多类"的办法来解决这个问题。坦率地说Java I/O系统的类实在是太多了,以至于初看起来会把人吓着(但是,具有讽刺意味的是,这种设计实际上是限制了类的爆炸性增长)。此外,Java在1.0版之后又对其I/O类库作了重大的修改,原先是面向byte的,现在又补充了面向Unicode字符的类库。为了提高性能,完善功能,JDK 1.4又加了一个nio(意思是"new I/O"。这个名字会用上很多年)。这么以来,如果你想对Java的I/O 类库有个全面了解,并且做到运用自如,你就得先学习大量的类。此外,了解 I/O类库的演化的历史也是相当重要的。可能你的第一反应是"别拿什么历史来烦我了,告诉我怎么用就可以了!"但问题是,如果你对这段历史一无所知,很快就会被一些有用或是没用的类给搞糊涂了。

本章会介绍Java标准类库中的各种I/O类,及其使用方法。 File 类 在介绍直接从流里读写数据的类之前,我们先介绍一下处理文件和目录的类。 File类有一个极具欺骗性的名字;或许你会认为这是一个关于文件的类,但它不是。你可以用它来表示某个文件的名字,也可以用它来表示目录里一组文件的名字。如果它表示的是一组文件,那么你还可以用list( )方法来进行查询,让它会返回String数组。由于元素数量是固定的,因此数组会比容器更好一些。如果你想要获取另一个目录的清单,再建一个File对象就是了。实际上,叫它"FilePath"可能会更好一些。下面我们举例说明怎样使用这个类及其相关的FilenameFilter接口。 目录列表器 假设你想看看这个目录。有两个办法。一是不带参数调用list( )。它返回的是File对象所含内容的完整清单。但是,如果你要的是一个"限制性列表(restricted list)"的话——比方说,你想看看所有扩展名为.java的文件——那么你就得使用"目录过滤器"了。这是一个专门负责挑选显示File对象的内容的类。 下面就是源代码。看看,用了java.utils.Arrays.sort( )和11章的AlphabeticComparator之后,我们没费吹灰之力就对结果作了排序(按字母顺序): //: c12:DirList.java // Displays directory listing using regular expressions. // {Args: "D.*\.java"} import java.io.*; import java.util.*; import java.util.regex.*; import com.bruceeckel.util.*; public class DirList { public static void main(String[] args) { File path = new File("."); String[] list; if(args.length == 0) list = path.list(); else list = path.list(new DirFilter(args[0])); Arrays.sort(list, new AlphabeticComparator());

JAVA外文文献+翻译

Java and the Internet If Java is, in fact, yet another computer programming language, you may question why it is so important and why it is being promoted as a revolutionary step in computer programming. The answer isn’t immediately obvious if you’re coming from a traditional programming perspective. Although Java is very useful for solving traditional stand-alone programming problems, it is also important because it will solve programming problems on the World Wide Web. 1.Client-side programming The Web’s in itial server-browser design provided for interactive content, but the interactivity was completely provided by the server. The server produced static pages for the client browser, which would simply interpret and display them. Basic HTML contains simple mechanisms for data gathering: text-entry boxes, check boxes, radio boxes, lists and drop-down lists, as well as a button that can only be programmed to reset the data on the form or “submit” the data on the form back to the server. This submission passes through the Common Gateway Interface (CGI) provided on all Web servers. The text within the submission tells CGI what to do with it. The most common action is to run a program located on the server in a directory that’s typically called “cgi-bin.” (If you watch the address window at the top of your browser when you push a button on a Web page, you can sometimes see “cgi-bin” within all the gobbledygook there.) These programs can be written in most languages. Perl is a common choice because it is designed for text manipulation and is interpreted, so it can be installed on any server regardless of processor or operating system. Many powerful Web sites today are built strictly on CGI, and you can in fact do nearly anything with it. However, Web sites built on CGI programs can rapidly become overly complicated to maintain, and there is also the problem of response time. The response of a CGI program depends on how much data must

JAVA外文文献翻译基于Java技术的Web应用设计模型的比较研究

中文翻译 基于Java技术的Web应用设计模型的比较研究 来源:School of Computer Science and Engineering University of New South Wales Sydney, NSW 2052, Australia 作者:Budi Kurniawan and Jingling Xue 摘要 Servlet技术是在建立可扩展性Web应用中被应用最广泛的技术。在运用JAVA技术开发Web应用中有四种模型,分别是:Model 1、Model 2、Struts和JavaServer Faces JSF。Model 1使用一连串的JSP页面,Model 2采用了模型,视图,控制器MVC模式。Struts是一个采用了Model 2设计模型的框架,JSF是一种支持ready-to-use组件来进行快速Web应用开发的新技术。Model 1对于中等和大型的应用来说很难维护,所以不推荐使用。本文通过利用Model 2、Struts和JSF这三种模型分别构建三个不同版本的在线商店应用程序来比较和评价这三种模型在应用程序开发和性能上的差异。 1.绪论 当今Web应用是一种展现动态内容的最普遍的方式。构建Web应用有许多种方法,其中最流行的是Servlet技术。这种技术的流行是因为它比CGI、PHP等其他技术更具优越性。然而Servlet对于开发来说还是麻烦的,因为它在传送HTML 标签时需要程序员将他们组合成为一个字符串对象,再将这个对象传给浏览器。同样的,对于输出的一个很小的改动也要求Servlet被重新编译。基于这个原因SUN 公司发明了JavaServer Pages JSP技术。JSP允许HTML标签和Java代码混合在

JAVA思想外文翻译毕业设计

文献来源: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是专为文字的处理及解释而设计的,所以能在任何服务器上安装和使用,无论采用的处理器或操作系统是什么。 2、脚本编制语言 插件造成了脚本编制语言的爆炸性增长。通过这种脚本语言,可将用于自己客户端程序的源码直接插入HTML页,而对那种语言进行解释的插件会在HTML 页显示的时候自动激活。脚本语言一般都倾向于尽量简化,易于理解。而且由于它们是从属于HTML页的一些简单正文,所以只需向服务器发出对那个页的一

Java的面向对象编程外文资料翻译

毕业设计(论文)外文资料翻译 系:计算机系 专业:计算机科学与技术 姓名: 学号: 外文出处:Ghosh,D..Java Object-oriented (用外文写) programming[J]. IEEE Transactions on Software Engineering,2009, 13(3):42-45. 附件: 1.外文资料翻译译文;2.外文原文。

注:请将该封面与附件装订成册。

附件1:外文资料翻译译文 Java的面向对象编程 ——面向对象编程和它的关键技术—继承和多态性 软件的重用可以节省程序开发时间。它鼓励重复使用已经调试好的高质量的软件,从而减少系统运行后可能出现的问题。这些都是令人振奋的可能性。多态性允许我们用统一的风格编写程序,来处理多种已存在的类和特定的相关类。利用多态性我们可以方便地向系统中添加新的功能。继承和多态对于解决软件的复杂性是一种有效可行的技术。当创建一个新的类时,而不用完整的写出新的实例变量和实例方法,程序员会指定新的类继承已定义的超类的实例变量和实例方法。这个新的类被称为一个子类。每个子类本身将来亦可有新的子类,而其本身将成为父类。一个类的直接父类就是该类所直接继承的类(通过关键字extends继承)。一个间接超类是通过从两级或更多级以上的类继承而来的。例如,从类JApplet(包javax.swing 中)扩展来的类Applet(包java.applet)。一个类单一的从一个父类继承而来。 Java 不支持多重继承(而C++可以),但它支持接口的概念。接口可以使Java实现许多通过多重继承才能实现的优点而没有关联的问题。我们将在本章讨论的接口的详细内容。我们会给出创建和使用接口的一般规律和具体实例。一个子类通常添加自己的实例变量和自己的实例方法,因此子类通常比父类大。一个子类比它的父类更具体并且代表一组更小、更专业的对象。通过单一继承,子类在开始时拥有父类的所有特性。继承性真正的力量在于它可以在定义子类时增加或取代从超类中继承来的特征。每个子类对象也是该类的父类的对象。例如,每一个我们所定义的小程序被认为是类JApplet 的对象。此外,因为Japplet继承了Applet,每一个我们所定义的小程序同时也被认为是一个Applet 的对象。当开发applets时,这些信息是至关重要的,因为一个小程序容器只有当它是一个Applet才可以执行一个程序。虽然子类对象始终可以作为它的父类的一种来看待,父类对象却不被认为是其子类类型的对象。我们将利用这种“子类对象是父类对象”的关系来执行一些强大的操作。例如,绘图程序可以显示一系列图形,如果所有的图形类型都直接或间接地继

java外文翻译

毕业设计外文资料翻译 (译文) 题目名称:Java and the Internet 学院:计算机科学技术 专业年级:计算机科学与技术(师)08 级 学生姓名:aaa 班级学号:a班a号 指导教师:aaa

二○一一年五月十三日 译文题目:Java和因特网 原文题目:Java and the Internet 原文出处:https://www.360docs.net/doc/08344026.html,/view.html

Java and the Internet If Java is, in fact, yet another computer programming language, you may question why it is so important and why it is being promoted as a revolutionary step in computer programming. The answer isn’t immediately obvious if you’re coming from a traditional programming perspective. Although Java is very useful for solving traditional stand-alone programming problems, it is also important because it will solve programming problems on the World Wide Web. 1.Client-side programming The Web’s initial server-browser design provided for interactive content, but the interactivity was completely provided by the server. The server produced static pages for the client browser, which would simply interpret and display them. Basic HTML contains simple mechanisms for data gathering: text-entry boxes, check boxes, radio boxes, lists and drop-down lists, as well as a button that can only be programmed to reset the data on the form or “submit” the data on the form back to the server. This submission passes through the Common Gateway Interface (CGI) provided on all Web servers. The text within the submission tells CGI what to do with it. The most common action is to run a program located on the server in a directory that’s typically called “cgi-bin.” (If you watch the address window at the top of your browser when you push a button on a Web page, you can so metimes see “cgi-bin” within all the gobbledygook there.) These programs can be written in most languages. Perl is a common choice because it is designed for text manipulation and is interpreted, so it can be installed on any server regardless of processor or operating system. Many powerful Web sites today are built strictly on CGI, and you can in fact do nearly anything with it. However, Web sites built on CGI programs can rapidly become overly complicated to maintain, and there is also the problem of response time. The response of a CGI program depends on how much data must be sent, as well as the load on both the server and the Internet. (On top of this, starting a CGI program tends to be slow.) The initial designers of the Web did not foresee how rapidly this bandwidth would be exhausted for the kinds of applications people developed. For example, any sort of dynamic graphing is nearly impossible to perform with consistency because a GIF file must be created and moved from the server to the client for eac h version of the graph. And you’ve no doubt had direct experience with something as simple as validating the data on an input form. You press the submit button on a page; the data is shipped back to the server; the server starts a CGI program that discovers an error, formats an HTML page informing you of the error, and then sends the page back to you; you must then back up a page and try again. Not only is this slow, it’s inelegant. The solution is client-side programming. Most machines that run Web browsers are powerful engines capable of doing vast work, and with the original static HTML

15000字的Java外文翻译

xxxx大学高新学院毕业设计(论文) 外文翻译 学生姓名: 院(系): 专业班级: 指导教师: 完成日期:

JSP基础学习资料 一、JSP 技术概述 在Sun 正式发布JSP(JavaServer Pages) 之后,这种新的Web 应用开发技术很快引起了人们的关注。JSP 为创建高度动态的Web 应用提供了一个独特的开发环境。按照Sun 的说法,JSP 能够适应市场上包括Apache WebServer 、IIS4.0 在内的85% 的服务器产品。即使您对ASP “一往情深”,我们认为,关注JSP 的发展仍旧很有必要。 ㈠JSP 与ASP 的简单比较 JSP 与Microsoft 的ASP 技术非常相似。两者都提供在HTML 代码中混合某种程序代码、由语言引擎解释执行程序代码的能力。在ASP 或JSP 环境下,HTML 代码主要负责描述信息的显示样式,而程序代码则用来描述处理逻辑。普通的HTML 页面只依赖于Web 服务器,而ASP 和JSP 页面需要附加的语言引擎分析和执行程序代码。程序代码的执行结果被重新嵌入到HTML 代码中,然后一起发送给浏览器。ASP 和JSP 都是面向Web 服务器的技术,客户端浏览器不需要任何附加的软件支持。 ASP 的编程语言是VBScript 之类的脚本语言,JSP 使用的是Java ,这是两者最明显的区别。此外,ASP 与JSP 还有一个更为本质的区别:两种语言引擎用完全不同的方式处理页面中嵌入的程序代码。在ASP 下,VBScript 代码被ASP 引擎解释执行;在JSP 下,代码被编译成Servlet 并由Java 虚拟机执行,这种编译操作仅在对JSP 页面的第一次请求时发生。 ㈡运行环境 Sun 公司的JSP 主页在https://www.360docs.net/doc/08344026.html,/products/jsp/index.html ,从这里还可以下载JSP 规范,这些规范定义了供应商在创建JSP 引擎时所必须遵从的一些规则。 执行JSP 代码需要在服务器上安装JSP 引擎。此处我们使用的是Sun 的JavaServer Web Development Kit (JSWDK )。为便于学习,这个软件包提供了大量可供修改的示例。安装JSWDK 之后,只需执行startserver 命令即可启动服务器。在默认配置下服务器在端口8080 监听,使用http://localhost:8080 即可打开缺省页面。 在运行JSP 示例页面之前,请注意一下安装JSWDK 的目录,特别是“ work ”子目录下的内容。执行示例页面时,可以在这里看到JSP 页面如何被转换成Java 源文件,然后又被编译成class 文件(即Servlet )。JSWDK 软件包中的示例页

java外文翻译资料

*** 学院 毕业设计(论文)外文资料翻译 系(院):计算机工程学院 专业:计算机科学与技术(软件技术)姓名:*** 学号:*** 外文出处:The Programmer (用外文写) 附件: 1.外文资料翻译译文;2.外文原文。

注:请将该封面与附件装订成册。

附件1:外文资料翻译译文 JSP技术概述 JSP的优点 JSP页面最终会转换成servler。因而,从根本上,JSP页面能够执行的任何任务都可以用servler来完成。然而,这种底层的等同性并不意味着servler和JSP页面对于所有的情况都等同适用。问题不在于技术的能力,而是二者在便利性、生产率和可维护性上的不同。毕竟,在特定平台上能够用Java编程语言完成的事情,同样可以用汇编语言来完成,但是选择哪种语言依旧十分重要。 和单独使用servler相比,JSP提供下述好处: (1)JSP中HTML的编写与维护更为简单。JSP中可以使用常规的HTML:没有额外的反斜杠,没有额外的双引号,也没有暗含的Java语法。 (2)能够使用标准的网站开发工具。即使对那些对JSP一无所知的HTML 工具,我们也可以使用,因为它们会忽略JSP标签(JSP tags)。 (3)可以对开发团队进行划分。Java程序员可以致力于动态代码。Web 开发人员可以将经理集中在表示层(presentation layer)上。对于大型的项目,这种划分极为重要。依据开发团队的大小,及项目的复杂程度,可以对静态HTML和动态内容进行弱分离(weaker separation)和强分离(stronger separation)。 在此,这个讨论并不是让您停止使用servlets,只使用JSP。几乎所有的项目都会同时用到这两种技术。针对项目中的某些请求,您可能会在MVC构架下组合使用这两项技术。我们总是希望用适当的工具完成相对应的工作,仅仅是servlet并不能填满您的工具箱。 JSP相对于竞争技术的优势

(完整版)Java外文翻译1毕业设计

以下文档格式全部为word格式,下载后您可以任意修改编辑。 毕业设计(论文)外文文献翻 译 译文: Java IO 系统[1] 对编程语言的设计者来说,创建一套好的输入输出(IO)系统,是一项难度极高的任务。 这一类可以从解决方案的数量之多上看出端倪。这个问题就难在它要面对的可能性太多了。不仅是因为有那么多的IO的源和目的(文件,控制台,网络连接等等),而且还有很多方法(顺序的,随机的,缓存的,二进制的,字符方式的,行的,字的等等)。 Java类库的设计者们用“创建很多类”的办法来解决这个问题。坦率地说,Java IO系统的类实在太多了,以至于初看起来会把人吓着(但是,具有讽刺意味的是,这种设计实际上是限制了类的爆炸性增长)。此外,Java在1.0版之后又对其IO类库进行了重大的修改,原先是面向byte的,现在又补充了面向Unicode字符的类库。为了提高性能,完善功能,JDK1.4又加了一个nio(意思是“new IO”。这个名字会用上很多年)。这么以来,如果你想对Java 的IO类库有个全面了解,并且做到运用自如,你就得先

学习大量的类。此外,了解IO类库的演化历史也是相当重要的。可能你的第一反应是“别拿什么历史来烦我了,告诉我怎么用就可以了!”但问题是,如果你对这段一无所知,很快就会被一些有用或是没用的类给搞糊涂了。 本文会介绍Java 标准类库中的各种IO类,及其使用方法。 File 类 在介绍直接从流里读写数据的类之前,我们先介绍一下处理文件和目录的类。 你会认为这是一个关于文件的类,但它不是。你可以用它来表示某个文件的名字,也可以用它来表示目录里一组文件的名字。如果它表示的是一组文件,那么你还可以用list( )方法来进行查询,让它会返回String 数组。由于元素数量是固定的,因此数组会比容器更好一些。如果你想要获取另一个目录的清单,再建一个File对象就是了。 目录列表器 假设你想看看这个目录。有两个办法。一是不带参数调用list( )。它返回的是File对象所含内容的完整清单。但是,如果你要的是一个"限制性列表(restricted list)"的话——比方说,你想看看所有扩展名为.java的文件——那么你就得使用"目录过滤器"了。这是一个专门负责挑选显示File对象的内容的类。 FilenameFilter接口的声明: public interface FilenameFilter { boolean accept(File dir, String name); } accept( )方法需要两个参数,一个是File对象,表示这个文件是在

(完整版)毕设外文翻译-详细解析Java中抽象类和接口的区别

Parsing Java Abstraction of the Difference Between Classes and Interfaces In Java language, abstract scale-up and with support class abstraction definition of two mechanisms. Because of these two kinds of mechanism of existence, just gives Java powerful object-oriented skills. Abstract scale-up and with between classes abstraction definition for support has great similarities, even interchangeable, so many developers into line non-abstract class definition for abstract scale-up and it is becoming more casual with choice. In fact, both between still has the very big difference, for their choice even reflected in problem domain essence of understanding, to design the intentions of the understanding correctly and reasonable. This paper will for the difference analysis, trying to give a developer with a choice between them are based. Understand class abstraction Abstract class and interface in Java language is used for abstract classes (in this article non-abstract class not from abstract scale-up translation, it represents an abstract body, and abstract scale-up for Java language used to define class abstraction in one way, please readers distinguish) defined, then what are the abstract classes, use abstract classes for us any good? In object-oriented concept, we know all objects is through class to describe, but in turn not such. Not all classes are used to describe object, if a class does not contain enough information to portray a concrete object, this class is abstract classes. Abstract classes are often used to characterization of problem field in our analysis, design that the abstract concepts, is to the series will look different, but essentially the same exact conception of abstraction. For example: if we carry out a graphical editing software development, will find problem domain exists round, triangle so some specific concept, they are different, but they all belong to shape such a concept, shape this concept in problem domain is not exist, it is an abstract concept. Precisely because the abstract concepts in problem field no corresponding specific concept, so to characterization abstract concepts non-abstract class cannot be instantiated. In an object-oriented field, mainly used for class abstraction types hidden. We can

java介绍外文翻译

外文原文 Introduction to Java autor:Martin Ngobye. source:Computing Static Slice for Java Programs Java 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 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. The design requirements of Java are driven by the nature of the computing environments in which software must be deployed. 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 must enable the development of secure, high performance, and highly robust applications on multiple platforms in heterogeneous, distributed networks. 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, Java must be architecture neutral, portable, and dynamically adaptable. The Java 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 Java; object oriented, to take advantage of modern software development methodologies and to fit into distributed client-server applications;

java毕业论文外文文献翻译

Advantages of Managed Code Microsoft intermediate language shares with Java byte code the idea that it is a low-level language witha simple syntax , which can be very quickly translated intonative machine code. Having this well-defined universal syntax for code has significant advantages. Platform independence First, it means that the same file containing byte code instructions can be placed on any platform; atruntime the final stage of compilation can then be easily accomplished so that the code will run on thatparticular platform. In other words, by compiling to IL we obtain platform independence for .NET, inmuch the same way as compiling to Java byte code gives Java platform independence. Performance improvement IL is actually a bit more ambitious than Java bytecode. IL is always Just-In-Time compiled (known as JIT), whereas Java byte code was ofteninterpreted. One of the disadvantages of Java was that, on execution, the process of translating from Javabyte code to native executable resulted in a loss of performance. Instead of compiling the entire application in one go (which could lead to a slow start-up time), the JITcompiler simply compiles each portion of code as it is called (just-in-time). When code has been compiled.once, the resultant native executable is stored until the application exits, so that it does not need to berecompiled the next time that portion of code is run. Microsoft argues that this process is more efficientthan compiling the entire application code at the start, because of the likelihood that large portions of anyapplication code will not actually be executed in any given run. Using the JIT compiler, such code willnever be compiled.

相关文档
最新文档