Title: Java ???????????
1Java ???????????
2????????http//www.uestc.edu.cn/web3/
3????
- Java 2????(???),?????,???,???????,2006.8?
- Java????(???),???Thinking in JAVA,Second
Edition,??Bruce Eckel,????? ,???????,2007.6? - Java??????(?5?),???Java How to Program,Fifth
Edition,?? H.M.Deitel,P.J.Deitel,?????,???,???,?
??????,2004.3? - Java???????,???Distributed Programming with
Java,??Qusay H.Mahmoud,?????,??,???????,2002.1?
4??? Java??
- Java???????
- Java?????
- J2EE????
- Java????(JDK)??
- Java????
- Application??
- Applet??
- Java?????
51.1 Java???????
- Java??????????????,??????Internet???????
- ?????????????????????????????
- ?????,???????????????????????,?????????????????
6????
- 1991?,SUN??????James Gosling,?C?????,?????
????????????????????????oak(Java)?
7????
- 1994?Web???,SUN??????Bill Joy (Berkeley
Unix????)??Oak??????Web????????????????,Oak???????
?????Applet??????,??Applet???????????? - 1995?1?,Sun????Oak?????????,Oak???Java
- Java????????????Java applet?Web??? Hotjava?
8????(?)
- 1995?5?,Sun???San Francisco???Sunworld????????Java
??? - ??????Netscape???????Web????????Java,????,Navigato
r 2.0?????Java? - ??,Sun?SGI? Macromedia ????????????Java???????????
????????,?IBM?Microsoft?Novell?Oracle?Borland?,???
????Java? - 12?,Sun?Netscape?????????????????????JavaScript?
9????(?)
- 1996?1?,???Java?????(Java Development
Kit)JDK1.0??? - 1996?4?,10??????????????????????Java??1996?9?,?8.
3???????Java?????? - 1997?2?18?,JDK1.1???
- 1997?4?2?,JavaOne????,???????,???????????????
- 1997?9?,Java Developer Connection?????????
- 1998?2?,JDK1.1?????2,000,000??
10????(?)
- 1998?12?4?,JDK1.2????,???Java2??????
- 1998?12?8?,Java2?????J2EE???
- 1999?6?,SUN????Java?????
- J2SE(Java 2 Standard Edition)????????????????API?
???? - J2EE(Java 2 Enterprise Edition)?????J2SE????,????
???????????????????????????? - J2ME(Java 2 Micro Edition)???????????????????????
?API?????,?????????????PDA????????????????????J2SE
???? - ?Java 2???????????????????????????????,????Java???
???????,?????????,????????????
11??
- 2005?6?,JavaOne????,SUN????Java SE
6(2007??????)???,Java?????????????????2 - J2EE???Java EE
- J2SE???Java SE,
- J2ME???Java ME
121.2 Java?????
Java C - ??????? ????????
131.2.1 ???
- Java?C????,??????C?????
- Java?C??,???C????????????,????????????????????
?????????
141.2.2 ???
- Java?????C???????,???????????,?????Java???????????
?????????? - Java???????????,??????????????
- Java?????????????????????(PKC)?
- ??????????????????
- ? ?????? ? ????
- ? ??????? ? ??????
151.2.3 ????
- Java????????????????,????????????????????,????????
? - ?????????????
- ? ??????????????????,??????
- ? ?????????,???????????
- ? ???????????????????????????,
- Java???????,?????,??????????????????????????,?????
??????????
16???????????
??
??
?
?????
17????
class Car int color int
door_number int speed void brake()
void speedUp() void slowDown()
18class Car int color_number int
door_number int speed void brake()
void speedUp() void slowDown()
Car myCar new Car() myCar. speedUp()
myCar.brake()
19Java?????
- ?
- ??Java????????,???Java???????
- ??Java?????,Java?????Java???
- ??????????????
- ??
- ????????,??????????????????
- ??????????,???????????,?????????
- ??????????????????,?????????????????
20????
- ???????????
- ?????????????????????
- ??????????
- ??????
- ???????,
- ???????,
- ?????????????????????
21????
- ?????????????????????
- ??????????
- 1. ???????
- 2. ?????
- 3. ???????
22??????????
void doStuff ( shape s ) s.erase ( )
// s.draw ( )
- Circle c new Circle ( )
- Triangle t new Triangle ( )
- Line l new Line ( )
- doStuff ( c )
- doStuff ( t )
- doStuff ( l )
231.2.4 ???
- Java??????????,????Java?????????
- Java????????????????,?????????,?????C????,??????
??????????? - Java???????????????????????,??????????????
241.2.5 ????
- ?Java????????????????????????????????,?Java???????
????????????????--Java???(Java Virual
Machine)???? - Java?????,???????,???????,?????????
- ? Java??????????????,???????????
- ? ??????,??????????????Java???,?????????????????
251.2.6 ????
- ????
- ??Java???????,??????????????????,???????????C?C
??????????? - ???
- ? ????????,?????????????????
- ? ????????????,?????????
- ???
- Java????????????????????TCP/IP??,????URL?????????
????
261.3 J2EE?????
27J2EE??
- J2EE????????????J2EE???????????????,??????????????
J2EE?????,???????????? - J2EE???????J2EE???
- ????????applet???????????
- Java Servlet?JavaServer Pages (JSP)?????????Web???
- Enterprise JavaBean(EJB)??(enterprise
bean)???????????? - J2EE???Java??????,????????????????????
- J2EE???"???"Java??????????????J2EE?????,?????????
?J2EE??,????????,?J2EE??????????
28J2EE??
29????(?)
- ??(Container)?????????????????(????)?????????Web??
?EJB??J2EE?????????,???????????J2EE?????,???????? - J2EE?????
- EJB????J2EE?????EJB????EJB???????J2EE???????
- Web????J2EE?????JSP???Servlet??????Web???????J2EE
??????? - Application client container(?????????)??????????
????????????????????????
30????(?)
- Servlet??
- ?Java???????????,??????????????
- Servlet??????Java??,??????Java Servlet API????
- JSP(Java Server Page)
- ????????????,????????????????(???Servlet??)???(???
?),??????? - ?????????,?????????
- ??JSP?????,????????????????
31????(?)
- EJB(Enterprise JavaBeans)--J2EE????
- EJB ???????????????CORBA ? RMI ????? java ???EJB
????????,??????? JavaBeans ????????? - EJB ????????????????????????????,????????????(?
servlets),??? HTML ???? JSP ??,??????? AWT?Swing
??? java ??????? - ??? EJB ??????????????????????????????????????????
?????,????????????
32(No Transcript)
33Java ??????(IDE)
- Eclipse(IBM)
- 2001?6?,IBM???4000????Eclipse??????? ?3.2
- NetBeans (Sun )
- 5.5
- JBuilder
341.4 Java????(JDK)??
- Java???javac
- Java???java
- Java????javap
- ????????AppletViewer
35(No Transcript)
36Java 2 ??
- ?????,?????????
- ????????Sun?Solaris?Microsoft?windows???Linux????
???,?IBM AIX?HP-Unix?? - JDK??Java?????(????????)??????
- Java?????????????,????????????????JVM???????
- JDK??????
- Java???????????(Application Programming
Interface,API) - Java????JRE
37JDK???
- ?Sun????????,??
- http//java.sun.com/javase/downloads/index.jsp
- ??JDK(JDK????Java????(JRE),?JRE????????,?
Windows?Linux?Solaris? ) - ??jdk-6u6-windows-i586-p.exe
- jdk-1_5_0-windows-i586.exe
38JDK???
39JDK?????
- ??Windows 2000?XP
- ???????????,??????,????????(???????,????
),????????? - ????????????,??????????,????????????
- ???????Path,??
- C\Program Files\Java\jdk1.6.0_06\bin
- ???????????Path??,??????,?????????????,
40Java???javac
- Java?????????Java??????????
- ???????????,??????Java???(.java??)????Java???(.cla
ss??)? - ?????????????,??????????
- ?????
- javac options source_file
- javac source_name.java
- options?????
- -classpath lt????...gt ??javac??????,????????????
???,?????? - -d lt????...gt ??????????,??????
- -g ??????????,??????
- -ng ???????
- -nowarn ?????????
- -o ????
- -verbase ???????????????????????
- -debug ??????Java???jdb?
41Java???java
- ????????????????????,???Java???java???????????
- java interpreter options classname program
arguments - ??,classname???,?????.calss??????,????????
- ??????????????main()??,???????main()????
- program arguments??,??????main()????args??????,m
ain()?????? - public static void main(String args)
- Java?????????????,????????,???????????????,???????
????????,??????????????Java??????
42Java???java(?)
- -verifyremote ?????????????,?????
- -oss stacksizekm ??????????,???kbyte?mbyte
- -profltfilegt ??????????????java.prof????file??
- -help ??????
- -ss stacksizekm ??????????,???kbyte?mbyte
- -v,-verbose ?????????
- -verbosegc ??????????????
- -version ?????
- interpreter options?????
- -classpath ltpathgt ?????????
- -cs, -checksource ??????,????????????
- -debug ??????Java???jdb
- -ms initmemkm ??????????,???kbyte?mbyte
- -mx maxmemkm ??????????,???kbyte?mbyte
- -noasyncgc ????????????
- -noverify ???????
- -verify ?????????
43Java????javap
- Java????javap????????????,????????,??????
- javap options classname classname ...
- ??,classname???,???????,??????
- javap??????????,??????,?????,?????????????
- options??????
- -p ???????????,????????????????
- -c ???????????
- -classpath ??javap???????????,???zip?????
- -l ????(?-o??????)??????(?-g??????)?
-public ??public???????? -protected
??protected???????? -package ????? -private
??private???????? -version ?????? -verigy
???????
44????????AppletViewer
- applet??Java????????,???????????AppletViewer????Ja
va?WWW??????? - ??????????????HTML????applet,??????
- appletviewer -debug urls
- ??,-debug????,???????????????JDb(Java???)????,????
???HTML???????applet? - urls?Internet??????????????
451.5 Java????
- Java???????
- ????Java????????Java application
- Java application???????Java??,??????????,????????
????main()??,main()????C???main?????Java
application??????? - ???????Web???,?Java?????????Java applet?
46application????????? (?)
- 1.??????Java?application???(.java??)
- ???????HelloWorldApp.java???,??????????????????Jav
a????? - import java.io.
- class HelloWorldApp
- public static void main(String args)
-
- System.out.println("Hello, World !")
-
-
- ??????????HelloWorldApp?,????????????????(?HelloWo
rldApp.java??)?
47application????????? (?)
- 2.??????????Java???(.java)?????
- ?????Java????Java???(.java)???????????????(.class)
???????,?????????????.class????????????????? - javac HelloWorldApp.java
- ??????????,????????HelloWorldApp.class????????????
????
48application????????? (?)
- 3.????????????????????(.class)
- ?Java???java?Java?????(.class)?????
- ??????HelloWorldApp.class??,?????java?????,???????
- java HelloWorldApp
- ?????,????????????
- Hello, World !
- Java?????????,????????,??????,??????java????????,?
??????????(HelloWorldApp.class)?????????????
49applet?????????(?)
- 1.??????HTML????
- ????????????HTML??,???HTML????????,???????
- ?UNIX???
- mkdir -/HTML
- cd -/HTML
- ?Windows 95/NT?DOS???
- md \HTML
- cd \HTML
- ????????HTML????,??????????
50applet?????????(?)
- 2.??Java?applet???(.java??)
- ???????????applet????,???????????main()???????????
?Applet???,??????????????extends Applet??? - ??,Applet????,???????,???????????????
- extends????,??????????????
51applet?????????(?)?
- 2.??Java?applet???(.java??)
- ????????????HTML??????????HelloJavaApp.java?applet
?????? - import java.awt.Graphics
- import java.applet.Applet
- public class HelloJavaApp extends Applet
-
- public void paint(Graphics g)
-
- g.drawString("Hello, Java Applet World
!",50,25) -
-
52applet?????????(?)
- 3.??????????applet???(.java)?????
- ?Java????Java?applet???(.java)???????????????(.cla
ss)? - ??????,?????????????.class????????????application?
????????? - ???????
- javac HelloJavaApp.java
- ??????HelloJavaApp.class????????????????
53applet?????????(?)
- 4.?????applet???HTML???
- ????applet?????,???HTML???,??????????
- ?????????HelloJava.html?,???HelloJavaApp.class????
? - ltHTMLgt
- ltHEADgt
- ltTITLEgt A Simple Program lt/TITLEgt
- lt/HEADgt
- ltBODYgt
- ltAPPLET CODE"HelloJavaApp.class" WIDTH500
HEIGHT200gt - lt/APPLETgt
- lt/BODYgt
- lt/HTMLgt
54applet?????????(?)
- ?Java???????URL?,??????????HTML??
- C\HTML\HelloJava.html
55applet?????????(?)
- ??,JDK???????????Web?????Applet?????AppletViewer,
?????????????????????,???????
AppletViewer HelloJava.html
56Java Applet??????
57Java Application??????
581.6 Java?????
- Java???(JVMJava Virtual Machine)?????Java????????
? - Java??????Java???????JVM?????,????(byte-code),????
C?C???,?????????????????????????,???????????????
????,??????????????????,??,????????Java??????????
- Java??????????????Java????????????
591.6.1 Java????
- ????JVM??????,?????
- ?????,??????(class loader)??
- ?????,?????????????
- ?????,?????????????
- ????????????
- ???????????????????????,?????????
- ??????????????????????????????????????
601.6.2 Java?????
- Java????????Java???????????????????
- Java???????????Java?????????byte?short?long?int?b
oolean?float?double?char,????????????????? - Java???????Object???????????
- Java????????????????,?????????
611.6.2 Java?????
- Java??????????????????32?,long?double?????64??
- Java????????????????????????????????????
- Java??????????.java????????,Java??????????????.cla
ss?????????????????,?????Java??Java????????? - Java?????????????????????8??,???????????