Download presentation
Presentation is loading. Please wait.
Published byStephany Rodgers Modified over 9 years ago
1
Java Tutorial 1 2004/10/21
2
Java Resource Java SDK –Download from http://www.javasoft.comhttp://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]); }
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.