What is a Java Applet? 4 A Java program that can be included in an HTML page. An applet tag is used in the HTML file to identify the source of the applet code, which resides on the server. 4 Example applet tag in HTML file:
How a Java Applet works 4 When we use a Java-compatible browser to view a Web page which contains a Java applet, the applet’s code is transferred to our system and executed by the browser. 4 Java-Compatible Browsers: HotJava, Netscape Navigator, Internet Explorer, etc.
Why a Java Applet? ADVANTAGES: 4 Less load on the server 4 More user interaction (Applet Vs. CGI) 4 Arbitrary graphics 4 Arbitrary data types
Java Applets Vs. Java Applications 4 Java Application: Standalone Java programs that can be run by using just the Java interpreter. 4 Java Applet: Run and displayed inside a Web page with Java-enabled Web browser.
Embedding Applet in HTML <APPLET CODEBASE = codebaseURL ARCHIVE = archiveList CODE = appletFile...or... OBJECT = serializedApplet ALT = alternateText NAME = appletInstanceName WIDTH = pixels HEIGHT = pixels ALIGN = alignment VSPACE = pixels HSPACE = pixels >... alternateHTML ( Applet Tag )
Java Language 4 Syntactically similar to C++ 4 Semantically different –Strong and statically typed –Single inheritance plus an interface mechanism –Run-time type information 4 Automatic storage management: –No pointers –Garbage collection 4 Security/safety
Advantages of Java 4 Combine many programming mechanisms –Object oriented language –Strongly and statically typed –Automatic storage management: garbage collection –Run-time type information –Safety 4 Faster build cycle (prototyping) –Dynamic linking
Advantages of Java (cont.) 4 Platform independence –The ability of write code once and use it anywhere –The ultimate in portability –Compiled code can move around a network 4 Java is “Open” –Documentation and source code available –Not tied down to a single vendor (i.e. Sun or Microsoft)
Disadvantages of Java 4 Implementations have traditionally been interpreted –Execute slower than compiled languages –Typically in the order of 10x slower than native code 4 “Write Once, Run Anywhere” Implementation challenges 4 Is Microsoft playing????