Anda di halaman 1dari 18

A SEMINAR REPORT ON JAVA APPLETS

In partial fulfillment of requirements for the degree of Bachelor of Technology In Computer Science & Engineering SUBMITTED BY: Manish Jain

DEPARTMENT OF COMPUTER SCIENCE & ENGG.

RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY GHAZIABAD

CERTIFICATE
This is to certify that the Seminar entitled JAVA
APPLETS

Submitted by MANISH JAIN under my guidance in partial fulfillment of the degree of B.Tech in Computer Science & Engineering of U.P.Technical University, Lucknow during the academic year 20102011(6th SEM). Date: 18/04/20111 Place: Ghaziabad Head, Computer Science Dept. S.K.Gaur

ACKNOWLEDGEMENT
It gives me immense pleasure in presenting seminar on the topic JAVA APPLETS. I acknowledge the enormous assistance and excellent co-operation extended to by my respected guide Mr. Manish Gupta. I would also like to thank the staff members for their valuable support. Lastly I would like to express my heartfelt indebtedness towards all those who have helped me directly or indirectly for the success of the seminar.

Manish Jain

Table of Contents
ABSTRACT CONCEPT TECHNICAL INFORMATION SIMILAR TECHNOLOGIES EMBEDDING IN WEB PAGE EXAMPLE UNSIGNED APPLETS SIGNED APPLETS ADVANTAGES DISADVANTAGES ALTERNATIVES CONCLUSION RECOMMENDATION REFERENCES

1.ABSTRACT

Web design has moved to the next level with the introduction of java technology in the computing and programming industry. This introduction has made a tremendous impact in the capabilities and functionalities of web pages. Now using not only HTML codes but java scripts and java applets, more interactivities and functionalities can be added to web pages. This seminar paper looks at what a java applet is, how to write applet codes and how to deploy them on web pages.

Java Applet-Concept

Java Applet is an applet delivered to the users in the form of Java bytecode.

Java applets can run in a Web browser using a Java Virtual Machine (JVM), or in Sun's AppletViewer, a stand-alone tool for testing applets. Java applets were introduced in the first version of the Java language in 1995. Java applets are usually written in the Java programming language but they can also be written in other languages that compile to Java bytecode such as Jython,[8] JRuby,[9] or Eiffel (via SmartEiffel).[10] Java applets run at a speed that is comparable to (but generally slower than) other compiled languages such as C++, but many times faster than JavaScript.[11] In addition they can use 3D hardware acceleration that is available from Java. This makes applets well suited for non trivial, computation intensive visualizations. Since Java's bytecode is platform independent, Java applets can be executed by browsers for many platforms, including Microsoft Windows, Unix, Mac OS and Linux. It is also trivial to run a Java applet as an application with very little extra code. This has the advantage of running a Java applet in offline mode without the need for any Internet browser software and also directly from the development IDE.

