for more Https://www.ThesisScientist.com
UNIT 4
DYNAMIC CONTENT TECHNOLOGIES
ASP(ACTIVE SERVER PAGES)
“ACTIVE SERVER PAGES OR ASP IS COMMONLY KNOWN AS A TECHNOLOGY
THAT ENABLES TO MAKE DYNAMIC AND INTERACTIVE WEB PAGES.”
ASP uses server-side scripting to dynamically produce web pages that are not affected
by the type of browser the web site visitor is using.
The default scripting language used for writing ASP is VBScript, although some other
languages can also be used like Jscript (Microsoft‟s version of JavaScript).
ASP pages have the extension .asp instead of .htm, when a page with extension .asp is
requested by a browser the web server knows to interpret any ASP contained within the
web page before sending the HTML produced to the browser.
Any web pages containing ASP cannot be run by just simply opening the page in a web
browser. The page must be requested through a web server that supports ASP, this is
why ASP stands for Active Server Pages, means no server, no active pages.
4.1 HOW ASP LOOK LIKE
The appearance of an Active Server Page depends on who or what is viewing it. To
the web browser that receives it, an ASP looks just like a normal HTML page. In
addition to text and HTML tags, there also exists server side scripts.
The code below shows what a real, live ASP page looks like:
<html>
<head>
<title> New Page </title>
</head>
<body>
for more Https://www.ThesisScientist.com
<h1> My Welcome Page</h1>
<p> <% if Time>#12:00:00 AM# AND_ Time<#12:00:00 PM# Then %> </p>
<h2> Good Morning !!! </h2>
<p> <% if Time>#12:00:00 AM# AND_ Time<#6:00:00 PM# Then %> </p>
<h2> Good Afternoon !!! </h2>
</body></html>
SYNTAX RULE
An ASP file normally contains HTML tags, just like an HTML file. However, an ASP file
can also contain server scripts, surrounded by the delimiters <% and %>.
Server scripts are executed on the server, and can contain any expressions, statements,
procedures, or operators valid for the scripting language preferred to be used.
Write Output to a Browser
The response.write command is used to write output to a browser. The following
example sends the text “Hello World !” to the browser:
<html>
<body>
<%
Response.write(“Hello World ! ”)
%>
</body>
</html>
There is also a shorthand method for the response.write command. The following
example also sends the text “Hello World !” to the browser:
for more Https://www.ThesisScientist.com
<html>
<body>
<%=”Hello World ! ”%>
</body>
</html>
4.2 LIFE TIME OF A VARIABLE
A variable declared outside a procedure can be accessed and changed by any script in
the ASP file. A variable declared inside a procedure is created and destroyed every time
the procedure is executed.
To declare variables accessible to more than one ASP file, declare them as session
variables or application variables.
4.2.1 Session Variables
Session variables are used to store information about ONE single user, and are
available to all pages in one application. Typically information stored in session
variables are name, id, and preferences.
4.2.2 Application Variables
Application variables are also available to all pages in one application. Application
variables are used to store information about ALL users in a specific application.
Procedures
The ASP source code can contain procedures and functions:
<html>
<head>
<% sub vbproc(num1,num2)
Response.write(num1*num2)
for more Https://www.ThesisScientist.com
end sub
%>
</head>
<body>
<p> Result: <% call vbproc(3,4) %></p>
</body>
</html>
Insert the <%@language=”language”%> line above the <html> tag to write
procedures or functions in another scripting language than default:
<%@ language=”javascript” %>
<html>
<head>
<%
function jsproc(num1,num2)
{
Response.write(num1*num2)
}
%>
</head>
<body>
<p> Result: <% jsproc(3,4) %></p>
</body>
for more Https://www.ThesisScientist.com
</html>
4.2.3 USER INPUT
The request object may be used to retrieve user information from forms.
For example:
<form method=”get” action=”simpleform.asp”>
First Name: <input type=”text” name=”fname” /> <br />
Last Name: <input type=”text” name=”lname” /><br /><br />
<input type=”submit” value=”Submit” />
</form>
User input can be retrieved in two ways: With Request.QueryString or Request.form
4.2.4 Request.QueryString
This command is used to collect values in a form with method= “get”. Information sent
from a form with the GET method is visible to everyone (will be displayed in the
browser‟s address bar) and has limits on the amount of information to send.
If a user typed “pankaj” and “sharma” in the form example above, the URL sent to the
server would look like this:
http://www.abes.ac.in/simpleform.asp?fname=pankaj&lname=sharma
Assume that the ASP file “simpleform.asp” contains the following script:
<body>
Welcome
<% response.write(request.querystring(“fname”))
Response.write(“ ” & request.querystring(“lname”))
%>
for more Https://www.ThesisScientist.com
</body>
The browser will display the following in the body of the document:
Welcome pankaj sharma
4.2.5 Request.Form
This command is used to collect values in a form with method= “post”. Information sent
from a form with the POST method is invisible to others and has no limits on the
amount of information to send.
If a user typed “Bill” and “Gates” in the form example above, the URL sent to the server
would look like this:
Http://www.abes.ac.in/simpleform.asp
Assume that the ASP file “simpleform.asp” contains the following script:
<body>
Welcome
<%
Response.write(request.form(“fname”))
Response.write(“ ” & request.form(“lname”))
%>
</body>
The browser will display the following in the body of the document:
Welcome Bill Gates
4.2.6 FORM VALIDATION
for more Https://www.ThesisScientist.com
User input should be validated on the browser whenever possible (by client scripts).
Browser validation is faster and reduces the server load.
Using server validation should be considered if the user input will be inserted into a
database. A good way to validate a form on the server is to post the form to itself,
instead of jumping to a different page. The user will then get the error messages on the
same page as the form. This makes it easier to discover the error.
4.2.7 HOW ASP WORKS
• ASP files are only processed when a client requests them from the server.
• There are some .dll files such as ASP.dll which contains standard objects.
• Functions are called from these dlls.
• Since these functions are previously defined and known, things can be done
with ASP are bounded.
• ASP codes do not need to be compiled.
• There exists a global.asa file which is used to specify events and global
session variables which are used for all ASP files in the server.
• Before any ASP file is processed, global.asa is processed and it defines global
events.
• The processing of an ASP file starts with the separation of ASP scripts and
HTML codes in IIS.
• Then each script code is processed.
• The HTML corresponds of these scripts are created, and injected related
places.
• Final HTML codes are sent to the client and displayed by the web browser.
• 4.2.7 WHAT AN ASP DO?
• The most important feature of ASP is creating dynamic pages.
• You can manage data with database operations such as getting and storing
people‟s information in the Database.
• Interactive applications can be implemented, i.e. news type people like may be
displayed.
• Script codes are not sent to the client, which brings security.
•
• ADVANTAGES OF ASP
• It gives dynamism to the pages created.
• Interactive pages reflecting the preferences of the user can be developed.
• ASP is a very good innovation to dynamic web programming.
• Data obtaining and displaying became more easy and efficient.
for more Https://www.ThesisScientist.com
• DISADVANTAGES OF ASP
• It is slower than most of similar technologies.
• Not very much portable.
4.3 JAVA SERVER PAGES
“JAVASERVER PAGES (JSP) IS A JAVA TECHNOLOGY THAT ALLOWS SOFTWARE
DEVELOPERS TO DYNAMICALLY GENERATE HTML, XML OR OTHER TYPES OF
DOCUMENTS IN RESPONSE TO A WEB CLIENT REQUEST.”
The technology allows java code and certain pre-defined actions to be embedded into
static content..”
4.3.1 FEATURE OFF JSP
JSP gives an ideal platform for creating web applications easily and quickly. The
various features supported by JSP are:
1. Platform and Server Independence. The JSP technology follows the „write
once‟ run anywhere, rule which is the basis of the java language. JSP technology
can run on various web server including Apache, Netscape and IIS and is
supported by a large variety of tools from different vendors.
2. Environment. JSP uses pure java and takes full advantage of its object-
oriented nature. This technology lets the designer separate content generation
from layout by accessing component from the page.
3. Extensible JSP Tags. JSP uses a combination of tags and scripting to create
dynamic web pages. It allows the designer to extend the JSP tags available. JSP
developers can create custom tag libraries, so that more functionality can be
extracted using XML-like tags and this leads to less use of scripting in JSP
pages.
4. Reusability Across Platform. The JSP pages uses components which are
reusable. These reusable components help keep the pages simple and run faster.
5. Easier Maintenance. Application made using JSP technology are easier to
maintain.
for more Https://www.ThesisScientist.com
JSP Architecture
JSP is a part of the Java platform, Enterprise Edition (J2EE), which is the java
architecture for developing multitier enterprise applications. A JSP page is executed
by a JSP engine, which is installed in a web server or a JSP enabled application
server. The JSP engine receives the request from a client to the JSP page and
generates responses from the JSP page to the client.
Handling JSP Page
JSP page may be a combination of different protocols, components and formats. A
JSP page is also a place to enter user information. A user may be asked to enter his
home, address, a word or a phrase.
The information the user enters in the form is stored in the request object, which is
sent to the JSP engine.
The JSP engine sends the request object to the component (Servlet) the JSP
specifies. The component handles the request. The request may be to retrieve
certain data or other data store. The component sends the response back to the JSP
engine.
Response
JSP engine
And
Web serverRequest
Response
JSP File
Response
Request
Request
Client
Component
for more Https://www.ThesisScientist.com
The JSP engine passes the response back to the JSP page, where the data is
formatted according to the HTML design. The JSP engine and web server then sends
the revised JSP page back to the client, where the user can view the results in the
web browser. The communication protocol used between the client and server can
be HTTP, or it can be some other protocol.
JSP SYNTAX
Everything in JSP can be broken into two categories:
 Elements: That are processed on the server.
 Template: Data are everything other than elements that the JSP engine
ignores.
Element data can be classified into the following categories:
 Directives
 Declarations
 Scriptlets
 Expressions
 Standard Actions
A JSP page contains scripting language and some special JSP tags that can
encapsulate tasks that are difficult or time consuming to program.
JSP Directives
Directives are instructions for JSP engine that are processed when the JSP page is
translated into a servlet. They are used to set global values such as class
declarations, methods to be implemented, output content type etc. The directives
should start with <%@ and end with %>. There are three types of JSP directives.
They are:
1. The page directive defines a number of attributes that affect the whole page.
The syntax is as follows:
<%@ page attributes %>
2. The include directive is used to insert text and code at JSP translation time.
The syntax is as follows:
for more Https://www.ThesisScientist.com
<%@ include file = “relative URL” %>
The file that the file attribute refers to can reference a normal HTML file or
another JSP file which will be evaluated at translation time.
3. The taglib directive declares that the page uses custom tags. Uniquely names
the tag library defining them and associates a tag prefix that will distinguish
the usage of these tags. The syntax is as follows:
<%@ taglib uri = “taglibrary URL prefix” %>
JSP Scriptlets
JSP scripting is a mechanism for embedding code fragments directly into an HTML.
There are three types of scripting elements, namely scriptlets, expressions and
declarations.
Scriptlets are used to embed any piece of java code into the page. The code is
inserted into the generated servlet and is executed when the page is requested. The
syntax for a scriptlets is as follows:
<% Scriptlet source %>
Scriptlet are executed at request time, when the JSP client processes the client
request. If the scriptlet produces output, the output is stored in the JSP writer
implicit object out.
Writing a simple JSP page using Scriptlets:
Hello.jsp
<html>
<head><title> Hello </title></head>
<body>
<%
int x = 0;
for(x = 0; x < 5; x++)
for more Https://www.ThesisScientist.com
{
out.println(“<h1> Hello world ! </h1>”);
}
%>
</body>
</html>
JSP Lifecycle
JSP life cycle can be grouped into seven phases.
1. JSP Page Translation: A java servlet file is generated from the JSP source
file. Generated servlet implements the interface javax.servlet.jsp.HttpJspPage.
The interface HttpJspPage extends the interface JspPage. This interface
JspPage extends the interface javax.servlet.Servlet.
2. JSP Page Compilation: The generated java servlet file is compiled into a java
servlet class. The generated servlet class thus implements all the methods of
the above said three (javax.servlet.jsp.HttpJspPage, JspPage,
javax.servlet.Servlet) interfaces.
3. Class Loading: The java servlet class that was compiled from the JSP source
is loaded into the container.
4. Instance Creation: An instance is created for the loaded servlet class. The
interface JspPage contains jspInit() and jspDestroy(). The JSP specification
has provided a special interface HttpJspPage for JSP pages serving HTTP
requests and this interface contains _jspService().
5. jspInit( ) execution: This method is called when the instance is created and
it is called only once during JSP life cycle. It is called for the servlet instance
initialization.
6. _jspService() execution: This method is called for every request of this JSP
during its life cycle. It passes the request and the response objects.
_jspService() cannot be overridden.
7. jspDestroy() execution: This method is called when this JSP is destroyed
and will not be available for future requests.
for more Https://www.ThesisScientist.com
JSP Expressions (Conditional Processing)
Expressions are used to dynamically calculate values to be inserted directly into the
JSP page. These are elements that are evaluated with the result being converted to
java.lang.String. After the string is converted, it is written to the out object. The
expression should be enclosed within <% = and %>.
While writing an expression, following points should be taken care of:
1. Semicolon cannot be used to end an expression.
2. The expression element can contain any expression that is valid according to
java language specification.
An expression can be complex and composed of more than one part or expression.
For example, the following shows the date and time that the page requested:
Current Time : <% = new java . util . Date() %>
JSP Declarations (Declaring Variables and Methods)
JSP declarations are used to define methods or variables that are to be used in java
code later in the JSP file. The declarations get inserted into the main body of the
servlet class. It has the following form:
<% ! declarations %>
Since declarations do not generate any output they are usually used with JSP
scriptlets or expressions. For example,
<% ! int i = 0; %>
<% ! circle a = new circle(2,0); %>
A declaration element may contain any number of variables or methods
4.4 MULTIMEDIA OVER WEB
“MULTIMEDIA IS MEDIA OF CONTENTS THAT UTILIZES A COMBINATION OF
DIFFERENT CONTENT FORMS INCLUDING A COMBINATION OF TEXT, AUDIO,
STILL IMAGES, ANIMATION, VIDEO, AND INTERACTIVITY CONTENT FORMS.”
for more Https://www.ThesisScientist.com
The term can be used as a noun (a medium with multiple content forms) or as an
adjective describing a medium as having multiple content forms. The term is used in
contrast to media which only utilize traditional forms of printed or hand-produced
material.
Multimedia is any combination of digitally manipulated text, art, sound, animation and
video.
Multimedia is usually recorded and played, displayed or accessed by information
content processing devices, such as computerized and electronic devices, but can also
be part of a live performance. Multimedia (as an adjective) also describes electronic
media devices used to store and experience multimedia content. Multimedia is similar
to traditional mixed media in fine art, but with a broader scope. The term "rich media"
is synonymous for interactive multimedia. Hypermedia can be considered one
particular multimedia application.
CATEGORIES OF MULTIMEDIA
Multimedia may be broadly divided into linear and non-linear categories.
 Linear active content progresses without any navigation control for the viewer
