1 / 10

Java Tutorial 1

Java Tutorial 1. 2004/10/21. Java Resource. Java SDK Download from http://www.javasoft.com Install Jdk-1.5.0-windows-i586.exe 設定環境變數 Set classpath=c:program filesjavajdk-1.5.0libtools.jar;c;examplelibexample.jar;. Set Path=c:program filesjavajdk-1.5.0 測試 Java Javac.

Download Presentation

Java Tutorial 1

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 Tutorial 1 2004/10/21

  2. Java Resource • Java SDK • Download from http://www.javasoft.com • Install • Jdk-1.5.0-windows-i586.exe • 設定環境變數 • Set classpath=c:\program files\java\jdk-1.5.0\lib\tools.jar;c;\example\lib\example.jar;. • Set Path=c:\program files\java\jdk-1.5.0 • 測試 • Java • Javac

  3. Java Program • Require • Program Editor • Notepad • UltraEdit • 可以編輯文字的編輯器都可以 • 檔案名稱需要與 Class 名稱相同(注意大小寫) • 副檔名需儲存為 .java • J2SE 5.0 Documentation • Java 2 Platform API Specification

  4. Example • Like C Example --------------------------------------------------------------- public class forLoop { public static void main(String args[]) { for (int count=0;count<10;count++) { Systm.out.println (“count=“+count); } } } ---------------------------------------------------------------

  5. Example(1) • forLoop.java • Class name is “forLoop”, 將 forLoop class 儲存成 forLoop.java • public static void main(args[])是程式執行的進入點 • for (int count=0;count<10;count++) { • 需要使用變數時才宣告 • Compile • Javac forLoop.java • 產生 forLoop.class 的可執行 byte code • Run • Java forLoop

  6. Java Example(2) public class forLoop2 { public static void main(String args[]) { for (int count=0;count<10;count++) { Systm.out.println (“count=“+count); } System.out.println (“”); for (int count=0;count<10;count++) { Systm.out.println (“count=“+count); } } } • Save class as “forLoop2.java”

  7. Java Standard Output • System.out • System.out.print(); • System.out.println(); • System.out.printf() • J2SE 5.0支援, 可寫跟 C 一樣的printf方式輸出

  8. Java Input public class JavaInput { public static void main(String args[]) { If (args.length>0) { System.out.println (args[0]); System.out.println (args[1]); System.out.println (args[2]); } } } • Java使用args陣列來接收外部的輸入參數 • Javac JavaInput.java • Java JavaInput I am here • 輸出 I am here • 小於三個輸入會有錯誤

  9. Course Example public class StringMatch { private String source; public void match(String taget) { for (int count=0;count<source.length();count++) { If (target.equals(source.substring(count,count+target.length()) { System.out.println (target); } } } public void setSource(String source) { this.source=source; } public static void main(String args[]) { StringMatch stm=new StringMatch(); stm.setSource(“abcabcabcabc”); stm.match(“cab”); } }

  10. Course Example(2) public class StringMatch { private String source; public void match(String taget) { for (int count=0;count<source.length();count++) { If (target.equals(source.substring(count,count+target.length()) { System.out.println (target); } } } public void setSource(String source) { this.source=source; } public static void main(String args[]) { StringMatch stm=new StringMatch(); stm.setSource(“abcabcabcabc”); stm.match(args[0]); } }

More Related