《java毕业论文外文文献翻译.pdf》由会员分享,可在线阅读,更多相关《java毕业论文外文文献翻译.pdf(10页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、-.Advantages of Managed CodeMicrosoft intermediate language shares with Java byte code the idea that it is a low-level language withasimple syntax,which can be very quickly translated intonative machine code.Having this well-defineduniversal syntax for code has significant advantages.Platform indepe
2、ndencePlatform independenceFirst,it means that the same file containing byte code instructions can be placed on any platform;atruntime the final stage of compilation can then be easily accomplished so that the code will run onthatparticular platform.In other words,by compiling to IL we obtain platfo
3、rm independence for.NET,inmuch the same way as compiling to Java byte code gives Java platform independence.Performance improvementPerformance improvementIL is actually a bit more ambitious than Java bytecode.IL is always Just-In-Time compiled(known as JIT),whereas Java byte code was ofteninterprete
4、d.One of the disadvantages of Java was that,on execution,theprocess of translating from Javabyte code to native executable resulted in a loss of performance.Instead of compiling the entire application in one go(which could lead to a slow start-up time),theJITcompiler simply compiles each portion of
5、code as it is called(just-in-time).When code has beencompiled.once,the resultant native executable is stored until the application exits,so that it does not needto berecompiled the next time that portion of code is run.Microsoft argues that this process is moreefficientthan compiling the entire appl
6、ication code at the start,because of the likelihood that large portionsof anyapplication code will not actually be executed in any given run.Using the JIT compiler,such codewillnever be compiled.-考试资料-.This explains why we can expect that execution of managed IL code will be almost as fast as execut
7、ingnative machine code.What it doesnt explain is why Microsoft expects that we will get a performanceimprovement.The reason given for this is that,since the final stage of compilation takes place atruntime,the JIT compiler will know exactly what processor type the program will run on.This means that
8、 itcanoptimize the final executable code to take advantage of any features or particular machine codeinstructionsoffered by that particular processor.实际上,IL 比 Java 字节代码的作用还要大。IL 总是即时编译的(简称JIT),而 Java字节代码常常是解释型的,Java 的一个缺点是,在运行应用程序时,把Java 字节代码转换为内部可执行代码的过程可可能导致性能的损失。JIT 编译器并不是把整个应用程序一次编译完(这样会有很长的启动时间
9、),而是只编译它调用的那部分代码。代码编译过一次后,得到的内部可执行代码就存储起来,直到退出该应用程序为止,这样在下次运行这部分代码时,就不需要重新编译了。Microsoft 认为这个过程要比一开始就编译整个应用程序代码的效率高得多,因为任何应用程序的大部分代码实际上并不是在每次运行过程中都执行。使用 JIT 编译器,从来都不会编译这种代码从来都不会被编译。这解释了为什么托管IL 代码的执行几乎和内部机器代码的执行速度一样快,但是并没有说明为什么Microsoft 认为这会提高性能。其原因是编译过程的最后一部分是在运行时进行的,JIT 编译器确切地知道程序运行在什么类型的处理器上,利用该处理器
10、提供的任何特性或特定的机器代码指令来优化最后的可执行代码。传统的编译器会优化代码,但它们的优化过程是独立于代码所运行的特定处理器的。这是因为传统的编译器是在发布软件之前编译为内部机器可执行的代码。即编译器不知道代码所运行的处理器类型,例如该处理器是 x86 兼容处理器或 Alpha 处理器,这超出了基本操作的范围。例如Visual Studio 6 优化了一台一般的 Pentium机器,所以它生成的代码就不能利用Pentium III 处理器的硬件特性。相反,JIT 编译器不仅可以进行 Visual Studio6 所能完成的优化工作,还可以优化代码所运行的特定处理器。Traditional
11、compilers will optimize the code,but they can only perform optimizations that areindependentof the particular processor that the code will run on.This is because traditional compilerscompileto native executable before the software is shipped.This means that the compiler doesnt knowwhattype of proces
12、sor the code will run on beyond basic generalities,such as that it will be anx86-compatibleprocessor or an Alpha processor.Visual Studio 6,for example,optimizes for a genericPentium machine,so the code that it generates cannot take advantage of hardware features of Pentium III processors.Onthe other
13、 hand,the JIT compiler can do all the optimizations that Visual Studio 6 can,and in addition it-考试资料-.will optimize for the particular processor the code is running on.Language interoperabilityThe use of IL not only enables platform independence;it also facilitates language interoperability.Simplypu
14、t,you can compile to IL from one language,and this compiled code should then be interoperablewithcode that has been compiled to IL from another language.Youre probably now wondering which languages aside from C#are interoperable with.NET,so letsbriefly discuss how some of the other common languages
15、fit into.NET.Visual Basic.NETVisual Basic.NET has undergone a complete revamp from Visual Basic 6 to bring it up-to-datewith.NET.The way that Visual Basic has evolved over the last few years means that in its previous version,VisualBasic 6,it was not a suitable language for running.NET programs.For
16、example,it is heavilyintegratedinto COM and works by exposing only event handlers as source code to the developermost ofthe backgroundcode is not available as source code.Not only that,it does not support implementationinheritance,and the standard data types Visual Basic 6 uses are incompatible with
17、.NET.Visual Basic 6 wasupgraded to Visual Basic.NET,and the changes that were made to the language areso extensive you mightas well regard Visual Basic.NET as a new language.Existing Visual Basic 6 codedoes not compile asVisual Basic.NET code.Converting a Visual Basic 6 program to Visual Basic.NETre
18、quires extensivechanges to the code.However,Visual Studio.NET(the upgrade of VS for use with.NET)can do most of thechanges for you.If you attempt to read a Visual Basic 6 project into VisualStudio.NET,it will upgrade theproject for you,which means that it will rewrite the Visual Basic 6 source code
19、into Visual Basic.NETsource code.Although this means that the work involved for you isheavily cut down,you will need tocheck through the new Visual Basic.NET code to make sure that theproject still works as intended because-考试资料-.the conversion might not be perfect.One side effect of this language u
20、pgrade is that it is no longer possible to compile Visual Basic.NETtonative executable code.Visual Basic.NET compiles only to IL,just as C#does.If you need tocontinuecoding in Visual Basic 6,you may do so,but the executable code produced will completely ignorethe.NET Framework,and you ll need to kee
21、p Visual Studio 6 installed if you want to continue to work inthisdeveloper environment.Visual C+.NETVisual C+6 already had a large number of Microsoft-specific extensions on Windows.With VisualC+.NET,extensions have been added to support the.NET Framework.This means that existing C+sourcecode will
22、continue to compile to native executable code without modification.It also means,however,that it will run independently of the.NET runtime.If you want your C+code to run withinthe.NETFramework,then you can simply add the following line to the beginning of your code:#using You can also pass the flag/
23、clr to the compiler,which then assumes that you want to compile to managedcode,and will hence emit IL instead of native machine code.The interesting thing about C+isthat when you compile to managed code,the compiler can emit IL that contains an embedded nativeexecutable.This means that you can mix m
24、anaged types and unmanaged types in your C+code.Thusthe managed C+code:class MyClassdefines a plain C+class,whereas the code:_gc class MyClass-考试资料-.will give you a managed class,just as if youd written the class in C#or Visual Basic.NET.The advantageof using managed C+over C#code is that we can cal
25、l unmanaged C+classes from managed C+code without having to resort to COM interop.The compiler raises an error if you attempt to use features that are not supported by.NET on managedtypes(for example,templates or multiple inheritance of classes).You will also find that you will need touse nonstandar
26、d C+features(such as the _gc keyword shown in the previous code)when usingmanaged classes.Because of the freedom that C+allows in terms of low-level pointer manipulation and so on,the C+compiler is not able to generate code that will pass the CLRs memory type safety tests.If its importantthat your c
27、ode is recognized by the CLR as memory type safe,then youll need to write your source codein some other language(such as C#or Visual Basic.NET).Visual J#.NETThe latest language to be added to the mix is Visual J#.NET.Prior to.NET Framework 1.1,users wereable to use J#only after making a separate dow
28、nload.Now the J#language is built into the.NETFramework.Because of this,J#users are able to take advantage of all the usual features of Visual Studio.NET.Microsoft expects that most J+users will find it easiest to use J#if they want to work with.NET.Instead of being targeted at the Java runtime libr
29、aries,J#uses the same base class libraries that the restof the.NET compliant languages use.This means that you can use J#for building ASP.NET Webapplications,Windows Forms,XMLWeb services,and everything else that is possiblejust as C#and VisualBasic.NET can.-考试资料-.Scripting languagesScripting langua
30、ges are still around,although,in general,their importance is likely to decline with theadvent of.NET.JScript,on the other hand,has been upgraded to JScript.NET.We can now write ASP.NETpages in JScript.NET,run JScript.NET as a compiled rather than an interpreted language,and writestrongly typed JScri
31、pt.NET code.With ASP.NET there is no reason to use scripting languages inserversideWeb pages.VBA is,however,still used as a language for Microsoft Office and Visual Studio macros.COM and COM+Technically speaking,COM and COM+arent technologies targeted at.NET,because components basedon them cannot be
32、 compiled into IL(although its possible to do so to some degree using managed C+,ifthe original COM component was written in C+).However,COM+remains an important tool,becauseits features are not duplicated in.NET.Also,COM components will still workand.NET incorporatesCOM interoperability features th
33、at make it possible for managed code to call up COM components andvice versa(this is discussed in Chapter 29).In general,however,you will probably find it more convenientfor most purposes to code new components as.NET components,so that you can take advantage of the.NET base classes as well as the o
34、ther benefits of running as managed code.-考试资料-.-考试资料-.托管代码的优点Microsoft 中间语言与 Java 字节代码共享一种理念:它们都是一种低级语言,语法很简单,可以非常快速地转换为机器码。对于代码来说,这种精心设计的通用语法,有很大的优点。1.平台无关性首先,这意味着包含字节代码指令的同一个文件可以放在任一个平台中,运行时编译过程的最后阶段可以很容易完成,这样代码就可以运行在该特定的平台上。也就是说编译为中间语言就可以获得.NET 平台无关性,这与编译为 Java 字节代码就会得到 Java 平台无关性是一样的。2.提高性能实际上,
35、IL 比 Java 字节代码的作用还要大。IL 总是即时编译的(简称JIT),而 Java字节代码常常是解释型的,Java 的一个缺点是,在运行应用程序时,把Java 字节代码转换为内部可执行代码的过程可可能导致性能的损失。JIT 编译器并不是把整个应用程序一次编译完(这样会有很长的启动时间),而是只编译它调用的那部分代码(这是其名称由来)。代码编译过一次后,得到的内部可执行代码就存储起来,直到退出该应用程序为止,这样在下次运行这部分代码时,就不需要重新编译了。Microsoft 认为这个过程要比一开始就编译整个应用程序代码-考试资料-.的效率高得多,因为任何应用程序的大部分代码实际上并不是在
36、每次运行过程中都执行。使用JIT 编译器,从来都不会编译这种代码。这解释了为什么托管IL 代码的执行几乎和内部机器代码的执行速度一样快,但是并没有说明为什么Microsoft 认为这会提高性能。其原因是编译过程的最后一部分是在运行时进行的,JIT 编译器确切地知道程序运行在什么类型的处理器上,利用该处理器提供的任何特性或特定的机器代码指令来优化最后的可执行代码。传统的编译器会优化代码,但它们的优化过程是独立于代码所运行的特定处理器的。这是因为传统的编译器是在发布软件之前编译为内部机器可执行的代码。即编译器不知道代码所运行的处理器类型,例如该处理器是 x86 兼容处理器或 Alpha 处理器,这
37、超出了基本操作的范围。例如Visual Studio 6 优化了一台一般的 Pentium机器,所以它生成的代码就不能利用Pentium III 处理器的硬件特性。相反,JIT 编译器不仅可以进行 Visual Studio6 所能完成的优化工作,还可以优化代码所运行的特定处理器。3.语言的互操作性使用 IL 不仅支持平台无关性,还支持语言的互操作性。简言之,就是能将任何一种语言编译为中间代码,编译好的代码可以与从其他语言编译过来的代码进行交互操作。那么除了 C#之外,还有什么语言可以通过.NET 进行交互操作呢?下面就简要讨论其他常见语言如何与.NET交互操作。(1)VB.NETVisual
38、 Basic 6 在升级到 Visual Basic.NET 时,经历了一番脱胎换骨的变化。Visual Basic 是在最近的几年中演化的,其早期版本 Visual Basic 6 并不适合运行.NET 程序。例如,它与 COM 的高度集成,且只把事件处理程序作为源代码显示给开发人员,大多数后台代码不能用作源代码。另外,它不支持继承,Visual Basic 使用的标准数据类型也与.NET 不兼容。Visual Basic 6 已经升级为 Visual Basic.NET,对 VB 进行的改变非常大,完全可以把Visual Basic.NET 当作是一种新语言。现有的VB6 代码不能编译为
39、VB.NET 代码,把VB6 程序转换为 VB.NET 时,需要对代码进行大量的改动,但大多数修改工作都可以由Visual Studio.NET(VS 的升级版本,用于与.NET 一起使用)自动完成。如果要把一个 VB6 项目读取到 Visual Studio.NET 中,Visual Studio.NET 就会升级该项目,也就是说把VB6 源代码重写为 VB.NET 源代码。虽然这意味着其中的工作已大大减轻,但用户仍需要检查新的VB.NET 代码,以确保项目仍可正确工作,因为这种转换并不十分完美。这种语言升级的一个副作用是不能再把 VB.NET 编译为内部可执行代码了。VB.NET 只编译为
40、中间语言,就像 C#一样。如果需要继续使用 VB6 编写程序,就可以这么做,但生成的可执行代码会完全忽略.NET Framework,如果继续把 Visual Studio 作为开发环境,就需要安装Visual Studio 6。(2)Visual C+.NETVisual C+6 有许多 Microsoft 对 Windows 的特定扩展。通过Visual C+.NET,又加入了更多的扩展内容,来支持.NET Framework。现有的 C+源代码会继续编译为内部可执行代码,不会有修改,但它会独立于.NET 运行库运行。如果要让 C+代码在.NET Framework 中运行,就要在代码的开
41、头添加下述命令:#using 还要把标记/clr 传递给编译器,编译器假定要编译托管代码,因此会生成中间语言,而不是内部机器码。C+的一个有趣的问题是在编译托管代码时,编译器可以生成包含内嵌本机可执行代码的IL。这表示在 C+代码中可以把托管类型和非托管类型合并起来,因此托管C+代码:class MyClass定义了一个普通的 C+类,而代码:-考试资料-._gc class MyClass生成了一个托管类,就好像使用C#或 VB.NET 编写类一样。实际上,托管C+比 C#更优越的一点是可以在托管 C+代码中调用非托管 C+类,而不必采用 COM 交互功能。如果在托管类型上试图使用.NET
42、不支持的特性(例如,模板或类的多继承),编译器就会出现一个错误。另外,在使用托管类时,还需要使用非标准的C+特性(例如上述代码中的_gc 关键字)。因为 C+允许低级指针操作,C+编译器不能生成可以通过 CLR 内存类型安全测试的代码。如果 CLR 把代码标识为内存类型安全是非常重要的,就需要用其他一些语言编写源代码,例如C#或 VB.NET。(3)Visual J#最新添加的语言是 Visual J#。在.NET Framework 1.1 版本推出之前,用户必须下载相应的软件,才能使用 J#。现在 J#语言内置于.NET Framework 中。因此,J#用户可以利用 Visual Stu
43、dio.NET的所有常见特性。Microsoft 希望大多数 J+用户认为他们在使用.NET 时,将很容易使用J#。J#不使用 Java 运行库,而是使用与其他.NET 兼容语言一样的基类库。这说明,与 C#和 VB.NET 一样,可以使用 J#创建 ASP.NET Web 应用程序、Windows 窗体、XMLWeb 服务和其他应用程序。(4)脚本语言脚本语言仍在使用之中,但由于.NET 的推出,一般认为它们的重要性在降低。另一方面,JScript 升级到JScript.NET。ASP.NET 页面可以用 JScript.NET 编写,现在可以把 JScript.NET 当作一种编译语言来运
44、行,而不是解释性的语言,也可以编写输入量比较大的JScript.NET 代码。有了ASP.NET 后,就没有必要在服务器端的Web页面上使用脚本语言了,但VBA 仍用作 Office 文档和 Visual Studio 宏语言。(5)COM 和 COM+从技术上讲,COM 和 COM+并不是面向.NET 的技术,因为基于它们的组件不能编译为IL(但如果原来的COM组件是用 C+编写的,使用托管C+,在某种程度上可以这么做)。但是,COM+仍然是一个重要的工具,因为其特性没有在.NET 中完全实现。另外,COM 组件仍可以使用.NET 组合了 COM 的互操作性,从而使托管代码可以调用 COM 组件,COM 组件也可以调用托管代码(见第 29 章)。在大多数情况中,把新组件编写为.NET 组件,其多数目的是为了更加方便,因为这样可以利用.NET 基类和托管代码的其他优点。-考试资料