1 / 10

Java 程式的撰寫、編譯與執行

Java 程式的撰寫、編譯與執行. 陳富國. Java 基本概念. Java 的歷史與簡介 http://zh.wikipedia.org/zh-tw/Java Write once, run anywhere! 跨平台,同樣的程式,不用經過重新編譯,可以在不同的作業系統上 (Windows/Linux/Mac OS) 執行。 在文字模式下,進行程式的開發 ( 學習階段 ) 。 有類似 Visual C++/C# 的視窗式開發環境 JCreator Eclipse Sun NetBeans IntelliJ IDEA JBuilder.

amil
Download Presentation

Java 程式的撰寫、編譯與執行

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java程式的撰寫、編譯與執行 陳富國

  2. Java 基本概念 • Java的歷史與簡介 http://zh.wikipedia.org/zh-tw/Java • Write once, run anywhere! • 跨平台,同樣的程式,不用經過重新編譯,可以在不同的作業系統上(Windows/Linux/Mac OS)執行。 • 在文字模式下,進行程式的開發(學習階段)。 • 有類似Visual C++/C#的視窗式開發環境 • JCreator • Eclipse • Sun NetBeans • IntelliJ IDEA • JBuilder

  3. Java程式在文字模式下的開發 • 用文字編輯器編寫程式碼 (.java檔) • 使用javac編譯程式 (產生.class檔) • 使用java(Java程式的執行環境)執行編譯好的程式

  4. HelloWorld.java public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); } }

  5. Java編譯與執行環境的安裝 • 下載並執行jdk-1_5_0_22-windows-i586-p.exe • 放在課程網頁中的共享文件夾 • 設定安裝目錄在c:\jdk • 用較簡短的目錄以方便操作 • 裝完後,最重要的二個程式javac(編譯器)與java(執行環境)在c:\jdk\bin下

  6. 用notepad編輯HelloWorld.java • 進入命令列文字模式 • 執行->cmd 或 從 開始->附屬應用程式->命令提示字元進入 • 下指令 • notepad HelloWorld.java • 輸入HelloWorld.java的內容,存檔!

  7. 檢查HelloWorld.java • 下 dir • 下 • type HelloWorld.java

  8. 編譯HelloWorld.java • 下指令 • C:\jdk\bin\javac HelloWorld.java 沒有錯誤訊息即表示編譯成功! • 此時,目錄應該新產生一個檔HelloWorld.class

  9. 執行HelloWorld • 下指令 • C:\jdk\bin\java HelloWorld • 記住,不可以下 C:\jdk\bin\java HelloWorld.class

  10. 附註:在電腦教室中學習Java • 電腦教室中裝了多版的JDK與JRE,我們要使用的是JDK 1.5以上的版本 • 為了不要像上面的方式以絕對路徑下javac和java,我們要在我們系統的環境變數上設定指令搜尋路徑:PATH=…

More Related