such as a cinema presentation.
 Non-linear content offers user interactivity to control progress as used with a
computer game or used in self-paced computer based training.
 FEATURE OF MULTIMEDIA
 Multimedia presentations may be viewed in person on stage, projected,
transmitted, or played locally with a media player.
 Multimedia games and simulations may be used in a physical
environment with special effects, with multiple users in an online
network, or locally with an offline computer, game system, or simulator.
 Enhanced levels of interactivity are made possible by combining multiple
forms of media content.
APPLICATION OF MULTIMEDIA
Multimedia finds its application in various areas including, but not limited to,
advertisements, art, education, entertainment, engineering, medicine, mathematics,
business, scientific research and spatial temporal applications. Below are the several
examples as follows:
for more Https://www.ThesisScientist.com
1 Creative industries
Creative industries use multimedia for a variety of purposes ranging from fine
arts, to entertainment, to commercial art, to journalism, to media and
software services provided for any of the industries listed below. An individual
multimedia designer may cover the spectrum throughout their career.
Request for their skills range from technical, to analytical, to creative.
2 Entertainment and Fine Arts
In addition, multimedia is heavily used in the entertainment industry,
especially to develop special effects in movies and animations. Multimedia
games are a popular pastime and are software programs available either as
CD-ROMs or online. Some video games also use multimedia features.
Multimedia applications that allow users to actively participate instead of just
sitting by as passive recipients of information are called Interactive
Multimedia.
In the Arts there are multimedia artists, whose minds are able to blend
techniques using different media that in some way incorporates interaction
with the viewer. One of the most relevant could be Peter Greenaway who is
melding Cinema with Opera and all sorts of digital media. Another approach
entails the creation of multimedia that can be displayed in a traditional fine
arts arena, such as an art gallery. For the most part these artists are using
materials that will not hold up over time.
3 Education
In Education, multimedia is used to produce computer-based training
courses (popularly called CBTs) and reference books like encyclopedia and
almanacs. A CBT lets the user go through a series of presentations, text
about a particular topic, and associated illustrations in various information
formats. Edutainment is an informal term used to describe combining
education with entertainment, especially multimedia entertainment.
4 Engineering
Software engineers may use multimedia in Computer Simulations for
anything from entertainment to training such as military or industrial
for more Https://www.ThesisScientist.com
training. Multimedia for software interfaces are often done as a collaboration
between creative professionals and software engineers.
5 Industry
In the Industrial sector, multimedia is used as a way to help present
information to shareholders, superiors and coworkers. Multimedia is also
helpful for providing employee training, advertising and selling products all
over the world via virtually unlimited web-based technologies.
6 Mathematical and Scientific Research
In Mathematical and Scientific Research, multimedia are mainly used for
modelling and simulation. For example, a scientist can look at a molecular
model of a particular substance and manipulate it to arrive at a new
substance. Representative research can be found in journals such as the
Journal of Multimedia.
7 Medicine
In Medicine, doctors can get trained by looking at a virtual surgery or they
can simulate how the human body is affected by diseases spread by viruses
and bacteria and then develop techniques to prevent it.
4.5 DELIVERING MULTIMEDIA OVER WEB PAGES
Multimedia can be delivered over Web pages by using various HTML tags. When
multimedia is embedded into an HTML document or a Web page, it is termed as
Hypermedia. The application of various multimedia elements in a Web Page can be
done as follows:
1 Images
Images are included in an HTML document by using an <IMG> tag as follows:
<IMG SRC="image.gif" />
Where IMG stands for image and SRC stands for source. The source of the
image is going to be the Web address of the image.
Some of the standard attributes used to control image appearance are:
for more Https://www.ThesisScientist.com
ALT: The "ALT" attribute tells the reader what he or she is missing on a page
if the browser can't load images. The browser will then display the alternate
text instead of the image.
HEIGHT: The “HEIGHT” attribute determines the height of the image on the
web page.
WIDTH: The “WIDTH” attribute determines the width of the image on the web
page.
BORDER: The “BORDER” attribute determines the boundary or border size
on the web page.
ALIGN: The “ALIGN” attribute provides proper alignment to the image relative
to the web page.
For example,
<img src = “image.gif” alt = “Demo” height = “250” width = “200” border = “2”
align = “center” />
2 Other Multimedia Contents
Other multimedia contents like audio file or video file can be included in a
Web page by using <embed> tag
In general embed element takes src attribute to specify the URL of the
included binary object. The height and width attributes often are used to
indicate the pixel dimensions of the included object, if it is visible. For
example,
<EMBED src = “welcome.avi” height = “100” width = “100”></embed>
The <embed> tag displays the plug – in as part of the HTML / XHTML
document.
Some of the other attributes used in embed element are:
(i) align: used to align the object relative to the page and allow text to flow
around the object.
(ii) hspace and vspace: used to set the buffer region, in pixels, between
the embedded objects and the surrounding text.
for more Https://www.ThesisScientist.com
(iii) Border: used to set a border for the plug – in, in pixels.
Values for height and width should always be set, unless the hidden
attribute is used. Setting the hidden attribute to true in an <embed> tag
causes the plug – in to be hidden and overrides any height and width
settings.
4.5 VRML
“VRML STANDS FOR VIRTUAL REALITY MODELLING LANGUAGE AND IS
PRONOUNCED „VERMIL‟. IT IS A STANDARD FOR DELIVERING 3D RENDERING
ON THE NET, JUST LIKE HTML IS A STANDARD FOR WEB PAGES.”
Purpose: The Virtual Reality Modeling Language is a file format for describing
interactive 3D objects and worlds. VRML is designed to be used on the Internet,
intranets, and local client systems. VRML is also intended to be a universal interchange
format for integrated 3D graphics and multimedia.
Use: VRML may be used in a variety of application areas such as engineering and
scientific visualization, multimedia presentations, entertainment and educational titles,
web pages, and shared virtual worlds.
HISTORY OF VRML
VRML 1.0
 This is the first generation of VRML.
 It describes the foundations of a world including geometry, lighting,
color, texture and linking.
 VRML 1.0 is designed to meet the following requirements:
– Platform independence
– Extensibility
– Ability to work well over low-bandwidth connections
for more Https://www.ThesisScientist.com
 No support for interactive behaviors.
VRML 2.0
 This is the current generation of VRML.
 It has a richer level for interactivity and includes support for animation,
spatial sound and scripting in addition to features that are already
supported in VRML 1.0.
 VRML Architecture Board made it official in March 1996.
VRML 97
 VRML 97 is the ISO standard for VRML.
 It is developed based on VRML 2.0.
 More realism in static worlds.
 Interaction from sensors.
 Can be used to represent Motion, behaviors.
FEATURE OF VRML
The various features of VRML are as follows:
1 Extensibility
Provide the ability to add new object types not explicitly defined in VRML, e.g.
Sound.
2 Dynamic
Interaction and animation is achieved via an event model, behaviour can be
programmed in Java and JavaScript.
3 Compact
Descriptions of geometry can be compact, using a reuse mechanism. High
compression ratios are achieved with gzip.
for more Https://www.ThesisScientist.com
4 Composability
Provide the ability to use and combine dynamic 3D objects within a VRML
world and thus allow re-usability (Object orientated approach).
5 Platform Independent
Emphasize scalable, interactive performance on a wide variety of computing
platforms.
6 Multimedia Support
Capable of representing multimedia objects with hyperlinks to other media
such as text, sounds, movies, and images.
BASICS OF VRML
VRML code is simply a text file, case sensitive.
Header:
– #VRML V2.0 utf8
Comments indicated by „#‟ sign
A VRML file is essentially a collection of Objects called Nodes which can be something
 physically: Sphere, Cylinder, etc. or
 non-physically: Viewpoints, Hyperlinks, Transformations, Sound, etc.
Each Node contains Fields which hold the data of the node.
Some nodes are container nodes or grouping nodes, which contain other nodes.
Nodes are arranged in hierarchical structures called scene graphs. Scene graphs are
more than just a collection of nodes; the scene graph defines an ordering for the nodes.
The scene graph has a notion of state, i.e. nodes earlier in the world can affect nodes
that appear later in the world.
for more Https://www.ThesisScientist.com
4.5 JAVA AN INTRODUCTION
“JAVA IS AN OBJECT-ORIENTED PROGRAMMING LANGUAGE THAT WAS
DESIGNED TO MEET THE NEED FOR A PLATFORM INDEPENDENT LANGUAGE.”
Java is used to create applications that can run on a single computer as well as
distributed network. Java is both a language and a technology used to develop stand-
alone and Internet-based applications.
Java technology is simultaneously a programming language and a platform.
1. Java as a Programming Language
Java is a general-purpose high-level object programming language that provides the
following characteristics:
 Simple
 Object Oriented
 Interpreted
 Architecture-Neutral
 Platform Independent
 Multithread
 Dynamic
 High-Performance
 Distributes
 Robust
 Secure
Usually, a programming language requires either a compiler or an interpreter to
translate a code written in high-level programming language (source code) into its
machine language (object code) equivalent. But, to run a Java Program, Java uses a
combination of compiler and interpreter. The compiler translates the Java program into
an intermediate code called Java byte code. Java interpreter is used to run the
compiled Java Byte Code. This allows Java Programs to be executed on different
platforms.
Java
source code
(Sample.java)
Compiler
Java
byte code
(Sample.class)
Interpreter Object
Code
for more Https://www.ThesisScientist.com
Java as a compiler and interpreter
Java is a strongly typed language, means, every variable (or expression) has a type
associated with it and the type is known at the time of compilation. Thus, in Java, data
type conversions do not take place implicitly.
There are three kinds of Java Programs:
 Applications. These are stand-alone programs that run on a computer.
 Applets. These are programs that run on web browser. Appletviewer is
provided to ensure that these programs run without a web browser.
 Servlets. These are programs that run at the server side.
2. Java as a Platform
A software and/or hardware environment in which a program runs is referred to as a
„platform‟. The Java platform is a software that is compatible with and/ or executes on
platform based on different hardwares. The Java run-time environment is shown below:
Source Code
Compiler
Byte Code
Virtual
Machine
(Interpreter)
Object Code
Operating System
for more Https://www.ThesisScientist.com
Run-time Environment for Java
The Java platform consists of the Java Virtual Machine and the Java application
Programming Interface. These two important components of the Java platform can be
analyzed as follows:
Java Virtual Machine ( JVM ). It is an interpreter, which receives bytecode files and
translates them into machine language (object code) instructions. The JVM is specific to
each operating system (for example, UNIX, Linux, Windows).
Java Application Programming Interface ( Java API ). This is a collection of software
components that offer various useful functions. The API is grouped in the form of
packages (libraries) of interrelated classes as well as interfaces.
NEED FOR JAVA
Java is needed for the following many reasons:
1. Java is a platform independent programming language that enables us to
compile an application on one platform and execute it on any platform.
2. Java is a software independent programming language as its applications
can be run on any operating system.
3. Java is a hardware / device independent programming language such
that it can work everywhere, from the smallest device, such as microwave
ovens and remote controls to supercomputers.
4. Java programming language enables us to develop an Internet - based
applications that can be accessed by programmers working on various types
of computers.
5. Java provides a runtime environment, which implements various security
checks on Java applets or applications and does not allow them to perform
any malicious tasks.‟
To develop an efficient application with above mentioned features, Java is needed.
CHARACTERTICS OF JAVA
Hardware
for more Https://www.ThesisScientist.com
Java has unrivalled features that make it popular as a programming language. It is
simple, is highly robust, secure, platform-independent, and hence portable. These
features of Java are given below:
1. Java is a simple and object oriented language. A Java programmer does not
need to know about the details of Java as to how memory is allocated to data, because
in Java, the programmer does not need to handle memory manipulations.
Java is a true object-oriented programming language. Almost everything in Java is an
object and data reside within objects and classes. Java supports various features of
object-oriented programming language, such as, abstraction, encapsulation,
inheritance and polymorphism.
2. Java is Highly Secure. Java allows programmers to develop (or create) highly
reliable software applications. It provides extensive compile-time checking, followed by a
second level of run-time checking. Java technology is designed to operate in distributed
environments, which means that security is of paramount importance.
3. Java is Portable / Platform Independent. Portability refers to the ability of a
program to run on any platform without changing the source code of the program. The
programs developed on one computer can run on another computer which might have a
different platform. Java enables the creation of cross-platform programs by compiling
the program into an intermediate code called Java Byte Code.
Source Code
JVM
Compiler
Byte Code
In „JAVA‟
Byte Code
JVM
Interpreter
Machine Language
HOST
LOCAL
for more Https://www.ThesisScientist.com
In „C‟
4. Java Shows High Performance. Java performance is impressive for an
interpreted language, mainly due to the use of intermediate byte code.
 Java‟s architecture is designed to reduce overheads during runtime.
 Incorporation of multi-threading enhances the overall execution speed of Java
programs.
5. Java is Compiled and Interpreted. The Java programs are first compiled and
then interpreted. While compiling, the compiler checks for the errors in the program
and list them all on the screen. After error-correction, the program is recompiled and
then the compiler converts the program into computer language. The Java compiler
compiles the code to a Byte code that is understood by Java. When Java source code
file (.java) is compiled, the Java compiler generates the Bytecode, which is a compiled
Java program with a „.class‟ extension.
The Java Virtual Machine (JVM) then interprets the Byte code into the computer code
and runs it. While interpreting the interpreter software reads and executes the code line
by line.
6. Java is Distributed. Java is used to develop applications that can be distributed
among various computers on the network. Java applications can open and access
remote objects on the Internet in the same manner as they can open and access objects
in a local network.
7. Multithreaded and Interactive. Multithreaded means handling multiple tasks
simultaneously. Java supports multithreaded programs. For example, we can listen to
an audio clip while scrolling a page and at the same time download an applet from a
distant computer. This feature greatly improves the interactive performance of graphical
applications.
8. Java is Dynamic and Extensible. Java is a dynamic language. It is capable of
dynamically linking in new class libraries, methods, and objects. While the Java
compiler is strict in its compile-time static checking, the language and run-time system
are dynamic in their linking only as needed. New code modules can be linked in on
demand from a variety of sources, even from sources across a network.
9. Java is Software Independent. Java is a software independent language. An
application compiled in Java can be executed with another software using JVM.
for more Https://www.ThesisScientist.com
10. Java is Hardware / Device Independent. Java is a hardware / device
independent programming language such that it can work everywhere from the smallest
device, such as microwave oven, and remote controls to supercomputers.
JAVA DEVELOPMENT KIT (JDK)
Sun Microsystems offer the JDK, which is required to write, compile and run Java
programs. JDK is offered as part of commercial development environments by third-
party vendors.
The JDK consists of the following:
 Java development tools, including the compiler, debugger, and Java interpreter.
 Java class libraries, organized into a collection of packages.
 A number of sample programs.
 Various supporting tools and components, including the source code of the
