談一談Java的前生今世

{"type":"doc","content":[{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"大家好,我是孫叫獸,微信公衆號【孫叫獸雜談】,本期給大家分享一下JavaSE的入門部分之Java的前生今世。","attrs":{}}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Java : 一個帝國的誕生","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"C語言帝國的統治","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"現在是公元1995年, C語言帝國已經統治了我們20多年, 實在是太久了。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"1972年, 隨着C語言的誕生和Unix的問世, 帝國迅速建立統治, 從北美到歐洲, 從歐洲到亞洲, 無數程序員臣服在他的腳下。帝國給我們提供了極好的福利:貼近硬件, 運行極快, 效率極高。使用這些福利, 程序員們用C 開發了很多系統級軟件,操作系統, 編譯器, 數據庫,網絡系統.....","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"但是帝國也給我們安上了兩個沉重的枷鎖: 指針和內存管理。雖然指針無比強大, 能直接操作內存, 但是帝國卻沒有給我們工具去做越界的檢查, 導致很多新手程序員輕易犯錯。至於內存管理, 帝國更完全是放任的態度: 你自己分配的空間, 自己去釋放 !更要命的是這些問題在編譯期發現不了, 在運行時纔會突然暴露, 常常讓我們手忙腳亂, 昏天黑地去調試。我們的大量時間和寶貴的精力都被浪費在小心翼翼的處理指針和內存分配上。每個程序員都被這兩個東西搞的焦頭爛額!","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"帝國宣稱的可移植性騙了我們,他宣稱我們在一個機器上寫的程序, 只要在另外一個機器上編譯就可以了, 實際上不是這樣。 他要求我們儘量用標準的C函數庫。其次,如果遇到了一些針對特定平臺的調用, 需要對每個平臺都得寫一份 ! 有一點點小錯誤,都會導致編譯失敗。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"1982年,帝國又推出了一門新的語言C++, 添加了面向對象的功能,兼容C, 有靜態類型檢查, 性能也很好。但是這門新的語言實在是太複雜了, 複雜到比我聰明的多的人都沒有辦法完全掌握這門語言,它的很多特性複雜的讓人喫驚。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"C++在圖形領域和遊戲上取得了一些成功, 但是我一直學不好它。反抗我決定反抗這個龐大的帝國, 我偷偷的帶領着一幫志同道合的兄弟離開了,我們要新建一塊清新自由的領地。爲了吸引更多的程序員加入我們, 我們要建立一個新的語言,這個語言應該有這樣的特性:","attrs":{}}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"1.語法有點像C , 這樣大家容易接受沒有C語言那樣的指針","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"2.再也不要考慮內存管理了, 實在受不了了","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"3.真正的可移植性, 編寫一次, 到處運行","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"4.面向對象","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"5.類型安全","attrs":{}}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"還有,我們要提供一套高質量的類庫, 隨語言發行,我想把這個語言命名爲C++-- , 即C++減減, 因爲我想在C++的基礎上改進,把它簡化。後來發現不行, 設計理念差別太大。乾脆重啓爐竈。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我看到門口的一棵橡樹, 就把這個語言叫做Oak。但是後來發佈的時候, 發現Oak已經被別人用了, 我們討論很久, 最終決定把這門新的語言叫做Java。爲了實現跨平臺, 我們在操作系統和應用程序之間增加了一個抽象層: ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Java 虛擬機","attrs":{}},{"type":"text","text":"。用Java寫的程序都跑在虛擬機上, 除非個別情況, 都不用看到操作系統。一鳴驚人。爲了吸引更多的人加入我們的新領地, 我們決定搞一個演示, 向大家展示Java 的能力。出世未久的Java其實還遠不完善。 搞點什麼好呢?","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我們把眼光盯上了剛剛興起的互聯網, 1995年的網頁簡單而粗糙, 缺乏互動性。 於是我們在瀏覽器上弄了個小插件, 把java 運行環境放了上去。然後在上面開發了一個圖形界面的程序(Applet), 讓它看起來美輪美奐, 震撼人心。每一個看到他的程序員都會發出“Wow”的驚歎 !爲之傾倒。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Java 活了!通過Applet , 無數的程序員看到了Java這門語言,瞭解了這門語言特性以後, 很多無法忍受C帝國暴政的程序員, 很快加入了我們, 我們的領地開始迅速擴大。連C語言帝國裏的一些商業巨頭也紛紛來和我們合作, 其中就包括Oracle , 微軟這樣的巨頭 , 微軟的頭領Bill Gates還說 :這是迄今爲止設計的最好的語言!但是Bill Gates非常的不地道, 買了我們的Java 許可以後,雖然在自家的瀏覽器上也支持Applet, 但是他們卻偷偷的試圖修改Java , 想把Java綁死在自家的操作系統上賺錢, Java會變的不可移植。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這是我們難於忍受的, 我們和微軟發起了一場曠日持久的游擊戰爭, 逼着微軟退出了Java領域, 開發了自己的.NET , 這是後話。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"開拓疆土","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"從1995年到1997年,我們依靠 Java 不斷的攻城略地, 開拓疆土,我們王國的子民不斷增加, 達到了幾十萬之衆, 已經是一個不可忽視的力量了。但是大家發現, Java除了Applet, 以及一些小程序之外, 似乎幹不了別的事情。C帝國的人還不斷的嘲笑我們慢, 像個玩具。到了1998年, 經過密謀, 我們Java 王國決定派出三隻軍隊向外擴展:","attrs":{}}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Java 2 標準版(J2SE): 去佔領桌面","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Java 2 移動版(J2ME): 去佔領手機","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Java 2 企業版(J2EE): 去佔領服務器","attrs":{}}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"其中的兩隻大軍很快敗下陣來。J2SE 的首領發現, 開發桌面應用的程序員根本接受不了Java, 雖然我們有做的很優雅的Swing 可以開發界面, 但是開發出的界面非常難看, 和原生的桌面差距很大。 尤其是爲了運行程序還得安裝一個虛擬機, 大家都受不了。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"J2ME也是, 一直不受待見, 當然更重要的原因是喬布斯還沒有重新發明手機, 移動互聯網還沒有啓動。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"失之東隅,收之桑榆, J2EE趕上了好時候, 互聯網大發展, 大家忽然發現, Java簡直是爲寫服務器端程序所發明的!","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"強大, 健壯, 安全, 簡單, 跨平臺 !","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在J2EE規範的指導下, 特別適合團隊開發複雜的大型項目。我們授權BEA公司第一個使用J2EE許可證, 推出了Weblogic, 憑藉其集羣功能, 第一次展示了複雜應用的可擴展性和高可用性。 ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"【三高:高可用,高性能,高併發】","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這個後來被稱爲中間件的東西把程序員從事務管理,安全管理,權限管理等方面解放出來, 讓他們專注於業務開發。 這立刻捕獲了大量程序員的心。很快Java 王國的子民就達到數百萬之衆。榜樣的力量是無窮的, 很快其他商業巨頭也紛紛入場, 尤其是IBM,在Java 上瘋狂投入,不僅開發了自己的應用服務器 Websphere, 還推出了Eclipse這個極具魅力的開源開發平臺。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"當然IBM利用java 獲得了非常可觀的效益, 軟件+硬件+服務 三駕馬車滾滾向前, 把IBM推向了一個新的高峯。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"帝國的誕生","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"大家也沒有想到,除了商業巨頭以外, 程序員們也會對Java王國 這麼熱愛, 他們基於Java 開發了巨多的平臺,系統,工具,例如:","attrs":{}}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"構建工具: Ant,Maven, Jekins","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"應用服務器: Tomcat,Jetty, Jboss, Websphere, weblogic","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Web開發: Struts,Spring,Hibernate, myBatis","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"開發工具: Eclipse, Netbean,intellij idea, Jbuilder","attrs":{}}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"。。。。等等等等。。。。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"並且絕大部分都是開源的 !","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"微軟眼睜睜的看着服務器端的市場被Java 王國佔據, 豈能善罷甘休? 他們趕緊推出.NET來對抗, 但我們已經不在乎了, 因爲他的系統是封閉的,所有的軟件都是自家的:開發工具是Visual Studio, 應用服務器是IIS, 數據庫是SQL Server,只要你用.NET,基本上就會綁定微軟。另外他們的系統只能運行在Windows服務器上, 這個服務器在高端市場的佔有率實在是太低了。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"2005年底, 一個新的王國突然崛起, 他們號稱開發效率比java 快5-10倍, 由此吸引了大批程序員前往加盟。這個新的王國叫做Ruby on Rails, 它結合了PHP體系的優點(快速開發)和Java體系的優點(程序規整), 特別適合快速的開發簡單的Web網站。雖然發展很快, 但沒有對Java 王國產生實質性的威脅, 使用Ruby on Rails搭建大型商業系統的還很少。除了Ruby on Rails ,還有PHP, Python , 都適合快速開發不太複雜的Web系統。 但是關鍵的,複雜的商業系統開發還是Java 王國的統治之下。 所以我們和他們相安無事。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"2006年, 一隻叫Hadoop的軍隊讓Java王國入侵了大數據領域, 由於使用Java 語言, 絕大多數程序員在理解了Map/Reduce , 分佈式文件系統在Hadoop中的實現以後, 很快就能編寫處理處理海量數據的程序, Java 王國的領地得到了極大的擴展。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"2008年, 一個名叫Android 的系統橫空出世, 並且隨着移動互聯網的爆發迅速普及, 運行在Android之上的正是Java !Java 王國在Google的支持下, 以一種意想不到的方式佔領了手機端, 完成了當年J2ME 壯志未酬的事業!","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"到今年爲止, 全世界估計有1000萬程序員加入了Java王國,它領土之廣泛, 實力之強大, 是其他語言無法比擬的。Java 佔據了大部分的服務器端開發,尤其是關鍵的複雜的系統, 絕大多數的手機端, 以及大部分的大數據領域。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"一個偉大的帝國誕生了。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"Java的特性和優勢","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"簡單性","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"就是c++語法的純淨版。沒有頭文件,指針運算,結構,聯合,操作符重載,虛基類等等。由於語法基於c,因此學習起來完全不費力。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"面向對象","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"面向對象是一種程序設計技術,他將重點放在數據(即對象)和對象之間的接口上。模擬人的思維寫程序,萬物皆對象!","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"可移植性(跨平臺性)","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這是JAVA的一個重要的優勢。JAVA代碼或者說字節碼、二進制碼可以跨平臺的移植,而不用管具體的操作系統和硬件環境。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"“一次編寫,隨處運行”:“write once, run anywhere”","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"JAVA在設計時就很注重移植和跨平臺性。比如:JAVA的Int永遠都是32位。不像c++可能是16,32,可能是根據編譯器廠商規定的變化。這樣的話程序的移植就會非常麻煩。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"高性能","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"JIT(JUST IN TIME)即時編譯。將一些“熱點”字節碼編譯成本地機器碼,並將結果緩存起來,在需要的時候重新調用。這樣的話,使JAVA程序的執行效率大大提高,某些代碼甚至接近c++的效率。隨着這種技術的一天天完善,也許有一天會超越編譯代碼的效率。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"分佈式","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"JAVA是爲internet的分佈式環境設計的,因爲他能夠處理tcp/ip協議。事實上,通過url訪問一個網絡資源和訪問本地文件是一樣簡單的。Java還支持遠程方法調用(RMI,remote method Invocation),使程序能夠通過網絡調用方法。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"動態性","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"就是在需要時將某些代碼添加到正在運行的程序中。反射機制。當需要把某些代碼添加到正在運行的程序中時,動態性是一個非常重要的特性。Java的動態特性是其面向對象設計方法的擴展。它允許程序動態地裝入運行過程中所需要的類,這是C++語言進行面向對象程序設計所無法實現的","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"多線程","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"多線程的使用可以帶來更好的交互響應和實時行爲。多線程的簡單性是Java成爲主流服務器端開發語言的主要原因之一。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"安全性","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Java適合於網絡/分佈式環境,爲了達到這個目標,在安全性方面投入了很大的精力,使Java可以構建防病毒,防篡改的系統。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"健壯性","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Java是一種健壯的語言,吸收了C/C++ 語言的優點,但去掉了其影響程序健壯性的部分(如:指針、內存的申請與釋放等)。Java程序不可能造成計算機崩潰。Java系統仔細檢測對內存的每次訪問,確認它是合法的,而且不致引起任何問題。不過,即使Java程序也可能有錯誤。如果出現某種出乎意料之事,程序也不會崩潰,而是把該例外拋棄。再通過異常處理機制,程序就會發現這類例外,並加以處理。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"當然,我們學習他這門語言,最初的目的,是因爲使用的人多,我們需要去掌握學習,但是當我們慢慢的越來越深入的時候,你就會愛上他,發現他的無窮魅力併爲之沉醉!","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"JAVA語言爲什麼能夠成功","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"一個產品的成功和一個人的成功是一個道理。除了自身具備過硬的優勢外,還需要那麼一點點狗屎運,甚至狗屎運非常關鍵。就是我們所講的天時地利人和。JAVA的成功除了自己具備跨平臺特性外,更重要的是正好踩中了互聯網發展的節奏。微軟的成功除了windows好用外,也是正好踩中了個人電腦發展的節奏。所以,我們除了自己努力外,也需要出去走走努力才踩一坨狗屎纔行!","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"學技術,也需要知道很多事情和歷史對吧,我們來聊聊硅谷。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"斯坦福大學依靠自身龐大的校區,創建了斯坦福科技園(硅谷的前身),初期採用房租免費等方式,鼓勵自己的畢業生在科技園創業、鼓勵社會企業入駐。由於免費的方式再加上其他優惠的政策,吸引了大量的創業者加入進來。最終大家添柴加火,造就了今天的硅谷。這纔是最高明的房地產商啊!說到房地產,我們現在這個社會是不是就很難受了,年薪20萬,買一套房子180萬,你算算,是不是大概下來就需要十年了,你說你一個大好青年,因爲一個房子,就一下變成中年大叔了!哎,人間不值得啊,所以我們需要通過不斷的學習來提高自己,從而進步!讓自己的人生更有價值,而不是活着而已。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"看着這麼多的牛人,各位,是不是我們也得努努力了,少刷點抖音,少玩點王者,喫雞(玩得時候帶帶我~)多跟着我敲敲代碼,沒準以後咋們的同學也能搞出一個改變世界的東西是吧。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"好了,不多說話,我們先來認識一下我們即將要學習的最終要的階段,JavaSE。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Java三大版本","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"首先,新人在剛入行的時候,不論是抱着什麼目的(當然最後是因爲興趣,因爲興趣是一個很強的推動力),我們要了解學習什麼東西,或者說從什麼東西學起----JAVA。作爲一款高級程序設計語言,它的學習難度上面,至少我認爲要比C語言簡單許多,再加上如今市場對這方面的人才需求非常大,所以很多人將它作爲了首選。目前來說JAVA的應用比較偏向於WEB的設計,也是我們很多學習JAVA的同志,日久就業的一個方向。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"JAVA最大的特點","attrs":{}},{"type":"text","text":":","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Java的主要優勢在於其做出的WORA:即一次編寫(Write Once)、隨處運行(Run Anywhere)。簡單來講,這意味着開發團隊能夠利用Java編寫一款應用程序,並將其編譯爲可執行形式,而後將其運行在任何支持Java的平臺之上。這顯然能夠極大提高編程工作的實際效率,這種優勢來源於Java Virtual Machine(JAVA虛擬機的縮寫),JVM是一種用於計算設備的規範,它是一個虛構出來的計算機,是通過在實際的計算機上仿真模擬各種計算機功能來實現的。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"JAVA語言的一個非常重要的特點就是與平臺的無關性,而使用Java虛擬機是實現這一特點的關鍵。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"JAVA的三大版本:","attrs":{}}]},{"type":"blockquote","content":[{"type":"numberedlist","attrs":{"start":1,"normalizeStart":1},"content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"JAVA SE:它是JAVA的標準版,是整個JAVA的基礎和核心,這是我們主要學習的一個部分,也是JAVAEE和JAVAME技術的基礎,主要用於開發桌面應用程序。學會後可以做一些簡單的桌面應用","attrs":{}}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如:掃雷,連連看等。","attrs":{}}]},{"type":"numberedlist","attrs":{"start":1,"normalizeStart":1},"content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"JAVA ME:它是JAVA的微縮版,主要應用於嵌入式開發,比如手機程序的開發。目前來說就業範圍不是很廣,在一些城市可能相對的不好找工作。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"JAVA EE:也叫JAVA的企業版,它提供了企業級應用開發的完整解決方案,比如開發網站,還有企業的一些應用系統,是JAVA技術應用最廣泛的領域。主要還是偏向於WEB的開發,而JAVA EE的基礎就是JAVA SE,所以我們在學習JAVA SE的時候,基礎一定要打好,因爲這是最基本的,也是最核心的。","attrs":{}}]}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Java SE:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"經過這麼多的介紹,相信大家已經很明白,如果學習JAVA的目的是爲了就業,我們應該先學好JAVA SE,然後繼續學習JAVA EE。精髓在於多思考,多練習,不要怕會出錯,沒有完美的程序,都是不斷的在改進,不斷的在完善,出錯是好事,這樣你可以瞭解更多的異常情況和突發情況,可以爲日後工作中出現問題時及時解決積累足夠的經驗。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"最後希望大家在學習程序開發的時候,要有一定勇於探索的精神,搞不懂的問題可以自己先思考(程序開發的核心也是在於不斷思考),實在搞不懂可以在網上查詢,也可以和大家討論,但是不要太過於較真,畢竟學海無涯,你永遠都學不完所有的東西,要勞逸結合,不要讓自己過於疲憊,爲了學習更多的東西犧牲健康,那是偉人才會做的事情,得不償失。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"JDK 和 JRE","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我們回頭看看我們JavaSE的圖。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/7e/7e6d9039b7f83c5f10ab4e79cdf04d12.png","alt":null,"title":"點擊查看源網頁","style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"JDK","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Java 2 SDK (Development Kit)包含","attrs":{}},{"type":"text","text":":JRE的超集,包含編譯器和調試器等用於程序開發的文件","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"JRE","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Java Runtime Environment (JRE) 包含","attrs":{}},{"type":"text","text":":Java虛擬機、庫函數、運行Java應用程序和Applet所必須文件","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Java運行環境的三項主要功能:","attrs":{}}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"加載代碼:由class loader 完成;","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"校驗代碼:由bytecode verifier 完成;","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"執行代碼:由 runtime interpreter完成。","attrs":{}}]}],"attrs":{}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"區別和聯繫:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"sdk(也就是jdk)是jre的超集","attrs":{}},{"type":"text","text":",是在jre的基礎上增加了編譯器及其他一些開發工具。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"jre就是java運行時環境,包括了jvm和其它一些java核心api,任何一臺電腦,只有安裝了jre纔可以運行java程序.如果只是要運行JAVA程序,之需要JRE就可以。 JRE通常非常小,也包含了JVM.如果要開發JAVA程序,就需要安裝JDK。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"初識JVM(JAVA Virtual Machine)","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"JVM是一種規範,可以使用軟件來實現,也可以使用硬件來實現,就是一個虛擬的用於執行bytecodes字節碼的計算機。他也定義了指令集、寄存器集、結構棧、垃圾收集堆、內存區域。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"JVM負責將java字節碼解釋運行,邊解釋邊運行,這樣,速度就會受到一定的影響。JAVA提供了另一種解釋運行的方法JIT(just in time),可以一次解釋完,再運行特定平臺上的機器碼,高級的JIT可以只能分析熱點代碼,並將這些代碼轉成本地機器碼,並將結果緩存起來,下次直接從內存中調用,這樣就大大提高了執行JAVA代碼的效率。這樣就實現了跨平臺、可移植的功能。","attrs":{}}]},{"type":"blockquote","content":[{"type":"numberedlist","attrs":{"start":1,"normalizeStart":1},"content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"JVM是指在一臺計算機上由軟件或硬件模擬的計算機;它類似一個小巧而高效的CPU。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"byte-code代碼是與平臺無關的是虛擬機的機器指令。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":3,"align":null,"origin":null},"content":[{"type":"text","text":"java字節代碼運行的兩種方式:","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":4,"align":null,"origin":null},"content":[{"type":"text","text":"1)方式interpreter(解釋)","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":5,"align":null,"origin":null},"content":[{"type":"text","text":"2)Just-in-time(即時編譯):由代碼生成器將字節代碼轉換成本機的機器代碼,然後可以以較高速度執行。","attrs":{}}]}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"JAVA的跨平臺實現的核心是不同平臺使用不同的虛擬機不同的操作系統有不同的虛擬機。Java 虛擬機機制屏蔽了底層運行平臺的差別,實現了“一次編譯,隨處運行”。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"欲工善其事必先利其器,我們先把我們的環境搭建好,才能開始咱們的征程!","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"Java開發環境搭建","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"百度搜索JDK,找到下載地址,瀏覽Oracle的網站。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#9254DE","name":"purple"}}],"text":"https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"numberedlist","attrs":{"start":1,"normalizeStart":1},"content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"選擇版本(我們採用JDK8)","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"同意協議(流氓協議)","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":3,"align":null,"origin":null},"content":[{"type":"text","text":"查看電腦的環境(64位,還是32位等等)","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":4,"align":null,"origin":null},"content":[{"type":"text","text":"下載安裝包","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":5,"align":null,"origin":null},"content":[{"type":"text","text":"安裝JDK ,JRE (改安裝目錄,注意規範,作爲一個程序人,規範很重要。所以給電腦上環境單獨分類最好,)","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":6,"align":null,"origin":null},"content":[{"type":"text","text":"配置電腦的環境變量 :","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":7,"align":null,"origin":null},"content":[{"type":"text","text":"環境變量-->添加 JAVA_HOME (JDK的安裝地址:D:Environmentjavajdk1.8.0_201)","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":8,"align":null,"origin":null},"content":[{"type":"text","text":"配置path:%JAVA_HOME%bin ;%JAVA_HOME%jrebin","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":9,"align":null,"origin":null},"content":[{"type":"text","text":"測試是否安裝成功:","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":10,"align":null,"origin":null},"content":[{"type":"text","text":"輸出 java –version 查看版本信息,是否成功輸出!","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":11,"align":null,"origin":null},"content":[{"type":"text","text":"安裝notpad++,或者一個好用的文本編輯器,最好不要用記事本,很不方便!","attrs":{}}]}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"HelloWorld","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"環境安裝好了,測試代碼一定要寫HelloWorld!代表你向這個世界的吶喊,儀式感很重要,就像你生活","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"中和家人,朋友,妻子在節日中或者紀念日一定要做一些事情,這就是儀式感,所以各位來跟着我寫哈!","attrs":{}}]},{"type":"blockquote","content":[{"type":"numberedlist","attrs":{"start":1,"normalizeStart":1},"content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"我們先隨便建立一個文件夾,放我們的代碼","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"新建文件 Hello.java","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":3,"align":null,"origin":null},"content":[{"type":"text","text":"編寫我們的HelloWorld程序!","attrs":{}}]}]}]}],"attrs":{}},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"public class Hello{\n\npublic static void main(String[] args){\n\nSystem.out.println(\"Hello,World!\");\n\n}}","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"4.保存文件,打開命令行,利用javac編譯!","attrs":{}}]},{"type":"blockquote","content":[{"type":"numberedlist","attrs":{"start":1,"normalizeStart":1},"content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":" javac Hello.java","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":" # 如果沒有報錯,查看文件夾下是否有新的一個文件","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":3,"align":null,"origin":null},"content":[{"type":"text","text":" # Hello.class","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":4,"align":null,"origin":null},"content":[{"type":"text","text":" # 如果沒有出現,恭喜!說明你遇到了你在學Java當中的第一個Bug","attrs":{}}]}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"5.java 執行!","attrs":{}}]},{"type":"blockquote","content":[{"type":"numberedlist","attrs":{"start":1,"normalizeStart":1},"content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"1 java Hello","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"2 # 成功輸出Hello,World!","attrs":{}}]}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果出現錯誤,檢查字母大小寫是否有錯誤,或者是否標點符號錯誤,文件名錯誤等等,一定要確保成功輸出,我們之後再來研究,它是怎麼輸出的!","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"編寫 Java 程序時,應注意以下幾點:","attrs":{}}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"大小寫敏感","attrs":{}},{"type":"text","text":":Java 是大小寫敏感的,這就意味着標識符 Hello 與 hello 是不同的。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"類名","attrs":{}},{"type":"text","text":":對於所有的類來說,類名的首字母應該大寫。如果類名由若干單詞組成,那麼每個單詞的首字母應該大寫,例如 MyFirstJavaClass 。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"方法名","attrs":{}},{"type":"text","text":":所有的方法名都應該以小寫字母開頭。如果方法名含有若干單詞,則後面的每個單詞首字母大寫。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"源文件名","attrs":{}},{"type":"text","text":":源文件名必須和類名相同。當保存文件的時候,你應該使用類名作爲文件名保存(切記Java 是大小寫敏感的),文件名的後綴爲 .java。(如果文件名和類名不相同則會導致編譯錯誤)。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"主方法入口","attrs":{}},{"type":"text","text":":所有的 Java 程序由 public static void main(String []args) 方法開始執行。","attrs":{}}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"JAVA程序運行機制","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"計算機的高級編程語言類型: 編譯型 ,解釋型. Java 語言是兩種類型的結合;","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"【科普:編譯型 ,解釋型】","attrs":{}}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"字面上看,“編譯”和“解釋”的確都有“翻譯”的意思,它們的區別則在於翻譯的時機安排不大一樣。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"我們先看看編譯型","attrs":{}},{"type":"text","text":":有一個負責翻譯的程序來對我們的源代碼進行轉換,生成相對應的可執行代碼。這個過程說得專業一點,就稱爲編譯(Compile),而負責編譯的程序自然就稱爲編譯器(Compiler)。就類似於把一本中文書直接翻譯成英文版進行出售。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"現在再看看解釋型","attrs":{}},{"type":"text","text":":打個比方:假如你打算閱讀一本外文書,而你不知道這門外語,那麼你可以找一名翻譯,給他足夠的時間讓他從頭到尾把整本書翻譯好,然後把書的母語版交給你閱讀(編譯型);或者,你也立刻讓這名翻","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"譯輔助你閱讀,讓他一句一句給你翻譯,如果你想往回看某個章節,他也得重新給你翻譯。(解釋型)","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":" 編譯型與解釋型","attrs":{}},{"type":"text","text":",兩者各有利弊。前者由於程序執行速度快,同等條件下對系統要求較低,因此像開發操作系統、大型應用程序、數據庫系統等時都採用它,像C/C++、Pascal/Object 、Pascal(Delphi)、VB等基本都可視爲編譯語言,而一些網頁腳本、服務器腳本及輔助開發接口這樣的對速度要求不高、對不同系統平臺間的兼容性有一定要求的程序則通常使用解釋性語言,如Java、JavaScript、VBScript、Perl、Python等等。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Java語言雖然比較接近解釋型語言的特徵,但在執行之前已經預先進行一次預編譯,生成的代碼是介於機器碼和Java源代碼之間的中介代碼,運行的時候則由JVM(Java的虛擬機平臺,可視爲解釋器)解釋執行。它既保留了源代碼的高抽象、可移植的特點,又已經完成了對源代碼的大部分預編譯工作,所以執行起來比“純解釋型”程序要快許多。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 總之,隨着設計技術與硬件的不斷髮展,編譯型與解釋型兩種方式的界限正在不斷變得模糊。","attrs":{}}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"第一步:編譯","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"利用編譯器(javac)將源程序編譯成字節碼à 字節碼文件名:源文件名.class","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"第二步:運行","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"利用虛擬機(解釋器,java)解釋執行class字節碼文件。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"總結","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"1.我們瞭解了計算機的發展史","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"2.看到了Java帝國的誕生","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"3.瞭解了Java這門語言的特性","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"4.跟着歷史看懂了Java的三大版本","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"5.安裝了Java的開發環境","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"6.寫了自己的第一個程序HelloWorld!","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"7.知道了編譯型和解釋型語言的區別","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"當然,我認爲這些都不是最重要的,關鍵是,今天我們踏出了第一步,我看過這樣一個故事:一個原始人擡頭仰望星空,宇宙發出了警告!人類問爲什麼,宇宙使者說:從他擡頭仰望星空開始,整個人類的發展就不過是爲了實現他的願望而已!所以,只要確定了方向,只要不停下腳步,我們終會抵達終點,實現自己的夢!","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"好了本期內容就分享到這裏,我們下期見!","attrs":{}}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章