版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、<p> 文獻來源:Bruce Eckel. Thinking in Java [J]. Pearson Higher Isia Education,2006-2-20.</p><p> Java編程思想 (Java和因特網(wǎng))</p><p> 既然Java不過另一種類型的程序設計語言,大家可能會奇怪它為什么值得如此重視,為什么還有這么多的人認為它是計算機程序設計的一個里
2、程碑呢?如果您來自一個傳統(tǒng)的程序設計背景,那么答案在剛開始的時候并不是很明顯。Java除了可解決傳統(tǒng)的程序設計問題以外,還能解決World Wide Web(萬維網(wǎng))上的編程問題。</p><p><b> 1、客戶端編程</b></p><p> Web最初采用的“服務器-瀏覽器”方案可提供交互式內容,但這種交互能力完全由服務器提供,為服務器和因特網(wǎng)帶來了不小的
3、負擔。服務器一般為客戶瀏覽器產(chǎn)生靜態(tài)網(wǎng)頁,由后者簡單地解釋并顯示出來?;綡TML語言提供了簡單的數(shù)據(jù)收集機制:文字輸入框、復選框、單選鈕、列表以及下拉列表等,另外還有一個按鈕,只能由程序規(guī)定重新設置表單中的數(shù)據(jù),以便回傳給服務器。用戶提交的信息通過所有Web服務器均能支持的“通用網(wǎng)關接口”(CGI)回傳到服務器。包含在提交數(shù)據(jù)中的文字指示CGI該如何操作。最常見的行動是運行位于服務器的一個程序。那個程序一般保存在一個名為“cgi-bi
4、n”的目錄中(按下Web頁內的一個按鈕時,請注意一下瀏覽器頂部的地址窗,經(jīng)常都能發(fā)現(xiàn)“cgi-bin”的字樣)。大多數(shù)語言都可用來編制這些程序,但其中最常見的是Perl。這是由于Perl是專為文字的處理及解釋而設計的,所以能在任何服務器上安裝和使用,無論采用的處理器或操作系統(tǒng)是什么。</p><p><b> 2、腳本編制語言</b></p><p> 插件造成了
5、腳本編制語言的爆炸性增長。通過這種腳本語言,可將用于自己客戶端程序的源碼直接插入HTML頁,而對那種語言進行解釋的插件會在HTML頁顯示的時候自動激活。腳本語言一般都傾向于盡量簡化,易于理解。而且由于它們是從屬于HTML頁的一些簡單正文,所以只需向服務器發(fā)出對那個頁的一次請求,即可非??斓剌d入。缺點是我們的代碼全部暴露在人們面前。另一方面,由于通常不用腳本編制語言做過分復雜的事情,所以這個問題暫且可以放在一邊。</p>&
6、lt;p> 腳本語言真正面向的是特定類型問題的解決,其中主要涉及如何創(chuàng)建更豐富、更具有互動能力的圖形用戶界面(GUI)。然而,腳本語言也許能解決客戶端編程中80%的問題。你碰到的問題可能完全就在那80%里面。而且由于腳本編制語言的宗旨是盡可能地簡化與快速,所以在考慮其他更復雜的方案之前(如Java及ActiveX),首先應想一下腳本語言是否可行。</p><p> 目前討論得最多的腳本編制語言包括Jav
7、aScript(它與Java沒有任何關系;之所以叫那個名字,完全是一種市場策略)、VBScript(同Visual Basic很相似)以及Tcl/Tk(來源于流行的跨平臺GUI構造語言)。當然還有其他許多語言,也有許多正在開發(fā)中。</p><p> JavaScript也許是日常用的,它得到的支持也最全面。無論NetscapeNavigator,Microsoft Internet Explorer,還是Ope
8、ra,目前都提供了對JavaScript的支持。除此以外,市面上講述JavaScript的書籍也要比講述其他語言的書多得多。有些工具還能利用JavaScript自動產(chǎn)生網(wǎng)頁。當然,如果你已經(jīng)有Visual Basic或者Tcl/Tk的深厚功底,當然用它們要簡單得多,起碼可以避免學習新語言的煩惱(解決Web方面的問題就已經(jīng)夠讓人頭痛了)。</p><p><b> 3、Java</b><
9、;/p><p> 如果說一種腳本編制語言能解決80%的客戶端程序設計問題,那么剩下的20%又該怎么辦呢?它們屬于一些高難度的問題嗎?目前最流行的方案就是Java。它不僅是一種功能強大、高度安全、可以跨平臺使用以及國際通用的程序設計語言,也是一種具有旺盛生命力的語言。對Java的擴展是不斷進行的,提供的語言特性和庫能夠很好地解決傳統(tǒng)語言不能解決的問題,比如多線程操作、數(shù)據(jù)庫訪問、連網(wǎng)程序設計以及分布式計算等等。Jav
10、a通過“程序片”(Applet)巧妙地解決了客戶端編程的問題。</p><p> 程序片(或“小應用程序”)是一種非常小的程序,只能在Web瀏覽器中運行。作為Web頁的一部分,程序片代碼會自動下載回來(這和網(wǎng)頁中的圖片差不多)。激活程序片后,它會執(zhí)行一個程序。程序片的一個優(yōu)點體現(xiàn)在:通過程序片,一旦用戶需要客戶軟件,軟件就可從服務器自動下載回來。它們能自動取得客戶軟件的最新版本,不會出錯,也沒有重新安裝的麻煩。
11、由于Java的設計原理,程序員只需要創(chuàng)建程序的一個版本,那個程序能在幾乎所有計算機以及安裝了Java解釋器的瀏覽器中運行。由于Java是一種全功能的編程語言,所以在向服務器發(fā)出一個請求之前,我們能先在客戶端做完盡可能多的工作。例如,再也不必通過因特網(wǎng)傳送一個請求表單,再由服務器確定其中是否存在一個拼寫或者其他參數(shù)錯誤。大多數(shù)數(shù)據(jù)校驗工作均可在客戶端完成,沒有必要坐在計算機前面焦急地等待服務器的響應。這樣一來,不僅速度和響應的靈敏度得到了
12、極大的提高,對網(wǎng)絡和服務器造成的負擔也可以明顯減輕,這對保障因特網(wǎng)的暢通是至關重要的。 與腳本程序相比,Java程序片的另一個優(yōu)點是它采用編譯好的形式,所以客戶端看不到源碼。當然在另一方面,反編譯Java程序片也并不是件</p><p><b> 4、因特網(wǎng)和內聯(lián)網(wǎng)</b></p><p> Web是解決客戶機/服務器問題的一種常用方案,所以最好能用相同的
13、技術解決此類問題的一些“子集”,特別是公司內部的傳統(tǒng)客戶機/服務器問題。對于傳統(tǒng)的客戶機/服務器模式,我們面臨的問題是擁有多種不同類型的客戶計算機,而且很難安裝新的客戶軟件。但通過Web瀏覽器和客戶端編程,這兩類問題都可得到很好的解決。若一個信息網(wǎng)絡局限于一家特定的公司,那么在將Web技術應用于它之后,即可稱其為“內聯(lián)網(wǎng)”(Intranet),以示與國際性的“因特網(wǎng)”(Internet)有別。內聯(lián)網(wǎng)提供了比因特網(wǎng)更高的安全級別,因為可以
14、物理性地控制對公司內部服務器的使用。說到培訓,一般只要人們理解了瀏覽器的常規(guī)概念,就可以非常輕松地掌握網(wǎng)頁和程序片之間的差異,所以學習新型系統(tǒng)的開銷會大幅度減少。</p><p> 安全問題將我們引入客戶端編程領域一個似乎是自動形成的分支。若程序是在因特網(wǎng)上運行,由于無從知曉它會在什么平臺上運行,所以編程時要特別留意,防范可能出現(xiàn)的編程錯誤。需作一些跨平臺處理,以及適當?shù)陌踩婪?,比如采用某種腳本語言或者Jav
15、a。</p><p> 但假如在內聯(lián)網(wǎng)中運行,面臨的一些制約因素就會發(fā)生變化。全部機器均為Intel/Windows平臺是件很平常的事情。在內聯(lián)網(wǎng)中,需要對自己代碼的質量負責。而且一旦發(fā)現(xiàn)錯誤,就可以馬上改正。除此以外,可能已經(jīng)有了一些“歷史遺留”的代碼,并用較傳統(tǒng)的客戶機/服務器方式使用那些代碼。但在進行升級時,每次都要物理性地安裝一道客戶程序。浪費在升級安裝上的時間是轉移到瀏覽器的一項重要原因。使用了瀏覽器
16、后,升級就變得易如反掌,而且整個過程是透明和自動進行的。如果真的是牽涉到這樣的一個內聯(lián)網(wǎng)中,最明智的方法是采用ActiveX,而非試圖采用一種新的語言來改寫程序代碼。</p><p><b> 5、服務器端編程</b></p><p> 我們的整個討論都忽略了服務器端編程的問題。如果向服務器發(fā)出一個請求,會發(fā)生什么事情?大多數(shù)時候的請求都是很簡單的一個“把這個文件
17、發(fā)給我”。瀏覽器隨后會按適當?shù)男问浇忉屵@個文件:作為HTML頁、一幅圖、一個Java程序片、一個腳本程序等等。向服務器發(fā)出的較復雜的請求通常涉及到對一個數(shù)據(jù)庫進行操作(事務處理)。其中最常見的就是發(fā)出一個數(shù)據(jù)庫檢索命令,得到結果后,服務器會把它格式化成HTML頁,并作為結果傳回來(當然,假如客戶通過Java或者某種腳本語言具有了更高的智能,那么原始數(shù)據(jù)就能在客戶端發(fā)送和格式化;這樣做速度可以更快,也能減輕服務器的負擔)。另外,有時需要在
18、數(shù)據(jù)庫中注冊自己的名字(比如加入一個組時),或者向服務器發(fā)出一份訂單,這就涉及到對那個數(shù)據(jù)庫的修改。這類服務器請求必須通過服務器端的一些代碼進行,我們稱其為“服務器端的編程”。在傳統(tǒng)意義上,服務器端編程是用Perl和CGI腳本進行的,但更復雜的系統(tǒng)已經(jīng)出現(xiàn)。其中包括基于Java的Web服務器,它允許我們用Java進行所有服務器端編程,寫出的程序就叫做“小服務程序”(Servlet)。</p><p> 6、一個
19、獨立的領域:應用程序</p><p> 與Java有關的大多數(shù)爭論都是與程序片有關的。Java實際是一種常規(guī)用途的程序設計語言,可解決任何類型的問題,至少理論上如此。而且正如前面指出的,可以用更有效的方式來解決大多數(shù)客戶機/服務器問題。如果將視線從程序片身上轉開(同時放寬一些限制,比如禁止寫盤等),就進入了常規(guī)用途的應用程序的廣闊領域。這種應用程序可獨立運行,毋需瀏覽器,就象普通的執(zhí)行程序那樣。在這兒,Java
20、的特色并不僅僅反應在它的移植能力,也反映在編程本身上。就像貫穿全書都會講到的那樣,Java提供了許多有用的特性,使我們能在較短的時間里創(chuàng)建出比用從前的程序設計語言更健壯的程序。</p><p> 但要注意任何東西都不是十全十美的,我們?yōu)榇艘惨冻鲆恍┐鷥r。其中最明顯的是執(zhí)行速度放慢了(盡管可對此進行多方面的調整)。和任何語言一樣,Java本身也存在一些限制,使得它不十分適合解決某些特殊的編程問題。但不管怎樣,J
21、ava都是一種正在快速發(fā)展的語言。隨著每個新版本的發(fā)布,它變得越來越可愛,能充分解決的問題也變得越來越多。</p><p> Thingking in Java(Java and the Internet)</p><p> If Java is, in fact, yet another computer programming language, you may question
22、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
23、 useful for solving traditional stand-alone programming problems, it is also important because it will solve programming problems on the World Wide Web.</p><p> 1.Client-side programming</p><p>
24、; The Web’s initial server-browser design provided for interactive content, but the interactivity was completely provided by the server. The server produced static pages for the client browser, which would simply interp
25、ret 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
26、the form or “submit” the data on the form back to the server. T</p><p> 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 C
27、GI 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 a
28、nd 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 band</p><p> The solution is client-side programming. Most machi
29、nes 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 program
30、ming 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.</p><p> The problem with discussions
31、 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 syst
32、em. 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 i
33、n client-side programming.</p><p> 2.Scripting languages</p><p> Plug-ins resulted in an explosion of scripting languages. With a scripting language you embed the source code for your client-s
34、ide 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,
35、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 tra</p><p> This points out that the scripting languages
36、 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 perc
37、ent of the problems encountered in client-side programming. Your problems might very well fit completely within that 80 percent, and since scripting languages can allow easier and faster development, you should probably
38、consider a scrip</p><p> 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), VBScr
39、ipt (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.</p><p> JavaScript is probab
40、ly 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 l
41、anguages, 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.
42、 (You’ll have your hands full dealing wi</p><p><b> 3.Java</b></p><p> If a scripting language can solve 80 percent of the client-side programming problems, what about the other 20
43、 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 p
44、rovide language features and libraries that elegantly handle problems that are difficult in traditional programming languages, such as multithreading, database access, net</p><p> An applet is a mini-progra
45、m 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. Th
46、is 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 c
47、lient software without fail and wi</p><p> One advantage a Java applet has over 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
48、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 mo
49、dules and take multiple server “hits” (accesses) to download. (In Java 1.1 and higher this is minimized by Java archi</p><p> 4.Internet vs. intranet</p><p> The Web is the most general soluti
50、on 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 a
51、pproaches 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
52、technology is used for an </p><p> 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 In
53、ternet, 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. <
54、/p><p> 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 responsible for the qu
55、ality 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 physical
56、ly install client programs every time you do an upgrade. The time wasted in ins</p><p> 5.Server-side programming</p><p> This whole discussion has ignored the issue of server-side programming
57、. 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
58、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</p>
59、<p> 6.separate arena: applications</p><p> Much 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
60、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 again
61、st writing to disk) you enter the world of general-purpose applications that run standalone, without a Web browser, just like </p><p> Be aware that this is a mixed blessing. You pay for the improvements th
62、rough 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 limitation
63、s 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 solvin</p>
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- java外文翻譯---java和因特網(wǎng)
- java和因特網(wǎng)外文翻譯
- java編程思想整理
- java 編程外文翻譯
- java和因特網(wǎng)
- java編程思想-畢業(yè)論文外文文獻翻譯
- 畢業(yè)論文外文翻譯-java和因特網(wǎng)
- java思想外文翻譯畢業(yè)設計
- 外文翻譯 - java思想 第二版
- java 外文翻譯
- java外文翻譯
- java的面向對象編程外文資料翻譯
- java介紹外文翻譯
- java編程題
- java介紹外文翻譯
- java音頻編程
- java編程題
- 5,JAVA編程思想[第四版].pdf
- java網(wǎng)絡編程
- java的基礎外文翻譯
評論
0/150
提交評論