classes in the libraries.
 Documentation describing all the packages, classes and methods in Java.
To transform a program into a format that a computer can understand, a compiler is
needed. The default Java compiler provided by the JDK is called javac. In order to
execute or run a program a run-time environment containing a Java interpreter is
needed. The Java interpreter provided by JDK is called java. Other run-time
environments include Java Run-Time Environment (JRE), browsers with inbuilt
runtime environments and AppletViewer to execute/run applets even without browser.
The JDK also provides a debugger tool for debugging programs. Debugging is the
process of locating and fixing errors in programs.
JAVA RUNTIME ENVIRONMENT
The Java Runtime Environment (JRE), also known as Java Runtime, is part of the Java
Development Kit (JDK), a set of programming tools for developing Java applications.
The Java Runtime Environment provides the minimum requirements for executing a
Java application; it consists of the Java Virtual Machine (JVM), core classes, and
supporting files.
The Java Runtime Environment, or JRE, or J2RE is a software bundle from Sun
Microsystems that allows a computer system to run a Java application. Java
applications are in widespread use and necessary to view many Internet pages.
The software bundle consists of the JVM and programming interface (API). The API
(Application Programming Interface) provides a set of standard class libraries. The
virtual machine and API have to be consistent with each other and are therefore
for more Https://www.ThesisScientist.com
bundled together as the JRE. This can be considered a virtual computer in which the
virtual machine is the processor and the API is the user interface.
JAVA ARCHITECTURE
Various important components of the Java Architecture are:
 Java Virtual Machine (JVM).
 Java Application Programming Interface (API).
Java Virtual Machine (JVM)
Java Virtual Machine (JVM) is an interpreter that converts the Bytecode file
into Machine object code. The JVM needs to be implemented for each
platform running on a different operating system.
JVM forms the base for the Java platform and is convenient to use on various
hardware-based platforms.
Components of the JVM:
JVM for different platforms uses different techniques to execute the Bytecode.
The major components of JVM are:
 Class Loader. It loads the class files, which are required by a program
running in the memory. The classes are loaded dynamically when
required by the running program.
 Execution Engine. The Java execution engine is the component of the
JVM that runs the Bytecode one line after another. The execution
engines implemented by different vendors use different techniques to
run the Bytecode. The Java execution engine converts the Bytecode to
the machine object code and runs it.
 Just In Time (JIT) Compiler. The JIT compiler is used to compile the
Bytecode into executable code. The JVM runs the JIT-compiled code
without interpreting because JIT compiled code is in the machine code
format. Running the JIT-compiled code is faster than running the
interpreted code because it is compiled and does not require to be run,
line after line.
Java Application Programming Interface (API)
The Java API is a collection of software components that provide capabilities,
such as GUI. The related classes and interfaces of the Java API are grouped
into packages.
for more Https://www.ThesisScientist.com
The following figure shows how the Java API and the JVM forms the platform
for the Java programs on top of the hardware:
Java Platform
Components of Java Platform
JAVA APPLICATION TO APPLET
Typically, Java programs are compiled into applets or applications.
Applications are stand-alone programs executed by a virtual machine, while applets are
intended to be loaded into and interpreted by a browser such as Netscape or Internet
Explorer.
Applets are more complex than applications because they interact with the current
environment of the browser, while applications are more like standard programs.
Java has no pointer types and presents a computation model that guarantees safety.
Thus, when an user executes a Java application or applet from an untrusted source, he
or she can be assured that the Java program will not use the memory in unknown or
perhaps cruel manner.
Simple Java Application Program
class StartProgram Class declaration
Start of program block
Java
Program
(.java)
Java API
(JVM)
Hardware
for more Https://www.ThesisScientist.com
{
// Comments
public static void main(String args[ ])
{
System.out.println(“This is a simple java program.”);
}
}
The above program declares a class named StartProgram in which a method called
main() is defined. In this method a single method is invocated that displays the
string „ This is a simple java program.‟ This string is displayed on the console when
the program is executed.
Output is achieved by invoking the println method of the object out. The object
out is a class variable in the class System that performs output operations on
files..
Compiling and Running a Java Program
A simple program is usually written using notepad (or any other compatible editor)
and saved with the extension java). The name of the program should match the
name of the class(as in program above StartProgram.java).
The Java compiler is used to compile the program. The Java compiler is offered
with the Java development kit.
Compiling a Java program
On compiling the program a class file is created, i.e., StartProgram.class.
Program Name
C:> javac StartProgram.java
Java Compiler
Method
End of program block
for more Https://www.ThesisScientist.com
For the purpose of executing (running) the class file, Java provides an interpreter
(java). This can be invoked as shown below:
Invoking the Java Interpreter
JAVA APPLET
“AN APPLET IS A JAVA PROGRAM THAT CAN BE EMBEDDED IN AN HTML WEB
PAGE.”
To create a user friendly and interactive application, it is a better technique to use
forms to interact with the users. To accept data from user applets can be created in
Java. Java provides Java Development Kit (JDK) that enables to create user interactive
forms in applets.
JDK consists of a package Abstract Window Toolkit (AWT). AWT is an Application
Programming Interface (API) that is responsible for building Graphical User Interface
(GUI) in Java. The API of the AWT package consists of a collection of classes and
methods that enables to design and manage the Graphical User Interface (GUI)
applications. The AWT package supports applets, which help in creating containers,
such as frames or panels that run in the GUI environment.
Java programs are categorized into applications and applets. An application is a Java
program that runs by using the Java interpreter from the command line. Java
applications support the Character User Interface (CUI).
Class File
Java interpreter
C:>java StartProgram
This is a simple java program.
Output Generated
for more Https://www.ThesisScientist.com
An applet is compiled on one computer and can run on another computer through a
Java enabled Web browser or an appletviewer. Applets are developed to support the GUI
in Java.
APPLET CLASS
The Applet class is a member of the Java API package, java.applet. It is used to create a
Java program that displays an applet.
Some of the common methods available in Applet package are:
void init()
• This is the first method to execute
• It is an ideal place to initialize variables
• It is the best place to define the GUI Components (buttons, text fields,
scrollbars, etc.), lay them out, and add listeners to them
• Almost every applet you ever write will have an init( ) method
void start()
• Not always needed
• Called after init( )
• Called each time the page is loaded and restarted
• Used mostly in conjunction with stop( )
• start() and stop( ) are used when the Applet is doing time-consuming
calculations that you don‟t want to continue when the page is not in front
void stop()
• Not always needed
• Called when the browser leaves the page
• Called just before destroy( )
for more Https://www.ThesisScientist.com
• Use stop( ) if the applet is doing heavy computation that you don‟t want to
continue when the browser is on some other page
• Used mostly in conjunction with start()
void destroy()
• Seldom needed
• Called after stop( )
• Use to explicitly release system resources (like threads)
• System resources are usually released automatically
void paint(Graphics g)
• Needed if you do any drawing or painting other than just using standard GUI
Components
• Any painting you want to do should be done here, or in a method you call from
here
• Painting that you do in other methods may or may not happen
• Never call paint(Graphics), call repaint( )
void repaint()
• Call repaint( ) when you have changed something and want your changes to
show up on the screen
• repaint( ) is a request--it might not happen
• When you call repaint( ), Java schedules a call to update(Graphics g)
CREATING AN APPLET
for more Https://www.ThesisScientist.com
Creating an Applet program involves following steps:
1. Create a Java program.
2. Compile the Java program.
3. Create a Web page that contains an applet.
4. Run the applet using appletviewer.
5.
A SIMPLE APPLET JAVA PROGRAM
import java.applet.*;
public class StartApplet extends Applet
{
String message = “Applet program”;
String message1 = “ ”;
public void Start()
{
System.out.println(message);
System.out.println(message1);
}
public void init()
{
StartApplet Text;
Text = new StartApplet();
Text.message1 = “Write the message”;
Text.Start();
}
}
In the above program, the line
import java.applet.*;
implies that the standard class Applet should be imported before writing an applet
program. This would ensure that all the features of the class Applet can be accessed by
the program.
Extension to the class Applet ensures that StartApplet would be a child class of the
class Applet.
The method Start() outputs two lines of text to the default system output that is the
DOS window.
for more Https://www.ThesisScientist.com
The method init() is the main executable part of a Java program when StartApplet is
run as an applet. This method instantiates the class Text and replaces the empty
string in message1 with „Write the message‟, and then calls the method Start to print
the two lines of text.
These programs are placed inside a web page that is usually written in HTML (Hyper
Text Markup Language).
After the program StartApplet.java is compiled, a HTML document (written as below)
calls and runs the applet StartApplet.class:
<html>
<head>
<title> StartApplet</title>
</head>
<body bgcolor = “aaaaaa”>
<h1>An Applet Program</h1>
<applet code = StartApplet.class width=400 height=400>
</applet>
</body>
</html>
The above HTML file is saved as AppletHtml.html. When this file is opened through a
web browser, the program StartApplet.class is executed.
Invoking the applet without a HTML code. Another method to invoke the applet
without writing the HTML code is by including the following code in the StartApplet
program itself.
import java.applet.*;
/*<applet code=StartApplet height=400 width=400></applet>*/
public class StartApplet extends Applet
{
……….
……….
}
To run this program use appletviewer:
for more Https://www.ThesisScientist.com
C:>appletviewer StartApplet.java
Running the applet gives the following output:
Applet program.
Write the message.
A Simple Applet Program to Design a Human Face
import java.awt.*;
import java.applet.*;
/*<applet code=StartApplet height=400 width=400></applet>*/
public class Face extends Applet
{
public void paint(Graphics g)
{
g.drawOval(40,40,120,150);
g.drawOval(57,75,30,20);
g.drawOval(110,75,30,20);
g.fillOval(68,81,10,10);
g.fillOval(121,81,10,10);
g.drawOval(85,100,30,30);
g.fillArc(60,125,80,40,180,180);
g.drawOval(25,92,15,30);
g.drawOval(160,92,15,30);
}
}
The output of the program will be as shown below:
for more Https://www.ThesisScientist.com
4.8 APPLET WINDOW TOOLKIT
“APPLET WINDOW TOOLKIT (AWT) IS THE USER INTERFACE TOOLKIT PROVIDED
BY THE JAVA LANGUAGE LIBRARY.”
The package Java.awt.* implements the Java AWT and contains all the classes and
interfaces necessary for creating a user interface.
The key elements required to create a GUI include the following:
for more Https://www.ThesisScientist.com
Components. A component is a visual object containing text or graphics. It can
respond to keyboard or mouse inputs. For example, buttons, labels, textboxes, check
boxes, and lists.
Container. A container is a graphical object that contains components or other
containers. Frame is the most important type of container.
Event Handlers. An event is generated when an action occurs, such as mouse click on
a button or a carriage return (enter) in a text field. Events are handled by creating
listener classes which implement listener interfaces (ActionListener, MouseListener,
MouseMotionListener, WindowListener, etc). The standard listener interfaces are found
in java.awt.event.
Layout Manager. A layout manager is automatically associated with each container
when it is created. Examples are BorderLayout and GridLayout.
BASIC CLASSES OF APPLET
Graphics
The class Graphics is an abstract class that provides methods for drawing
and manipulating fonts and colors. This class provides features for
designing different shapes like Line, Rectangle, Oval, Arc, Polygon, etc. The
various methods in the Graphics Class are:
Method Function
drawLine() Draws a line in an applet
drawRect() Draws an outlined rectangle in an applet
drawOval() Draws an ellipse in an applet
drawArc() Draws an arc in an applet
drawPolygon() Draw a polygon in an applet
draw3DRect() Draws a highlighted 3D rectangle in an applet
drawRoundRect() Draws a round cornered rectangle in an applet
fillRect() Draw a filled rectangle in an applet
fillOval() Draws a filled ellipse in an applet
fillArc() Draws a filled arc in an applet
for more Https://www.ThesisScientist.com
fillPolygon() Draws a filled polygon in an applet
fill3DRect() Draws a 3D rectangle in an applet
drawImage() Draws an image in an applet
drawPolyline() Draws a sequence of lines in an applet
fillPolygon() Fills a sequence of lines in an applet
fillRoundRect() Fills a rounded rectangle in an applet
drawstring() Draws a string of text at the specified position
in an applet
getColor() Gets the foreground drawing color
setColor() Sets the foreground drawing color
Sample Graphics Methods
• A Graphics is something you can paint on
• g.drawString(“Hello”, 20, 20);
• g.drawRect(x, y, width, height);
• g.fillRect(x, y, width, height);
• g.drawOval(x, y, width, height);
• g.fillOval(x, y, width, height);
• g.setColor(Color.red);
• g.drawArc(x, y, width, height, startAngle, arcAngle)
Color
The Color class is used to manipulate colors using the methods and
constants defined in it. Every color is a combination of Red, Green, and
Blue. Combinations of these three colors, which take values from 0 to 255
or 0.0 to 1.0, can generate any new color. Graphics class has the methods
setColor() and getColor().
for more Https://www.ThesisScientist.com
CLASS HEIRARCHY OF AWT
The key concepts of AWT class hierarchy are the following:
 Component is an object that can be displayed on the screen and can interact
with the user. For example, textbox, labels, buttons, etc. It is an abstract class.
All other classes are non-abstract.
 The Component class is superclass of all the non-menu-related user-interface
classes. It provides support for event-handling, drawing of components and so
on.
 Container is a component that contains other components. These have special
properties, and layout managers.
 Windows is a container with some special features such as a toolkit for creating
components and a warning message for security purpose. The Window class
represents a top-level window. Neither Window nor Panel classes has title, menus
or borders. The Window class is rarely used directly and its sub-classes Frame
and Dialog are more common.
 The Panel class does not have a title, menu, or border. The Applet class is used
to run programs that run in a web browser.
 The Frame class is a sub-class of the Window class. It is used to create a GUI
application window.
Component
Container
Panel Window
Applet Dialog Frame
for more Https://www.ThesisScientist.com
AWT CONTROLS
Controls are the components that allows the user to interact with an application. The
layout managers are used to arrange the AWT components. AWT supports several types
of controls. These are listed below:
 Label
 Radiobuttons
 Choice Lists
 Buttons
 Scroll Bars
 Text Area
 Lists
 Text Field
 Check Boxes
4.8 EVEVT HANDLING
In Java, each component fires an event whenever a user carries out a specific action.
Each event is represented by a class.
“AN EVENT IS AN INSTANCE OF THE CLASS EVENT WHICH IS IN THE AWT
LIBRARY.”
Whenever an event is fired, it is received by one or more listeners which can act on that
event. This process is known as the event delegation process. When an event is fired
on a component, it is passed to another component called the listener. This listener
continuously listens for the event to be fired and takes up a specific task on receiving
the signal.
The steps taken in handling the events that take place are the following:
 A class that extends a frame or an applet (any container) and implements a
particular listener is created.
 The event with the component that fires the event is registered.
 A class has the implementation for the methods in the listener interface is
