Java Tutorial - Spring 2000Part 1- Introduction to Java .ppt
《Java Tutorial - Spring 2000Part 1- Introduction to Java .ppt》由会员分享,可在线阅读,更多相关《Java Tutorial - Spring 2000Part 1- Introduction to Java .ppt(43页珍藏版)》请在麦多课文档分享上搜索。
1、njmnpac.syr.edu,1,Java Tutorial - Spring 2000 Part 1: Introduction to Java Language and Applets,http:/www.npac.syr.edu/projects/tutorials/Java/ Instructors: Geoffrey Fox , Nancy McCracken Syracuse University 111 College Place Syracuse New York 13244-4100,njmnpac.syr.edu,2,Abstract of Java Tutorial,P
2、art 1: Overview including History of Java Development Overall Java Philosophy and Features including security etc. Part 2: Java Programming Language Object Oriented and Class Structure Exceptions Part 3: Applet Programming and Threads Abstract Windowing Toolkit Part 4: Networking and I/O Multithread
3、ing,njmnpac.syr.edu,3,What is Java in a NutShell?,What is Java? A simple, object oriented, distributed, interpreted, robust, safe, architecture neutral, portable, high performance, multithreaded, dynamic language. Java is interesting because It is both a general purpose object-oriented language alon
4、g the lines of C+ and it is particularly designed to interface with Web pages and to enable distributed applications over the internet. The Web is becoming the dominant software development arena; this will drive Java as the best supported, most widely taught language Particularly good as a language
5、 for K-12 teaching Even outside the web, e.g. in scientific computing, Java is as good and in some (modest) respects better than all other languages,njmnpac.syr.edu,4,Java is an important language in the world,The Java Language has several good design features secure, safe (wrt bugs), object-oriente
6、d, familiar (to C C+ and even Fortran programmers) Java has a very good set of libraries covering everything from commerce, multimedia, images to math functions (under development at http:/math.nist.gov/javanumerics) Java has best available electronic and paper training and support resources, growin
7、g labor force trained in Java Java is rapidly getting best integrated program development environments Java naturally integrated with network and universal machine supports powerful “write once-run anywhere” model,njmnpac.syr.edu,5,Java is also important in computer science,Increasingly, Java is the
8、 language used for important computing paradigms that support applications: object-oriented computing, event-driven computing, distributed objects, linkage to databases, visual/component computing, client/servers, networking, multimedia computing . . . So Java is an important language to include at
9、an advanced computer science level, along with other languages such as C+, that are useful to students to get jobs. But the good design features of Java also make it suitable for teaching basic computer science concepts: algorithms, data structures, software design, . . . See the (old, but still rel
10、evant) discussion by Doug Lea at http:/gee.cs.oswego.edu/dl/html/javaInCS.html,njmnpac.syr.edu,6,Architecture of Java Applets,Browsers (HotJava, Netscape 2.0/3.0/4.0, Microsoft IE .) supporting Java allow arbitrarily sophisticated dynamic multimedia applications inserts called Applets, written in Ja
11、va, to be embedded in the regular HTML pages and activated on each exposure of a given page.,web server,Java codeis compiled to produceapplet codes, part of web document collection,web client, running browser such as Netscape or IE,executes (restricted) applet code to display in browser window,Inter
12、net,njmnpac.syr.edu,7,Architecture of Java Applications,Java applications are compiled and run on a machine just like any other general programming language such as C/C+. No web server or network are required although Java applications may also use network connections for distributed computing.,Java
13、 codeis compiled to producebytecodesrun by Java interpreter to produce results,OR Java codeis compiled to producenative coderun directly on machine for better performance,njmnpac.syr.edu,8,Java Applications in a Nutshell,All Java programs are written into a file with a “.java“ extension. Application
14、s are .java files with a main method which is excuted first. How to compile and run a Java application (via bytecodes): Run the compiler on a .java file: javac MyProgram.javaproducing a file “MyProgram.class“ of Java bytecodes Run the interpreter on a .class file: java MyProgramwhich executes the by
15、tecodes The resources javac and java are part of JDK and are not in Netscape and so are not necessarily available on the same machine as your web server.,njmnpac.syr.edu,9,The Simplest Java Application: Hello,World!,Since Java is object-oriented, programs are organized into modules called classes, w
16、hich may have data in variables and subroutines called methods.,class HelloWorld public static void main (String args) System.out.println(“Hello World!”); ,Each program is enclosed in a class definition.,main() is the first method that is run.,The notation class.method or package.class.method is how
17、 to refer to a public method (with some exceptions).,Syntax is similar to C - braces for blocks, semicolon after each statement. One difference: upper and lower case matter!,njmnpac.syr.edu,10,Java Applets,Java applets are classes written in Java which are intended not to run as stand-alone programs
18、 (as applications do) but as subprograms of a browser which is already managing a window. Applets should NOT have a main method but rather init, start, paint etc. for displaying on the browser window Applets are not trusted as a default, so they have several restrictions on running on the client mac
19、hine no printing or file I/O cannot connect through the network to any machine but its own server any new windows created by the applet have a warning label,njmnpac.syr.edu,11,Preparing an Applet,The applet should be run through javac compiler getting a .class file as before: javac MyApplet.java The
20、 resulting file MyApplet.class is then stored in the document collection of a web server (hence has a URL location). Also create an HTML file (say MyApplet.html) with an applet tag to MyApplet.class.When the browser loads the .html file, it will also download the .class file and invoke the java inte
21、rpreter to run the init, start, and paint methods.,njmnpac.syr.edu,12,The Simplest Java Applet: Hello, World!,Java applets are part of the class hierarchy that can call methods to display on a screen (within the browser window). One way to draw on the screen is to call the method drawString from the
22、 standard method paint.,import java.awt.Graphics;public class HelloApplet extends java.applet.Applet public void paint (Graphics g) g.drawString(“Hello World!”, 5, 25); ,The import statement (similar to an include) allows the use of methods from the Graphics class .,The paint method displays a graph
23、ics object on the screen - one of the standard methods that takes the place of main for applets.,Puts this as a subclass of Applet.,njmnpac.syr.edu,13,Displaying your applet from a Web page.,You should name the file with your applet name, HelloWorldApplet.java, run the compiler (javac), getting a by
24、tecode file HelloWorldApplet.class, which you put in a web directory., Simple Hello PageMy Java applet says:,Name of your applet class.,The browser will use a rectangle of width 150 pixels and height 25 pixels to display the applet within the other html.,njmnpac.syr.edu,14,More Details on Applet Tag
25、s - I,Given the following HTMLRuns the “StockGraph.class“ executable as an applet. WIDTH and HEIGHT are attributes that are passed along to the applet. If the optional CODEBASE attribute is provided, then load the executable image from the directory specified by CODEBASE. Without the CODEBASE attrib
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- JAVATUTORIALSPRING2000PART1INTRODUCTIONTOJAVAPPT

链接地址:http://www.mydoc123.com/p-372957.html