11.07.2015 Views

Encyclopedia of Computer Science and Technology

Encyclopedia of Computer Science and Technology

Encyclopedia of Computer Science and Technology

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

JJavaJava is a computer language similar in structure to C++.Although Java is a general-purpose programming language,it is most <strong>of</strong>ten used for creating applications to run on theInternet, such as Web servers. A special type <strong>of</strong> Java programcalled an applet can be linked into Web pages <strong>and</strong> runon the user’s Web browser (see applet).As an object-oriented language, Java uses classes thatprovide commonly needed functions including the creation<strong>of</strong> user interface objects such as windows <strong>and</strong> buttons (seeclass <strong>and</strong> object-oriented programming). A variety <strong>of</strong>sets <strong>of</strong> classes (“class frameworks”) are available, such asthe AWT (Abstract Windowing Toolkit).are built. The AWT (Abstract Windowing Toolkit) is a set <strong>of</strong>classes that provide a graphical user interface.The program then declares a new class called Hello-World <strong>and</strong> specifies that it is built on (extends) the appletclass.Program StructureA Java program begins by importing or defining classes <strong>and</strong>using them to create the objects needed for the program’sfunctions. Code statements then create the desired output orinteraction from the objects, such as drawing a picture or puttingtext in a window. Here is a simple Java applet program:import java.applet.Applet;import java.awt.Graphics;public class HelloWorld extends Applet {public void paint(Graphics g) {g.drawString(“Hello world!”, 50, 25);}}The first two lines import (bring in) st<strong>and</strong>ard classes.The applet class is the foundation on which applet programsAfter an embedded Java program (called an applet) is compiled, itsexecutable file (Javacode) is stored on the Web server, together withthe HTML file for the Web page to which the program is linked.254

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!