外文翻译java
Java编程语言外文翻译、英汉互译、中英对照
文档从互联网中收集,已重新修正排版,word格式支持编辑,如有帮助欢迎下载支持。
外文翻译原文及译文学院计算机学院专业计算机科学与技术班级学号姓名指导教师负责教师Java(programming language)Java is a general-purpose, concurrent, class-based, object-oriented computer program- -ming language that is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere" (WORA), meaning that code that runs on one platform does not need to be recompiled to run on another. Java applications are typically compiled to byte code (class file) that can run on any Java virtual machine(JVM) regardless of computer architecture. Java is, as of 2012, one of the most popular programming languages in use, particularly for client-server web applications, with a reported 10 million users. Java was originally developed by James Gosling at Sun Microsystems (which has since merged into Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++, but it has fewer low-level facilities than either of them.The original and reference implementation Java compilers, virtual machines, and class libraries were developed by Sun from 1991 and first released in 1995. As of May 2007, in compliance with the specifications of the Java Community Process, Sun relicensed most of its Java technologies under the GNU General Public License. Others have also developed alternative implementations of these Sun technologies, such as the GNU Compiler for Java and GNU Classpath.Java is a set of several computer software products and specifications from Sun Microsystems (which has since merged with Oracle Corporation), that together provide a system for developing application software and deploying it in across-platform computing environment. Java is used in a wide variety of computing platforms from embedded devices and mobile phones on the low end, to enterprise servers and supercomputers on the high end. While less common, Java appletsare sometimes used to provide improved and secure functions while browsing the World Wide Web on desktop computers.Writing in the Java programming language is the primary way to produce code that will be deployed as Java bytecode. There are, however, byte code compilers available forother languages such as Ada, JavaScript, Python, and Ruby. Several new languages have been designed to run natively on the Java Virtual Machine (JVM), such as Scala, Clojure and Groovy.Java syntax borrows heavily from C and C++, but object-oriented features are modeled after Smalltalk and Objective-C. Java eliminates certain low-level constructs such as pointers and has a very simple memory model where every object is allocated on the heap and all variables of object types are references. Memory management is handled through integrated automatic garbage collection performed by the JVM.An edition of the Java platform is the name for a bundle of related programs from Sun that allow for developing and running programs written in the Java programming language. The platform is not specific to any one processor or operating system, but rather an execution engine (called a virtual machine) and a compiler with a set of libraries that are implemented for various hardware and operating systems so that Java programs can run identically on all of them. The Java platform consists of several programs, each of which provides a portion of its overall capabilities. For example, the Java compiler, which converts Java source code into Java byte code (an intermediate language for the JVM), is provided as part of the Java Development Kit (JDK). The Java Runtime Environment(JRE), complementing the JVM with a just-in-time (JIT) compiler, converts intermediate byte code into native machine code on the fly. An extensive set of libraries are also part of the Java platform.The essential components in the platform are the Java language compiler, the libraries, and the runtime environment in which Java intermediate byte code "executes" according to the rules laid out in the virtual machine specification.In most modern operating systems (OSs), a large body of reusable code is provided to simplify the programmer's job. This code is typically provided as a set of dynamically loadable libraries that applications can call at runtime. Because the Java platform is not dependent on any specific operating system, applications cannot rely on any of the pre-existing OS libraries. Instead, the Java platform provides a comprehensive set of its own standard class libraries containing much of the same reusable functions commonly found in modern operating systems. Most of the system library is also written in Java. For instance, Swing library paints the user interface and handles the events itself, eliminatingmany subtle differences between how different platforms handle even similar components.The Java class libraries serve three purposes within the Java platform. First, like other standard code libraries, the Java libraries provide the programmer a well-known set of functions to perform common tasks, such as maintaining lists of items or performing complex string parsing. Second, the class libraries provide an abstract interface to tasks that would normally depend heavily on the hardware and operating system. Tasks such as network access and file access are often heavily intertwined with the distinctive implementations of each platform. The and java.io libraries implement an abstraction layer in native OS code, then provide a standard interface for the Java applications to perform those tasks. Finally, when some underlying platform does not support all of the features a Java application expects, the class libraries work to gracefully handle the absent components, either by emulation to provide a substitute, or at least by providing a consistent way to check for the presence of a specific feature.The success of Java and its write once, run anywhere concept has led to other similar efforts, notably the .NET Framework, appearing since 2002, which incorporates many of the successful aspects of Java. .NET in its complete form (Microsoft's implementation) is currently only fully available on Windows platforms, whereas Java is fully available on many platforms. .NET was built from the ground-up to support multiple programming languages, while the Java platform was initially built to support only the Java language, although many other languages have been made for JVM since..NET includes a Java-like language called Visual J# (formerly named J++) that is incompatible with the Java specification, and the associated class library mostly dates to the old JDK 1.1 version of the language. For these reasons, it is more a transitional language to switch from Java to the .NET platform, than a first class .NET language. Visual J# was discontinued with the release of Microsoft Visual Studio 2008. The existing version shipping with Visual Studio 2005will be supported until 2015 as per the product life-cycle strategy.In June and July 1994, after three days of brainstorming with John Gage, the Director of Science for Sun, Gosling, Joy, Naughton, Wayne Rosing, and Eric Schmidt, the team re-targeted the platform for the World Wide Web. They felt that with the advent of graphical web browsers like Mosaic, the Internet was on its way to evolving into the samehighly interactive medium that they had envisioned for cable TV. As a prototype, Naughton wrote a small browser, Web Runner (named after the movie Blade Runner), later renamed Hot Java.That year, the language was renamed Java after a trademark search revealed that Oak was used by Oak Technology. Although Java 1.0a was available for download in 1994, the first public release of Java was 1.0a2 with the Hot Java browser on May 23, 1995, announced by Gage at the Sun World conference. His announcement was accompanied by a surprise announcement by Marc Andreessen, Executive Vice President of Netscape Communications Corporation, that Netscape browsers would be including Java support. On January 9, 1996, the Java Soft group was formed by Sun Microsystems to develop the technology.Java编程语言Java是一种通用的,并发的,基于类的并且是面向对象的计算机编程语言,它是为实现尽可能地减少执行的依赖关系而特别设计的。
java英汉互译
java英汉互译Java是一种广泛使用的编程语言,它是一种面向对象的语言,最初由Sun Microsystems开发。
Java的设计目标是让开发者编写一次代码,然后可以在不同的平台上运行,这种特性被称为“一次编写,到处运行”。
Java的语法与C++类似,但是Java具有更强的安全性和可移植性。
Java的英汉互译是Java English-Chinese Translation,它是指将Java程序中的英文单词翻译成中文,或将中文翻译成英文。
Java英汉互译在软件开发中非常重要,因为Java程序中的注释、变量名、方法名等都需要进行翻译,以便程序员能够更好地理解和维护代码。
Java英汉互译的实现方式有多种,其中最常用的是使用翻译工具或翻译软件。
这些工具可以自动将Java程序中的英文单词翻译成中文,或将中文翻译成英文。
翻译工具的优点是速度快、准确度高,但是由于语言的复杂性,翻译工具有时会出现错误或不准确的翻译结果。
除了翻译工具,Java程序员还可以使用在线翻译网站或翻译软件进行英汉互译。
这些工具可以帮助程序员快速翻译Java程序中的英文单词,但是需要注意的是,翻译结果需要进行人工校对,以确保翻译的准确性和可读性。
在进行Java英汉互译时,程序员需要注意以下几点:1. 翻译结果需要符合语法规范,以便程序能够正常运行。
2. 翻译结果需要准确无误,以避免程序出现错误或漏洞。
3. 翻译结果需要易于理解和维护,以便程序员能够快速定位和修复问题。
总之,Java英汉互译是Java程序员必备的技能之一,它可以帮助程序员更好地理解和维护代码,提高程序的可读性和可维护性。
在进行翻译时,程序员需要注意翻译结果的准确性和可读性,以确保程序的正常运行和稳定性。
JAVA外文文献+翻译
Java and the InternetIf 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 programmingThe 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 sometimes see “cgi-bin” within all the gobbledygook there.) These programs can be written in most languages. Perl is acommon 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 each 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 approach they are sitting there, just idly waiting for the server to dish up the next page. Client-side programming means that the Web browser is harnessed to do whatever work it can, and the result for the user is a much speedier and more interactive experience at your Web site.The problem with discussions of client-side programming is that they aren’t very different from discussions of programming in general. The parameters are almost the same, but the platform is different: a Web browser is like a limited operating system. In the end, you must still program, and this accounts for the dizzying array of problems and solutions produced by client-side programming. The rest of this section provides an overview of the issues and approaches in client-side programming.2.Plug-insOne of the most significant steps forward in client-side programming is the development of the plug-in. This is a way for a programmer to add new functionality to the browser by downloading a piece of code that plugs itself into the appropriate spot in the browser. It tells the browser “from now on you can perform this new activity.” (You ne ed to download the plug-in only once.) Some fast and powerful behavior is added to browsers via plug-ins, but writing a plug-in is not a trivial task, and isn’t something you’d want to do as part of the process of building a particular site. The value of the plug-in for client-side programming is that it allows an expert programmer to develop a new language and add that language to a browser without the permission of the browser manufacturer. Thus, plug-ins provide a “back door” that allows the creation of new client-side programming languages (although not all languages are implemented as plug-ins).3.Scripting languagesPlug-ins resulted in an explosion of scripting languages. With a scripting language you embed the source code for your client-side program directly into the HTML page, and the plug-in that interprets that language is automatically activated while the HTML page is being displayed. Scripting languages tend to be reasonably easy to understand and, because they are simply text that is part of an HTML page, they load very quickly as part of the single server hit required to procure that page. The trade-off is that your code is exposed for everyone to see (and steal). Generally, however, you aren’t doing amazingly sophisticated things with scripting languages so this is not too much of a hardship.This points out that the scripting languages used inside Web browsers are really intended to solve specific types of problems, primarily the creation of richer and more interactive graphical user interfaces (GUIs). However, a scripting language might solve 80 percent of the problems encountered in client-side programming. Your problems might very well fit completely withinthat 80 percent, and since scripting languages can allow easier and faster development, you should probably consider a scripting language before looking at a more involved solution such as Java or ActiveX programming.The most commonly discussed browser scripting languages are JavaScript (which has nothing to do with Java; it’s named that way just to grab some of Java’s marketing momentum), VBScript (which looks like Visual Basic), and Tcl/Tk, which comes from the popular cross-platform GUI-building language. There are others out there, and no doubt more in development.JavaScript is probably the most commonly supported. It comes built into both Netscape Navigator and the Microsoft Internet Explorer (IE). In addition, there are probably more JavaScript books available than there are for the other browser languages, and some tools automatically create pages using JavaScript. However, if you’re already fluent in Visual Basic or Tcl/Tk, you’ll be more productive using those scripting languages rather than learning a new one. (You’ll have your hands full dealing with the Web issues already.)4.JavaIf a scripting language can solve 80 percent of the client-side programming problems, what about the other 20 percent—the “really hard stuff?” The most popular solution today is Java. Not only is it a powerful programming language built to be secure, cross-platform, and international, but Java is being continually extended to provide language features and libraries that elegantly handle problems that are difficult in traditional programming languages, such as multithreading, database access, network programming, and distributed computing. Java allows client-side programming via the applet.An applet is a mini-program that will run only under a Web browser. The applet is downloaded automatically as part of a Web page (just as, for example, a graphic is automatically downloaded). When the applet is activated it executes a program. This is part of its beauty—it provides you with a way to automatically distribute the client software from the server at the time the user needs the client software, and no sooner. The user gets the latest version of the client software without fail and without difficult reinstallation. Because of theway Java is designed, the programmer needs to create only a single program, and that program automatically works with all computers that have browsers with built-in Java interpreters. (This safely includes the vast majority of machines.) Since Java is a full-fledged programming language, you can do as much work as possible on the client before and after making requests of the server. F or example, you won’t need to send a request form across the Internet to discover that you’ve gotten a date or some other parameter wrong, and your client computer can quickly do the work of plotting data instead of waiting for the server to make a plot and ship a graphic image back to you. Not only do you get the immediate win of speed and responsiveness, but the general network traffic and load on servers can be reduced, preventing the entire Internet from slowing down.One advantage a Java applet has ove r a scripted program is that it’s in compiled form, so the source code isn’t available to the client. On the other hand, a Java applet can be decompiled without too much trouble, but hiding your code is often not an important issue. Two other factors can be important. As you will see later in this book, a compiled Java applet can comprise many modules and take multiple server “hits” (accesses) to download. (In Java 1.1 and higher this is minimized by Java archives, called JAR files, that allow all the required modules to be packaged together and compressed for a single download.) A scripted program will just be integrated into the Web page as part of its text (and will generally be smaller and reduce server hits). This could be important to the responsiveness of your Web site. Another factor is the all-important learning curve. Regardless of what you’ve heard, Java is not a trivial language to learn. If you’re a Visual Basic programmer, moving to VBScript will be your fastest solution, and since it will probably solve most typical client/server problems you might be hard pressed to justify learning Java. If you’re experienced with a scripting language you will certainly benefit from looking at JavaScript or VBScript before committing to Java, since they might fit your needs handily and you’ll be more productive sooner.to run its applets withi5.ActiveXTo some degree, the competitor to Java is Microsoft’s ActiveX, although it takes a completely different approach. ActiveX was originally a Windows-only solution, although it is now being developed via an independent consortium to become cross-platform. Effectively, ActiveX says “if your program connects to its environment just so, it can be dropped into a Web page and run under a browser that supports ActiveX.” (I E directly supports ActiveX and Netscape does so using a plug-in.) Thus, ActiveX does not constrain you to a particular language. If, for example, you’re already an experienced Windows programmer using a language such as C++, Visual Basic, or Borland’s Del phi, you can create ActiveX components with almost no changes to your programming knowledge. ActiveX also provides a path for the use of legacy code in your Web pages.6.SecurityAutomatically downloading and running programs across the Internet can sound like a virus-builder’s dream. ActiveX especially brings up the thorny issue of security in client-side programming. If you click on a Web site, you might automatically download any number of things along with the HTML page: GIF files, script code, compiled Java code, and ActiveX components. Some of these are benign; GIF files can’t do any harm, and scripting languages are generally limited in what they can do. Java was also designed to run its applets within a “sandbox” of safety, which prevents it from wri ting to disk or accessing memory outside the sandbox.ActiveX is at the opposite end of the spectrum. Programming with ActiveX is like programming Windows—you can do anything you want. So if you click on a page that downloads an ActiveX component, that component might cause damage to the files on your disk. Of course, programs that you load onto your computer that are not restricted to running inside a Web browser can do the same thing. Viruses downloaded from Bulletin-Board Systems (BBSs) have long been a problem, but the speed of the Internet amplifies the difficulty.The solution seems to be “digital signatures,” whereby code is verified to show who the author is. This is based on the idea that a virus works because its creator can be anonymous, so if you remove the anonymity individuals will be forced to be responsible for their actions. This seems like a good plan because it allows programs to be much more functional, and I suspect it will eliminate malicious mischief. If, however, a program has an unintentional destructive bug it will still cause problems.The Java approach is to prevent these problems from occurring, via the sandbox. The Java interpreter that lives on your local Web browser examines the applet for any untoward instructions as the applet is being loaded. In particular, the applet cannot write files to disk or erase files (one of the mainstays of viruses). Applets are generally considered to be safe, and since this is essential for reliable client/server systems, any bugs in the Java language that allow viruses are rapidly repaired. (It’s worth noting that the browser software actually enforces these security restrictions, and some browsers allow you to select different security levels to provide varying degrees of access to your system.) You might be skeptical of this rather draconian restriction against writing files to your local disk. For example, you may want to build a local database or save data for later use offline. The initial vision seemed to be that eventually everyone would get online to do anything important, but that was soon seen to be impractical (although low-cost “Internet appliances” might someday satisfy the needs of a significant segment of users). The solution is the “signed applet” that uses public-key encryption to verify that an applet does indeed come from where it claims it does. A signed applet can still trash your disk, but the theory is that since you can now hold the applet creator accountable they won’t do vicious things. Java provides a framework for digital signatures so that you will eventually be able to allow an applet to step outside the sandbox if necessary. Digital signatures have missed an important issue, which is the speed that people move around on the Internet. If you download a buggy program and it does something untoward, how long will it be before you discover the damage? It could be days or even weeks. By then, how will you track down the program that’s done it? And what good will it do you at that point?7.Internet vs. intranetThe Web is the most general solution to the client/server problem, so it makes sense that you can use the same technology to solve a subset of the problem, in particular the classic client/server problem within a company. With traditional client/server approaches you have the problem of multiple types of client computers, as well as the difficulty of installing new client software, both of which are handily solved with Web browsers and client-side programming. When Web technology is used for an information network that is restricted to a particular company, it is referred to as an intranet. Intranets provide much greater security than the Internet, since you can physically control access to the servers within your company. In terms of training, it seems that once people und erstand the general concept of a browser it’s much easier for them to deal with differences in the way pages and applets look, so the learning curve for new kinds of systems seems to be reduced.The security problem brings us to one of the divisions that seems to be automatically forming in the world of client-side programming. If your program is running on the Internet, you don’t know what platform it will be working under, and you want to be extra careful that you don’t disseminate buggy code. You need something cross-platform and secure, like a scripting language or Java.If you’re running on an intranet, you might have a different set of constraints. It’s not uncommon that your machines could all be Intel/Windows platforms. On an intranet, you’re respon sible for the quality of your own code and can repair bugs when they’re discovered. In addition, you might already have a body of legacy code that you’ve been using in a more traditional client/server approach, whereby you must physically install client programs every time you do an upgrade. The time wasted in installing upgrades is the most compelling reason to move to browsers, because upgrades are invisible and automatic. If you are involved in such an intranet, the most sensible approach to take is the shortest path that allows you to use your existing code base, rather than trying to recode your programs in a new language.When faced with this bewildering array of solutions to the client-side programming problem, the best plan of attack is a cost-benefit analysis. Consider the constraints of your problem and what would be the shortest path to your solution. Since client-side programming is still programming, it’s always a good idea to take the fastest development approach for your particular situation. This is an aggressive stance to prepare for inevitable encounters with the problems of program development.8.Server-side programmingThis whole discussion has ignored the issue of server-side programming. What happens when you make a request of a server? Most of the time the request is simply “send me this file.” Your browser then interprets the file in some appropriate fashion: as an HTML page, a graphic image, a Java applet, a script program, etc. A more complicated request to a server generally involves a database transaction. A common scenario involves a request for a complex database search, which the server then formats into an HTML page and sends to you as the result. (Of course, if the client has more intelligence via Java or a scripting language, the raw data can be sent and formatted at the client end, which will be faster and less load on the server.) Or you might want to register your name in a database when you join a group or place an order, which will involve changes to that database. These database requests must be processed via some code on the server side, which is generally referred to as server-side programming. Traditionally, server-side programming has been performed using Perl and CGI scripts, but more sophisticated systems have been appearing. These include Java-based Web servers that allow you to perform all your server-side programming in Java by writing what are called servlets. Servlets and their offspring, JSPs, are two of the most compelling reasons that companies who develop Web sites are moving to Java, especially because they eliminate the problems of dealing with differently abled browsers.9. separate arena: applicationsMuch of the brouhaha over Java has been over applets. Java is actually a general-purpose programming language that can solve any type of problem—at least in theory. And as pointed out previously, there might be more effective ways to solve most client/server problems. When you move out of the applet arena (and simultaneously release the restrictions, such as the one against writing to disk) you enter the world of general-purpose applications that run standalone, without a Web browser, just like any ordinary program does. Here, Java’s strength is not only in its portability, but also its programmability. As you’l l see throughout this book, Java has many features that allow you to create robust programs in a shorter period than with previous programming languages. Be aware that this is a mixed blessing. You pay for the improvements through slower execution speed (although there is significant work going on in this area—JDK 1.3, in particular, introduces the so-called “hotspot” performance improvements). Like any language, Java has built-in limitations that might make it inappropriate to solve certain types of programming problems. Java is a rapidly evolving language, however, and as each new release comes out it becomes more and more attractive for solving larger sets of problems.Java和因特网既然Java不过另一种类型的程序设计语言,大家可能会奇怪它为什么值得如此重视,为什么还有这么多的人认为它是计算机程序设计的一个里程碑呢?如果您来自一个传统的程序设计背景,那么答案在刚开始的时候并不是很明显。
Java中英翻译
abstract (关键字) 抽象['.bstr.kt]access vt.访问,存取['.kses]'(n.入口,使用权)algorithm n.算法['.lg.riem]Annotation [java]代码注释[.n.u'tei..n]anonymous adj.匿名的[.'n.nim.s]'(反义:directly adv.直接地,立即[di'rektli, dai'rektli])apply v.应用,适用[.'plai]application n.应用,应用程序[,.pli'kei..n]' (application crash 程序崩溃) arbitrary a.任意的['ɑ:bitr.ri]argument n.参数;争论,论据['ɑ:gjum.nt]'(缩写args)assert (关键字) 断言[.'s.:t] ' (java 1.4 之后成为关键字)associate n.关联(同伴,伙伴) [.'s.u.ieit]attribute n.属性(品质,特征) [.'tribju:t]boolean (关键字) 逻辑的, 布尔型call n.v.调用; 呼叫; [k.:l]circumstance n.事件(环境,状况) ['s.:k.mst.ns]crash n.崩溃,破碎[kr..]cohesion内聚,黏聚,结合[k.u'hi:..n](a class is designed with a single, well-focoused purpose. 应该不止这点) command n. 命令,指令[k.'mɑ:nd](指挥, 控制) (command-line 命令行)Comments [java]文本注释['k.ments]compile [java] v.编译[k.m'pail]' Compilation n.编辑[,k.mpi'lei..n] const (保留字)constant n. 常量, 常数, 恒量['k.nst.nt]continue (关键字)coupling耦合,联结['k.pli.]making sure that classes know about other classes only through their APIs. declare [java]声明[di'kl..]default (关键字) 默认值; 缺省值[di'f.:lt]delimiter定义符; 定界符Encapsulation[java]封装(hiding implementation details)Exception [java]例外; 异常[ik'sep..n]entry n.登录项, 输入项, 条目['entri]enum (关键字)execute vt.执行['eksikju:t]exhibit v.显示, 陈列[ig'zibit]exist存在, 发生[ig'zist] '(SQL关键字exists)extends (关键字) 继承、扩展[ik'stend]false (关键字)final (关键字) finally (关键字)fragments段落; 代码块['fr.gm.nt]FrameWork [java]结构,框架['freimw.:k]Generic [java]泛型[d.i'nerik]goto (保留字) 跳转heap n.堆[hi:p]implements (关键字) 实现['implim.nt]import (关键字) 引入(进口,输入)Info n.信息(information [,inf.'mei..n] )Inheritance [java]继承[in'herit.ns] (遗传,遗产)initialize预置初始化[i'iz]instanceof (关键字) 运算符,用于引用变量,以检查这个对象是否是某种类型。
【java】简单实现中英文互翻译功能界面
【java】简单实现中英⽂互翻译功能界⾯ 1import java.awt.*;2import java.awt.event.*;3import javax.swing.*;45/*6有两个⽂本框,第⼀个框输⼊英⽂,再第⼆个⽂本框中⾃动显⽰汉语解释;7在第⼀个框输⼊中⽂,第⼆个框给出英⽂翻译8*/9class MyFrame58 extends JFrame implements ActionListener{10 JLabel engl;11 JLabel chnl;12 JTextField tfEng;13 JTextField tfChn;14 String [][] dictArr =15 {16 {"hello","你好"},17 {"frame","框架"},18 {"label","标签"},19 {"text","⽂本"},20 {"textfield","⽂本区域"}21 };2223 MyFrame58(){24// Constructor25 engl = new JLabel("输⼊英⽂或中⽂:");26 chnl = new JLabel("翻译结果:");27 tfEng = new JTextField();28 tfChn = new JTextField();2930 setSize(400,200);31 setTitle("简单中英⽂互翻译");32 Container conPane = getContentPane();33 conPane.setBackground(Color.WHITE);34 conPane.setLayout(new GridLayout(2,2));35 conPane.add(engl);36 conPane.add(tfEng);37 conPane.add(chnl);38 conPane.add(tfChn);39 tfEng.addActionListener(this);40 }4142public void actionPerformed(ActionEvent e){43int i=0;44if (e.getSource() == tfEng){ //⽂本框获得事件源45while (i<dictArr.length){46if (tfEng.getText().equals(dictArr[i][0])){ //字符串判断内容是否相等应该使⽤str1.equals(str2)⽅法47 tfChn.setText(dictArr[i][1]);48break;49 }50else if (tfEng.getText().equals(dictArr[i][1])){51 tfChn.setText(dictArr[i][0]);52break;53 }54else{55 tfChn.setText("⽆匹配");56 i++;57 }58 }59 }6061 }62 }6364public class Ex_5_8{65public static void main(String[] args) {66 MyFrame58 mf = new MyFrame58();67 mf.setVisible(true);68 }69 }。
计算机java外文翻译外文文献英文文献
英文原文:Title: Business Applications of Java. Author: Erbschloe, Michael, Business Applications of Java -- Research Starters Business, 2008DataBase: Research Starters - BusinessBusiness Applications of JavaThis article examines the growing use of Java technology in business applications. The history of Java is briefly reviewed along with the impact of open standards on the growth of the World Wide Web. Key components and concepts of the Java programming language are explained including the Java Virtual Machine. Examples of how Java is being used bye-commerce leaders is provided along with an explanation of how Java is used to develop data warehousing, data mining, and industrial automation applications. The concept of metadata modeling and the use of Extendable Markup Language (XML) are also explained.Keywords Application Programming Interfaces (API's); Enterprise JavaBeans (EJB); Extendable Markup Language (XML); HyperText Markup Language (HTML); HyperText Transfer Protocol (HTTP); Java Authentication and Authorization Service (JAAS); Java Cryptography Architecture (JCA); Java Cryptography Extension (JCE); Java Programming Language; Java Virtual Machine (JVM); Java2 Platform, Enterprise Edition (J2EE); Metadata Business Information Systems > Business Applications of JavaOverviewOpen standards have driven the e-business revolution. Networking protocol standards, such as Transmission Control Protocol/Internet Protocol (TCP/IP), HyperText Transfer Protocol (HTTP), and the HyperText Markup Language (HTML) Web standards have enabled universal communication via the Internet and the World Wide Web. As e-business continues to develop, various computing technologies help to drive its evolution.The Java programming language and platform have emerged as major technologies for performing e-business functions. Java programming standards have enabled portability of applications and the reuse of application components across computing platforms. Sun Microsystems' Java Community Process continues to be a strong base for the growth of the Java infrastructure and language standards. This growth of open standards creates new opportunities for designers and developers of applications and services (Smith, 2001).Creation of Java TechnologyJava technology was created as a computer programming tool in a small, secret effort called "the Green Project" at Sun Microsystems in 1991. The Green Team, fully staffed at 13 people and led by James Gosling, locked themselves away in an anonymous office on Sand Hill Road in Menlo Park, cut off from all regular communications with Sun, and worked around the clock for18 months. Their initial conclusion was that at least one significant trend would be the convergence of digitally controlled consumer devices and computers. A device-independent programming language code-named "Oak" was the result.To demonstrate how this new language could power the future of digital devices, the Green Team developed an interactive, handheld home-entertainment device controller targeted at the digital cable television industry. But the idea was too far ahead of its time, and the digital cable television industry wasn't ready for the leap forward that Java technology offered them. As it turns out, the Internet was ready for Java technology, and just in time for its initial public introduction in 1995, the team was able to announce that the Netscape Navigator Internet browser would incorporate Java technology ("Learn about Java," 2007).Applications of JavaJava uses many familiar programming concepts and constructs and allows portability by providing a common interface through an external Java Virtual Machine (JVM). A virtual machine is a self-contained operating environment, created by a software layer that behaves as if it were a separate computer. Benefits of creating virtual machines include better exploitation of powerful computing resources and isolation of applications to prevent cross-corruption and improve security (Matlis, 2006).The JVM allows computing devices with limited processors or memory to handle more advanced applications by calling up software instructions inside the JVM to perform most of the work. This also reduces the size and complexity of Java applications because many of the core functions and processing instructions were built into the JVM. As a result, software developersno longer need to re-create the same application for every operating system. Java also provides security by instructing the application to interact with the virtual machine, which served as a barrier between applications and the core system, effectively protecting systems from malicious code.Among other things, Java is tailor-made for the growing Internet because it makes it easy to develop new, dynamic applications that could make the most of the Internet's power and capabilities. Java is now an open standard, meaning that no single entity controls its development and the tools for writing programs in the language are available to everyone. The power of open standards like Java is the ability to break down barriers and speed up progress.Today, you can find Java technology in networks and devices that range from the Internet and scientific supercomputers to laptops and cell phones, from Wall Street market simulators to home game players and credit cards. There are over 3 million Java developers and now there are several versions of the code. Most large corporations have in-house Java developers. In addition, the majority of key software vendors use Java in their commercial applications (Lazaridis, 2003).ApplicationsJava on the World Wide WebJava has found a place on some of the most popular websites in the world and the uses of Java continues to grow. Java applications not only provide unique user interfaces, they also help to power the backend of websites. Two e-commerce giants that everybody is probably familiar with (eBay and Amazon) have been Java pioneers on the World Wide Web.eBayFounded in 1995, eBay enables e-commerce on a local, national and international basis with an array of Web sites-including the eBay marketplaces, PayPal, Skype, and -that bring together millions of buyers and sellers every day. You can find it on eBay, even if you didn't know it existed. On a typical day, more than 100 million items are listed on eBay in tens of thousands of categories. Recent listings have included a tunnel boring machine from the Chunnel project, a cup of water that once belonged to Elvis, and the Volkswagen that Pope Benedict XVI owned before he moved up to the Popemobile. More than one hundred million items are available at any given time, from the massive to the miniature, the magical to the mundane, on eBay; the world's largest online marketplace.eBay uses Java almost everywhere. To address some security issues, eBay chose Sun Microsystems' Java System Identity Manager as the platform for revamping its identity management system. The task at hand was to provide identity management for more than 12,000 eBay employees and contractors.Now more than a thousand eBay software developers work daily with Java applications. Java's inherent portability allows eBay to move to new hardware to take advantage of new technology, packaging, or pricing, without having to rewrite Java code ("eBay drives explosive growth," 2007).Amazon (a large seller of books, CDs, and other products) has created a Web Service application that enables users to browse their product catalog and place orders. uses a Java application that searches the Amazon catalog for books whose subject matches a user-selected topic. The application displays ten books that match the chosen topic, and shows the author name, book title, list price, Amazon discount price, and the cover icon. The user may optionally view one review per displayed title and make a buying decision (Stearns & Garishakurthi, 2003).Java in Data Warehousing & MiningAlthough many companies currently benefit from data warehousing to support corporate decision making, new business intelligence approaches continue to emerge that can be powered by Java technology. Applications such as data warehousing, data mining, Enterprise Information Portals (EIP's), and Knowledge Management Systems (which can all comprise a businessintelligence application) are able to provide insight into customer retention, purchasing patterns, and even future buying behavior.These applications can not only tell what has happened but why and what may happen given certain business conditions; allowing for "what if" scenarios to be explored. As a result of this information growth, people at all levels inside the enterprise, as well as suppliers, customers, and others in the value chain, are clamoring for subsets of the vast stores of information such as billing, shipping, and inventory information, to help them make business decisions. While collecting and storing vast amounts of data is one thing, utilizing and deploying that data throughout the organization is another.The technical challenges inherent in integrating disparate data formats, platforms, and applications are significant. However, emerging standards such as the Application Programming Interfaces (API's) that comprise the Java platform, as well as Extendable Markup Language (XML) technologies can facilitate the interchange of data and the development of next generation data warehousing and business intelligence applications. While Java technology has been used extensively for client side access and to presentation layer challenges, it is rapidly emerging as a significant tool for developing scaleable server side programs. The Java2 Platform, Enterprise Edition (J2EE) provides the object, transaction, and security support for building such systems.Metadata IssuesOne of the key issues that business intelligence developers must solve is that of incompatible metadata formats. Metadata can be defined as information about data or simply "data about data." In practice, metadata is what most tools, databases, applications, and other information processes use to define, relate, and manipulate data objects within their own environments. It defines the structure and meaning of data objects managed by an application so that the application knows how to process requests or jobs involving those data objects. Developers can use this schema to create views for users. Also, users can browse the schema to better understand the structure and function of the database tables before launching a query.To address the metadata issue, a group of companies (including Unisys, Oracle, IBM, SAS Institute, Hyperion, Inline Software and Sun) have joined to develop the Java Metadata Interface (JMI) API. The JMI API permits the access and manipulation of metadata in Java with standard metadata services. JMI is based on the Meta Object Facility (MOF) specification from the Object Management Group (OMG). The MOF provides a model and a set of interfaces for the creation, storage, access, and interchange of metadata and metamodels (higher-level abstractions of metadata). Metamodel and metadata interchange is done via XML and uses the XML Metadata Interchange (XMI) specification, also from the OMG. JMI leverages Java technology to create an end-to-end data warehousing and business intelligence solutions framework.Enterprise JavaBeansA key tool provided by J2EE is Enterprise JavaBeans (EJB), an architecture for the development of component-based distributed business applications. Applications written using the EJB architecture are scalable, transactional, secure, and multi-user aware. These applications may be written once and then deployed on any server platform that supports J2EE. The EJB architecture makes it easy for developers to write components, since they do not need to understand or deal with complex, system-level details such as thread management, resource pooling, and transaction and security management. This allows for role-based development where component assemblers, platform providers and application assemblers can focus on their area of responsibility further simplifying application development.EJB's in the Travel IndustryA case study from the travel industry helps to illustrate how such applications could function. A travel company amasses a great deal of information about its operations in various applications distributed throughout multiple departments. Flight, hotel, and automobile reservation information is located in a database being accessed by travel agents worldwide. Another application contains information that must be updated with credit and billing historyfrom a financial services company. Data is periodically extracted from the travel reservation system databases to spreadsheets for use in future sales and marketing analysis.Utilizing J2EE, the company could consolidate application development within an EJB container, which can run on a variety of hardware and software platforms allowing existing databases and applications to coexist with newly developed ones. EJBs can be developed to model various data sets important to the travel reservation business including information about customer, hotel, car rental agency, and other attributes.Data Storage & AccessData stored in existing applications can be accessed with specialized connectors. Integration and interoperability of these data sources is further enabled by the metadata repository that contains metamodels of the data contained in the sources, which then can be accessed and interchanged uniformly via the JMI API. These metamodels capture the essential structure and semantics of business components, allowing them to be accessed and queried via the JMI API or to be interchanged via XML. Through all of these processes, the J2EE infrastructure ensures the security and integrity of the data through transaction management and propagation and the underlying security architecture.To consolidate historical information for analysis of sales and marketing trends, a data warehouse is often the best solution. In this example, data can be extracted from the operational systems with a variety of Extract, Transform and Load tools (ETL). The metamodels allow EJBsdesigned for filtering, transformation, and consolidation of data to operate uniformly on datafrom diverse data sources as the bean is able to query the metamodel to identify and extract the pertinent fields. Queries and reports can be run against the data warehouse that contains information from numerous sources in a consistent, enterprise-wide fashion through the use of the JMI API (Mosher & Oh, 2007).Java in Industrial SettingsMany people know Java only as a tool on the World Wide Web that enables sites to perform some of their fancier functions such as interactivity and animation. However, the actual uses for Java are much more widespread. Since Java is an object-oriented language like C++, the time needed for application development is minimal. Java also encourages good software engineering practices with clear separation of interfaces and implementations as well as easy exception handling.In addition, Java's automatic memory management and lack of pointers remove some leading causes of programming errors. Most importantly, application developers do not need to create different versions of the software for different platforms. The advantages available through Java have even found their way into hardware. The emerging new Java devices are streamlined systems that exploit network servers for much of their processing power, storage, content, and administration.Benefits of JavaThe benefits of Java translate across many industries, and some are specific to the control and automation environment. For example, many plant-floor applications use relatively simple equipment; upgrading to PCs would be expensive and undesirable. Java's ability to run on any platform enables the organization to make use of the existing equipment while enhancing the application.IntegrationWith few exceptions, applications running on the factory floor were never intended to exchange information with systems in the executive office, but managers have recently discovered the need for that type of information. Before Java, that often meant bringing together data from systems written on different platforms in different languages at different times. Integration was usually done on a piecemeal basis, resulting in a system that, once it worked, was unique to the two applications it was tying together. Additional integration required developing a brand new system from scratch, raising the cost of integration.Java makes system integration relatively easy. Foxboro Controls Inc., for example, used Java to make its dynamic-performance-monitor software package Internet-ready. This software provides senior executives with strategic information about a plant's operation. The dynamic performance monitor takes data from instruments throughout the plant and performs variousmathematical and statistical calculations on them, resulting in information (usually financial) that a manager can more readily absorb and use.ScalabilityAnother benefit of Java in the industrial environment is its scalability. In a plant, embedded applications such as automated data collection and machine diagnostics provide critical data regarding production-line readiness or operation efficiency. These data form a critical ingredient for applications that examine the health of a production line or run. Users of these devices can take advantage of the benefits of Java without changing or upgrading hardware. For example, operations and maintenance personnel could carry a handheld, wireless, embedded-Java device anywhere in the plant to monitor production status or problems.Even when internal compatibility is not an issue, companies often face difficulties when suppliers with whom they share information have incompatible systems. This becomes more of a problem as supply-chain management takes on a more critical role which requires manufacturers to interact more with offshore suppliers and clients. The greatest efficiency comes when all systems can communicate with each other and share information seamlessly. Since Java is so ubiquitous, it often solves these problems (Paula, 1997).Dynamic Web Page DevelopmentJava has been used by both large and small organizations for a wide variety of applications beyond consumer oriented websites. Sandia, a multiprogram laboratory of the U.S. Department of Energy's National Nuclear Security Administration, has developed a unique Java application. The lab was tasked with developing an enterprise-wide inventory tracking and equipment maintenance system that provides dynamic Web pages. The developers selected Java Studio Enterprise 7 for the project because of its Application Framework technology and Web Graphical User Interface (GUI) components, which allow the system to be indexed by an expandable catalog. The flexibility, scalability, and portability of Java helped to reduce development timeand costs (Garcia, 2004)IssueJava Security for E-Business ApplicationsTo support the expansion of their computing boundaries, businesses have deployed Web application servers (WAS). A WAS differs from a traditional Web server because it provides a more flexible foundation for dynamic transactions and objects, partly through the exploitation of Java technology. Traditional Web servers remain constrained to servicing standard HTTP requests, returning the contents of static HTML pages and images or the output from executed Common Gateway Interface (CGI ) scripts.An administrator can configure a WAS with policies based on security specifications for Java servlets and manage authentication and authorization with Java Authentication andAuthorization Service (JAAS) modules. An authentication and authorization service can bewritten in Java code or interface to an existing authentication or authorization infrastructure. Fora cryptography-based security infrastructure, the security server may exploit the Java Cryptography Architecture (JCA) and Java Cryptography Extension (JCE). To present the user with a usable interaction with the WAS environment, the Web server can readily employ a formof "single sign-on" to avoid redundant authentication requests. A single sign-on preserves user authentication across multiple HTTP requests so that the user is not prompted many times for authentication data (i.e., user ID and password).Based on the security policies, JAAS can be employed to handle the authentication process with the identity of the Java client. After successful authentication, the WAS securitycollaborator consults with the security server. The WAS environment authentication requirements can be fairly complex. In a given deployment environment, all applications or solutions may not originate from the same vendor. In addition, these applications may be running on different operating systems. Although Java is often the language of choice for portability between platforms, it needs to marry its security features with those of the containing environment.Authentication & AuthorizationAuthentication and authorization are key elements in any secure information handling system. Since the inception of Java technology, much of the authentication and authorization issues have been with respect to downloadable code running in Web browsers. In many ways, this had been the correct set of issues to address, since the client's system needs to be protected from mobile code obtained from arbitrary sites on the Internet. As Java technology moved from a client-centric Web technology to a server-side scripting and integration technology, it required additional authentication and authorization technologies.The kind of proof required for authentication may depend on the security requirements of a particular computing resource or specific enterprise security policies. To provide such flexibility, the JAAS authentication framework is based on the concept of configurable authenticators. This architecture allows system administrators to configure, or plug in, the appropriate authenticatorsto meet the security requirements of the deployed application. The JAAS architecture also allows applications to remain independent from underlying authentication mechanisms. So, as new authenticators become available or as current authentication services are updated, system administrators can easily replace authenticators without having to modify or recompile existing applications.At the end of a successful authentication, a request is associated with a user in the WAS user registry. After a successful authentication, the WAS consults security policies to determine if the user has the required permissions to complete the requested action on the servlet. This policy canbe enforced using the WAS configuration (declarative security) or by the servlet itself (programmatic security), or a combination of both.The WAS environment pulls together many different technologies to service the enterprise. Because of the heterogeneous nature of the client and server entities, Java technology is a good choice for both administrators and developers. However, to service the diverse security needs of these entities and their tasks, many Java security technologies must be used, not only at a primary level between client and server entities, but also at a secondary level, from served objects. By using a synergistic mix of the various Java security technologies, administrators and developers can make not only their Web application servers secure, but their WAS environments secure as well (Koved, 2001).ConclusionOpen standards have driven the e-business revolution. As e-business continues to develop, various computing technologies help to drive its evolution. The Java programming language and platform have emerged as major technologies for performing e-business functions. Java programming standards have enabled portability of applications and the reuse of application components. Java uses many familiar concepts and constructs and allows portability by providing a common interface through an external Java Virtual Machine (JVM). Today, you can find Java technology in networks and devices that range from the Internet and scientific supercomputers to laptops and cell phones, from Wall Street market simulators to home game players and credit cards.Java has found a place on some of the most popular websites in the world. Java applications not only provide unique user interfaces, they also help to power the backend of websites. While Java technology has been used extensively for client side access and in the presentation layer, it is also emerging as a significant tool for developing scaleable server side programs.Since Java is an object-oriented language like C++, the time needed for application development is minimal. Java also encourages good software engineering practices with clear separation of interfaces and implementations as well as easy exception handling. Java's automatic memory management and lack of pointers remove some leading causes of programming errors. The advantages available through Java have also found their way into hardware. The emerging new Java devices are streamlined systems that exploit network servers for much of their processing power, storage, content, and administration.中文翻译:标题:Java的商业应用。
外文翻译 Java技术及SSH框架和Jsp技术的介绍
毕业设计(论文)外文资料翻译学院:计算机工程学院专业班级:学生姓名:学号:指导教师:外文出处:(外文)/wiki/java_(programming_language)附件:1.外文资料翻译译文; 2.外文原文Java技术及SSH框架和Jsp技术的介绍Java,是一种可以撰写跨平台应用软件的面向对象的程序设计语言,由当时任职太阳微系统的詹姆斯·高斯林(James Gosling)等人于1990年代初开发。
它最初被命名为Oak,目标设置在家用电器等小型系统的编程语言,来解决诸如电视机、电话、闹钟、烤面包机等家用电器的控制和通讯问题。
由于这些智能化家电的市场需求没有预期的高,Sun放弃了该项计划。
就在Oak 几近失败之时,随着互联网的发展,Sun看到了Oak在计算机网络上的广阔应用前景,于是改造了Oak,在1995年5月以“Java”的名称正式发布了。
Java 伴随着互联网的迅猛发展而发展,逐渐成为重要的网络编程语言。
Java编程语言的风格十分接近C++语言。
继承了C++ 语言面向对象技术的核心,Java 舍弃了C++语言中容易引起错误的指针(以引用取代)、运算符重载(operator overloading)、多重继承(以接口取代)等特性,增加了垃圾回收器功能用于回收不再被引用的对象所占据的内存空间。
在Java SE 1.5版本中Java又引入了泛型编程(Generic Programming)、类型安全的枚举、不定长参数和自动装/拆箱等语言特性。
Java不同于一般的编译运行计算机语言和解释执行计算机语言。
它首先将源代码编译成字节码(bytecode),然后依赖各种不同平台上的虚拟机来解释执行字节码,从而实现了“一次编译、到处执行”的跨平台特性。
不过,这同时也在一定程度上降低了Java程序的运行效率。
但在J2SE1.4.2发布后,Java的运行速度有了大幅提升。
与传统程序不同Sun公司在推出Java之际就将其作为一种开放的技术。
java介绍外文翻译
外文原文Introduction to Javaautor:Martin Ngobye.source:Computing Static Slice for Java ProgramsJava 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; multithreaded, for high performance in applications that need to perform multiple concurrent activities, such as multimedia; and interpreted, for maximum portability and dynamic capabilities.Together, the above requirements comprise quite a collection of buzzwords, so let’sexamine some of them and their respective benefits before going on.What’s completely new is the manner in which Java and its run-time system have combined them to produce a flexible and powerful programming system..Developing your applications using Java results in software that is portable across multiple machine architectures, operating systems, and graphical user interfaces, secure, and high performance, With Java, 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 Java. The better way to develop software is here, now, brought to you by the Java language platform.Very dynamic languages like Lisp, TCL, and SmallTalk are often used for prototyping. One of the reasons for their success at this is that they are very robust—you don’t have to worry about freeing or corrupting memory.Similarly, programmers can be relatively fearless about dealing with memory when programming in Java, The garbage collection sy stem makes the programmer’s job vastly easier; with the burden of memory management taken off the programmer’s shoulders, storage allocation errors go away. Another reason commonly given that languages like Lisp, TCL, and SmallTalk are good for prototyping is that they don’t require you to pin down decisions early on—these languages are semantically rich.Java has exactly the opposite property: it forces you to make explicit choices. Along with these choices come a lot of assistance—you can write method invocations and, if you get something wrong, you get told about it at compile time. You don’t have to worry about method invocation error.The Java beginner must grasp 30 basic conceptsBasic concept1.In OOP the only relations is what the object’s interface, such as the computer seller he leaves alone internal structure of electrical source, but he is only concerned about that whether the power will be supplied to you, also so long as know can or not but is not how and why.All procedures are make up of certain attribute and the behavior object, the different object visit invokes through the function invocation, between the object all intercommunion are invoke through the method invocation, By object data encapsulation, enhances reuse rate very much..2.In OOP the most important thought is class, the class is the template ,is a blueprint, construct an object from a class, namely construct an instance of the class.3. Encapsulation: is that combines the data and the behavior in a package) and hides the data the realization process to the object user, in an object data is called its instance field.4.Through expands a class to obtain a new class is called inheritance, but all classes are constructed by the object super root class of expansion, super root class of as follows can make the introduction.5.Object 3 principal characteristicsBehavior--- explained this object can make what.Tate--- when the object exerts the method object reflection.Dentity--- and other similar behavior objects discrimination symbols.Each object has only indentity and among three characteristics they affect mutually.6. Relations among classes:Use-a:Dependent relationHas-a:Polymerization relationIs-a: inheritor relation -- example:A class has inherited B class, this time A class not only has B class of method, but also has its own method(Individuality exists in general character)7.Structure object use structure:Structure proposing, the structure is one special method, the structure object and to its initialization.Example:A Data class of structure calls DataNew Data () --- structure a new object, also initialize current time.Data happyday=new Data () --- an object evaluates an variable happyday, thus enables this object to be used many times, here be stated the cause variable and the object variable are different.New returns the value is a quotation.Constructor characteristic:The constructor may have 0, one or many parametersThe constructor and the class have the same nameA class may have many constructor. The constructor has not returned valueThe constructor always be together used with the new operator8. Over loading: When many methods have the same name when includes the different parameter, then has the over loading Which method does the compiler have to choose invokes.9.Package : Java allow one or many classes to become together as group, is called package, to organizing duty easily, the standard Java storehouse divides into many packages ng java.Util java, net and so on, the package is layered and all java packages are in java and in a javax package.10. Extendable thought: permit to construct new class on existing classes , when you extend the class which already existed, then you reuse this class of method and the field,at the same time you might add the new method and the field in the new class.11.Expandable class:The expandable class fully manifested is-a to extend the relations The form is:Class (subclass) extends (base class).12. Multi-modality: In java, the object variable is multi-modality But in java does not support multiple extend.13.Dynamic combine: the mechanism of invoking object method mechanism.1) compiler examines object statement type and method name.2) the compiler examines that method invokes parameter type.3) static combine: If the method type is priavte static the final ,compiler can accurately know which method should invoke.4) when the procedure runs and uses dynamic combine to invoke a method, the method edition which then hypothesized machine must invoke x the object actual type which aims at to match.5) dynamic combine: is a very important characteristic, it can cause the procedure to change again may expand but does not need to translate has saved the code.14.Final class:In order to prevent other people derive the new class from yours class, this class is cannot expanded.15.The dynamic invocation spend longer time than the static invocation expenditure.16.Abstract class:Stipulated or many abstract methods class of itself must define is abstract.Example: Public abstract string getDescripition17.In Java each class is be extended by object class.18. equal and toString method in object class .Equal uses in testing an object is whether equal with another object.ToString returns to represent this object the string of character, each class can nearly over loading this method, in order to returns to the current condition the correct expression.(The toString method is a very important method)19.General programming:Any class of type all values all may replace with a object class of variable.20.The array tabulates: The ArrayList dynamic array tabulates, is a class of storehouse, defines in java.In uitl package, but automatic control array size.21.in class and class of object ,getclass method returns to the class type an example, when the procedure start contains can increase in the main method class, hypothesized confidential increase all classes which he needs, each increase class all must increase the classwhich it needs.22.The class: class might dynamic operate the java code for the compilation the procedure to provide the formidable function reflection, this function was JavaBeans is specially useful, the use reflected Java to be able to support the VB programmer to be familiar with the use the tool.procedure of analysis class ability is called the reflector, in Java to provide this function the package to call ng.The reflect reflection mechanism is extremely formidable.1) when run analysis class ability.2) when run searches observes a class of object.3) realizes the general array operation code.4) provides the method object.But this mechanism mainly aims at the tool but not the application and the procedure.In the reflection mechanism most important part is that permits class that you inspect structure. With to API includes:ng.Reflect.Field returns to the field.Java.Reflect.Method returns to the method.ng.Reflect.Constructor returns to the parameter.Method pointer: Java does not have the method pointer, makes a method address another method, may invoke it in behind, but the interface is the better solution.23. interface: should showing class could do what but not to assign how to do, a class may realize one or many interfaces.24.The interface is not a class, but is to conforms to a interface request class of set of standard.If realizes a interface to need 2 steps:1) the statement class needs to realize assigns the interface.2) provides in the interface all methods definition.Stated a class realizes a interface to need to use the implements key wordsClass actionB implements Comparable its actionb needs to provide the CompareTo method, the interface is not the class, cannot use a new example interface.25.A class only then a super class, but a class can realize many interfaces. In a Java important interface: Cloneable26.The interface and call-back :to programs a commonly used pattern is call-back,in the pattern, you may refer when this class of pattern settled specific time occurs returns toadjusts on the object the method.Example:ActionListener interface monitor.Similar API includes:Java.Swing.JOptionPaneJava.Swing.TimerJava.Awt.Tookit27.Object clone:The clone method is a object protection method, this meant your code cannot simple invoke it.28.Inner class an inner class definition is the definition in another class.The reason is:1) an inner class object can visit founds its object realization, including private data.2) about other classes in the same package in that, inner class can be hided.3) the anonymous inner class may the very convenient definition accent.In 4) uses the category to be possible the extremely convenient compilation event driver.29.Agent class (proxy):1) appointing all codes that interfaces request2) all methods (toString equals) that object class define30.Data type:Java is kind of emphasizing type language, each variable all must be declared its types at first, in java altogether has 8 basic types . four kinds are the long, two kinds are the float, one is the char, being used in the Unicode code char, Boolean.1. java is simpleJava and C + + are very similar, but much simpler. All the high-level programming language features, is not absolutely necessary have been deleted. For example, Java does not overload operator, the title of the document, pre-processing, computing pointer, the structure of the joint, multi-dimensional array, templates and implicit type conversion. If you know a little C, C + + or Pascal, you will soon master Java. Here is a simple procedure JavaHelloWorld:publicclassHelloInternet (publicstaticvoidmain (Stringargv []) (System. out. println ( "HelloIn-ternet!")))2. Java is object-orientedJava is an object-oriented programming language. In addition to the simple types,such as digital and Boolean operators in addition, Java is an object of most. As with any object-oriented languages, Java code also organized by category. Each category provides a definition of the object behavior. Another type of succession can be a kind of behavior. In the category of the root level, often the target category. Java support for the single type of inherited hierarchy. This means that each category can only inherit one other category. Some of the language to allow multiple inheritance, but it may cause confusion and unnecessarily complicated language. For example, imagine that an object would inherit two completely different category. Java also supports the kind of summary of the interface. This allows programmers to define the interface methods, and do not have to rush immediately to determine the methods to achieve. A type of interface can be a number of purposes in order to truly multi-inheritance of a number of advantages. The implementation of an object can be any number of interfaces. IDL interface and Java interface very similar. Very easy to set up IDLJ compiler. In other words, Java can be used to create a CORBA object system distributed object system. In the view of many computer systems use IDL interface and CORBA objects, such compatibility is important.3. Java is a type of staticIn a Java program, it is essential to the definition used by the target (number of characters, such as an array) type. This will help programmers quickly found because the procedure when the compiler can detect the type of error. However, Java System objects are also dynamic types. A requirement for the type of dynamic is often possible, so programmers can write the procedures for different types of objects to do different things.4. Is a Java-based compilerWhen running Java programs, which were first compiled into byte code. Byte code is very similar to the machine instructions, so Java program is very efficient. However, the byte code does not specifically for a particular machine, so no need to recompile Java program can be in many different computer implementation. Java source code files were compiled into a category, which is equivalent to process byte code performance. In a Java class file, and an example for all of the variables are in the light of, and for the first time in the implementation of the code be resolved. This makes the code more common and more easily subject to revision, but still high.5. Java is architecture neutralJava language is the same for each computer. For example, simple types are the same: 32-bit integer always, always 64-bit long integers. It is strange, such as C and C + + programming language, and so fashionable it is not the case. As a result of these languages so the definition of freedom, each of the compiler and development environment will bedifferent, so that this process nuisance become a transplant. Java programs can easily gain access to transplants, and there is no need to re-compile.6. Java is a soundJava program can not be caused by the collapse of the computer. Java careful testing of the system memory of each visit, make sure it is legitimate and will not cause any problems. However, even if the Java program may also be wrong. If there is some kind of unexpected things, the process will not collapse, and to abandon the exception. Procedures for such an exception would be found to address them. Traditional computer programs can access the full memory. May (unconsciously) to amend any of the value of memory, which will cause problems. Java program can only access memory to allow them access to those parts of the Java program can not modify it does not seek to change the value.7. Java is a compactAs the Java is designed to run on a small computer, as a programming language for the system is relatively small. It effectively in more than 4MB of RAM to run on PC machine. Java translator occupied by only a few hundred KB. This translator for the Java platform independence and portability is reliable. Due to Java is very small, it is a very small computer memory, such as the Java-based PC, as well as television sets, ovens, telephone and home computer, and so on, it is ideal.8. Java is a multi-threadedJava program can run more than one thread. For example, it can be a thread in a time-consuming to complete the calculation, and other users to interact with the threads of dialogue. Therefore, users do not have to stop working, waiting for the Java computing time-consuming process. In the multi-threaded programming environment, it is often difficult because many things may occur at the same time. However, Java provides easy-to-use features simultaneously, so that the programming easier.中文翻译JA V A介绍作者:Martin Ngobye.出处:Computing Static Slice for Java ProgramsJava是被设计用来解决在上下文分布式的异构网络中应用程序开发的问题。
外文翻译---JAVA学习过程
D 科技译文Java Learning Path processEach person's study method is different, a person's method suits another person not necessarily, I only can discuss own study method. Because I study Java am study independently completely, has not asked others, therefore the study process basically is completely oneself tries to find out. I did not know whether this method is the quite good method, only could give everybody to provide refers.Studies Java first step installs good JDK, writes Hello World? Actually the JDK study is not so simple, has two questions about JDK is very easy to puzzle the Java programmer continuously the place: Is the CLASSPATH question, actually said from the principle, is how must make clear JRE ClassLoader increase Class; Another question is package and the import question, how seeks the kind of way question. These two questions tried to find out clear, eliminated has studied Java and uses JDK the biggest barrier. The recommendation looked Wang Sen "the Java Depth Experiences dangers", has carried on the thorough discussion to these two questionsSecond step is studies Java the grammar. The Java grammar is kind of C++, the basically mainstream programming language is not kind of C, is kind of C++, does not have what new thing, therefore the grammar study, probably was the quite a while time is enough. Only needs to pay attention is has the key words usage which several is not easy to make clear, public, protected, private, static, when uses, why has to use, how uses, this possible need some people to direct, I initially was own ponder over completely, has spent the very long time. Butafterwards I saw above this book spoke these concepts to "Thinking in Java".Third step is studies Java the object-oriented programming language characteristic place. For instance inherits, structure, abstract class, the connection, the method are many condition, heavy load, cover, Java exception handling mechanism. Said regarding a not object-oriented language background person that, I thought this process needs to spend the very long very long time, because studies in front of Java does not have C++ the experience, only then the C experience, I was have probably spent for a month, all made clear only then thoroughly these concepts, book example above repeatedly estimating, the revision, the attempt, repeatedly looked at that several chapter of contents, looked, looked has not gotten down 5, comprehended only then thoroughly. But I thought if has the C++ experience, should 12 days time be enough. Then in this process, may have a look "Thinking in Java" this book, opposite is extremely thorough to the object explanation. What a pity is I studies, has not seen to this book, therefore own have spent the massive time, and estimates through own attempt learns.Fourth step starts a familiar Java kind of storehouse. The Java foundation class storehouse actually is JDK installs under the table of contents jre\Lib\Rt.Jar this package. The study foundation class storehouse studies rt.Jar. Inside the foundation class storehouse kind are extremely extremely many. It is said some more than 3,000, I have not counted. But said the most core truly regarding us only then 4, respectively isng.*;Java.Io.*;Java.Util.*;Java.Sql.*;These four packages study, each package study all may write thick teaching material, but O'reilly also truly is does this. I thought if time quite tight, is impossible through to read four books to study. I thought the quite good study method is such:First must read through entire package the frame, understood entire package class, interface, the exception constitution, should better be can find the introduction entire package frame the article. These introduced specially package of books the first several chapters should be these overall frame content introductions. Is not must be familiar with each kind of usage to the package of overall frame assurance, which attributes remembers it have, the method. Wants to record also cannot remember. But is must know which aspects the package does have a kind of constitution, these kind of uses are any, most core several classifications maybe complete any function. I in the time which trains to the human generally is a class speaks a package, therefore not impossible detailed introduction each kind of usage, but I repeatedly stress, how do I speak these packages to you am must tell you a kind of method am transfer, also does not request you to remember the kind of method transfer, but wants you to understand, which kinds Java has provided to us, each kind is uses in any situation, when I meet the question the time, I knew which kind, or which several kind of combinations can solve my problem, That'all! When we write the procedure specifically time, so long as you knew which kind should complete your work with to be enough. Codes, the concrete method transfer, writes the code, Documentation, all things all inside Documentation, will not request you certainly to remember, are actual you also not to be able to remember more than3,000 kinds altogether the nearly 100,000 methods transfers. Therefore changes to each package overall frame assurance extremely importantly.Fifth step, through above study, if study the quite solid speech, built the Java foundation, is left over the work which had to do is sweeps clean inside Documentation besides above 4 packages other some comparisons to have the use the kind. Believed progressed to this step, Java studies independently the ability already to raise, might to study Documentation directly horizontal. Besides must make the GUI programming, inside JDK other can have the use the package is these:Java.Text.*;.*;Javax.Naming.*;These packages of inside real correct uses quite many kinds very are actually few, only then several, therefore does not need to spend the very much time.Sixth step, Java Web programmingThe Web programming core is the HTTP agreement, the HTTP agreement and Java irrelevant, if not familiar HTTP agreement, although also may learn Servlet/JSP programming, but cannot achieve extrapolates, by knowing one method you will know all boundary. Therefore the HTTP agreement study is necessary. If has been familiar with HTTP agreement, also had the Java programming good foundation, studies Servlet/JSP is simply easy as pie, I study Servlet/JSP has used not to week-long time, then started with JSP to make the project. In Servlet/In the JSP study, heavy still was Servlet Documentation. Servlet the API most commonly used kind are very few, the flowered quite fewtime might grasp. These kinds all looked at, writes several examples to try. Servlet/The JSP programming essence is transferring these kinds to come repeatedly through the HTTP agreement converses between Web Server and Brower. Moreover to JSP, but also needs to be familiar with several commonly used JSP the mark, the concrete mode of writing cannot remember the speech, looks up temporarily and that's the end of.In addition Java the Web programming study must place Web Application with emphasis in the design pattern, how carries on the service logic the analysis, and carries on the reasonable design, according to the MVC design pattern request, completes the different logical level separately using Servlet and JSP, how grasps carries on the flow between Servlet and JSP the control and data sharing, as well as how Web should Application dispose and the deployment.Seventh step, J2EE programmingThe above study process if is quite smooth, carries on to this step, the difficulty enhances suddenly. Because the above knowledge content all only involves an aspect, but likes EJB, JMS, core the and so on JTA J2EE standard often is several kind of Java technology synthesis utilization crystallization, therefore grasps the difficulty quite to be big.First certainly must study good JNDI, JNDI is App the Server localization server resources (the EJB module, Datasouce, JMS) searches the method, if to JNDI not familiar, EJB, JMS these things cannot study nearly. JNDI actually is javax.Naming.* This package, utilizes is very simple. The difficulty lies in the server resources document the disposition. Regarding the server resources document disposition, needed to have a look the special documents to be standard, for instance web.Xml mode of writing, ejb-jar.Xml mode of writingand so on. In view of each kind of different App Server, but also has own service resources disposition document, also is needs to be familiar with.Then may study JTA, mainly is must understand JTA regarding business control method, as well as should use JTA in any situation. Here may simple cite an example, we knew the ordinary circumstances may carry on business regarding a database connection (conn.SetAutoCommit (false)....,mit ()), does is an atomic operation, but the supposition my service demand is needs to hold artificially to two different databases is an atomic operation, you can do to? At this time only could use JTA. The supposition operating process inserts a record first toward the A database, then deletes the B database another record, we wrote the code are cannot control entire hold artificially are an atomic operation. With the JTA speech, completes the control by App Server.In studies in front of EJB must study the object sequence and RMI, RMI is the EJB foundation. Then studies JMS and EJB, said regarding EJB, most is essential is must understand how EJB is realizes through RMI to the far-end object transfer, as well as must use in any situation to EJB.In studies EJB, after JMS these things, you possibly can realize must extremely anxiously study two domains the knowledge, is UML, another is Design Pattern. The Java enterprise software design takes the frame extremely (Framework) the design, a good software frame is the software develops the successful essential condition. In this time, should start the study key point to place the design pattern and in the frame study, experiences through the study and the actual programming grasps EJB the design pattern and the J2EE core pattern.Inside J2EE standard, except EJB, JMS, JTA, Servlet/JSP, outside JDBCalso has the very many very many enterprises technology, here 11 did not carry on introducedMoreover also has newest domain Web Services. Web Services also completely does not have any new thing, it likes is one kind of adhesive, may unify the different service provides a unified transfer connection, said as the user, I so long as obtain the service provider for mine WSDL (to service description), has sufficed, I did not know completely the server tenderer provides actually the service is the EJB module,The Net module, any CORBA module, other any realizations, I do not need to know. Web the Services greatest place lies in through the unified service provides the way and the transfer way, has realized the entire Internet service sharing, is an extremely excited area of technology. Web Services resembles at present not to have any very good books, but may through look up the material above the network the way to study.JA V A学习过程每个人的学习方法是不同的,一个人的方法不见得适合另一个人,我只能是谈自己的学习方法。
JAVA相关毕业论文外文翻译
Java 堆Java 堆,每一个Java 对象在其中分派,是您在编写Java 应用程序时利用最频繁的内存区域。
JVM 设计用于将咱们与主机的特性隔离,因此将内存看成堆来考虑再正常只是了。
您必然碰着过Java 堆 OutOfMemoryError ,它可能是由于对象泄漏造成的,也可能是因为堆的大小不足以存储所有数据,您也可能了解这些场景的一些调试技术。
可是随着您的Java 应用程序处置愈来愈多的数据和愈来愈多的并发负载,您可能就会碰着无法利用常规技术进行修复的OutOfMemoryError。
在一些场景中,即便java 堆未满,也会抛犯错误。
当这种场景发生时,您需要明白得Java 运行时环境(Java Runtime Environment,JRE)内部到底发生了什么。
Java 应用程序在Java 运行时的虚拟化环境中运行,可是运行时本身是利用C 之类的语言编写的本机程序,它也会耗用本机资源,包括本机内存。
本机内存是可用于运行时进程的内存,它与Java 应用程序利用的java 堆内存不同。
每种虚拟化资源(包括Java 堆和Java 线程)都必需存储在本机内存中,虚拟机在运行时利用的数据也是如此。
这意味着主机的硬件和操作系统施加在本机内存上的限制会阻碍到Java 应用程序的性能。
硬件限制本机进程碰着的许多限制都是由硬件造成的,而与操作系统没有关系。
每台运算机都有一个处置器和一些随机存取存储器(RAM),后者也称为物理内存。
处置器将数据流说明为要执行的指令,它拥有一个或多个处置单元,用于执行整数和浮点运算和更高级的计算。
处置器具有许多寄放器——常快速的内存元素,用作被执行的计算的工作存储,寄放器大小决定了一次计算可利用的最大数值。
处置器通过内存总线连接到物理内存。
物理地址(处置器用于索引物理RAM 的地址)的大小限制了能够寻址的内存。
例如,一个16 位物理地址能够寻址0x0000 到0xFFFF 的内存地址,那个地址范围包括2^16 = 65536 个惟一的内存位置。
Java外文翻译
附件1:外文资料翻译译文图形用户接口一个基本的设计方针是“简单的事情变得容易,困难的事情成为可能。
”劳在Java的图形用户界面(GUI)库原设计目标是允许程序员建立一个GUI ,在所有平台上看起来好。
这一目标没有实现。
相反,Java的罗湖抽象窗口工具包(AWT )产生一个GUI,看着所有系统上同样表现平平。
此外,它是限制性的,你可以用四种字体,你不能访问任何更复杂的GUI 元素,在你的操作系统存在。
也尴尬和非面向对象的Java 1.0 AWT编程模型。
一个学生在我的一个研讨会(曾在Sun公司一直在创造Java的)解释原因:原来的AWT已经构思,设计,并在一个月内实施。
一定的生产力的奇迹,也是为什么设计对象的教训是非常重要的。
Java 1.1 AWT的事件模型,这需要一个更清晰的,面向对象的方法的JavaBeans组件的编程模型是面向可视化编程环境容易创造此外,情况有所好转。
的Java 2(JDK 1.2 ),基本上取代Java基础类(JFC),被称为GUI部分的所有“摇摆完成了转型。
”从旧的Java 1.0 AWT的这是一个易于使用的一整套丰富,易于理解的JavaBeans ,可以拖动和下降(以及手工编程),以建立一个合理的GUI 。
“第三次修订版”的软件产业规则(一个产品是不是良好,直到第三次修订版),似乎与编程语言也是如此。
本章介绍了现代的Java Swing库,使得Swing是Sun公司的最终目的地的GUI库,为Java.2合理的假设,如果你有一些原因,因为你支持旧的代码,你需要使用原有的“老”的AWT (或浏览器的限制),你可以找到介绍,在这本书的第一版在下载。
请注意,一些AWT 组件保持在Java中,并在某些情况下,你必须使用他们。
请注意,这是不是所有的Swing组件或描述类的所有方法的综合词汇。
你在这里看到的是一个简单的介绍。
Swing库是巨大的,本章的目的是只让你的要领和舒适的概念开始。
外文翻译java
外文资料译文及原文JavaJava 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字符的类库。
为了提高性能,完善功能,JDK1.4又加了一个nio(意思是"new I/O"。
这个名字会用上很多年)。
这么以来,如果你想对Java的I/O 类库有个全面了解,并且做到运用自如,你就得先学习大量的类。
此外,了解 I/O 类库的演化的历史也是相当重要的。
可能你的第一反应是 "别拿什么历史来烦我了,告诉我怎么用就可以了! "但问题是,如果你对这段历史一无所知,很快就会被一些有用或是没用的类给搞糊涂了。
本章会介绍 Java 标准类库中的各种 I/O 类,及其使用方法。
File 类在介绍直接从流里读写数据的类之前,我们先介绍一下处理文件和目录的类。
File 类有一个极具欺骗性的名字;或许你会认为这是一个关于文件的类,但它不是。
你可以用它来表示某个文件的名字,也可以用它来表示目录里一组文件的名字。
java-毕业论文外文文献翻译
Advantages of Managed CodeMicrosoft intermediate language shares with Java byte code the idea that it is a low—level language with a simple syntax ,which can be very quickly translated into native machine code。
Having this well-defined universal syntax for code has significant advantages。
Platform independenceFirst,it means that the same file containing byte code instructions can be placed on any platform;at runtime the final stage of compilation can then be easily accomplished so that the code will run on that particular platform. In other words, by compiling to IL we obtain platform independence for 。
NET, in much the same way as compiling to Java byte code gives Java platform independence。
Performance improvementIL is actually a bit more ambitious than Java byte code。
IL is always Just-In—Time compiled (known as JIT),whereas Java byte code was often interpreted。
Java技术外文翻译文献
Java技术外文翻译文献(文档含中英文对照即英文原文和中文翻译)外文:Core Java™ Volume II–Advanced Features When Java technology first appeared on the scene, the excitement was not about a well-crafted programming language but about the possibility of safely executing applets that are delivered over the Internet (see V olume I, Chapter 10 for more information about applets). Obviously, delivering executable applets is practical only when the recipients are sure that the code can't wreak havoc on their machines. For this reason, security was and is a major concern of both the designers and the users of Java technology. This means that unlike other languages andsystems, where security was implemented as an afterthought or a reaction to break-ins, security mechanisms are an integral part of Java technology.Three mechanisms help ensure safety:•Language design features (bounds checking on arrays, no unchecked type conversions, no pointer arithmetic, and so on).•An access control mechanism that controls what the code can do (such as file access, network access, and so on).•Code signing, whereby code authors can use standard cryptographic algorithms to authenticate Java code. Then, the users of the code can determine exactly who created the code and whether the code has been altered after it was signed.Below, you'll see the cryptographic algorithms supplied in the java.security package, which allow for code signing and user authentication.As we said earlier, applets were what started the craze over the Java platform. In practice, people discovered that although they could write animated applets like the famous "nervous text" applet, applets could not do a whole lot of useful stuff in the JDK 1.0 security model. For example, because applets under JDK 1.0 were so closely supervised, they couldn't do much good on a corporate intranet, even though relatively little risk attaches to executing an applet from your company's secure intranet. It quickly became clear to Sun that for applets to become truly useful, it was important for users to be able to assign different levels of security, depending on where the applet originated. If an applet comes from a trusted supplier and it has not been tampered with, the user of that applet can then decide whether to give the applet more privileges.To give more trust to an applet, we need to know two things:•Where did the applet come from?•Was the code corrupted in transit?In the past 50 years, mathematicians and computer scientists have developed sophisticated algorithms for ensuring the integrity of data and for electronic signatures. The java.security package contains implementations of many of these algorithms. Fortunately, you don't need to understand the underlying mathematics to use the algorithms in the java.security package. In the next sections, we show you how message digests can detect changes in data files and how digital signatures can prove the identity of the signer.A message digest is a digital fingerprint of a block of data. For example, the so-called SHA1 (secure hash algorithm #1) condenses any data block, no matter how long, into a sequence of 160 bits (20 bytes). As with real fingerprints, one hopes that no two messages have the same SHA1 fingerprint. Of course, that cannot be true—there are only 2160 SHA1 fingerprints, so there must be some messages with the same fingerprint. But 2160is so large that the probability of duplication occurring is negligible. How negligible? According to James Walsh in True Odds: How Risks Affect Your Everyday Life (Merritt Publishing 1996), the chance that you will die from being struck by lightning is about one in 30,000. Now, think of nine other people, for example, your nine least favorite managers or professors. The chance that you and all of them will die from lightning strikes is higher than that of a forged message having the same SHA1 fingerprint as the original. (Of course, more than ten people, none of whom you are likely to know, will die from lightning strikes. However, we are talking about the far slimmer chance that your particular choice of people will be wiped out.)A message digest has two essential properties:•If one bit or several bits of the data are changed, then the message digest also changes.• A forger who is in possession of a given message cannot construct a fake message that has the same message digest as the original.The second property is again a matter of probabilities, of course. Consider the following message by the billionaire father:"Upon my death, my property shall be divided equally among my children; however, my son George shall receive nothing."That message has an SHA1 fingerprint of2D 8B 35 F3 BF 49 CD B1 94 04 E0 66 21 2B 5E 57 70 49 E1 7EThe distrustful father has deposited the message with one attorney and the fingerprint with another. Now, suppose George can bribe the lawyer holding the message. He wants to change the message so that Bill gets nothing. Of course, that changes the fingerprint to a completely different bit pattern:2A 33 0B 4B B3 FE CC 1C 9D 5C 01 A7 09 51 0B 49 AC 8F 98 92Can George find some other wording that matches the fingerprint? If he had been the proud owner of a billion computers from the time the Earth was formed, each computing a million messages a second, he would not yet have found a message he could substitute.A number of algorithms have been designed to compute these message digests. The two best-known are SHA1, the secure hash algorithm developed by the National Institute of Standards and Technology, and MD5, an algorithm invented by Ronald Rivest of MIT. Both algorithms scramble the bits of a message in ingenious ways. For details about these algorithms, see, for example, Cryptography and Network Security, 4th ed., by William Stallings (Prentice Hall 2005). Note that recently, subtle regularities have been discovered in both algorithms. At this point, most cryptographers recommend avoiding MD5 and using SHA1 until a stronger alternative becomes available.The Java programming language implements both SHA1 and MD5. The MessageDigest class is a factory for creating objects that encapsulate the fingerprinting algorithms. It has a static method, called getInstance, that returns an object of a class that extends the MessageDigest class. This means the MessageDigest class serves double duty:•As a factory class•As the superclass for all message digest algorithmsFor example, here is how you obtain an object that can compute SHA fingerprints:MessageDigest alg = MessageDigest.getInstance("SHA-1");(To get an object that can compute MD5, use the string "MD5" as the argument to getInstance.)After you have obtained a MessageDigest object, you feed it all the bytes in the message by repeatedly calling the update method. For example, the following code passes all bytes in a file to the alg object just created to do the fingerprinting:InputStream in = . . .int ch;while ((ch = in.read()) != -1)alg.update((byte) ch);Alternatively, if you have the bytes in an array, you can update the entire array at once:byte[] bytes = . . .;alg.update(bytes);When you are done, call the digest method. This method pads the input—as required by the fingerprinting algorithm—does the computation, and returns the digest as an array of bytes.byte[] hash = alg.digest();The program in Listing 9-15 computes a message digest, using either SHA or MD5. You can load the data to be digested from a file, or you can type a message in the text area.Message SigningIn the last section, you saw how to compute a message digest, a fingerprint for the original message. If the message is altered, then the fingerprint of the altered message will not match the fingerprint of the original. If the message and its fingerprint are delivered separately, then the recipient can check whether the message has been tampered with. However, if both the message and the fingerprint were intercepted, it is an easy matter to modify the message and then recompute the fingerprint. After all, the message digest algorithms are publicly known, and they don't require secret keys. In that case, the recipient of the forged message and the recomputed fingerprint would never know that the message has been altered. Digital signatures solve this problem.To help you understand how digital signatures work, we explain a few concepts from the field called public key cryptography. Public key cryptography is based on the notion of a public key and private key. The idea is that you tell everyone in the world your public key. However, only you hold the private key, and it is important that you safeguard it and don't release it to anyone else. The keys are matched by mathematical relationships, but the exact nature of these relationships is not important for us.The keys are quite long and complex. For example, here is a matching pair of public and private Digital Signature Algorithm (DSA) keys.Public key:Code View:p:fca682ce8e12caba26efccf7110e526db078b05edecbcd1eb4a208f3ae1617ae01f35b91a47e6df 63413c5e12ed0899bcd132acd50d99151bdc43ee737592e17q: 962eddcc369cba8ebb260ee6b6a126d9346e38c5g:678471b27a9cf44ee91a49c5147db1a9aaf244f05a434d6486931d2d14271b9e35030b71fd7 3da179069b32e2935630e1c2062354d0da20a6c416e50be794ca4y:c0b6e67b4ac098eb1a32c5f8c4c1f0e7e6fb9d832532e27d0bdab9ca2d2a8123ce5a8018b8161 a760480fadd040b927281ddb22cb9bc4df596d7de4d1b977d50Private key:Code View:p:fca682ce8e12caba26efccf7110e526db078b05edecbcd1eb4a208f3ae1617ae01f35b91a47e6df 63413c5e12ed0899bcd132acd50d99151bdc43ee737592e17q: 962eddcc369cba8ebb260ee6b6a126d9346e38c5g:678471b27a9cf44ee91a49c5147db1a9aaf244f05a434d6486931d2d14271b9e35030b71fd73 da179069b32e2935630e1c2062354d0da20a6c416e50be794ca4x: 146c09f881656cc6c51f27ea6c3a91b85ed1d70aIt is believed to be practically impossible to compute one key from the other. That is, even though everyone knows your public key, they can't compute your private key in your lifetime, no matter how many computing resources they have available.It might seem difficult to believe that nobody can compute the private key from the public keys, but nobody has ever found an algorithm to do this for the encryption algorithms that are in common use today. If the keys are sufficiently long, brute force—simply trying all possible keys—would require more computers than can be built from all the atoms in the solar system, crunching away for thousands of years. Of course, it is possible that someone could come up with algorithms for computing keys that are much more clever than brute force. For example, the RSA algorithm (the encryption algorithm invented by Rivest, Shamir, and Adleman) depends on the difficulty of factoring large numbers. For the last 20 years, many of the best mathematicians have tried to come up with good factoring algorithms, but so far with no success. For that reason, most cryptographers believe that keys with a "modulus" of 2,000 bits or more are currently completely safe from any attack. DSA is believed to be similarly secure.Figure 9-12 illustrates how the process works in practice.Suppose Alice wants to send Bob a message, and Bob wants to know this message came from Alice and not an impostor. Alice writes the message and then signs the message digest with her private key. Bob gets a copy of her public key. Bob then applies the public key to verify thesignature. If the verification passes, then Bob can be assured of two facts:•The original message has not been altered.•The message was signed by Alice, the holder of the private key that matches the public key that Bob used for verification.You can see why security for private keys is all-important. If someone steals Alice's private key or if a government can require her to turn it over, then she is in trouble. The thief or a government agent can impersonate her by sending messages, money transfer instructions, and so on, that others will believe came from Alice.The X.509 Certificate FormatTo take advantage of public key cryptography, the public keys must be distributed. One of the most common distribution formats is called X.509. Certificates in the X.509 format are widely used by VeriSign, Microsoft, Netscape, and many other companies, for signing e-mail messages, authenticating program code, and certifying many other kinds of data. The X.509 standard is part of the X.500 series of recommendations for a directory service by the international telephone standards body, the CCITT.The precise structure of X.509 certificates is described in a formal notation, called "abstract syntax notation #1" or ASN.1. Figure 9-13 shows the ASN.1 definition of version 3 of the X.509 format. The exact syntax is not important for us, but, as you can see, ASN.1 gives a precise definition of the structure of a certificate file. The basic encoding rules, or BER, and a variation, called distinguished encoding rules (DER) describe precisely how to save this structure in a binary file. That is, BER and DER describe how to encode integers, character strings, bit strings, and constructs such as SEQUENCE, CHOICE, and OPTIONAL.译文:Java核心技术卷Ⅱ高级特性当Java技术刚刚问世时,令人激动的并不是因为它是一个设计完美的编程语言,而是因为它能够安全地运行通过因特网传播的各种applet。
(完整word版)JAVA外文文献+翻译
Java and the InternetIf 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 comin g 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 programmingThe 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。
Java 编程外文翻译
外文资料原文Thinking In Java 1stBruce EckelLike any human language, Java provides a way to express concepts. If successful, this medium of expression will be significantly easier and more flexible than the alternatives as problems grow larger and more complex.You can’t look at Java as just a collection of features; some of the features make no sense in isolation. You can use the sum of the parts only if you are thinking about design, not simply coding. And to understand Java in this way, you must understand the problems with it and with programming in general. This book discusses programming problems, why they are problems, and the approach Java has taken to solve them. Thus, the set of features I explain in each chapter are based on the way I see a particular type of problem being solved with the language. In this way I hope to move you, a little at a time, to the point where the Java mindset becomes your native tongue.Throughout, I’ll be taking the attitude that you want to build a model in your head that allows you to develop a deep understanding of the language; if you encounter a puzzle you’ll be able to feed it to your model and deduce the answerAt about the same time that my first book Using C++ (Osborne/McGraw-Hill 1989) came out, I began teaching that language. Teaching programming languages has become my profession; I’ve seen nodding heads, blank faces, and puzzled expressions in audiences all over the world since 1989. As I began giving in-house training with smaller groups of people, I discovered something during the exercises. Even those people who were smiling and nodding were confused about many issues. I found out, by chairing the C++ track at the Software Development Conference for the past few years (and now also the Java track), that I and other speakers tended to give the typical外文资料原文audience too many topics too fast. So eventually, through both variety in the audience level and the way that I presented the material, I would end up losing some portion of the audience. Maybe it’s asking too much, but because I am one of those people resistant to traditional lecturing (and for most people, I believe, such resistance results from boredom), I wanted to try to keep everyone up to speed.For a time, I was creating a number of different presentations in fairly short order. Thus, I ended up learning by experiment and iteration (a technique that also works well in Java program design). Eventually I developed a course using everything I had learned from my teaching experience – one that I would be happy giving for a long time. It tackles the learning problem in discrete, easy-to-digest steps and in a hands-on seminar (the ideal learning situation), there are exercises following each of the short lessons. I now give this course in public Java seminars, which you can find out about at . (The introductory seminar is also available as a CD ROM. Information is available at the same Web site.)The feedback that I get from each seminar helps me change and refocus the material until I think it works well as a teaching medium. But this book isn’t just a seminar handout –I tried to pack as much information as I could within these pages and structured it to draw you through onto the next subject. More than anything, the book is designed to serve the solitary reader who is struggling with a new programming language.电子科技大学成都学院本科毕业设计论文译文Java 编程思想第一版Trans Bot同人类任何语言一样,Java为我们提供了一种表达思想的方式。
java实现英文翻译程序
java实现英⽂翻译程序本⽂实例为⼤家分享了java实现英⽂翻译程序的具体代码,供⼤家参考,具体内容如下1.功能简介将⽂本⽂件中的英⽂转换为对应的中⽂词库如下:源⽂件:翻译后的⽂件:输⼊源⽂件路径,将翻译后的内容输出到result.txt⽂件中。
2.重要技术(1)如何载⼊词库⽂件因为词库⽂件是 kry=value的形式,所有可以⽤到Properties类的load函数(2)如何将源⽂件中的⼀段英⽂分理处⼀个个的单词可以⽤StringTokenizer类(3)如何进⾏翻译直接⽤中⽂替换相应的英⽂3.项⽬结构(4)代码编写①FileLoader类/*⽂件载⼊类,将源⽂件中的内容输出到字节数组中*/package zhidao3_2;import java.io.FileInputStream;import java.io.File;public class FileLoad {public static byte[] getContent(String fileName)throws Exception{File file = new File(fileName);if(!file.exists()){System.out.println("输⼊有误,该⽂件不存在");}FileInputStream fis = new FileInputStream(file);int length = (int)file.length();byte[] data = new byte[length];fis.read(data);fis.close();return data;}}②TxtTrans类/*⽂件翻译,将字节数组变为字符串,分离出其中的单词,然后翻译为对应的汉字,去掉空格,变为字符串*/ package zhidao3_2;import java.util.StringTokenizer;import java.util.Properties;import java.io.*;public class TxtTrans {private Properties pps;public TxtTrans(){loadCiku();}public void loadCiku(){pps = new Properties();try{FileReader fis = new FileReader("g:/ciku.txt");//以字符载⼊时没有乱码,以字节载⼊时出现了乱码pps.load(fis);fis.close();}catch(Exception ex){ex.printStackTrace(System.out);System.out.println("载⼊词库时出错");}//System.out.println(pps.get("china")) ;}public String trans(byte[] data){String srcTxt = new String(data);String dstTxt = srcTxt;String delim = " ,.!\n\t"; //分隔符可以指定StringTokenizer st = new StringTokenizer(srcTxt,delim,false);String sub,lowerSub,newSub;//int i=0;while(st.hasMoreTokens()){sub = st.nextToken(); //分割出的⼀个个单词lowerSub = sub.toLowerCase();//统⼀转换为⼩写,这样可以简化词库//System.out.println(sub);newSub = pps.getProperty(lowerSub);if(newSub != null){ //如果找到了匹配的汉字,则进⾏替换dstTxt = dstTxt.replaceFirst(sub, newSub); //只替换第⼀个,即只替换了当前的字符串,否则容易造成ch我na的例⼦ //System.out.println(dstTxt);}}return dstTxt.replaceAll(" ", ""); //去掉空格}}③FileOutput类/*将字符串输出到⽂件*/package zhidao3_2;import java.io.File;import java.io.FileOutputStream;public class FileOutput {public static void output(String text,String fileName)throws Exception{File file = new File(fileName);FileOutputStream fos = new FileOutputStream(file);fos.write(text.getBytes());fos.close();}}④主函数package zhidao3_2;import javax.swing.JOptionPane;public class Main {public static void main(String[] args) {String srcFile = JOptionPane.showInputDialog("输⼊源⽂件");try{byte[] data = FileLoad.getContent(srcFile);TxtTrans tt = new TxtTrans();String dString = tt.trans(data);FileOutput.output(dString, "g:/result.txt");}catch(Exception ex){JOptionPane.showMessageDialog(null, "操作异常");System.exit(1);}JOptionPane.showMessageDialog(null, "翻译完毕");}}最后的项⽬结构如下:以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
Java编程语言基础(外文文献翻译)(可编辑)
JavaTM Programming Language BasicsLike applications, applets are created from classes. However, applets do not have a main method as an entry point, but instead, have several methods to control specific aspects of applet execution.This lesson converts an application from Lesson 2 to an applet and describes the structure and elements of an applet.1、Application to Applet2、Run the Applet3、Applet Structure and Elements4、Packages5、More Information1、Application to AppletThe following code is the applet equivalent to the LessonTwoB application from Lesson 2. The figure below shows how the running applet looks. The structure and elements of the applet code are discussed after the section on how to run the applet just below.import et;import hics;import r;public class SimpleApplet extends AppletString text "I'm a simple applet";public void inittext "I'm a simple applet";setBackground Color.cyan ;public void startSytln "starting..." ;public void stopSytln "stopping..." ;public void destroySytln "preparing to unload..." ;public void paint Graphics gSytln "Paint" ;g.setColor Color.blue ;g.drawRect 0, 0,getSize .width -1,getSize .height -1 ;g.setColor Color.red ;g.drawString text, 15, 25 ;The SimpleApplet class is declared public so the program that runs the applet a browser or appletviewer , which is not local to the program can access it.2、Run the AppletTo see the applet in action, you need an 6>HTML file with the Applet tag as follows:APPLET CODE SimpleApplet.class WIDTH 200 HEIGHT 100The easiest way to run the applet is with appletviewer shown below where simpleApplet.html is a file that contains the above HTML code:appletviewer simpleApplet.htmlNote: To run an applet written with JavaTM 2 APIs in a browser, the browser must be enabled for the Java 2 Platform. If your browser is not enabled for the Java 2 Platform, you have to use appletviewer to run the applet or install Java Plug-in. Java Plug-in lets you run applets on web pages under the 1.2 version of the Java VM instead of the web browser's default Java VM.3、Applet Structure and ElementsThe Java API Applet class provides what you need to design the appearance and manage the behavior of an applet. This class provides a graphical user interface GUI component called a Panel and a number of methods. To create an applet, you extend or subclass the Applet class and implement the appearance and behavior you want.The applet's appearance is created by drawing onto the Panel or by attaching other GUI components such as push buttons, scrollbars, or text areas to the Panel. The applet's behavior is defined by implementing the methods.3.1 Extending a ClassMost classes of any complexity extend other classes. To extend another class means to write a new class that can use the fields and methods defined in the class being extended. The class being extended is the parent class, and the class doing the extending is the child class. Another way to say this is the child class inherits the fields and methods of its parent or chain of parents. Child classes either call or override inherited methods. This is called single inheritance.The SimpleApplet class extends Applet class, which extends the Panel class, which extends the Container class. The Container class extends Object, which is the parent of all Java API classes. The Applet class provides the init, start, stop, destroy, and paint methods you saw in the example applet. The SimpleApplet class overrides these methods to do what the SimpleApplet class needs them to do. The Applet class provides no functionality for these methods.However, the Applet class does provide functionality for the setBackground method,which is called in the init method. The call to setBackground is an example of calling a method inherited from a parent class in contrast to overriding a method inherited from a parent class.You might wonder why the Java language provides methods without implementations. It is to provide conventions for everyone to use for consistency across Java APIs. If everyone wrote their own method to start an applet, for example, but gave it a different name such as begin or go, the applet code would not be interoperable with other programs and browsers, or portable acrossmultiple platforms. For example, Netscape and Internet Explorer know how to look for the init and start methods.3.2 BehaviorAn applet is controlled by the software that runs it. Usually, the underlying software is a browser, but it can also be appletviewer as you saw in the example. The underlying software controls the applet by calling the methods the applet inherits from the Applet class.The init Method: The init method is called when the applet is first created and loaded by the underlying software. This method performs one-time operations the applet needs for its operation such as creating the user interface or setting the font. In the example, the init method initializes the text string and sets the background color.The start Method: The start method is called when the applet is visited such as when the end user goes to a web page with an applet on it. The example prints a string to the console to tell you the applet is starting. In a more complex applet, the start method would do things required at the start of the applet such as begin animation or play sounds.After the start method executes, the event thread calls the paint method to draw to the applet's Panel. A thread is a single sequential flow of control within the applet, and every applet can run in multiple threads. Applet drawing methods are always called from a dedicated drawing and event-handling thread.The stop and destroy Methods: The stop method stops the applet when the applet is no longer on the screen such as when the end user goes to another web page. The example prints a string to the console to tell you the applet is stopping. In a more complex applet, this method should do things like stop animation or sounds.The destroy method is called when the browser exits. Your applet should implement this method to do final cleanup such as stop live threads.3.3 AppearanceThe Panel provided in the Applet class inherits a paint method from its parent Container class. To draw something onto the Applet's Panel, you implement the paint method to do the drawing. The Graphics object passed to the paint method defines a graphics context for drawing on the Panel. The Graphics object has methods for graphical operations such as setting drawing colors, and drawing graphics, images, and text.The paint method for the SimpleApplet draws the I'm a simple applet string in red inside a blue rectangle.public void paint Graphics gSytln "Paint" ;//Set drawing color to blueg.setColor Color.blue ;//Specify the x, y, width and height for a rectangleg.drawRect 0, 0,getSize .width -1,getSize .height -1 ;//Set drawing color to redg.setColor Color.red ;//Draw the text string at the 15, 25 x-y locationg.drawString text, 15, 25 ;4、PackagesThe applet code also has three import statements at the top. Applications of any size and all applets use import statements to access ready-made Java API classes in packages. This is true whether the Java API classes come in the Java platform download, from a third-party, or are classes you write yourself and store in a directory separate from the program. At compile time, a program uses import statements to locate and reference compiled Java API classes stored in packages elsewhere on the local or networked system. A compiled class in one package can have the same name as a compiled class in another package. The package name differentiates the two classes.The examples in Lessons 1 and 2 did not need a package declaration to call the Sytln Java API class because the System class is in the ng package that is included by default. You never need an import ng.* statement to use the compiled classes in that package.5、More InformationYou can find more information on applets in the Writing Applets trail in The Java Tutorial.文献译文Java 编程语言基础像Java Application小应用程序一样,Java Applet小程序也是从类中创建来的。
外文翻译JavaIO系统
外文翻译(英文)The Java I/O SystemCreating a good input/output (I/O) system is one of the more difficult tasks for a language designer. This is evidenced by the number of different approaches.The challenge seems to be in covering all possibilities. 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 i.o, when the original byte-oriented library was supplemented with char-oriented, Unicode-based I/O classes. The nio classes (for "new I/O," a name we’ll still be using years from now eve n though they were introduced in JDK 1.4 and so are already "old") 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 proper ly. In addition, it’s rather important to understand the evolution 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 becom e confused with some of the classes and when you should and shouldn’t use them.Input and outputProgramming language 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. Through inheritance, everything derived from the InputStream or Reader classes has basic methods calledread( ) for reading a single byte or an array of bytes. Likewise, everything derived from OutputStream or Writer classes has basic methods called write( ) for writing a single byte or an 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 (this is the Decorator design pattern, as you shall see in this section). The fact that you create more than one object to produce a single stream is the primary reason that Java’s I/O library is confusing.It’s helpful to categorize the classes by their functionality. In Java l.o, 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.Type of InputStreamInputStream’s job is to represent classes that produce input from different sources.These sources can be:1.An array of bytes.2. A String obj ect.3. A file.4. A "pipe," which works like a physical pipe: You put things in at one end and theycome out the other.5. A sequence of other streams, so you can collect them together into a single stream.6.Other sources, such as an Internet connection. (This is covered in Thinking inEnterprise Java, available atEach of these has an associated subclass of InputStream. In addition, the FilterInputStream is also a type of InputStream, to provide a base class for "decorator" classes that attach attribute or useful interfaces to input streams.Types of OutputStreamThis category includes the classes that decide where your output will go: an array of bytes (but not a String—presumably, you can create one using the array of bytes), a file, or a "pipe."In addition, the FilterOutputStream provides a base class for "decorator" classes that attach attributes or useful interfaces to output streams. This is discussed later. Adding attributes and useful interfacesDecorators were introduced in the Generics chapter, on page 717. The Java I/O library requires many different combinations of features, and this is the justification for using the Decorator design pattern.1 The reason for the existence of the "filter" classes in the Java I/O library is that 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.There is a drawback to Decorator, however. Decorators give you much more flexibility while 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 FilterlnputStream and FilterOutputStream, which don’t hav e very intuitive names. FilterlnputStream and FilterOutputStream are derived from the base classes of the I/O library, InputStream and OutputStream, which is a key requirement of the decorator (so that it provides the common interface to all the objects that are being decorated).Readers & WritersJava 1.1 made significant modifications to the fundamental I/O stream library. When you see the Reader and Writer classes, your first thought (like mine) might be that these were meant to replace the InputStream and OutputStream classes. But that’s not the case. Although some aspects of the original streams library are deprecated (if you use them you will receive a warning from the compiler), the InputStream and OutputStream classes still provide valuable functionality in the form of byte-oriented I/O, whereas the Reader and Writer classes provide Unicode-compliant, character-based I/O. In addition:1.Java 1.1 added new classes into the InputStream and OutputStream hierarchy, soit’s obvious those hierarchies weren’t being replaced.There are times when you must use classes from the "byte" hierarchy in combination with classes in the "character" hierarchy. To accomplish this, there are "adapter" classes:InputStreamReader converts an InputStream to a Reader, and OutputStreamWriter converts anOutputStream to a Writer.The most important reason for the Reader and Writer hierarchies is for internationalization. The old I/O stream hierarchy supports only 8-bit byte streams and doesn’t handle the 16-bit Unicode characters well. Since Unicode is used for internationalization (and Java’s native char is 16-bit Unicode), the Reader and Writer hierarchies were added to support Unicode in all I/O operations. In addition, the new libraries are designed for faster operations than the old.Standard I/OThe term standard I/O refers to the Unix concept of a single stream of information that is used by a program (this idea is reproduced in some form in Windows and many other operating systems). All of the program’s input can come from standard input, all of its output can go to standard output, and all of its error messages can be sent to standard error. The value of standard I/O is that programs can easily be chained together, and one program’s standard output can become the standard input for another program. This is a powerful tool.Reading from standard inputFollowing the standard I/O model, Java has System.in, System.out, and System.err. Throughout this book, you’ve seen how to write to standard output using System.out, which is already pre-wrapped as a PrintStream object. System.err is likewise a PrintStream, but System.in is a raw InputStream with no wrapping. This means that although you can use System.out and System.err right away, System.in must be wrapped before you can read from it.You’ll typically read input a line at a time using readLine( ). To do this, wrap System.in in a BufferedReader, which requires you to convert System.in to a Reader using InputStreamReader.RedirectingThe Java System class allows you to redirect the standard input, output, and error I/O streams using simple static method calls:setIn(InputStream)setOut(PrintStream)setErr(PrintStream)Redirecting output is especially useful if you suddenly start creating a large amount of output on your screen, and it’s scrolling past faster than you can read it.4 Redirecting input is valuable for a command-line program in which you want to test a particular user-input sequence repeatedly.New I/OThe Java "new" I/O library, introduced in JDK 1.4 in the java.nio.* packages, has one goal: speed. In fact, the "old" I/O packages have been reimplemented using nio in order to take advantage of this speed increase, so you will benefit even if you don’t explicitly write code with nio. The speed increase occurs both in file I/O, which is explored here, and in network I/O, which is covered in Thinking in Enterprise Java.The speed comes from using structures that are closer to the operating system’s way of performing I/O: channels and buffers. You could think of it as a coal mine; the channel is the mine containing the seam of coal (the data), and the buffer is the cart that you send into the mine. The cart comes back full of coal, and you get the coal from the cart. That is, you don’t interact directly with the ch annel; you interact with the buffer and send the buffer into the channel. The channel either pulls data from the buffer, or puts data into the buffer.The only kind of buffer that communicates directly with a channel is a ByteBuffer—that is, a buffer that holds raw bytes. If you look at the JDK documentation for , you’ll see that it’s fairly basic: You create one by telling it how much storage to allocate, and there are methods to put and get data, in either raw byte form or as primitive data types. But th ere’s no way to put or get an object, or even a String. It’s fairly low-level, precisely because this makes a more efficient mapping with most operating systems.Three of the classes in the "old" I/O have been modified so that they produce aFileChannel: FileInputStream, FileOutputStream, and, for both reading and writing, RandomAccessFile. Notice that these are the byte manipulation streams, in keeping with the low-level nature of nio. The Reader and Writer character-mode classes do not produce channels, but the class has utility methods to produce Readers and Writers from channels.Reading from an InputStream with FilterlnputStreamThe FilterlnputStream classes accomplish two significantly different things. DatalnputStream 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.The remaining FilterlnputStream classes modify the way an InputStream behaves internally: whether it’s buffered or unbuffered, whether 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 (they were probably added to support the experiment of "building a Java compiler in Java"), 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 have a special case (or simply a method call) for unbuffered input rather than buffered input. Writing to an OutputStream with FilterOutputStreamThe complement to DatalnputStream is DataOutputStream, which formats each of the primitive types and String objects onto a stream in such a way that any DatalnputStream, on any machine, can read them. All the methods start with "write," such as writeByte( ), writeFloat( ), etc.The original intent of PrintStream was to print all of the primitive data types and String objects in a viewable format. This is different from DataOutputStream, whose goal is to put data elements on a stream in a way that DatalnputStream can portably reconstruct them.The two important methods in PrintStream are print( ) and println( ), which are overloaded to print all the various types. The difference between print( ) and println( )is that the latter adds a newline when it’s done. BufferedOutputStream is a modifier and tells the stream to use buffering so you don’t get a physical write every time you write to the stream.Off by itself: RandomAccessFileRandomAccessFile is used for files containing records of known size so that you can move from one record to another using seek( ), then read or change the records. The records don’t have to be the same size; you just have to determine how big they are and where they are placed in the file.At first it’s a little bit hard to believe that RandomAccessFile is not part of the InputStream or OutputStream hierarchy. However, it has no association with those hierarchies other than that it happens to implement the DataInput and DataOutput interfaces (which are also implemented by DataInputStream and DataOutputStream). It doesn’t even use any of the functionality of the existing InputStream or OutputStream classes; it’s a completely separate class, written from scratch, with all of its own (mostly native) methods. The reason for this may be that RandomAccessFile has essentially different behavior than the other I/O types, since you can move forward and backward within a file. In any event, it stands alone, as a direct descendant of Object.Essentially, a RandomAccessFile works like a DataInputStream pasted together with a DataOutputStream, along with the methods getFilePointer( ) to find out where you are in the file, seek( ) to move to a new point in the file, and length( ) to determine the maximum size of the file. In addition, the constructors require a second argument (identical to fopen( ) in C) indicating whether you are just randomly reading ("r") or reading and writing ("rw"). There’s no support for write-only files, which could suggest that RandomAccessFile might have worked well if it were inherited from DataInputStream.The seeking methods are available only in RandomAccessFile, which works for files only. BufferedInputStream does allow you to mark( ) a position (whose value is held in a single internal variable) and reset( ) to that position, but this is limited and not very useful.The File classBefore getting into the classes that actually read and write data to streams, we’ll look at a library utility that assists you with file directory issues. The File class has a deceiving name; you might think it refers to a file, but it doesn’t. In fact, "FilePath" would have been a better name for the class. It can represent either the name of a particular file or the names of a set of files in a dir ectory. If it’s a set of files, you can ask for that 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.A directory listerSuppose you’d like to see a directory listing. The File object can be used 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—then you use a "directory filter," which is a class that tells how to select the File objects for display.DirFilter’s sole r eason for existence 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 design 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 Strategy is to provide flexibility in the behavior of code.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. 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( ).外文翻译(中文)Java IO 系统“对语言设计人员来说,创建好的输入/输出系统是一项特别困难的任务。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
外文资料译文及原文JavaJava 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();elselist = 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 = 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( )里面用正则表达式(regularexpression)的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 = 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();elselist = 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();elselist = path.list(new FilenameFilter() {private Pattern pattern = 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]了。