The first two programs presented in this book are Java applications, stand-alone program slike any native programs. On the other hand, most of the hype about Java comes from its ability to run applets inside a web browser.
We want to show you how to build and run an applet from the command line. Then wewill load the applet into the applet viewer that comes with the JDK. Finally, we will displayit in a web browser.
First, open a shell window and go to the directory CoreJavaBook /v1ch02 /WelcomeApplet, then enter the following commands:
WelcomeApplet applet as viewed by the applet viewer
The first command is the now-familiar command to invoke the Java compiler. This compiles the WelcomeApplet .java source into the bytecode file WelcomeApplet .class.
This time, however, you do not run the java program. You invoke the applet viewer program instead. This program is a special tool included with the JDK that lets you quickly test anapplet. You need to give this program an HTML file name, rather than the name of a Javaclass file. The contents of the WelcomeApplet.html file.
If you are familiar with HTML, you will notice some standard HTML instructionsand the applet tag, telling the applet viewer to load the applet whose code is stored inWelcomeApplet.class. The applet viewer ignores all HTML tags except for the applet tag.
Unfortunately, the browser situation is a bit messy.
Provided you have a browser that supports a modern version of Java, you can try loading the applet inside the browser.
Running the WelcomeApplet applet in a browser
You can see that this application is actually alive and willing to interact with the Internet.Click on the Cay Horstmann button. The applet directs the browser to display Cay’sweb page. Click on the Gary Cornell button. The applet directs the browser to pop up amail window, with Gary’s e-mail address already filled in.
Notice that neither of these two buttons works in the applet viewer. The applet viewerhas no capabilities to send mail or display a web page, so it ignores your requests. Theapplet viewer is good for testing applets in isolation, but you need to put applets insidea browser to see how they interact with the browser and the Internet.
TIP: You can also run applets from inside your editor or integrated development environment.
In Emacs, select JDE -> Run Applet from the menu. In Eclipse, use the Run -> Run as
-> Java Applet menu option.
Finally, the code for the applet is shown in below. At this point, do not give it morethan a glance. We come back to writing applets later.
Here, you learned about the mechanics of compiling and running Java programs.
You are now ready to move on to next section, where you will start learning theJava language.
Core Java Related Interview Questions
|J2EE Interview Questions||Core Java Interview Questions|
|JDBC Interview Questions||JSP Interview Questions|
|Android Interview Questions||JavaServer Faces (JSF) Interview Questions|
|Java collections framework Interview Questions||Java 8 Interview Questions|
|Java Collections Interview Questions||Java Exception Handling Interview Questions|
|Java Concurrency Interview Questions||Java Serialization Interview Questions|
|Java Programmer Interview Questions||Java Inheritance Interview Questions|
|Java IO Interview Questions||Object Oriented Programming in PHP Interview Questions|
Core Java Tutorial
An Introduction To Java
The Java Programming Environment
Fundamental Programming Structures In Java
Objects And Classes
Interfaces And Inner Classes
User Interface Components With Swing
Deploying Applications And Applets
Exceptions, Logging, Assertions, And Debugging
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.