Java Programming (Part 1) Introduction - PowerPoint PPT Presentation

1 / 72
About This Presentation
Title:

Java Programming (Part 1) Introduction

Description:

Java Programming (Part 1) Introduction http://www.ywdeng.idv.tw joseph.deng_at_gmail.com * * Object[] possibleValues = { IDctSdk.KeyboardCaseOptions.ToUpper ... – PowerPoint PPT presentation

Number of Views:462
Avg rating:3.0/5.0
Slides: 73
Provided by: Jos686
Category:

less

Transcript and Presenter's Notes

Title: Java Programming (Part 1) Introduction


1
Java Programming (Part 1)Introduction
  • ???
  • http//www.ywdeng.idv.tw
  • joseph.deng_at_gmail.com

2
????
  • Java ????
  • Java ????
  • ??????Hello Java !
  • Java ??????
  • ???????
  • ???????
  • ????
  • ????? Java ??
  • ????????? Hello Java !

3
????
  • ??? ?,Java SE6 ????,????,2007?,??
    ACL023000,ISBN 9789861811321
  • ??? ?, Java SE 6.0????????,????,2009?,??
    AEL006900 ,ISBN 9789861816104

4
Java ????Java ???
  • 1995 ??? by Sun Microsystems
  • ?? Oak,Project Green,?????????
  • ?? James Gosling
  • Java ???????
  • Java Applet??????????
  • JavaScriptNetscape, ????????

5
Java ??????????
  • ?????? I/O??? Pointer
  • ???Java ???????(VM)???,????????????,????? Java
    ??
  • ???????????
  • API ??,????????,??????
  • ??,??? Exception Handling ??
  • ????(Multithread)
  • ??????

6
Java ????Java ????
  • Java ?????????????
  • ???????????? Java ??,??????? Java ??????????
  • ????????(The College Board)???????????????????????
    ,??? Java ???????????

7
Java ????Java ???
  • JAVA SE(Java Platform, Standard Edition)
  • ???????GUI????????
  • JAVA EE(Java Platform, Enterprise Edition)
  • N-Tier Applications?Web Applications?
  • JAVA ME(Java Platform, Micro Edition)
  • PDA????Smart Card?

8
JAVA ????
  • JDK 1.21.4 ?????,?? J2SE(Java 2 Platform,
    Standard Edition)
  • J2SE 5.0(Java 2 Platform Standard Edition
    5.0)??JDK??J2SE Development Kit 5.0
  • ?Java SE 6(Java Platform, Standard Edition
    6)???JDK6????Java SE Development Kit 6
  • ????2????,???6?1.6.0???
  • 6?????(Product Version),?1.6.0??????(Developer
    Version)

9
Java Platform Edition
??http//thisjava.blogsome.com/2005/03/28/java-tec
hnology/
10
Java Platform Products
11
Java ????Java ????
??http//www.sun.com/training/certification/java/i
ndex.xml
12
JAVA ????
  • JDK
  • http//java.sun.com
  • ???,?? JAVA_HOME ????
  • Online Document
  • NetBeans
  • http//www.netbeans.org
  • Eclipse
  • http//www.eclipse.org

13
??JDK (1)
  • JDK Java Development Kit ????
  • JRE Java Runtime Environment ????
  • ??JRE?????????????
  • JDK???????JRE
  • ??JDK??????jre????
  • JDK?????JRE???JRE???Server?VM(Virtual
    Machine)????

14
??JDK (2)
15
JDK?????
  • ?bin???
  • JDK?????
  • ?demo???
  • ????
  • ?jre???
  • JDK?????JRE
  • ?db???
  • Apache Derby???,?Java???????

16
JDK?????
  • ?lib???
  • ???????????Java????
  • JDK??????,?????Java?????
  • bin?????????,???????(Wrapper)
  • ??javac.exe????,?????lib???tools.jar??????

17
JDK?????
  • src.zip
  • Java???API???????????