created.
4.9 LAYOUT MANAGER
The layout managers are used to position the components within a container (an
applet, a panel, or a frame). Java defines the five layout managers:
for more Https://www.ThesisScientist.com
 FlowLayout
 BorderLayout
 CardLayout
 GridLayout
 GridBagLayout
These are all sub-classes that implement the LayoutManager interface. Each container
object is associated with the layout manager. The default layout manager for the applet
is FlowLayout and the default for frames is BorderLayout. Different layouts can be set
to the container using the method
Void setLayout(LayoutManager layoutmanagerinstance)
4.9.1 FLOW LAYOUT MANAGER
The FlowLayout manager is the layout manager that arranges the components of the
container in the same manner as the word-pad editor arranges the words contained in
it. That is, it arranges the components of the container from top-left of the container
and moving towards the bottom-right of the container with the small spaces between
them.
setLayout(new FlowLayout(FlowLayout.CENTER));
4.9.2 BORDER LAYOUT MANAGER
The BorderLayout manager divides the container into five regions: four borders and one
large central area. Only one object can be added on each region. To add a component
on the specified region, the add method is used. The various constants in the
BorderLayout manager are BorderLayout.NORTH, BorderLayout.SOUTH,
BorderLayout.EAST, BorderLayout.WEST, and BorderLayout.CENTER.
setLayout(new BorderLayout());
Button a=new Button(“OK”);
add(a, BorderLayout.EAST);
4.9.3 CardLayout Manager
The CardLayout is the only layout class which can hold several layouts in it. Each
layout can have separate index card in a deck that can be shuffled so that any card can
be on top at a given time. The cards are typically held in an object of type panel. This
panel must have CardLayout selected as its layout manager. The cards that form the
deck are also typically objects of type panel. Thus, a panel that contains the deck and
panel for each card in the deck have to be created. Next, the components of each card
have to be added to the appropriate panel. Then these panels have to be added to the
for more Https://www.ThesisScientist.com
panel for which CardLayout is the layout manager. Finally, this panel has to be added
to the main applet panel. This layout manager is not possible to be implemented in a
2D environment. Thus it is not used in practice.
4.9.4 GridLayout manager
The GridLayout is the layout that divides the container into rows and columns. The
components are then added to the layout in cells. The intersection of a row and a
column of the grid layout is called cell.
The GridLayout class of Java enables to create a grid layout. All the components are of
the same size. The position of a component in a grid is determined by the order in
which the components are added to the grid. The following describes the various
constructors that can be used to create an instance of the GridLayout class:
 GridLayout(): Creates a grid layout with the specified number of component in a
single row.
 GridLayout(int r, int c): Creates a grid layout with the specified number of rows
and columns.
 GridLayout(int r, int c, int h, int v): Creates a grid layout with the specified
