【正文】
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 libraries, J uses the same base class libraries that the rest of the .NET pliant languages use. This means that you can use J for building Web applications, Windows Forms, XMLWeb services, and everything else that is possible— just as C and Visual Basic .NET can. Scripting languages Scripting languages are still around, although, in general, their importance is likely to decline with the advent of .NET. JScript, on the other hand, has been upgraded to JScript .NET. We can now write pages in JScript .NET, run JScript .NET as a piled rather than an interpreted language, and write strongly typed JScript .NET code. With there is no reason to use scripting languages in serverside Web pages. VBA is, however, still used as a language for Microsoft Office and Visual Studio macros. COM and COM+ Technically speaking, COM and COM+ aren’t technologies targeted at .NET, because ponents based on them cannot be piled into IL (although it’s possible to do so to some degree using managed C++, if the original COM ponent was written in C++). However, COM+ remains an important tool, because its features are not duplicated in .NET. Also, COM ponents will still work— and .NET incorporates COM interoperability features that make it possible for managed code to call up COM ponents and vice versa (this is discussed in Chapter 29). In general, however, you will probably find it more convenient for most purposes to code new ponents as .NET ponents, so that you can take advantage of the 托管代碼的優(yōu)點(diǎn) Microsoft 中間語(yǔ)言與 Java 字節(jié)代碼共享一種理念:它們都是一種低級(jí)語(yǔ)言,語(yǔ)法很簡(jiǎn)單 (使用數(shù)字代碼,而不是文本代碼 ),可以非??焖俚剞D(zhuǎn)換為內(nèi)部機(jī)器碼。對(duì)于代碼來(lái)說(shuō),這種精心設(shè)計(jì)的通用語(yǔ)法,有很大的優(yōu)點(diǎn)。 1. 平臺(tái)無(wú)關(guān)性 首先,這意味著包含字節(jié)代碼指令的同一個(gè)文件可以放在任一個(gè)平臺(tái)中,運(yùn)行時(shí)編譯過(guò)程的最后階段可以很容易完成,這樣代碼就可以運(yùn)行在該特定的平臺(tái)上。也就是說(shuō)編譯為中間語(yǔ)言就可以獲得 .NET 平臺(tái)無(wú)關(guān)性,這與編譯為 Java 字節(jié)代碼就會(huì)得到 Java 平臺(tái)無(wú)關(guān)性是一樣的。 注意 .NET 的平臺(tái)無(wú)關(guān)性目前只是一種可能,因?yàn)樵诰帉懕緯鴷r(shí), .NET 只能用于 Windows 平臺(tái),但人們正在積極準(zhǔn)備,使它可以用于其他平臺(tái) (參見(jiàn) Mono項(xiàng)目,它用于創(chuàng)建 .NET 的開放源代碼的實(shí)現(xiàn),參見(jiàn) 2. 提高性能 實(shí)際上, IL 比 Java 字節(jié)代碼的作用還要大。 IL總是即時(shí)編譯的 (稱為 JIT編譯 ),而 Java字節(jié)代碼常常是解釋性的, Java 的一個(gè)缺點(diǎn)是,在運(yùn)行應(yīng)用程序時(shí),把 Java 字節(jié)代碼轉(zhuǎn)換為內(nèi)部可執(zhí)行代碼的過(guò)程會(huì)導(dǎo)致性能的損失 (但在最近,Java 在某些平臺(tái)上能進(jìn)行 JIT編譯 )。 JIT 編譯器并不是把整個(gè)應(yīng)用程序一次編譯完 (這樣會(huì)有很長(zhǎng)的啟動(dòng)時(shí)間 ),而是只編譯它調(diào)用的那部分代碼 (這是其名稱由來(lái) )。代碼編譯過(guò)一次后,得到的內(nèi)部可執(zhí)行代碼就存儲(chǔ)起來(lái),直到退出該應(yīng)用程序?yàn)橹?,這樣在下次運(yùn)行這部分代碼時(shí),就不需要重新編譯了。 Microsoft 認(rèn)為這個(gè)過(guò)程要比一開始就編譯整個(gè)應(yīng)用程序代碼的效率高得多,因?yàn)槿魏螒?yīng)用程序的大部分代碼實(shí)際上并不是在每次運(yùn)行過(guò)程中都執(zhí)行。使用 JIT 編譯器,從來(lái)都不會(huì)編譯這種代碼。 這解釋了為什么托管 IL 代碼的執(zhí)行幾乎和內(nèi)部機(jī)器代碼的執(zhí)行速度一樣快,但是并 沒(méi)有說(shuō)明為什么 Microsoft 認(rèn)為這會(huì)提高性能。其原因是編譯過(guò)程的最后一部分是在運(yùn)行時(shí)進(jìn)行的, JIT 編譯器確切地知道程序運(yùn)行在什么類型的處理器上,利用該處理器提供的任何特性或特定的機(jī)器代碼指令來(lái)優(yōu)化最后的可執(zhí)行代碼。 傳統(tǒng)的編譯器會(huì)