18
?? JAVA_HOME ????
  • JAVA_HOME ??????? JDK ?????

19
?? Path ???? (1)
  • ???javac????
  • ???????? Path ????

20
?? Path ???? (2)
  • Windows???JRE?,??java.exe????C\Windows\System32\?
    ????,??????Path?????????

21
?? CLASSPATH ???? (1)
  • Java???????????,??????????????????Java??
  • ??Path???????????????????(??Windows ?? exe)
  • ??classpath???????Java?????????Java??(JVM
    ??class)

22
?? CLASSPATH ???? (2)
  • JDK 6 ??????????,??JDK??lib??????Java??
  • Classpath ????????? JAR ???
  • ????????????
  • javac -classpath path1path2
  • ????????????
  • java -classpath path1path2

23
?? CLASSPATH ???? (3)
24
?? Windows ????????????
25
Java ????
  • ??????Hello Java !
  • Java ??????
  • ???????
  • ???????
  • ????
  • ????? Java ??
  • ????????? Hello Java !

26
??????Hello Java !
public class Hello public static void
main(String args) System.out.println("Hell
o Java !")
27
Java ??????
  • ???????????(Class)
  • Source file ??????? Class ?????,?????????,????
    .java?
  • public static void main(String args) ???????
  • main method ?????? public static
    void,???????????? class loader ??,??????????,?????
    ?????
  • System ?????,out ? stdout,println ????????
  • JRE class loader ???? class name ????????

28
????
  • CD ????(Change Directory)
  • CD C\
  • DIR ??????(Directory)
  • javac ?? JAVA ???(Java Compiler)
  • javac Hello.java
  • java ?? JAVA
  • java Hello

29
????? Java ??
  • To compile
  • javac Hello.java
  • To run
  • java Hello
  • javaw Hello (GUI ?)

30
JAVA ????????
31
????? Java ??????
32
JAVA ??????
33
(No Transcript)
34
?????????????
  • boolean The value is true or false. ??
  • char 16-bit Unicode. ?????
  • byte 8-bit signed integer. ????
  • short 16-bit signed integer.
  • int 32-bit signed integer.
  • long 64-bit signed integer.
  • float 32-bit signed floating point number. ???
  • double 64-bit signed floating point number.

35
Wrapper Classes????
  • Character
  • ?????? char
  • Integer, Short, Byte and Long
  • ?????? int, short, byte, long
  • Float and Double
  • ??????? float, double

36
Scalar V.S. Object
  • 123 ? Literal(???)
  • int n 123 ? Scalar(??)
  • String s "123" ?????
  • Integer n new Integer(123) ?????

37
Scalar V.S. Object(?)
  • ???????????
  • String s "123"
  • String z s s // z ??? "123123"
  • double d Double.parseDouble(s)
  • int i Integer.parseInt(s)
  • double x d i // x ??? 123123 246
  • ??????? Collection(??)??
  • Vector v new Vector()
  • v.add(new Integer(123))

38
Autoboxing ?????????
public class Boxing public static void
main(String args) Integer i new
Integer(10) System.out.println(i.intValue
() 10)
public class AutoBoxing public static void
main(String args) Integer i 10
System.out.println(i 10)
39
?????????
  • TypeName variableName INI_VALUE
  • double mathScore 75.5
  • ClassName variableName INI_VALUE
  • String authorName "Bill Day"
  • ClassName varName new ClassName() // ????
  • Hashtable ht new Hashtable()
  • ????
  • ClassName ???????????
  • variableName ???????????(Camel Naming ?????)
  • CONSTANT_NAME ????????

40
?????????(Constant Literal)
  • final int PASS_SCORE 60
  • final long LONG_ONE 14L
  • final int HEX_MASK 0x0e
  • final int OCT_MASK 016
  • final float PI 3.14F
  • final double PI 3.14
  • final double PI 314e-2
  • final String LANGUAGE "Java"

41
????
  • ????
  • gt lt gt lt
  • ??????
  • !
  • ??(???????????)
  • ??(???????????)

42
????
  • ????
  • - /
  • ???????
  • 5 2 ??? 1

43
??????????????
15 L ., , (args), (post), (post)-- 14 R
(pre), --(pre), (Positive), -(negative), ,
! 13 R new, (type) 12 L , /, 11 L ,
- 10 L ltlt, gtgt, gtgtgt 9 L lt, lt, gt, gt,
instanceof 8 L , ! 7 L 6 L 5 L
4 L 3 L 2 R ? 1 R , , /,
, , -, ltlt, gtgt, gtgtgt, , ,
44
??????????
  • int x 5
  • x x 1
  • x ltlt 2
  • boolean hitTop false
  • String baseName null
  • x
  • abs (a gt 0) ? a -a

45
????if-then-else
if (a gt b) // A else // B // C
if (a gt b) // A // C
46
public class EvenOdd public static void
main(String args) if (args.length !
1) System.err.println("????????")
System.exit(1) int
i Integer.parseInt(args0) String msg
(i 2 0) ? "??" "??"
System.out.println("" i " is an "
msg " number.")
args.length ? args ???? Integer.parseInt()
???????? ???????? ??????? System.err ?
stderr????????
47
???????
  • ??????(stdin)
  • ??? Console(???)
  • ???? Input Redirect(??????)????(Keyboard)
  • ??????(stdout)
  • ??? Console(???)
  • ???? Output Redirect(??????)????(tty)
  • ??????(stderr)
  • ??? Console(???)
  • ??? Output Redirect
  • ?? http//en.wikipedia.org/wiki/Standard_streams

48
????nested if-else, switch-case
switch (a) case 0 // A break
case 1 // B break case 2
// C break default // D
if (a 0) // A else if (a 1)
// B else if (a 2) // C else
// D
if (a 0) // A else if (a 1)
// B else if (a 2)
// C else
// D
Nested ??
49
??
  • ?????????????
  • ?? gt 60 ???
  • ?? lt 59 ????
  • ?? gt 100 ? lt 0 ??????
  • ???????? String args ??
  • ????
  • java Score 80
  • java Score 123
  • java Score 59

50
????while ? do-while ??
while (A) // B
do // B while (A)
51
????for ??
for (A B C) // D
for (int i 0 i lt names.length i)
System.out.println("Hello "namesi)
52
??
  • ???
  • ???????????????
  • ????
  • java Echo 1 2 3 4??1 2 3 4
  • ???
  • ?????????
  • ????
  • java Echo 1 2 3 4??4 3 2 1

53
????break ? continue
54
??
  • ????????????????????
  • ???????????
  • ?????,???????
  • ?????????????
  • 0 ???
  • ????
  • java Even 1 2 3 4??2 4
  • java Even 2 3 0 -1 4 5??2 0

55
??
  • ???? Java ??,??????????????????
  • ????
  • java Sum 1 2 3 4????? 10??? 2.5

56
??
  • ???? Java ??,?????? 1 ? 10 ?????,??1234567
    891055
  • ???? Java ??,?????? 1 ? n ?????,?? n
    ?????????????????

57
Java Applet
  • Application Let
  • ??????????????

58
HelloApplet.java
import java.applet.Applet import
java.awt. public class HelloApplet extends
Applet public void paint(Graphics g)
g.drawString("Hello Applet !!", 50, 50)
59
HelloApplet.html
lthtmlgt ltheadgtlttitlegtApplet Demolt/titlegtlt/headgt ltbo
dygt ltapplet codebase"classes" code"HelloApplet.c
lass" width"350" height"200"gt This browser does
not appear to support Applets. lt/appletgt lt/bodygt lt
/htmlgt
60
Applet ???
ltHTMLgtltHEADgtltTITLEgtApplet ???lt/TITLEgtlt/HEADgt ltBODY
gt ltAPPLET CODE"HelloApplet2" HEIGHT"200"
WIDTH"200"gt ltPARAM NAME"name"
VALUE"???"gtlt/APPLETgt lt/BODYgt lt/HTMLgt
61
HelloApplet2.java
import javax.swing. import java.awt. public
class HelloApplet2 extends JApplet private
String name null public void paint(Graphics
g) g.drawString(name " ??!", 100, 100)
public void init() this.name
this.getParameter("name")
62
??UIJavax.swing.JOptionPane
  • showConfirmDialog
  • ????, yes/no/cancel.
  • showInputDialog
  • ????
  • showMessageDialog
  • ????
  • showOptionDialog
  • The Grand Unification of the above three.

63
JOptionPane
import javax.swing. public class Square
public Square() String s
JOptionPane.showInputDialog("???????") int n
Integer.parseInt(s) int nn n n
JOptionPane.showMessageDialog(null, s "
???? " nn, "?????",
JOptionPane.PLAIN_MESSAGE) public static
void main(String args) Square square new
Square()
64
class ConfirmExit implements Application.ExitListe
ner public boolean canExit(EventObject e)
if (dctsdk.isServerOnLine()) int option
JOptionPane.showConfirmDialog(
getFrame(), "Do you really wants
exit?", "Confirmation Required",
JOptionPane.YES_NO_OPTION) if (option
JOptionPane.YES_OPTION)
dctsdk.stopServer() else
return false return true
public void willExit(EventObject e) //
ask for confirmation on exit getApplication().addE
xitListener(new ConfirmExit())
65
(No Transcript)
66
Object possibleValues IDctSdk.KeyboardCase
Options.ToUpper " ????", IDctSdk.KeyboardCaseO
ptions.ToLower " ????", IDctSdk.KeyboardCaseOp
tions.Intact " ???", IDctSdk.KeyboardCaseOptio
ns.Inverse " ?????" String selectedValue
(String) JOptionPane.showInputDialog(this.getFrame
(), "????????????????", "????????",
JOptionPane.INFORMATION_MESSAGE, null,
possibleValues, possibleValues0) String ss
selectedValue.split(" ") if (ss0.equals(IDctSdk
.KeyboardCaseOptions.ToUpper.toString()))
dctsdk.setKeyboardCase(IDctSdk.KeyboardCaseOptions
.ToUpper.ordinal()) else if (ss0.equals(IDctS
dk.KeyboardCaseOptions.ToLower.toString()))
dctsdk.setKeyboardCase(IDctSdk.KeyboardCaseOptions
.ToLower.ordinal()) else if (ss0.equals(IDctS
dk.KeyboardCaseOptions.Inverse.toString()))
dctsdk.setKeyboardCase(IDctSdk.KeyboardCaseOptions
.Inverse.ordinal()) else
dctsdk.setKeyboardCase(IDctSdk.KeyboardCaseOptions
.Intact.ordinal()) setStatusMessageKeyboardCase
(dctsdk.getKeyboardCase())
67
(No Transcript)
68
? BufferedReader ? Console ??????
BufferedReader con new BufferedReader( new
InputStreamReader(System.in))
String s con.readLine() int n -1 try
n Integer.parseInt(s) catch
(NumberFormatException ex) ex.
printStackTrace()
69
? Scanner? Console ????
  • java.util.Scanner

Scanner sc new Scanner(System.in) int i
sc.nextInt()
Scanner sc new Scanner(new File("myNumbers")) w
hile (sc.hasNextLong()) long aLong
sc.nextLong()
70
??
  • ???? Java ??,?????? 1 ? n ?????,??
    n101234567891055
  • ??/????
  • ? JOptionPane ?? n ?,JOptionPane ??
  • ??
  • ? Integer.parseInt() ???????

71
??
  • ?????,??????????,???????????????????
  • ??
  • Integer.toBinaryString(number) ???
  • Integer.toOctalString(number) ???
  • Integer.toHexString(number) ????

72
??
  • ???????
  • ???????
  • ????? \t ??
Write a Comment
User Comments (0)
About PowerShow.com