Java applet that was created as supplementary demonstration material for a scientific publication.[

Technical information

Java applets are executed in a ''[[sandbox (security)|sandbox]]'' by most web browsers, preventing them from accessing local data like [[Clipboard (software)|clipboard]] or [[file system]]. The code of the applet is downloaded from a [[web server]] and the browser either [[Compound document|embeds]] the applet into a web page or opens a new window showing the applet's [[user interface]]. A Java applet extends the class {{Javadoc:SE|package=java.applet|java/applet|Applet}}, or in the case of a [[Swing (Java)|Swing]] applet, {{Javadoc:SE|package=javax.swing|javax/swing|JApplet}}. The class must override methods from the applet class to set up a user interface inside itself (<code>Applet</code> is a descendant of {{Javadoc:SE|java/awt|Panel}} which is a descendant of {{Javadoc:SE|java/awt|Container}}. As applet inherits from container, it has largely the same user interface possibilities as an ordinary Java application, including regions with user specific visualization. The first implementations involved downloading an applet class by class. While classes are small files, there are frequently a lot of them, so applets got a reputation as slow loading components. However, since [[JAR (file format)|jar]]s were introduced, an applet is usually delivered as a single file that has a size of the bigger image (hundreds of kilobytes to several megabytes). The [[Domain Name System|domain]] from where the applet executable has been downloaded is the only domain to which the usual (unsigned) applet is allowed to communicate. This domain can be different from the domain where the surrounding HTML document is hosted.

Java [[Static library|system libraries]] and [[Runtime library|runtimes]] are backwards compatible, allowing to write code that runs both on current and on future versions of the Java virtual machine.

Similar technologies

Many Java developers, blogs and magazines are recommending that the [[Java Web Start]] technology be used in place of Applets.<ref>[http://www.javaworld.com/javaworld/jw-07-2001/jw0706-webstart.html JavaWorld.com]</ref><ref>[http://javachannel.net/wiki/pmwiki.php/F AQ/Applets JavaChannel.net]</ref> A [[Java Servlet]] is sometimes informally compared to be "like" a server-side applet, but it is different in its language, functions, and in each of the characteristics described here about applets.

Embedding into web page


The applet can be displayed on the web page by making use of the deprecated <code>[[HTML element#Images and objects|applet]]</code> HTML element,<ref>[http://www.w3.org/TR/html401/struct/objects.html#ed ef-APPLET W3.org]</ref> or the recommended <code>object</code> element.<ref>[http://www.w3.org/TR/html401/struct/objects.html#ed ef-OBJECT W3.org]</ref> A non standard <code>embed</code> element can be used<ref name="ja"/> with Mozilla family browsers. This specifies the applet's source and location. <code>Object</code> and <code>embed</code> tags can also download and install Java virtual machine (if required) or at least lead to the plugin page. <code>Applet</code> and <code>object</code> tags also support loading of the serialized applets that start in some particular (rather than initial) state. Tags also specify the message that shows up in place of the applet if the browser cannot run it due any reason.

However, despite <code>object</code> being officially a recommended tag, as of 2010, the support of the <code>object</code> tag was not yet consistent among browsers and Sun kept recommending the older <code>applet</code> tag for deploying in multibrowser environments,<ref name="ja">[http://download.java.net/jdk7/docs/technotes/guides/plu gin/developer_guide/using_tags.html#object Sun's position on applet and object tags]</ref> as it remained the only tag consistently supported by the most popular browsers. To support multiple browsers, the <code>object</code> tag currently requires JavaScript (that recognizes the browser and adjusts the tag), usage of additional browser-specific tags or delivering adapted output from the server side. Deprecating <code>applet</code> tag has been criticised.<ref>[http://mindprod.com/jgloss/applet.html#OBJECT Criticism] of APPLET tag deprecation</ref> Oracle now provides a

maintained JavaScript code <ref>[http://www.java.com/js/deployJava.txt Java applet launcher from Oracle]</ref> to launch applets with cross platform workarounds.

Example
The following example is made simple enough to illustrate the essential use of Java applets through its java.applet package. It also uses classes from the Java [[Abstract Window Toolkit]] (AWT) for producing actual output (in this case, the "[[Hello world program|Hello, world!]]" message). <source lang="java"> import java.applet.Applet; import java.awt.*;

// Applet code for the "Hello, world!" example. // This should be saved in a file named as "HelloWorld.java". public class HelloWorld extends Applet { // This method is mandatory, but can be empty (i.e., have no actual code). public void init() { }

// This method is mandatory, but can be empty.(i.e.,have no actual code). public void stop() { }

// Print a message on the screen (x=20, y=10). public void paint(Graphics g) { g.drawString("Hello, world!", 20,10);

// Draws a circle on the screen (x=40, y=30). g.drawArc(40,30,20,20,0,360); } } </source>

Additional simple applets are available at Wikiversity.<ref>[http://en.wikiversity.org/wiki/Java_applets Java applet section in Wikiversity]</ref>

For [[compiler|compilation]], this code is saved on a plain-[[ASCII]] file with the same name as the class and <tt>.java</tt> extension, i.e. <tt>HelloWorld.java</tt>. The resulting <tt>HelloWorld.class</tt> applet should be placed on the web server and is invoked within an [[HTML]] page by using an <tt>&lt;APPLET&gt;</tt> or an <tt>&lt;OBJECT&gt;</tt> tag. For example: <source lang="html4strict"> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML> <HEAD> <TITLE>HelloWorld_example.html</TITLE> </HEAD> <BODY> <H1>A Java applet example</H1> <P>Here it is: <APPLET code="HelloWorld.class" WIDTH="200" HEIGHT="40">

This is where HelloWorld.class runs.</APPLET></P> </BODY> </HTML> </source> Displaying the <tt>HelloWorld_example.html</tt> page from a Web server, the result should look as this: <blockquote> <p><font size="+2">'''A Java applet example'''</font></p> <p>Here it is: <font face="Times">Hello, world!</font></p> </blockquote>

To minimize download time, applets are usually delivered in a form of compressed [[ZIP (file format)|zip]] archive (having [[JAR (file format)|jar]] extension). If all needed classes (only one in our case) are placed in compressed archive ''example.jar'', the embedding code would look different: <source lang="html4strict"> <P>Here it is: <APPLET code="HelloWorld" WIDTH="200" HEIGHT="40" ARCHIVE="example.jar"> This is where HelloWorld.class runs.</APPLET></P> </source>

Applet inclusion is described in detail in Sun's official page about the APPLET tag.<ref name="appletinclusion">[http://java.sun.com/j2se/1.4.2/docs/guide/misc/applet.h tml Java.Sun.com] Sun's APPLET tag page</ref>

Sufficient running speed is also utilized in applets for playing non trivial computer games like chess

Unsigned Applets
Limitations for the unsigned applets are understood as "draconian":<ref>[http://www.wutka.com/hackingjava/ch3.htm Java Security FAQ Applet Security Restrictions] by Mark Wutka</ref> they have no access to the local filesystem and web access limited to the applet download site; there are also many other important restrictions. For instance, they cannot access system properties, use their own [[class loader]], call [[native code]], execute external commands on a local system or redefine classes belonging to core packages included as part of a Java release. While they can run in a standalone frame, such frame contains a header, indicating that this is an untrusted applet. Successful initial call of the forbidden method does not automatically create a security hole as an access controller checks the entire [[Call stack|stack]] of the calling code to be sure the call is not coming from an improper location.

As with any complex system, multiple security problems have been discovered and fixed since Java was first released. Some of these (like the Calendar serialization security bug<ref>[http://slightlyrandombrokenthoughts.blogspot.com/2008/12/calendarbug.html Description of Calendar serialization security bug]</ref>) persisted for many years without anybody being aware. However it seems that most (if not all) security holes are closed before anybody being able to exploit them in a larger scale.

Some studies mention applets crashing the browser or overusing [[Central processing unit|CPU]] resources but these are classified as nuisances<ref name="SIP"/> and not as true security flaws. However, unsigned applets may be involved in combined attacks that exploit a combination of multiple severe configuration errors in other parts of the system.<ref>[http://avirubin.com/block.java.pdf Avirubin.com]</ref> An unsigned applet can also be more dangerous to run directly on the server where it is hosted because while code base allows it to talk with the server, running inside it can bypass the firewall. An applet may also try [[Denial-of-service attack|DoS attacks]] on the server where it is hosted but usually people who manage the web site also manage the applet, making this unreasonable. Communities may solve this

problem via [[Code review|source code review]] or running applets on a dedicated domain.<ref>[http://strategy.wikimedia.org/wiki/Proposal:Java_applet_support Strategy.Wikimedia.org], proposal with discussion about Java applets in community sites</ref><ref>[http://Ultrastudio.org Ultrastudio.org], user editable educational site with full applet support</ref>

The unsigned applet can also try to download malware hosted on originating server. However it could only store such file into temporary folder (as its transient data) and has no means to complete the attack by executing it. There were attempts to use applets for spreading Phoenix and Siberia exploits this way{{citation needed|date=October 2010}}, while these exploits do not use Java internally and were also distributed in a number of other ways.

As of 1999 no real security breaches involving unsigned applets have ever been publicly reported.<ref name="SIP">[http://www.cs.princeton.edu/sip/faq/javafaq.php3 Java Security FAQ]</ref><ref>[http://www.securingjava.com/chapterfour/ ~ G.McGraw, E.W. Felten. Securing Java. ISBN 047131952X]</ref> Using an up-to-date Web browser is usually enough to be safe against the known direct attacks from unsigned applets.

SIGNED APPLETS

They do not have the security restrictions imposed on unsigned ones and can run outside the security sandbox. NOTE: When a signed applet is accessed from a java Script code in an HTML page, the applet is executed within the sandbox. This implies that signed applets essentially behaves like unsigned applets.

ADVANTAGES
Automatically integrated with HTML; hence, resolved virtually all installation issues. Can be accessed from various platforms and various java-enabled web browsers. Can provide dynamic, graphics capabilities and visualizations Implemented in Java, an easy-to-learn OO programming language

DISADVANTAGES

Applets cant find any information about the local computer They are quite slow. They need JVM enabled Browser to execute them. Stability depends on stability of the clients web server Performance directly depend on clients machine

Alternatives

Alternative technologies exist (for example, [[JavaScript]], [[Curl (programming language)|Curl]], [[Adobe Flash|Flash]], and [[Microsoft Silverlight]]) that satisfy some of the scope of what is possible with an applet. Of these, JavaScript is not always viewed as a competing replacement; JavaScript can coexist with applets in the same page, assist in launching applets (for instance, in a separate frame or providing platform workarounds) and later be called from the applet code.<ref>[http://www.rgagnon.com/javadetails/java-0170.html Rgagnon.com], calling a Java applet from JavaScript</ref> [[JavaFX]] that is an extension of Java platform may also be viewed as an alternative.

Conclusion

Having strategically discussed java applets, its development, deployment, advantages and disadvantages, it can be seen that writing java applet codes are very simple to do as well as can add functionality and interactivity to your web pages.

RECOMMENDATIONS
When designing a web page that you need that some logical applications run on, using java applet is more convenient. Finally, when designing a java applet, bear in mind that there are some fractions of people that will not view your applet, also before allowing an applet to run on your browser, make sure that you know and trust its source or that it is signed.

References

1. Deitel (2007):Java How to Program Seventh Edition, Pearson Education, Inc. USA 2. John.R.Hubbard, Phd (2004):Programming with java Second Edition.The McGraw-Hill Companies, Inc. USA. 3, Lesson: Applet (The Java Tutorials>Deployment). http://java.sun.com/doc/books/tutorial/deployment/applet/.

Anda mungkin juga menyukai