Java Tutorial - Spring 2000Part 1- Introduction to Java .ppt

上传人:lawfemale396 文档编号:372957 上传时间:2018-10-04 格式:PPT 页数:43 大小:135.50KB
下载 相关 举报
Java Tutorial - Spring 2000Part 1- Introduction to Java .ppt_第1页
第1页 / 共43页
Java Tutorial - Spring 2000Part 1- Introduction to Java .ppt_第2页
第2页 / 共43页
Java Tutorial - Spring 2000Part 1- Introduction to Java .ppt_第3页
第3页 / 共43页
Java Tutorial - Spring 2000Part 1- Introduction to Java .ppt_第4页
第4页 / 共43页
Java Tutorial - Spring 2000Part 1- Introduction to Java .ppt_第5页
第5页 / 共43页
亲,该文档总共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

26、ute, will look for StockGraph.class in the local servers hierarchy (relative to where the HTML was loaded), otherwise look for StockGraph.class on the given http hierarchy. May also supply an ARCHIVE attribute which specifies a “.jar” file to download (akin to tar on UNIX). The class named in the CO

27、DE attribute should be one of the classes in the jar file. Tag and attribute names are case insensitive.,njmnpac.syr.edu,15,More Details on Applet Tags - II, Put a bunch of text here to be displayed by browsers such as Netscape 2.0 on Windows 3.1 that do not support JavaALT specifies text to display

28、ed if the browser understands the applet tag, but if unable to run applets. NAME specifies the name of this instance of the applet; This will make it possible for applets on the same page to find and communicate with each other. ALIGN specifies the alignment of the applet. The possible values are th

29、e same as those available in the IMG tag (top, middle, bottom, texttop, absmiddle, baseline, absbottom, left, right). Align=top which aligns top of applet with top of tallest item in the line Align=texttop which aligns top of applet with top of the tallest text in the line VSPACE and HSPACE specifie

30、s the vertical and horizontal spacing in pixels, around the applet space.,njmnpac.syr.edu,16, Tags and Applets,The applet tag can be followed by parameters:.The Java program accesses this information byString attribute;attribute = getParameter(“attributename1“);if( attribute = null ) attribute = you

31、rdefaultvalue; / null is Java way of saying unset Typically this processing would be in init() method of Applet,njmnpac.syr.edu,17,Java vs. JavaScript,Despite the word “java” in the name, JavaScript is a different language than Java, albeit with some similarities. A JavaScript program is written dir

32、ectly into the HTML page, and is executed by the JavaScript intrepeter, so also executes dynamic web page content in the browser window. JavaScript is special purpose - it is an object-based language that deals directly with browser entities such as windows, textfields, forms, frames and documents.

33、JavaScript can respond to browser events (not as many as Javas more complex capabilities with the user interface) such as mouse clicks and user-typed text. JavaScript is easy and fast to write, but not as powerful as Java.,njmnpac.syr.edu,18,Multi-tier Architecture,Distributed applications on the we

34、b naturally have a multi-tier architecture. Java plays a role at all three levels: Graphical User Interface and client side analysis systems, including visualization Middle layer servers and software integration, including web servers, distributed object servers and other application servers. Less i

35、mportant for backend client software, which may be legacy code.,Middle level servers,Client user interface running through browser,Internet,Internet or proprietary network,Backend computing or databases,njmnpac.syr.edu,19,Overview and History of Java Development,njmnpac.syr.edu,20,History of Java La

36、nguage and Team,Starts in 1991 by Project Green - a group in Sun that detaches from the main campus as a semi-autonomous task force focused on operating software for consumer electronic devices such as smart set-top boxes Gosling (creator of Sun NeWS which had major conceptual impact both on current

37、 Java and Telescript models) realizes that C+ is not adequate and initiates development of a new language Oak, later renamed as Java. A PDA (Personal Digital Assistant - codename *7) based on Oak/Java ready in 1993. Green Team incorporates as FirstPerson, Inc. *7 proposal to Time-Warner rejected in

38、1993. 3DO deal falls through in 1994. FirstPerson, Inc. dissolves. Small group (30 people, now Java Team) continues development and decides to adapt Oak as a Web technology.,njmnpac.syr.edu,21,History of Java Language and Team until Dec. 95,An experimental web browser written in Java, called WebRunn

39、er and later renamed as HotJava, ready in 1994. Alpha release of Java and browser HotJava April 95. Netscape licences Java in May 95 and builds Java into Netscape 2.0 - This confuses ownership and open-ness of Java Beta JDK (Java Development Kit) published in summer/fall 95. It is better software bu

40、t lower functionality than Alpha. First alpha Java books appear in fall 95 such as a popular overview by SAMS and technical book “Java!“ by Tim Ritchey, edited by New Riders. Dec 4 1995 Business Week cover story on “Software Revolution - The Web Changes Everything“ exposes Java as a breakthrough for

41、ce in the expanding Web/Internet. Also points out that “Java as a business“ is yet to be defined. In next week, SGI IBM Adobe Macromedia and finally Microsoft adopt/license Java. Java goes into open standards process and is adopted by Web community.,njmnpac.syr.edu,22,More Recent Java History,1996 J

42、avaOne Developers Conference (now held annually in June) focused on applets. Attendance of 5000 people. 1997 JavaOne focused on JavaBeans and new version of the language JDK1.1, both designed to put Java in line with other developments in component and secure distributed web object computing and use

43、 of databases. 1998 JavaOne featured attendance of 14,000+ and focused on Enterprise JavaBeans and other Enterprise classes, developing more on server-side applications. 1999 JavaOne had over 20,000 attendees. Continued development of JINI for dynamic networking, embedded devices such as Palm Pilots

44、.,njmnpac.syr.edu,23,Overall Java Philosophy and Features,njmnpac.syr.edu,24,Some Key Java Features,First we discuss original Java base language features as discussed in Java: A White Paper by Sun Microsystems - October 1995 draft by James Gosling and Henry McGilton - enumerates the original design

45、of Java: Simple and Familiar Object-oriented Architecture-neutral Portable Somewhat Interpreted Distributed Robust Secure High performance Multi Threaded Dynamic Finally we mention additional features added to Java in more recent versions.,njmnpac.syr.edu,25,Java Features - Its Simple and Familiar!,

46、Java omits several rarely used, poorly understood and confusing features of C+ including operator overloading, multiple inheritance, pointers and automatic type coercions. It adds automatic garbage collection which makes dynamic programming easier in Java than in C or C+. No more mallocs! It also ad

47、ds Interface construct, similar to Objective C concept, which often compensates for the lack of multiple inheritance by allowing method calling syntax to be “inherited“. The resulting language is familiar as it looks like C+ but is simpler and hence easier to program in. It also results in a much sm

48、aller kernel which is suitable for planned Java ports to consumer electronic devices. Base (alpha) interpreter is 40Kb, libraries and threads add additional 175Kb.,njmnpac.syr.edu,26,Java Features - Its Object-oriented,Java model can be viewed as a C+ subset, with some dynamic elements inherited fro

49、m Objective-C (method overloading, garbage collection). Structures, Unions and Functions are absorbed into data and methods of Java classes - Java is Simple! The strength of Java object-oriented model is not is sophistication but in simplicity and the extensive class library associated with the syst

50、em (some 250 public classes were released in both alpha and beta). Java class plays also a role of a communication atom in the Web embedding model. Applet classes identify themselves by names in the HTML applet tag. Applet downloads other classes, present in the applet source. Hence, the Java class names play the role of addressing mode for the distributed Java code database.,

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 教学课件 > 大学教育

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1