number of rows and columns and the specified horizontal and vertical space
between the components.
void init()
{
setLayout(new GridLayout(2,3));
add(new Button(“Red”));
add(new Button(“White”));
add(new Button(“Green”));
add(new Button(“Blue”));
add(new Button(“Black”));
add(new Button(“Cyan”));
}
GridBagLayout manager
The GridBagLayout is a sophisticated and flexible layout manager. GridBagLayout
places components in a grid of rows and columns, allowing specified components to
span multiple rows or columns. Not all rows necessarily have the same height.
Similarly, not all columns necessarily have the same width.
The following constructor can be used to create an instance of the GridBagLayout class:
GridBagLayout()
for more Https://www.ThesisScientist.com
For example,
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code="AppletExample2.class" width="500" height="500"></applet>*/
public class AppletExample2 extends Applet implements ActionListener
{
String str=new String();
String str1=new String();
String str2=new String();
int len;
Panel p=new Panel();
Label l1;
Label l2;
Label l3;
TextField tf1=new TextField(20);
TextField tf2=new TextField(20);
TextField tf3=new TextField(20);
Button b;
public void init()
{
GridBagLayout gl=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
this.add(p);
p.setLayout(gl);
l1=new Label("Name:");
l2=new Label("Address:");
l3=new Label("Length:");
b=new Button("OK");
b.addActionListener(this);
gbc.gridx=0;
gbc.gridy=0;
for more Https://www.ThesisScientist.com
gbc.anchor=GridBagConstraints.CENTER;
gl.setConstraints(l1,gbc);
p.add(l1);
gbc.gridx=1;
gbc.gridy=0;
gbc.anchor=GridBagConstraints.CENTER;
gl.setConstraints(tf1,gbc);
p.add(tf1);
gbc.gridx=0;
gbc.gridy=1;
gbc.anchor=GridBagConstraints.CENTER;
gl.setConstraints(l2,gbc);
p.add(l2);
gbc.gridx=1;
gbc.gridy=1;
gbc.anchor=GridBagConstraints.CENTER;
gl.setConstraints(tf2,gbc);
p.add(tf2);
gbc.gridx=0;
gbc.gridy=2;
gbc.anchor=GridBagConstraints.CENTER;
gl.setConstraints(l3,gbc);
p.add(l3);
gbc.gridx=1;
gbc.gridy=2;
gbc.anchor=GridBagConstraints.CENTER;
gl.setConstraints(tf3,gbc);
p.add(tf3);
gbc.gridx=0;
gbc.gridy=3;
gbc.gridwidth=2;
` gbc.anchor=GridBagConstraints.CENTER;
gl.setConstraints(b,gbc);
for more Https://www.ThesisScientist.com
p.add(b);
}
public void actionPerformed(ActionEvent e)
{
str1=tf1.getText();
str2=tf2.getText();
int i=str1.length();
int j=str2.length();
str=String.valueOf(i+j);
tf3.setText(str);
}
}
4.9 SERVELET
“SERVLETS ARE JAVA PROGRAMS THAT CAN BE DEPLOYED ON JAVA
ENABLED WEB SERVER TO ENHANCE AND EXTEND THE FUNCTIONALITY OF
THE WEB SERVER.”
Servlets can also be used to add dynamic content to web pages.
Java Servlets are server side components that provides a powerful mechanism for
developing server side of web application. Earlier CGI was developed to provide server
side capabilities to the web application. Although CGI played a major role in the
explosion of the Internet, its performance, scalability and reusability issues make it less
than optimal solutions. Java Servlets changes all that. These provide excellent
framework for server side processing.
Servlet provide component-based, platform-independent methods for building Web-
based applications, without the performance limitations of CGI programs.
Servlets are not designed for a specific protocols. It is different thing that they are most
commonly used with the HTTP protocols.
HTTP Servlet typically used to:
for more Https://www.ThesisScientist.com
 Provide dynamic content like getting the results of a database query and
returning to the client.
 Process and/or store the data submitted by the HTML.
 Manage information about the state of a stateless HTTP. For example, an online
shopping car manages request for multiple concurrent customers.
ADVANTAGES OF SERVELETS
Java Servlets have a number of advantages over CGI and other API‟s. They are:
1. Platform Independence: Java Servlets are 100% pure Java, so it is platform
independent. It can run on any Servlet enabled Web server.
2. Performance: Due to interpreted nature of Java, programs written in Java are
slow. But the java servlets runs very fast. These are due to the way servlets run
on web server. For any program initialization takes significant amount of time.
But in case of servlets initialization takes place very first time it receives a request
and remains in memory till times out or server shut downs. After servlet is
loaded, to handle a new request it simply creates a new thread and runs service
method of servlet.
3. Extensibility: Java Servlets are developed in Java which is robust, well-designed
and object-oriented language which can be extended or polymorphed into new
objects. So the Java servlets can be extended from existing class to provide the
ideal solutions.
4. Safety: Java provides a very good safety features like memory management,
exception handling, etc. Servlets inherits all these features and emerged as a very
powerful web server extension.
5. Secure: Servlets are server side components, so it inherits the security provided
by the web server. Servlets are also benefited with Java Security Manager.
CHARECTERTICS OF SERVELETS
Servlets can be used to develop a variety of web-based applications. The characteristics
of Servlets that have gained them a wide spread acceptance are as follows:
 Servlets are Efficient. The initialization code for servlet is executed only when
the servlet is executed for the first time. Subsequently, the requests that are
received by the servlets are processed by its service() method. This helps to
increase the efficiency of the server by avoiding creation of unnecessary
processes.
for more Https://www.ThesisScientist.com
 Servlets are Robust. As servlets are based on Java, they provide all the powerful
features of Java, such as exception handling, and garbage collection, which
makes them robust.
 Servlets are Portable. Servlets are portable because they are developed in Java.
This enables easy portability across web servers.
 Servlets are Persistent. Servlets helps to increase the performance of the system
by preventing frequent disk access.
SERVELETS AND APPLETS
Applets Servlets
Applets are Java programs that are
embedded in Web pages. When a
web page containing an applet is
opened the byte code of the applet
is downloaded to the client
computer. This process becomes
time consuming if the size of applet
is too large.
As Servlets executed on the web
server, they help overcome
problems with download time faced
while using applets. Servlets do not
require the browser to be Java
enabled unlike applets because
they execute on web server and the
results are sent back to the client
or browser.
LIFECYCLE OF APPLETS
A Servlets is loaded only once in the memory and is initialized in the init() method.
After the servlet is initialized it starts accepting requests from the client and processes
them through the service() method till it shutdown by the destroy() method.
The service() method is executed for every incoming request.
The lifecycle of a servlet is depicted below:
Init( )
for more Https://www.ThesisScientist.com
Request
Response
Lifecycle of Servlet
J2EE
Java 2 Enterprise Edition (J2EE) is a set of specifications that defines the standard for
creating distributed objects.
J2EE also specifies how these technologies can be integrated to provide a complete
solution.
It is also a standard architecture that defines a multi-tier programming model.
The Java 2 Servlet Development Kit (J2SDK), Enterprise Edition (J2EE) server is a
product from Sun Microsystems that is based on the J2EE.
The J2EE server is used to deploy servlets and JSP files and enables users to access
the same by implementing appropriate security.
Client
(Browser)
Service( )
Destroy( )
for more Https://www.ThesisScientist.com
DEPLOPING A SERVELET
For a servlet or a html page (that might contain a link to servlet) to be accessible from
client, first it has to be deployed on the web server. Servlet can be deployed in:
 Java Web Server (JWS)
 JRun
 Apache
JWS is a web server from Sun Microsystems that is developed based on the servlet
technology and can be used to deploy servlets.
JRun and apache can also be used to deploy servlets. JRun is a Java application server
which is a product of live software. JRun provides a high performance, scalable solution
for creating and delivering enterprise applications. The other website technologies that
can be deployed in JRun are Java Server Pages and Enterprise Java Beans.
for more Https://www.ThesisScientist.com
Apache is a web server from an organization called Apache that can be used to deploy
servlets. Few features of Apache that have made it popular are its freely distributed
code, robustness and security that is offered.
SERVELETS API AND PACKEGES
Java Servlet API contains two core packages:
 javax.servlet
 javax.servlet.http
Servlets implement the javax.servlet.Servlet interface. The javax.servlet package
contains the generic interfaces and classes that are implemented and extended by all
servlets.
While the javax.servlet.http package contains the classes that are used when developing
HTTP-specific servlets. The HttpServlet is extended from GenericServlet base class and
it implements the Servlet interface. HttpServlet class provides a framework for handling
the HTTP requests.
HTTP
HTTP is a simple, stateless protocol. A client such as a web browser makes a request,
the web server responds, and the transaction is done. When the client sends a request,
the first thing it specifies is an HTTP command called a method, that tells the server the
type of action it wants to be performed. This first line of request also specifies the
address of a document (URL) and the version of the HTTP protocol it is using. For
example:
GET/intro.html HTTP/1.0
This request uses the GET method to ask for the document named intro.html, using
HTTP version 1.0.
GET and POST
When a client connects to a server and makes an HTTP request, the request can be of
several different types called methods. The most frequently used methods are GET and
POST. The GET method is designed for getting information (document, a chart or the
results from a database query). While the POST method is designed for posting
information.
for more Https://www.ThesisScientist.com
SERVELETS CREATION
To create a servlet following steps should be followed:
Step-1 Identify the mechanism
Step-2 Identify the classes to be used
Step-3 Identify the methods to be used
Step-4 Write and compile the servlet
Step-5 Deploy the servlet
Step-6 Execute the servlet.
SECURITY ISSUES
Security is the science of keeping sensitive information in the hands of authorized
users. On the web, this boils down to four important issues:
 Authentication. Being able to verify the indentification of the parties involved.
 Authorization. Limited access to resources to a selective set of users or
programs.
 Confidentiality. Ensuring that only the parties involved can understand the
communication.
 Integrity. Being able to verify that the context of the communication is not
changed during transmission.
Authentication, authorization, confidentiality and integrity are all linked by digital
certificate technology.
Digital certificate allow web server, and clients to use advanced cryptographic
techniques to handle identification and encryption in a secure manner.
Authentication can be of any one of two or both:
 HTTP authentication: User name and password protection.

More Related Content

PPT
Active Server Page(ASP)
PPT
Active server pages
PPT
PPT
Learn ASP
PPTX
Introduction to asp
PPTX
ACTIVE SERVER PAGES BY SAIKIRAN PANJALA
DOC
Tutorial asp.net
Active Server Page(ASP)
Active server pages
Learn ASP
Introduction to asp
ACTIVE SERVER PAGES BY SAIKIRAN PANJALA
Tutorial asp.net

What's hot (20)

PPTX
Overview of ASP.Net by software outsourcing company india
PPTX
Introduction ASP
PPTX
Web forms in ASP.net
PPTX
ASP.NET Lecture 1
PPT
Web forms and server side scripting
KEY
Server Side Programming
PPTX
New Features of ASP.NET 4.0
PPTX
Client and server side scripting
PPTX
Server and Client side comparision
PPTX
Client & server side scripting
PDF
ASP.NET Overview - Alvin Lau
PPTX
Client side scripting and server side scripting
PPTX
Industrial training seminar ppt on asp.net
PPT
Scripting Languages
PDF
Chapter 1 (asp.net over view)
DOCX
Client side vs server side
PPT
ASP.NET 4.0 Roadmap
Overview of ASP.Net by software outsourcing company india
Introduction ASP
Web forms in ASP.net
ASP.NET Lecture 1
Web forms and server side scripting
Server Side Programming
New Features of ASP.NET 4.0
Client and server side scripting
Server and Client side comparision
Client & server side scripting
ASP.NET Overview - Alvin Lau
Client side scripting and server side scripting
Industrial training seminar ppt on asp.net
Scripting Languages
Chapter 1 (asp.net over view)
Client side vs server side
ASP.NET 4.0 Roadmap
Ad

Similar to DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES) (20)

PPTX
Active Server Page - ( ASP )
PDF
PPTX
ASP Detailed Presentation With Coding .pptx
PDF
Intro To Asp
PPTX
asp_intro.pptx
PPT
CIS 451: Introduction to ASP.NET
PPTX
ASP, ASP.NET, JSP, COM/DCOM
PPT
DevNext - Web Programming Concepts Using Asp Net
PPT
Asp.net basic
PPT
Web server
PPT
Aspnet
PPT
Asp.net.
DOCX
JOB PORTALProject SummaryTitle JOB-PORT.docx
PPT
Web II - 01 - Introduction to server-side development
PPT
INTRO TO JAVASCRIPT basic to adcance.ppt
PDF
Asp .net web form fundamentals
PPT
Intro To Asp Net And Web Forms
PDF
Introductionto asp net-ppt
PDF
Asp.netrole
Active Server Page - ( ASP )
ASP Detailed Presentation With Coding .pptx
Intro To Asp
asp_intro.pptx
CIS 451: Introduction to ASP.NET
ASP, ASP.NET, JSP, COM/DCOM
DevNext - Web Programming Concepts Using Asp Net
Asp.net basic
Web server
Aspnet
Asp.net.
JOB PORTALProject SummaryTitle JOB-PORT.docx
Web II - 01 - Introduction to server-side development
INTRO TO JAVASCRIPT basic to adcance.ppt
Asp .net web form fundamentals
Intro To Asp Net And Web Forms
Introductionto asp net-ppt
Asp.netrole
Ad

More from Prof Ansari (20)

PDF
Sci Hub New Domain
PDF
Sci Hub cc Not Working
PDF
basics of computer network
PDF
JAVA INTRODUCTION
PDF
Project Evaluation and Estimation in Software Development
PDF
Stepwise Project planning in software development
PDF
Database and Math Relations
PDF
Normalisation in Database management System (DBMS)
PDF
Entity-Relationship Data Model in DBMS
PDF
A Detail Database Architecture
PDF
INTRODUCTION TO Database Management System (DBMS)
PDF
Master thesis on Vehicular Ad hoc Networks (VANET)
PDF
Master Thesis on Vehicular Ad-hoc Network (VANET)
PDF
INTERFACING WITH INTEL 8251A (USART)
PDF
HOST AND NETWORK SECURITY by ThesisScientist.com
PDF
SYSTEM NETWORK ADMINISTRATIONS GOALS and TIPS
PDF
INTRODUCTION TO VISUAL BASICS
PDF
introduction to Blogging ppt
PDF
INTRODUCTION TO SOFTWARE ENGINEERING
PDF
Introduction to E-commerce
Sci Hub New Domain
Sci Hub cc Not Working
basics of computer network
JAVA INTRODUCTION
Project Evaluation and Estimation in Software Development
Stepwise Project planning in software development
Database and Math Relations
Normalisation in Database management System (DBMS)
Entity-Relationship Data Model in DBMS
A Detail Database Architecture
INTRODUCTION TO Database Management System (DBMS)
Master thesis on Vehicular Ad hoc Networks (VANET)
Master Thesis on Vehicular Ad-hoc Network (VANET)
INTERFACING WITH INTEL 8251A (USART)
HOST AND NETWORK SECURITY by ThesisScientist.com
SYSTEM NETWORK ADMINISTRATIONS GOALS and TIPS
INTRODUCTION TO VISUAL BASICS
introduction to Blogging ppt
INTRODUCTION TO SOFTWARE ENGINEERING
Introduction to E-commerce

Recently uploaded (20)

PPT
Basics Of Pump types, Details, and working principles.
PDF
Traditional Programming vs Machine learning and Models in Machine Learning
PDF
02. INDUSTRIAL REVOLUTION & Cultural, Technical and territorial transformatio...
PDF
Water Industry Process Automation & Control Monthly - September 2025
PPTX
non conventional energy resorses material unit-1
PPTX
L1111-Important Microbial Mechanisms.pptx
PDF
Recent Trends in Network Security - 2025
PDF
B461227.pdf American Journal of Multidisciplinary Research and Review
PDF
IoT-Based Hybrid Renewable Energy System.pdf
PPTX
Ingredients of concrete technology .pptx
DOCX
web lab manual for fifth semester BE course fifth semester vtu belgaum
PPT
linux chapter 1 learning operating system
PDF
1.-fincantieri-investor-presentation2.pdf
PDF
Human CELLS and structure in Anatomy and human physiology
PPTX
highway-150803160405-lva1-app6891 (1).pptx
PPTX
quantum theory on the next future in.pptx
PPT
Module_1_Lecture_1_Introduction_To_Automation_In_Production_Systems2023.ppt
PPTX
5-2d2b20afbe-basic-concepts-of-mechanics.ppt
PPTX
sinteringn kjfnvkjdfvkdfnoeneornvoirjoinsonosjf).pptx
PPTX
CC PPTS unit-I PPT Notes of Cloud Computing
Basics Of Pump types, Details, and working principles.
Traditional Programming vs Machine learning and Models in Machine Learning
02. INDUSTRIAL REVOLUTION & Cultural, Technical and territorial transformatio...
Water Industry Process Automation & Control Monthly - September 2025
non conventional energy resorses material unit-1
L1111-Important Microbial Mechanisms.pptx
Recent Trends in Network Security - 2025
B461227.pdf American Journal of Multidisciplinary Research and Review
IoT-Based Hybrid Renewable Energy System.pdf
Ingredients of concrete technology .pptx
web lab manual for fifth semester BE course fifth semester vtu belgaum
linux chapter 1 learning operating system
1.-fincantieri-investor-presentation2.pdf
Human CELLS and structure in Anatomy and human physiology
highway-150803160405-lva1-app6891 (1).pptx
quantum theory on the next future in.pptx
Module_1_Lecture_1_Introduction_To_Automation_In_Production_Systems2023.ppt
5-2d2b20afbe-basic-concepts-of-mechanics.ppt
sinteringn kjfnvkjdfvkdfnoeneornvoirjoinsonosjf).pptx
CC PPTS unit-I PPT Notes of Cloud Computing

DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES)

  • 1. for more Https://www.ThesisScientist.com UNIT 4 DYNAMIC CONTENT TECHNOLOGIES ASP(ACTIVE SERVER PAGES) “ACTIVE SERVER PAGES OR ASP IS COMMONLY KNOWN AS A TECHNOLOGY THAT ENABLES TO MAKE DYNAMIC AND INTERACTIVE WEB PAGES.” ASP uses server-side scripting to dynamically produce web pages that are not affected by the type of browser the web site visitor is using. The default scripting language used for writing ASP is VBScript, although some other languages can also be used like Jscript (Microsoft‟s version of JavaScript). ASP pages have the extension .asp instead of .htm, when a page with extension .asp is requested by a browser the web server knows to interpret any ASP contained within the web page before sending the HTML produced to the browser. Any web pages containing ASP cannot be run by just simply opening the page in a web browser. The page must be requested through a web server that supports ASP, this is why ASP stands for Active Server Pages, means no server, no active pages. 4.1 HOW ASP LOOK LIKE The appearance of an Active Server Page depends on who or what is viewing it. To the web browser that receives it, an ASP looks just like a normal HTML page. In addition to text and HTML tags, there also exists server side scripts. The code below shows what a real, live ASP page looks like: <html> <head> <title> New Page </title> </head> <body>
  • 2. for more Https://www.ThesisScientist.com <h1> My Welcome Page</h1> <p> <% if Time>#12:00:00 AM# AND_ Time<#12:00:00 PM# Then %> </p> <h2> Good Morning !!! </h2> <p> <% if Time>#12:00:00 AM# AND_ Time<#6:00:00 PM# Then %> </p> <h2> Good Afternoon !!! </h2> </body></html> SYNTAX RULE An ASP file normally contains HTML tags, just like an HTML file. However, an ASP file can also contain server scripts, surrounded by the delimiters <% and %>. Server scripts are executed on the server, and can contain any expressions, statements, procedures, or operators valid for the scripting language preferred to be used. Write Output to a Browser The response.write command is used to write output to a browser. The following example sends the text “Hello World !” to the browser: <html> <body> <% Response.write(“Hello World ! ”) %> </body> </html> There is also a shorthand method for the response.write command. The following example also sends the text “Hello World !” to the browser:
  • 3. for more Https://www.ThesisScientist.com <html> <body> <%=”Hello World ! ”%> </body> </html> 4.2 LIFE TIME OF A VARIABLE A variable declared outside a procedure can be accessed and changed by any script in the ASP file. A variable declared inside a procedure is created and destroyed every time the procedure is executed. To declare variables accessible to more than one ASP file, declare them as session variables or application variables. 4.2.1 Session Variables Session variables are used to store information about ONE single user, and are available to all pages in one application. Typically information stored in session variables are name, id, and preferences. 4.2.2 Application Variables Application variables are also available to all pages in one application. Application variables are used to store information about ALL users in a specific application. Procedures The ASP source code can contain procedures and functions: <html> <head> <% sub vbproc(num1,num2) Response.write(num1*num2)
  • 4. for more Https://www.ThesisScientist.com end sub %> </head> <body> <p> Result: <% call vbproc(3,4) %></p> </body> </html> Insert the <%@language=”language”%> line above the <html> tag to write procedures or functions in another scripting language than default: <%@ language=”javascript” %> <html> <head> <% function jsproc(num1,num2) { Response.write(num1*num2) } %> </head> <body> <p> Result: <% jsproc(3,4) %></p> </body>
  • 5. for more Https://www.ThesisScientist.com </html> 4.2.3 USER INPUT The request object may be used to retrieve user information from forms. For example: <form method=”get” action=”simpleform.asp”> First Name: <input type=”text” name=”fname” /> <br /> Last Name: <input type=”text” name=”lname” /><br /><br /> <input type=”submit” value=”Submit” /> </form> User input can be retrieved in two ways: With Request.QueryString or Request.form 4.2.4 Request.QueryString This command is used to collect values in a form with method= “get”. Information sent from a form with the GET method is visible to everyone (will be displayed in the browser‟s address bar) and has limits on the amount of information to send. If a user typed “pankaj” and “sharma” in the form example above, the URL sent to the server would look like this: http://www.abes.ac.in/simpleform.asp?fname=pankaj&lname=sharma Assume that the ASP file “simpleform.asp” contains the following script: <body> Welcome <% response.write(request.querystring(“fname”)) Response.write(“ ” & request.querystring(“lname”)) %>
  • 6. for more Https://www.ThesisScientist.com </body> The browser will display the following in the body of the document: Welcome pankaj sharma 4.2.5 Request.Form This command is used to collect values in a form with method= “post”. Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send. If a user typed “Bill” and “Gates” in the form example above, the URL sent to the server would look like this: Http://www.abes.ac.in/simpleform.asp Assume that the ASP file “simpleform.asp” contains the following script: <body> Welcome <% Response.write(request.form(“fname”)) Response.write(“ ” & request.form(“lname”)) %> </body> The browser will display the following in the body of the document: Welcome Bill Gates 4.2.6 FORM VALIDATION
  • 7. for more Https://www.ThesisScientist.com User input should be validated on the browser whenever possible (by client scripts). Browser validation is faster and reduces the server load. Using server validation should be considered if the user input will be inserted into a database. A good way to validate a form on the server is to post the form to itself, instead of jumping to a different page. The user will then get the error messages on the same page as the form. This makes it easier to discover the error. 4.2.7 HOW ASP WORKS • ASP files are only processed when a client requests them from the server. • There are some .dll files such as ASP.dll which contains standard objects. • Functions are called from these dlls. • Since these functions are previously defined and known, things can be done with ASP are bounded. • ASP codes do not need to be compiled. • There exists a global.asa file which is used to specify events and global session variables which are used for all ASP files in the server. • Before any ASP file is processed, global.asa is processed and it defines global events. • The processing of an ASP file starts with the separation of ASP scripts and HTML codes in IIS. • Then each script code is processed. • The HTML corresponds of these scripts are created, and injected related places. • Final HTML codes are sent to the client and displayed by the web browser. • 4.2.7 WHAT AN ASP DO? • The most important feature of ASP is creating dynamic pages. • You can manage data with database operations such as getting and storing people‟s information in the Database. • Interactive applications can be implemented, i.e. news type people like may be displayed. • Script codes are not sent to the client, which brings security. • • ADVANTAGES OF ASP • It gives dynamism to the pages created. • Interactive pages reflecting the preferences of the user can be developed. • ASP is a very good innovation to dynamic web programming. • Data obtaining and displaying became more easy and efficient.
  • 8. for more Https://www.ThesisScientist.com • DISADVANTAGES OF ASP • It is slower than most of similar technologies. • Not very much portable. 4.3 JAVA SERVER PAGES “JAVASERVER PAGES (JSP) IS A JAVA TECHNOLOGY THAT ALLOWS SOFTWARE DEVELOPERS TO DYNAMICALLY GENERATE HTML, XML OR OTHER TYPES OF DOCUMENTS IN RESPONSE TO A WEB CLIENT REQUEST.” The technology allows java code and certain pre-defined actions to be embedded into static content..” 4.3.1 FEATURE OFF JSP JSP gives an ideal platform for creating web applications easily and quickly. The various features supported by JSP are: 1. Platform and Server Independence. The JSP technology follows the „write once‟ run anywhere, rule which is the basis of the java language. JSP technology can run on various web server including Apache, Netscape and IIS and is supported by a large variety of tools from different vendors. 2. Environment. JSP uses pure java and takes full advantage of its object- oriented nature. This technology lets the designer separate content generation from layout by accessing component from the page. 3. Extensible JSP Tags. JSP uses a combination of tags and scripting to create dynamic web pages. It allows the designer to extend the JSP tags available. JSP developers can create custom tag libraries, so that more functionality can be extracted using XML-like tags and this leads to less use of scripting in JSP pages. 4. Reusability Across Platform. The JSP pages uses components which are reusable. These reusable components help keep the pages simple and run faster. 5. Easier Maintenance. Application made using JSP technology are easier to maintain.
  • 9. for more Https://www.ThesisScientist.com JSP Architecture JSP is a part of the Java platform, Enterprise Edition (J2EE), which is the java architecture for developing multitier enterprise applications. A JSP page is executed by a JSP engine, which is installed in a web server or a JSP enabled application server. The JSP engine receives the request from a client to the JSP page and generates responses from the JSP page to the client. Handling JSP Page JSP page may be a combination of different protocols, components and formats. A JSP page is also a place to enter user information. A user may be asked to enter his home, address, a word or a phrase. The information the user enters in the form is stored in the request object, which is sent to the JSP engine. The JSP engine sends the request object to the component (Servlet) the JSP specifies. The component handles the request. The request may be to retrieve certain data or other data store. The component sends the response back to the JSP engine. Response JSP engine And Web serverRequest Response JSP File Response Request Request Client Component
  • 10. for more Https://www.ThesisScientist.com The JSP engine passes the response back to the JSP page, where the data is formatted according to the HTML design. The JSP engine and web server then sends the revised JSP page back to the client, where the user can view the results in the web browser. The communication protocol used between the client and server can be HTTP, or it can be some other protocol. JSP SYNTAX Everything in JSP can be broken into two categories:  Elements: That are processed on the server.  Template: Data are everything other than elements that the JSP engine ignores. Element data can be classified into the following categories:  Directives  Declarations  Scriptlets  Expressions  Standard Actions A JSP page contains scripting language and some special JSP tags that can encapsulate tasks that are difficult or time consuming to program. JSP Directives Directives are instructions for JSP engine that are processed when the JSP page is translated into a servlet. They are used to set global values such as class declarations, methods to be implemented, output content type etc. The directives should start with <%@ and end with %>. There are three types of JSP directives. They are: 1. The page directive defines a number of attributes that affect the whole page. The syntax is as follows: <%@ page attributes %> 2. The include directive is used to insert text and code at JSP translation time. The syntax is as follows:
  • 11. for more Https://www.ThesisScientist.com <%@ include file = “relative URL” %> The file that the file attribute refers to can reference a normal HTML file or another JSP file which will be evaluated at translation time. 3. The taglib directive declares that the page uses custom tags. Uniquely names the tag library defining them and associates a tag prefix that will distinguish the usage of these tags. The syntax is as follows: <%@ taglib uri = “taglibrary URL prefix” %> JSP Scriptlets JSP scripting is a mechanism for embedding code fragments directly into an HTML. There are three types of scripting elements, namely scriptlets, expressions and declarations. Scriptlets are used to embed any piece of java code into the page. The code is inserted into the generated servlet and is executed when the page is requested. The syntax for a scriptlets is as follows: <% Scriptlet source %> Scriptlet are executed at request time, when the JSP client processes the client request. If the scriptlet produces output, the output is stored in the JSP writer implicit object out. Writing a simple JSP page using Scriptlets: Hello.jsp <html> <head><title> Hello </title></head> <body> <% int x = 0; for(x = 0; x < 5; x++)
  • 12. for more Https://www.ThesisScientist.com { out.println(“<h1> Hello world ! </h1>”); } %> </body> </html> JSP Lifecycle JSP life cycle can be grouped into seven phases. 1. JSP Page Translation: A java servlet file is generated from the JSP source file. Generated servlet implements the interface javax.servlet.jsp.HttpJspPage. The interface HttpJspPage extends the interface JspPage. This interface JspPage extends the interface javax.servlet.Servlet. 2. JSP Page Compilation: The generated java servlet file is compiled into a java servlet class. The generated servlet class thus implements all the methods of the above said three (javax.servlet.jsp.HttpJspPage, JspPage, javax.servlet.Servlet) interfaces. 3. Class Loading: The java servlet class that was compiled from the JSP source is loaded into the container. 4. Instance Creation: An instance is created for the loaded servlet class. The interface JspPage contains jspInit() and jspDestroy(). The JSP specification has provided a special interface HttpJspPage for JSP pages serving HTTP requests and this interface contains _jspService(). 5. jspInit( ) execution: This method is called when the instance is created and it is called only once during JSP life cycle. It is called for the servlet instance initialization. 6. _jspService() execution: This method is called for every request of this JSP during its life cycle. It passes the request and the response objects. _jspService() cannot be overridden. 7. jspDestroy() execution: This method is called when this JSP is destroyed and will not be available for future requests.
  • 13. for more Https://www.ThesisScientist.com JSP Expressions (Conditional Processing) Expressions are used to dynamically calculate values to be inserted directly into the JSP page. These are elements that are evaluated with the result being converted to java.lang.String. After the string is converted, it is written to the out object. The expression should be enclosed within <% = and %>. While writing an expression, following points should be taken care of: 1. Semicolon cannot be used to end an expression. 2. The expression element can contain any expression that is valid according to java language specification. An expression can be complex and composed of more than one part or expression. For example, the following shows the date and time that the page requested: Current Time : <% = new java . util . Date() %> JSP Declarations (Declaring Variables and Methods) JSP declarations are used to define methods or variables that are to be used in java code later in the JSP file. The declarations get inserted into the main body of the servlet class. It has the following form: <% ! declarations %> Since declarations do not generate any output they are usually used with JSP scriptlets or expressions. For example, <% ! int i = 0; %> <% ! circle a = new circle(2,0); %> A declaration element may contain any number of variables or methods 4.4 MULTIMEDIA OVER WEB “MULTIMEDIA IS MEDIA OF CONTENTS THAT UTILIZES A COMBINATION OF DIFFERENT CONTENT FORMS INCLUDING A COMBINATION OF TEXT, AUDIO, STILL IMAGES, ANIMATION, VIDEO, AND INTERACTIVITY CONTENT FORMS.”
  • 14. for more Https://www.ThesisScientist.com The term can be used as a noun (a medium with multiple content forms) or as an adjective describing a medium as having multiple content forms. The term is used in contrast to media which only utilize traditional forms of printed or hand-produced material. Multimedia is any combination of digitally manipulated text, art, sound, animation and video. Multimedia is usually recorded and played, displayed or accessed by information content processing devices, such as computerized and electronic devices, but can also be part of a live performance. Multimedia (as an adjective) also describes electronic media devices used to store and experience multimedia content. Multimedia is similar to traditional mixed media in fine art, but with a broader scope. The term "rich media" is synonymous for interactive multimedia. Hypermedia can be considered one particular multimedia application. CATEGORIES OF MULTIMEDIA Multimedia may be broadly divided into linear and non-linear categories.  Linear active content progresses without any navigation control for the viewer such as a cinema presentation.  Non-linear content offers user interactivity to control progress as used with a computer game or used in self-paced computer based training.  FEATURE OF MULTIMEDIA  Multimedia presentations may be viewed in person on stage, projected, transmitted, or played locally with a media player.  Multimedia games and simulations may be used in a physical environment with special effects, with multiple users in an online network, or locally with an offline computer, game system, or simulator.  Enhanced levels of interactivity are made possible by combining multiple forms of media content. APPLICATION OF MULTIMEDIA Multimedia finds its application in various areas including, but not limited to, advertisements, art, education, entertainment, engineering, medicine, mathematics, business, scientific research and spatial temporal applications. Below are the several examples as follows:
  • 15. for more Https://www.ThesisScientist.com 1 Creative industries Creative industries use multimedia for a variety of purposes ranging from fine arts, to entertainment, to commercial art, to journalism, to media and software services provided for any of the industries listed below. An individual multimedia designer may cover the spectrum throughout their career. Request for their skills range from technical, to analytical, to creative. 2 Entertainment and Fine Arts In addition, multimedia is heavily used in the entertainment industry, especially to develop special effects in movies and animations. Multimedia games are a popular pastime and are software programs available either as CD-ROMs or online. Some video games also use multimedia features. Multimedia applications that allow users to actively participate instead of just sitting by as passive recipients of information are called Interactive Multimedia. In the Arts there are multimedia artists, whose minds are able to blend techniques using different media that in some way incorporates interaction with the viewer. One of the most relevant could be Peter Greenaway who is melding Cinema with Opera and all sorts of digital media. Another approach entails the creation of multimedia that can be displayed in a traditional fine arts arena, such as an art gallery. For the most part these artists are using materials that will not hold up over time. 3 Education In Education, multimedia is used to produce computer-based training courses (popularly called CBTs) and reference books like encyclopedia and almanacs. A CBT lets the user go through a series of presentations, text about a particular topic, and associated illustrations in various information formats. Edutainment is an informal term used to describe combining education with entertainment, especially multimedia entertainment. 4 Engineering Software engineers may use multimedia in Computer Simulations for anything from entertainment to training such as military or industrial
  • 16. for more Https://www.ThesisScientist.com training. Multimedia for software interfaces are often done as a collaboration between creative professionals and software engineers. 5 Industry In the Industrial sector, multimedia is used as a way to help present information to shareholders, superiors and coworkers. Multimedia is also helpful for providing employee training, advertising and selling products all over the world via virtually unlimited web-based technologies. 6 Mathematical and Scientific Research In Mathematical and Scientific Research, multimedia are mainly used for modelling and simulation. For example, a scientist can look at a molecular model of a particular substance and manipulate it to arrive at a new substance. Representative research can be found in journals such as the Journal of Multimedia. 7 Medicine In Medicine, doctors can get trained by looking at a virtual surgery or they can simulate how the human body is affected by diseases spread by viruses and bacteria and then develop techniques to prevent it. 4.5 DELIVERING MULTIMEDIA OVER WEB PAGES Multimedia can be delivered over Web pages by using various HTML tags. When multimedia is embedded into an HTML document or a Web page, it is termed as Hypermedia. The application of various multimedia elements in a Web Page can be done as follows: 1 Images Images are included in an HTML document by using an <IMG> tag as follows: <IMG SRC="image.gif" /> Where IMG stands for image and SRC stands for source. The source of the image is going to be the Web address of the image. Some of the standard attributes used to control image appearance are:
  • 17. for more Https://www.ThesisScientist.com ALT: The "ALT" attribute tells the reader what he or she is missing on a page if the browser can't load images. The browser will then display the alternate text instead of the image. HEIGHT: The “HEIGHT” attribute determines the height of the image on the web page. WIDTH: The “WIDTH” attribute determines the width of the image on the web page. BORDER: The “BORDER” attribute determines the boundary or border size on the web page. ALIGN: The “ALIGN” attribute provides proper alignment to the image relative to the web page. For example, <img src = “image.gif” alt = “Demo” height = “250” width = “200” border = “2” align = “center” /> 2 Other Multimedia Contents Other multimedia contents like audio file or video file can be included in a Web page by using <embed> tag In general embed element takes src attribute to specify the URL of the included binary object. The height and width attributes often are used to indicate the pixel dimensions of the included object, if it is visible. For example, <EMBED src = “welcome.avi” height = “100” width = “100”></embed> The <embed> tag displays the plug – in as part of the HTML / XHTML document. Some of the other attributes used in embed element are: (i) align: used to align the object relative to the page and allow text to flow around the object. (ii) hspace and vspace: used to set the buffer region, in pixels, between the embedded objects and the surrounding text.
  • 18. for more Https://www.ThesisScientist.com (iii) Border: used to set a border for the plug – in, in pixels. Values for height and width should always be set, unless the hidden attribute is used. Setting the hidden attribute to true in an <embed> tag causes the plug – in to be hidden and overrides any height and width settings. 4.5 VRML “VRML STANDS FOR VIRTUAL REALITY MODELLING LANGUAGE AND IS PRONOUNCED „VERMIL‟. IT IS A STANDARD FOR DELIVERING 3D RENDERING ON THE NET, JUST LIKE HTML IS A STANDARD FOR WEB PAGES.” Purpose: The Virtual Reality Modeling Language is a file format for describing interactive 3D objects and worlds. VRML is designed to be used on the Internet, intranets, and local client systems. VRML is also intended to be a universal interchange format for integrated 3D graphics and multimedia. Use: VRML may be used in a variety of application areas such as engineering and scientific visualization, multimedia presentations, entertainment and educational titles, web pages, and shared virtual worlds. HISTORY OF VRML VRML 1.0  This is the first generation of VRML.  It describes the foundations of a world including geometry, lighting, color, texture and linking.  VRML 1.0 is designed to meet the following requirements: – Platform independence – Extensibility – Ability to work well over low-bandwidth connections
  • 19. for more Https://www.ThesisScientist.com  No support for interactive behaviors. VRML 2.0  This is the current generation of VRML.  It has a richer level for interactivity and includes support for animation, spatial sound and scripting in addition to features that are already supported in VRML 1.0.  VRML Architecture Board made it official in March 1996. VRML 97  VRML 97 is the ISO standard for VRML.  It is developed based on VRML 2.0.  More realism in static worlds.  Interaction from sensors.  Can be used to represent Motion, behaviors. FEATURE OF VRML The various features of VRML are as follows: 1 Extensibility Provide the ability to add new object types not explicitly defined in VRML, e.g. Sound. 2 Dynamic Interaction and animation is achieved via an event model, behaviour can be programmed in Java and JavaScript. 3 Compact Descriptions of geometry can be compact, using a reuse mechanism. High compression ratios are achieved with gzip.
  • 20. for more Https://www.ThesisScientist.com 4 Composability Provide the ability to use and combine dynamic 3D objects within a VRML world and thus allow re-usability (Object orientated approach). 5 Platform Independent Emphasize scalable, interactive performance on a wide variety of computing platforms. 6 Multimedia Support Capable of representing multimedia objects with hyperlinks to other media such as text, sounds, movies, and images. BASICS OF VRML VRML code is simply a text file, case sensitive. Header: – #VRML V2.0 utf8 Comments indicated by „#‟ sign A VRML file is essentially a collection of Objects called Nodes which can be something  physically: Sphere, Cylinder, etc. or  non-physically: Viewpoints, Hyperlinks, Transformations, Sound, etc. Each Node contains Fields which hold the data of the node. Some nodes are container nodes or grouping nodes, which contain other nodes. Nodes are arranged in hierarchical structures called scene graphs. Scene graphs are more than just a collection of nodes; the scene graph defines an ordering for the nodes. The scene graph has a notion of state, i.e. nodes earlier in the world can affect nodes that appear later in the world.
  • 21. for more Https://www.ThesisScientist.com 4.5 JAVA AN INTRODUCTION “JAVA IS AN OBJECT-ORIENTED PROGRAMMING LANGUAGE THAT WAS DESIGNED TO MEET THE NEED FOR A PLATFORM INDEPENDENT LANGUAGE.” Java is used to create applications that can run on a single computer as well as distributed network. Java is both a language and a technology used to develop stand- alone and Internet-based applications. Java technology is simultaneously a programming language and a platform. 1. Java as a Programming Language Java is a general-purpose high-level object programming language that provides the following characteristics:  Simple  Object Oriented  Interpreted  Architecture-Neutral  Platform Independent  Multithread  Dynamic  High-Performance  Distributes  Robust  Secure Usually, a programming language requires either a compiler or an interpreter to translate a code written in high-level programming language (source code) into its machine language (object code) equivalent. But, to run a Java Program, Java uses a combination of compiler and interpreter. The compiler translates the Java program into an intermediate code called Java byte code. Java interpreter is used to run the compiled Java Byte Code. This allows Java Programs to be executed on different platforms. Java source code (Sample.java) Compiler Java byte code (Sample.class) Interpreter Object Code
  • 22. for more Https://www.ThesisScientist.com Java as a compiler and interpreter Java is a strongly typed language, means, every variable (or expression) has a type associated with it and the type is known at the time of compilation. Thus, in Java, data type conversions do not take place implicitly. There are three kinds of Java Programs:  Applications. These are stand-alone programs that run on a computer.  Applets. These are programs that run on web browser. Appletviewer is provided to ensure that these programs run without a web browser.  Servlets. These are programs that run at the server side. 2. Java as a Platform A software and/or hardware environment in which a program runs is referred to as a „platform‟. The Java platform is a software that is compatible with and/ or executes on platform based on different hardwares. The Java run-time environment is shown below: Source Code Compiler Byte Code Virtual Machine (Interpreter) Object Code Operating System
  • 23. for more Https://www.ThesisScientist.com Run-time Environment for Java The Java platform consists of the Java Virtual Machine and the Java application Programming Interface. These two important components of the Java platform can be analyzed as follows: Java Virtual Machine ( JVM ). It is an interpreter, which receives bytecode files and translates them into machine language (object code) instructions. The JVM is specific to each operating system (for example, UNIX, Linux, Windows). Java Application Programming Interface ( Java API ). This is a collection of software components that offer various useful functions. The API is grouped in the form of packages (libraries) of interrelated classes as well as interfaces. NEED FOR JAVA Java is needed for the following many reasons: 1. Java is a platform independent programming language that enables us to compile an application on one platform and execute it on any platform. 2. Java is a software independent programming language as its applications can be run on any operating system. 3. Java is a hardware / device independent programming language such that it can work everywhere, from the smallest device, such as microwave ovens and remote controls to supercomputers. 4. Java programming language enables us to develop an Internet - based applications that can be accessed by programmers working on various types of computers. 5. Java provides a runtime environment, which implements various security checks on Java applets or applications and does not allow them to perform any malicious tasks.‟ To develop an efficient application with above mentioned features, Java is needed. CHARACTERTICS OF JAVA Hardware
  • 24. for more Https://www.ThesisScientist.com Java has unrivalled features that make it popular as a programming language. It is simple, is highly robust, secure, platform-independent, and hence portable. These features of Java are given below: 1. Java is a simple and object oriented language. A Java programmer does not need to know about the details of Java as to how memory is allocated to data, because in Java, the programmer does not need to handle memory manipulations. Java is a true object-oriented programming language. Almost everything in Java is an object and data reside within objects and classes. Java supports various features of object-oriented programming language, such as, abstraction, encapsulation, inheritance and polymorphism. 2. Java is Highly Secure. Java allows programmers to develop (or create) highly reliable software applications. It provides extensive compile-time checking, followed by a second level of run-time checking. Java technology is designed to operate in distributed environments, which means that security is of paramount importance. 3. Java is Portable / Platform Independent. Portability refers to the ability of a program to run on any platform without changing the source code of the program. The programs developed on one computer can run on another computer which might have a different platform. Java enables the creation of cross-platform programs by compiling the program into an intermediate code called Java Byte Code. Source Code JVM Compiler Byte Code In „JAVA‟ Byte Code JVM Interpreter Machine Language HOST LOCAL
  • 25. for more Https://www.ThesisScientist.com In „C‟ 4. Java Shows High Performance. Java performance is impressive for an interpreted language, mainly due to the use of intermediate byte code.  Java‟s architecture is designed to reduce overheads during runtime.  Incorporation of multi-threading enhances the overall execution speed of Java programs. 5. Java is Compiled and Interpreted. The Java programs are first compiled and then interpreted. While compiling, the compiler checks for the errors in the program and list them all on the screen. After error-correction, the program is recompiled and then the compiler converts the program into computer language. The Java compiler compiles the code to a Byte code that is understood by Java. When Java source code file (.java) is compiled, the Java compiler generates the Bytecode, which is a compiled Java program with a „.class‟ extension. The Java Virtual Machine (JVM) then interprets the Byte code into the computer code and runs it. While interpreting the interpreter software reads and executes the code line by line. 6. Java is Distributed. Java is used to develop applications that can be distributed among various computers on the network. Java applications can open and access remote objects on the Internet in the same manner as they can open and access objects in a local network. 7. Multithreaded and Interactive. Multithreaded means handling multiple tasks simultaneously. Java supports multithreaded programs. For example, we can listen to an audio clip while scrolling a page and at the same time download an applet from a distant computer. This feature greatly improves the interactive performance of graphical applications. 8. Java is Dynamic and Extensible. Java is a dynamic language. It is capable of dynamically linking in new class libraries, methods, and objects. While the Java compiler is strict in its compile-time static checking, the language and run-time system are dynamic in their linking only as needed. New code modules can be linked in on demand from a variety of sources, even from sources across a network. 9. Java is Software Independent. Java is a software independent language. An application compiled in Java can be executed with another software using JVM.
  • 26. for more Https://www.ThesisScientist.com 10. Java is Hardware / Device Independent. Java is a hardware / device independent programming language such that it can work everywhere from the smallest device, such as microwave oven, and remote controls to supercomputers. JAVA DEVELOPMENT KIT (JDK) Sun Microsystems offer the JDK, which is required to write, compile and run Java programs. JDK is offered as part of commercial development environments by third- party vendors. The JDK consists of the following:  Java development tools, including the compiler, debugger, and Java interpreter.  Java class libraries, organized into a collection of packages.  A number of sample programs.  Various supporting tools and components, including the source code of the classes in the libraries.  Documentation describing all the packages, classes and methods in Java. To transform a program into a format that a computer can understand, a compiler is needed. The default Java compiler provided by the JDK is called javac. In order to execute or run a program a run-time environment containing a Java interpreter is needed. The Java interpreter provided by JDK is called java. Other run-time environments include Java Run-Time Environment (JRE), browsers with inbuilt runtime environments and AppletViewer to execute/run applets even without browser. The JDK also provides a debugger tool for debugging programs. Debugging is the process of locating and fixing errors in programs. JAVA RUNTIME ENVIRONMENT The Java Runtime Environment (JRE), also known as Java Runtime, is part of the Java Development Kit (JDK), a set of programming tools for developing Java applications. The Java Runtime Environment provides the minimum requirements for executing a Java application; it consists of the Java Virtual Machine (JVM), core classes, and supporting files. The Java Runtime Environment, or JRE, or J2RE is a software bundle from Sun Microsystems that allows a computer system to run a Java application. Java applications are in widespread use and necessary to view many Internet pages. The software bundle consists of the JVM and programming interface (API). The API (Application Programming Interface) provides a set of standard class libraries. The virtual machine and API have to be consistent with each other and are therefore
  • 27. for more Https://www.ThesisScientist.com bundled together as the JRE. This can be considered a virtual computer in which the virtual machine is the processor and the API is the user interface. JAVA ARCHITECTURE Various important components of the Java Architecture are:  Java Virtual Machine (JVM).  Java Application Programming Interface (API). Java Virtual Machine (JVM) Java Virtual Machine (JVM) is an interpreter that converts the Bytecode file into Machine object code. The JVM needs to be implemented for each platform running on a different operating system. JVM forms the base for the Java platform and is convenient to use on various hardware-based platforms. Components of the JVM: JVM for different platforms uses different techniques to execute the Bytecode. The major components of JVM are:  Class Loader. It loads the class files, which are required by a program running in the memory. The classes are loaded dynamically when required by the running program.  Execution Engine. The Java execution engine is the component of the JVM that runs the Bytecode one line after another. The execution engines implemented by different vendors use different techniques to run the Bytecode. The Java execution engine converts the Bytecode to the machine object code and runs it.  Just In Time (JIT) Compiler. The JIT compiler is used to compile the Bytecode into executable code. The JVM runs the JIT-compiled code without interpreting because JIT compiled code is in the machine code format. Running the JIT-compiled code is faster than running the interpreted code because it is compiled and does not require to be run, line after line. Java Application Programming Interface (API) The Java API is a collection of software components that provide capabilities, such as GUI. The related classes and interfaces of the Java API are grouped into packages.
  • 28. for more Https://www.ThesisScientist.com The following figure shows how the Java API and the JVM forms the platform for the Java programs on top of the hardware: Java Platform Components of Java Platform JAVA APPLICATION TO APPLET Typically, Java programs are compiled into applets or applications. Applications are stand-alone programs executed by a virtual machine, while applets are intended to be loaded into and interpreted by a browser such as Netscape or Internet Explorer. Applets are more complex than applications because they interact with the current environment of the browser, while applications are more like standard programs. Java has no pointer types and presents a computation model that guarantees safety. Thus, when an user executes a Java application or applet from an untrusted source, he or she can be assured that the Java program will not use the memory in unknown or perhaps cruel manner. Simple Java Application Program class StartProgram Class declaration Start of program block Java Program (.java) Java API (JVM) Hardware
  • 29. for more Https://www.ThesisScientist.com { // Comments public static void main(String args[ ]) { System.out.println(“This is a simple java program.”); } } The above program declares a class named StartProgram in which a method called main() is defined. In this method a single method is invocated that displays the string „ This is a simple java program.‟ This string is displayed on the console when the program is executed. Output is achieved by invoking the println method of the object out. The object out is a class variable in the class System that performs output operations on files.. Compiling and Running a Java Program A simple program is usually written using notepad (or any other compatible editor) and saved with the extension java). The name of the program should match the name of the class(as in program above StartProgram.java). The Java compiler is used to compile the program. The Java compiler is offered with the Java development kit. Compiling a Java program On compiling the program a class file is created, i.e., StartProgram.class. Program Name C:> javac StartProgram.java Java Compiler Method End of program block
  • 30. for more Https://www.ThesisScientist.com For the purpose of executing (running) the class file, Java provides an interpreter (java). This can be invoked as shown below: Invoking the Java Interpreter JAVA APPLET “AN APPLET IS A JAVA PROGRAM THAT CAN BE EMBEDDED IN AN HTML WEB PAGE.” To create a user friendly and interactive application, it is a better technique to use forms to interact with the users. To accept data from user applets can be created in Java. Java provides Java Development Kit (JDK) that enables to create user interactive forms in applets. JDK consists of a package Abstract Window Toolkit (AWT). AWT is an Application Programming Interface (API) that is responsible for building Graphical User Interface (GUI) in Java. The API of the AWT package consists of a collection of classes and methods that enables to design and manage the Graphical User Interface (GUI) applications. The AWT package supports applets, which help in creating containers, such as frames or panels that run in the GUI environment. Java programs are categorized into applications and applets. An application is a Java program that runs by using the Java interpreter from the command line. Java applications support the Character User Interface (CUI). Class File Java interpreter C:>java StartProgram This is a simple java program. Output Generated
  • 31. for more Https://www.ThesisScientist.com An applet is compiled on one computer and can run on another computer through a Java enabled Web browser or an appletviewer. Applets are developed to support the GUI in Java. APPLET CLASS The Applet class is a member of the Java API package, java.applet. It is used to create a Java program that displays an applet. Some of the common methods available in Applet package are: void init() • This is the first method to execute • It is an ideal place to initialize variables • It is the best place to define the GUI Components (buttons, text fields, scrollbars, etc.), lay them out, and add listeners to them • Almost every applet you ever write will have an init( ) method void start() • Not always needed • Called after init( ) • Called each time the page is loaded and restarted • Used mostly in conjunction with stop( ) • start() and stop( ) are used when the Applet is doing time-consuming calculations that you don‟t want to continue when the page is not in front void stop() • Not always needed • Called when the browser leaves the page • Called just before destroy( )
  • 32. for more Https://www.ThesisScientist.com • Use stop( ) if the applet is doing heavy computation that you don‟t want to continue when the browser is on some other page • Used mostly in conjunction with start() void destroy() • Seldom needed • Called after stop( ) • Use to explicitly release system resources (like threads) • System resources are usually released automatically void paint(Graphics g) • Needed if you do any drawing or painting other than just using standard GUI Components • Any painting you want to do should be done here, or in a method you call from here • Painting that you do in other methods may or may not happen • Never call paint(Graphics), call repaint( ) void repaint() • Call repaint( ) when you have changed something and want your changes to show up on the screen • repaint( ) is a request--it might not happen • When you call repaint( ), Java schedules a call to update(Graphics g) CREATING AN APPLET
  • 33. for more Https://www.ThesisScientist.com Creating an Applet program involves following steps: 1. Create a Java program. 2. Compile the Java program. 3. Create a Web page that contains an applet. 4. Run the applet using appletviewer. 5. A SIMPLE APPLET JAVA PROGRAM import java.applet.*; public class StartApplet extends Applet { String message = “Applet program”; String message1 = “ ”; public void Start() { System.out.println(message); System.out.println(message1); } public void init() { StartApplet Text; Text = new StartApplet(); Text.message1 = “Write the message”; Text.Start(); } } In the above program, the line import java.applet.*; implies that the standard class Applet should be imported before writing an applet program. This would ensure that all the features of the class Applet can be accessed by the program. Extension to the class Applet ensures that StartApplet would be a child class of the class Applet. The method Start() outputs two lines of text to the default system output that is the DOS window.
  • 34. for more Https://www.ThesisScientist.com The method init() is the main executable part of a Java program when StartApplet is run as an applet. This method instantiates the class Text and replaces the empty string in message1 with „Write the message‟, and then calls the method Start to print the two lines of text. These programs are placed inside a web page that is usually written in HTML (Hyper Text Markup Language). After the program StartApplet.java is compiled, a HTML document (written as below) calls and runs the applet StartApplet.class: <html> <head> <title> StartApplet</title> </head> <body bgcolor = “aaaaaa”> <h1>An Applet Program</h1> <applet code = StartApplet.class width=400 height=400> </applet> </body> </html> The above HTML file is saved as AppletHtml.html. When this file is opened through a web browser, the program StartApplet.class is executed. Invoking the applet without a HTML code. Another method to invoke the applet without writing the HTML code is by including the following code in the StartApplet program itself. import java.applet.*; /*<applet code=StartApplet height=400 width=400></applet>*/ public class StartApplet extends Applet { ………. ………. } To run this program use appletviewer:
  • 35. for more Https://www.ThesisScientist.com C:>appletviewer StartApplet.java Running the applet gives the following output: Applet program. Write the message. A Simple Applet Program to Design a Human Face import java.awt.*; import java.applet.*; /*<applet code=StartApplet height=400 width=400></applet>*/ public class Face extends Applet { public void paint(Graphics g) { g.drawOval(40,40,120,150); g.drawOval(57,75,30,20); g.drawOval(110,75,30,20); g.fillOval(68,81,10,10); g.fillOval(121,81,10,10); g.drawOval(85,100,30,30); g.fillArc(60,125,80,40,180,180); g.drawOval(25,92,15,30); g.drawOval(160,92,15,30); } } The output of the program will be as shown below:
  • 36. for more Https://www.ThesisScientist.com 4.8 APPLET WINDOW TOOLKIT “APPLET WINDOW TOOLKIT (AWT) IS THE USER INTERFACE TOOLKIT PROVIDED BY THE JAVA LANGUAGE LIBRARY.” The package Java.awt.* implements the Java AWT and contains all the classes and interfaces necessary for creating a user interface. The key elements required to create a GUI include the following:
  • 37. for more Https://www.ThesisScientist.com Components. A component is a visual object containing text or graphics. It can respond to keyboard or mouse inputs. For example, buttons, labels, textboxes, check boxes, and lists. Container. A container is a graphical object that contains components or other containers. Frame is the most important type of container. Event Handlers. An event is generated when an action occurs, such as mouse click on a button or a carriage return (enter) in a text field. Events are handled by creating listener classes which implement listener interfaces (ActionListener, MouseListener, MouseMotionListener, WindowListener, etc). The standard listener interfaces are found in java.awt.event. Layout Manager. A layout manager is automatically associated with each container when it is created. Examples are BorderLayout and GridLayout. BASIC CLASSES OF APPLET Graphics The class Graphics is an abstract class that provides methods for drawing and manipulating fonts and colors. This class provides features for designing different shapes like Line, Rectangle, Oval, Arc, Polygon, etc. The various methods in the Graphics Class are: Method Function drawLine() Draws a line in an applet drawRect() Draws an outlined rectangle in an applet drawOval() Draws an ellipse in an applet drawArc() Draws an arc in an applet drawPolygon() Draw a polygon in an applet draw3DRect() Draws a highlighted 3D rectangle in an applet drawRoundRect() Draws a round cornered rectangle in an applet fillRect() Draw a filled rectangle in an applet fillOval() Draws a filled ellipse in an applet fillArc() Draws a filled arc in an applet
  • 38. for more Https://www.ThesisScientist.com fillPolygon() Draws a filled polygon in an applet fill3DRect() Draws a 3D rectangle in an applet drawImage() Draws an image in an applet drawPolyline() Draws a sequence of lines in an applet fillPolygon() Fills a sequence of lines in an applet fillRoundRect() Fills a rounded rectangle in an applet drawstring() Draws a string of text at the specified position in an applet getColor() Gets the foreground drawing color setColor() Sets the foreground drawing color Sample Graphics Methods • A Graphics is something you can paint on • g.drawString(“Hello”, 20, 20); • g.drawRect(x, y, width, height); • g.fillRect(x, y, width, height); • g.drawOval(x, y, width, height); • g.fillOval(x, y, width, height); • g.setColor(Color.red); • g.drawArc(x, y, width, height, startAngle, arcAngle) Color The Color class is used to manipulate colors using the methods and constants defined in it. Every color is a combination of Red, Green, and Blue. Combinations of these three colors, which take values from 0 to 255 or 0.0 to 1.0, can generate any new color. Graphics class has the methods setColor() and getColor().
  • 39. for more Https://www.ThesisScientist.com CLASS HEIRARCHY OF AWT The key concepts of AWT class hierarchy are the following:  Component is an object that can be displayed on the screen and can interact with the user. For example, textbox, labels, buttons, etc. It is an abstract class. All other classes are non-abstract.  The Component class is superclass of all the non-menu-related user-interface classes. It provides support for event-handling, drawing of components and so on.  Container is a component that contains other components. These have special properties, and layout managers.  Windows is a container with some special features such as a toolkit for creating components and a warning message for security purpose. The Window class represents a top-level window. Neither Window nor Panel classes has title, menus or borders. The Window class is rarely used directly and its sub-classes Frame and Dialog are more common.  The Panel class does not have a title, menu, or border. The Applet class is used to run programs that run in a web browser.  The Frame class is a sub-class of the Window class. It is used to create a GUI application window. Component Container Panel Window Applet Dialog Frame
  • 40. for more Https://www.ThesisScientist.com AWT CONTROLS Controls are the components that allows the user to interact with an application. The layout managers are used to arrange the AWT components. AWT supports several types of controls. These are listed below:  Label  Radiobuttons  Choice Lists  Buttons  Scroll Bars  Text Area  Lists  Text Field  Check Boxes 4.8 EVEVT HANDLING In Java, each component fires an event whenever a user carries out a specific action. Each event is represented by a class. “AN EVENT IS AN INSTANCE OF THE CLASS EVENT WHICH IS IN THE AWT LIBRARY.” Whenever an event is fired, it is received by one or more listeners which can act on that event. This process is known as the event delegation process. When an event is fired on a component, it is passed to another component called the listener. This listener continuously listens for the event to be fired and takes up a specific task on receiving the signal. The steps taken in handling the events that take place are the following:  A class that extends a frame or an applet (any container) and implements a particular listener is created.  The event with the component that fires the event is registered.  A class has the implementation for the methods in the listener interface is created. 4.9 LAYOUT MANAGER The layout managers are used to position the components within a container (an applet, a panel, or a frame). Java defines the five layout managers:
  • 41. for more Https://www.ThesisScientist.com  FlowLayout  BorderLayout  CardLayout  GridLayout  GridBagLayout These are all sub-classes that implement the LayoutManager interface. Each container object is associated with the layout manager. The default layout manager for the applet is FlowLayout and the default for frames is BorderLayout. Different layouts can be set to the container using the method Void setLayout(LayoutManager layoutmanagerinstance) 4.9.1 FLOW LAYOUT MANAGER The FlowLayout manager is the layout manager that arranges the components of the container in the same manner as the word-pad editor arranges the words contained in it. That is, it arranges the components of the container from top-left of the container and moving towards the bottom-right of the container with the small spaces between them. setLayout(new FlowLayout(FlowLayout.CENTER)); 4.9.2 BORDER LAYOUT MANAGER The BorderLayout manager divides the container into five regions: four borders and one large central area. Only one object can be added on each region. To add a component on the specified region, the add method is used. The various constants in the BorderLayout manager are BorderLayout.NORTH, BorderLayout.SOUTH, BorderLayout.EAST, BorderLayout.WEST, and BorderLayout.CENTER. setLayout(new BorderLayout()); Button a=new Button(“OK”); add(a, BorderLayout.EAST); 4.9.3 CardLayout Manager The CardLayout is the only layout class which can hold several layouts in it. Each layout can have separate index card in a deck that can be shuffled so that any card can be on top at a given time. The cards are typically held in an object of type panel. This panel must have CardLayout selected as its layout manager. The cards that form the deck are also typically objects of type panel. Thus, a panel that contains the deck and panel for each card in the deck have to be created. Next, the components of each card have to be added to the appropriate panel. Then these panels have to be added to the
  • 42. for more Https://www.ThesisScientist.com panel for which CardLayout is the layout manager. Finally, this panel has to be added to the main applet panel. This layout manager is not possible to be implemented in a 2D environment. Thus it is not used in practice. 4.9.4 GridLayout manager The GridLayout is the layout that divides the container into rows and columns. The components are then added to the layout in cells. The intersection of a row and a column of the grid layout is called cell. The GridLayout class of Java enables to create a grid layout. All the components are of the same size. The position of a component in a grid is determined by the order in which the components are added to the grid. The following describes the various constructors that can be used to create an instance of the GridLayout class:  GridLayout(): Creates a grid layout with the specified number of component in a single row.  GridLayout(int r, int c): Creates a grid layout with the specified number of rows and columns.  GridLayout(int r, int c, int h, int v): Creates a grid layout with the specified number of rows and columns and the specified horizontal and vertical space between the components. void init() { setLayout(new GridLayout(2,3)); add(new Button(“Red”)); add(new Button(“White”)); add(new Button(“Green”)); add(new Button(“Blue”)); add(new Button(“Black”)); add(new Button(“Cyan”)); } GridBagLayout manager The GridBagLayout is a sophisticated and flexible layout manager. GridBagLayout places components in a grid of rows and columns, allowing specified components to span multiple rows or columns. Not all rows necessarily have the same height. Similarly, not all columns necessarily have the same width. The following constructor can be used to create an instance of the GridBagLayout class: GridBagLayout()
  • 43. for more Https://www.ThesisScientist.com For example, import java.awt.*; import java.applet.*; import java.awt.event.*; /*<applet code="AppletExample2.class" width="500" height="500"></applet>*/ public class AppletExample2 extends Applet implements ActionListener { String str=new String(); String str1=new String(); String str2=new String(); int len; Panel p=new Panel(); Label l1; Label l2; Label l3; TextField tf1=new TextField(20); TextField tf2=new TextField(20); TextField tf3=new TextField(20); Button b; public void init() { GridBagLayout gl=new GridBagLayout(); GridBagConstraints gbc=new GridBagConstraints(); this.add(p); p.setLayout(gl); l1=new Label("Name:"); l2=new Label("Address:"); l3=new Label("Length:"); b=new Button("OK"); b.addActionListener(this); gbc.gridx=0; gbc.gridy=0;
  • 45. for more Https://www.ThesisScientist.com p.add(b); } public void actionPerformed(ActionEvent e) { str1=tf1.getText(); str2=tf2.getText(); int i=str1.length(); int j=str2.length(); str=String.valueOf(i+j); tf3.setText(str); } } 4.9 SERVELET “SERVLETS ARE JAVA PROGRAMS THAT CAN BE DEPLOYED ON JAVA ENABLED WEB SERVER TO ENHANCE AND EXTEND THE FUNCTIONALITY OF THE WEB SERVER.” Servlets can also be used to add dynamic content to web pages. Java Servlets are server side components that provides a powerful mechanism for developing server side of web application. Earlier CGI was developed to provide server side capabilities to the web application. Although CGI played a major role in the explosion of the Internet, its performance, scalability and reusability issues make it less than optimal solutions. Java Servlets changes all that. These provide excellent framework for server side processing. Servlet provide component-based, platform-independent methods for building Web- based applications, without the performance limitations of CGI programs. Servlets are not designed for a specific protocols. It is different thing that they are most commonly used with the HTTP protocols. HTTP Servlet typically used to:
  • 46. for more Https://www.ThesisScientist.com  Provide dynamic content like getting the results of a database query and returning to the client.  Process and/or store the data submitted by the HTML.  Manage information about the state of a stateless HTTP. For example, an online shopping car manages request for multiple concurrent customers. ADVANTAGES OF SERVELETS Java Servlets have a number of advantages over CGI and other API‟s. They are: 1. Platform Independence: Java Servlets are 100% pure Java, so it is platform independent. It can run on any Servlet enabled Web server. 2. Performance: Due to interpreted nature of Java, programs written in Java are slow. But the java servlets runs very fast. These are due to the way servlets run on web server. For any program initialization takes significant amount of time. But in case of servlets initialization takes place very first time it receives a request and remains in memory till times out or server shut downs. After servlet is loaded, to handle a new request it simply creates a new thread and runs service method of servlet. 3. Extensibility: Java Servlets are developed in Java which is robust, well-designed and object-oriented language which can be extended or polymorphed into new objects. So the Java servlets can be extended from existing class to provide the ideal solutions. 4. Safety: Java provides a very good safety features like memory management, exception handling, etc. Servlets inherits all these features and emerged as a very powerful web server extension. 5. Secure: Servlets are server side components, so it inherits the security provided by the web server. Servlets are also benefited with Java Security Manager. CHARECTERTICS OF SERVELETS Servlets can be used to develop a variety of web-based applications. The characteristics of Servlets that have gained them a wide spread acceptance are as follows:  Servlets are Efficient. The initialization code for servlet is executed only when the servlet is executed for the first time. Subsequently, the requests that are received by the servlets are processed by its service() method. This helps to increase the efficiency of the server by avoiding creation of unnecessary processes.
  • 47. for more Https://www.ThesisScientist.com  Servlets are Robust. As servlets are based on Java, they provide all the powerful features of Java, such as exception handling, and garbage collection, which makes them robust.  Servlets are Portable. Servlets are portable because they are developed in Java. This enables easy portability across web servers.  Servlets are Persistent. Servlets helps to increase the performance of the system by preventing frequent disk access. SERVELETS AND APPLETS Applets Servlets Applets are Java programs that are embedded in Web pages. When a web page containing an applet is opened the byte code of the applet is downloaded to the client computer. This process becomes time consuming if the size of applet is too large. As Servlets executed on the web server, they help overcome problems with download time faced while using applets. Servlets do not require the browser to be Java enabled unlike applets because they execute on web server and the results are sent back to the client or browser. LIFECYCLE OF APPLETS A Servlets is loaded only once in the memory and is initialized in the init() method. After the servlet is initialized it starts accepting requests from the client and processes them through the service() method till it shutdown by the destroy() method. The service() method is executed for every incoming request. The lifecycle of a servlet is depicted below: Init( )
  • 48. for more Https://www.ThesisScientist.com Request Response Lifecycle of Servlet J2EE Java 2 Enterprise Edition (J2EE) is a set of specifications that defines the standard for creating distributed objects. J2EE also specifies how these technologies can be integrated to provide a complete solution. It is also a standard architecture that defines a multi-tier programming model. The Java 2 Servlet Development Kit (J2SDK), Enterprise Edition (J2EE) server is a product from Sun Microsystems that is based on the J2EE. The J2EE server is used to deploy servlets and JSP files and enables users to access the same by implementing appropriate security. Client (Browser) Service( ) Destroy( )
  • 49. for more Https://www.ThesisScientist.com DEPLOPING A SERVELET For a servlet or a html page (that might contain a link to servlet) to be accessible from client, first it has to be deployed on the web server. Servlet can be deployed in:  Java Web Server (JWS)  JRun  Apache JWS is a web server from Sun Microsystems that is developed based on the servlet technology and can be used to deploy servlets. JRun and apache can also be used to deploy servlets. JRun is a Java application server which is a product of live software. JRun provides a high performance, scalable solution for creating and delivering enterprise applications. The other website technologies that can be deployed in JRun are Java Server Pages and Enterprise Java Beans.
  • 50. for more Https://www.ThesisScientist.com Apache is a web server from an organization called Apache that can be used to deploy servlets. Few features of Apache that have made it popular are its freely distributed code, robustness and security that is offered. SERVELETS API AND PACKEGES Java Servlet API contains two core packages:  javax.servlet  javax.servlet.http Servlets implement the javax.servlet.Servlet interface. The javax.servlet package contains the generic interfaces and classes that are implemented and extended by all servlets. While the javax.servlet.http package contains the classes that are used when developing HTTP-specific servlets. The HttpServlet is extended from GenericServlet base class and it implements the Servlet interface. HttpServlet class provides a framework for handling the HTTP requests. HTTP HTTP is a simple, stateless protocol. A client such as a web browser makes a request, the web server responds, and the transaction is done. When the client sends a request, the first thing it specifies is an HTTP command called a method, that tells the server the type of action it wants to be performed. This first line of request also specifies the address of a document (URL) and the version of the HTTP protocol it is using. For example: GET/intro.html HTTP/1.0 This request uses the GET method to ask for the document named intro.html, using HTTP version 1.0. GET and POST When a client connects to a server and makes an HTTP request, the request can be of several different types called methods. The most frequently used methods are GET and POST. The GET method is designed for getting information (document, a chart or the results from a database query). While the POST method is designed for posting information.
  • 51. for more Https://www.ThesisScientist.com SERVELETS CREATION To create a servlet following steps should be followed: Step-1 Identify the mechanism Step-2 Identify the classes to be used Step-3 Identify the methods to be used Step-4 Write and compile the servlet Step-5 Deploy the servlet Step-6 Execute the servlet. SECURITY ISSUES Security is the science of keeping sensitive information in the hands of authorized users. On the web, this boils down to four important issues:  Authentication. Being able to verify the indentification of the parties involved.  Authorization. Limited access to resources to a selective set of users or programs.  Confidentiality. Ensuring that only the parties involved can understand the communication.  Integrity. Being able to verify that the context of the communication is not changed during transmission. Authentication, authorization, confidentiality and integrity are all linked by digital certificate technology. Digital certificate allow web server, and clients to use advanced cryptographic techniques to handle identification and encryption in a secure manner. Authentication can be of any one of two or both:  HTTP authentication: User name and password protection.