You are on page 1of 19

MC0078 Java Programming

(Book ID: B0831 & B0832)


Assignment Set 1
1. Explain the following major components of Java:
A) Class Loader :
The Java Class loader is a part of the Java Runtime Environment that
dynamically loads Java classes into the Java Virtual Machine. Usually
classes are only loaded on demand. The Java run time system does not
need to know about files and file systems because of class loaders.
Delegation is an important concept to understand when learning about
class loaders.

A software library is a collection of related object code. In the Java


language, libraries are typically packaged in Jar files. Libraries can contain
objects of different types. The most important type of object contained in
a Jar file is a Java class. A class can be thought of as a named unit of code.
The class loader is responsible for locating libraries, reading their
contents, and loading the classes contained within the libraries. This
loading is typically done "on demand", in that it does not occur until the
class is actually used by the program. A class with a given name can only
be loaded once by a given class loader.
B) Bytecode Verifier:
The bytecode verifier traverses the bytecodes, constructs the type
state information, and verifies the types of the parameters to all the
bytecode instructions.

C) Security Manager:
A security manager is a Java virtual machine (VM) object that implements
a security policy. By default, the Java 2 platform software provides a
security manager that disallows all access to local system resources apart
from read and write access to the directory and its subdirectories where
the program is invoked.
You can extend the default security manager to implement customized
verifications and approvals for applets and applications, but the
implementation must include the appropriate access verification code for
every checkXXX method you override. If you do not include this code, no
access verification check happens, and your code breaches the system
security policy.
2. Discuss the following with suitable example programs for each:
A) Data Types in Java:
When declaring a variable, besides its name, you must provide the type of information
that the variable will hold. The role of this type is to tell the compiler how much memory
will be needed to store the value(s) of that variable. Since your program is not the only
one used in the computer, memory has to be effectively managed.
The type of value that a variable will hold is called a data type. As you ay imagine,
different variables can be meant to hold different types of values. Each data type uses a
Java keyword to be characterized. As a modern language, Java provides even more
support for its traditional data types. To do this, a class was created for each data type.
This allows you to get more information from a variable declared with the particular data
type you want to use.
B) Variables in Java:
As we know, an object stores its state in fields.
int cadence = 0;
int speed = 0;
int gear = 1;
The What Is an Object? discussion introduced you to fields, but you probably have still a
few questions, such as: What are the rules and conventions for naming a field? Besides
int, what other data types are there? Do fields have to be initialized when they are
declared? Are fields assigned a default value if they are not explicitly initialized? We'll
explore the answers to such questions in this lesson, but before we do, there are a few
technical distinctions you must first become aware of. In the Java programming
language, the terms "field" and "variable" are both used; this is a common source of
confusion among new developers, since both often seem to refer to the same thing.
The Java programming language defines the following kinds of variables:
Instance Variables (Non-Static Fields) Technically speaking, objects store their
individual states in "non-static fields", that is, fields declared without the static keyword.
Non-static fields are also known as instance variables because their values are unique to

each instance of a class (to each object, in other words); the currentSpeed of one
bicycle is independent from the currentSpeed of another.
Class Variables (Static Fields) A class variable is any field declared with the static
modifier; this tells the compiler that there is exactly one copy of this variable in
existence, regardless of how many times the class has been instantiated. A field defining
the number of gears for a particular kind of bicycle could be marked as static since
conceptually the same number of gears will apply to all instances. The code static int
numGears = 6; would create such a static field. Additionally, the keyword final could be
added to indicate that the number of gears will never change.
Local Variables Similar to how an object stores its state in fields, a method will often
store its temporary state in local variables. The syntax for declaring a local variable is
similar to declaring a field (for example, int count = 0;). There is no special keyword
designating a variable as local; that determination comes entirely from the location in
which the variable is declared which is between the opening and closing braces of a
method. As such, local variables are only visible to the methods in which they are
declared; they are not accessible from the rest of the class.
Parameters You've already seen examples of parameters, both in the Bicycle class and
in the main method of the "Hello World!" application. Recall that the signature for the
main method is public static void main(String[] args). Here, the args variable is the
parameter to this method. The important thing to remember is that parameters are
always classified as "variables" not "fields". This applies to other parameter-accepting
constructs as well (such as constructors and exception handlers) that you'll learn about
later in the tutorial.

3. Write a program in Java to multiply two matrices.


import java.lang.*;
import java.io.*;
class Matrix
{
public static void main(String arg[])throws IOException
{
DataInputStream dis=new DataInputStream(System.in);
System.out.println("Enter The Row Size Of The First Matrix");
int r1=Integer.parseInt(dis.readLine());
System.out.println("Enter The Column Size Of The First Matrix");
int c1=Integer.parseInt(dis.readLine());
System.out.println("Enter The Row Size Of The Second Matrix");
int r2=Integer.parseInt(dis.readLine());
System.out.println("Enter The Column Size Of The Second Matrix");
int c2=Integer.parseInt(dis.readLine());
int a[][]=new int[r1][c1];
int b[][]=new int[r2][c2];
int c[][]=new int[r1][c2];
int i,j,k;
System.out.println("Enter The Elements Into The First Matrix");
for(i=0;ifor(j=0;j{
a[i][j]=Integer.parseInt(dis.readLine());
}
System.out.println("Enter The Elements Into The Second Matrix");
for(i=0;ifor(j=0;j{

b[i][j]=Integer.parseInt(dis.readLine());
} if(c1!=r2)
System.out.println("Multiplication Is Not Possible");
else
{
for(i=0;i{
for(j=0;j{
c[i][j]=0;
for(k=0;k{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
for(i=0;i{
for(j=0;j{
System.out.println(c[i][j]+" ");
}
System.out.println(" ");
}
}
}
}

4. Describe the theory of Exception Handling with relevant coding examples.


Exceptions in java are any abnormal, unexpected events or extraordinary conditions
that may occur at runtime. They could be file not found exception, unable to get
connection exception and so on. On such conditions java throws an exception
object. Java Exceptions are basically Java objects. No Project can never escape a
java error exception.
Java exception handling is used to handle error conditions in a program
systematically by taking the necessary action. Exception handlers can be written to
catch a specific exception such as Number Format exception, or an entire group of
exceptions by using a generic exception handlers. Any exceptions not specifically
handled within a Java program are caught by the Java run time environment
An exception is a subclass of the Exception/Error class, both of which are subclasses
of the Throwable class. Java exceptions are raised with the throw keyword and
handled within a catch block.
A Program Showing How the JVM throws an Exception at runtime
public class DivideException {
public static void main(String[] args) {
division(100,4);
division(100,0);

// Line 1
// Line 2

System.out.println("Exit main().");
}
public static void division(int totalSum, int totalNumber) {
System.out.println("Computing Division.");
int average = totalSum/totalNumber;
System.out.println("Average : "+ average);
}
}
An ArithmeticException is thrown at runtime when Line 11 is executed because
integer division by 0 is an illegal operation. The Exit main() message is never
reached in the main method

Output
Computing Division.
java.lang.ArithmeticException: / by zero

5. Describe the following in the context of Java threads:


A) The Java Thread Model:
Java environment has been built around the multithreading model. In fact all Java
class libraries have been designed keeping multithreading in mind. If a thread goes
off to sleep for some time, the rest of the program does not get affected by this.
Similarly, an animation loop can be fired that will not stop the working of rest of the
system.
At a point of time a thread can be in any one of the following states new, ready,
running, inactive and finished. A thread enters the new state as soon as it is
created. When it is started (by invoking start() method), it is ready to run. The
start() method in turn calls the run() method which makes the thread enter the
running state. While running, a thread might get blocked because some resource
that it requires is not available, or it could be suspended on purpose for some
reason (like put off to sleep by the programmer). In such a case the thread enters
the state of being inactive. A thread can also be stopped purposely because its time
has expired, then it enters the state of ready to run once again.
A thread that is in running state can be stopped once its job has finished. A thread
that is ready to run can also be stopped. A thread that is stopped enters the finished

state. A thread that is in inactive state can either be resumed, in which case it
enters the ready state again, or it can be stopped in which case it enters the
finished state.
B) Thread Priorities:
In multithreading environment, one thread might require the attention of the CPU
more quickly than other. In such a case that thread is said to be of high priority.
Priority of a thread determines the switching from one thread to another. In other
words, priority determines how a thread should behave with respect to the other
threads.
The word priority should not be confused with the faster running of a thread. A high
priority thread does not run any faster than the low priority thread. A thread can
voluntarily leave the control by explicitly stopping, sleeping or blocking on pending
I/O or it can pre-empted by the system to do so. In the first case the processor
examines all threads and assigns the control to the thread having the highest
priority. In the second case, a low priority thread that is not ready to leave the
control is simply pre-empted by the higher priority thread no matter what it is doing.
This is known as pre-emptive multi-tasking. It is advisable that in case two threads
have the same priority, they must explicitly surrender the control to their peers.
C) Thread Synchronization:
Multithreading produces asynchronous behavior among the programs. This means
that all threads run as independent units without affecting each other. But
sometimes it becomes necessary to synchronize these threads. For example,
synchronization must be provided when two threads share the same variable or
data structure like an array. In such a case there must be way by which they should
not come in each others way.

6. Define RMI. Define the architecture of RMI invocation.


RMI is the distributed object system that is built into the core Java environment. You
can think of RMI as a built-in facility for Java that allows you to interact with objects
that are actually running in Java virtual machines on remote hosts on the network.
Architecture of RMI invocation:
Now that we've seen a complete example of an RMI object in action, let's look at
what makes remote objects work, starting with an overview of the underlying RMI
architecture. There are three layers that comprise the basic remote-object
communication facilities in RMI:
The stub/skeleton layer, which provides the interface that client and server
application objects use to interact with each other.

The remote reference layer, which is the middleware between the stub/skeleton
layer and the underlying transport protocol. This layer handles the creation and
management of remote object references.
The transport protocol layer, which is the binary data protocol that sends remote
object requests over the wire.
These layers interact with each other as shown in Figure 3-1. In this figure, the
server is the application that provides remotely accessible objects, while the client
is any remote application that communicates with these server objects.
In a distributed object system, the distinctions between clients and servers can get
pretty blurry at times. Consider the case where one process registers a remoteenabled object with the RMI naming service, and a number of remote processes are
accessing it. We might be tempted to call the first process the server and the other
processes the clients. But what if one of the clients calls a method on the remote
object, passing a reference to an RMI object that's local to the client. Now the server
has a reference to and is using an object exported from the client, which turns the
tables somewhat. The "server" is really the server for one object and the client of
another object, and the "client" is a client and a server, too. For the sake of
discussion, I'll refer to a process in a distributed application as a server or client if its
role in the overall system is generally limited to one or the other. In peer-to-peer
systems, where there is no clear client or server, I'll refer to elements of the system
in terms of application-specific roles (e.g., chat participant, chat facilitator).

As you can see in Figure 3-1, a client makes a request of a remote object using a
client-side stub; the server object receives this request from a server-side object
skeleton. A client initiates a remote method invocation by calling a method on a
stub object. The stub maintains an internal reference to the remote object it
represents and forwards the method invocation request through the remote
reference layer by marshalling the method arguments into serialized form and
asking the remote reference layer to forward the method request and arguments to
the appropriate remote object. Marshalling involves converting local objects into
portable form so that they can be transmitted to a remote process. Each object is
checked as it is marshaled, to determine whether it implements the
java.rmi.Remote interface. If it does, its remote reference is used as its marshaled
data. If it isn't a Remote object, the argument is serialized into bytes that are sent to
the remote host and reconstituted into a copy of the local object. If the argument is
neither Remote nor Serializable, the stub throws a java.rmi.MarshalException back
to the client.

8. Describe the Web architecture and servlet life cycle.


A servlet life cycle can be defined as the entire process from its creation till the
destruction. The following are the paths followed by a servlet
The init() method :The init method is designed to be called only once. It is called
when the servlet is first created, and not called again for each user request. So, it is
used for one-time initializations, just as with the init method of applets.
The servlet is normally created when a user first invokes a URL corresponding to the
servlet, but you can also specify that the servlet be loaded when the server is first
started.
When a user invokes a servlet, a single instance of each servlet gets created, with
each user request resulting in a new thread that is handed off to doGet or doPost as
appropriate. The init() method simply creates or loads some data that will be used
throughout the life of the servlet.
The init method definition looks like this:
public void init() throws ServletException {}
The service() method :
The service() method is the main method to perform the actual task. The servlet
container (i.e. web server) calls the service() method to handle requests coming
from the client( browsers) and to write the formatted response back to the client.
Each time the server receives a request for a servlet, the server spawns a new
thread and calls service. The service() method checks the HTTP request type (GET,

POST, PUT, DELETE, etc.) and calls doGet, doPost, doPut, doDelete, etc. methods as
appropriate.
Here is the signature of this method:
public void service(ServletRequest request,
ServletResponse response)
throws ServletException, IOException{}
The service () method is called by the container and service method invokes doGe,
doPost, doPut, doDelete, etc. methods as appropriate. So you have nothing to do
with service() method but you override either doGet() or doPost() depending on
what type of request you receive from the client.
The doGet() and doPost() are most frequently used methods within each service
request. Here are the signature of these two methods.
The doGet() Method
A GET request results from a normal request for a URL or from an HTML form that
has no METHOD specified and it should be handled by doGet() method.
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {}
The doPost() Method
A POST request results from an HTML form that specifically lists POST as the
METHOD and it should be handled by doPost() method.
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {}
The destroy() method :
The destroy() method is called only once at the end of the life cycle of a servlet.
This method gives your servlet a chance to close database connections, halt
background threads, write cookie lists or hit counts to disk, and perform other such
cleanup activities.
After the destroy() method is called, the servlet object is marked for garbage
collection. The destroy method definition looks like this:
public void destroy() {// Finalization code... }

Java Programming (Book ID: B0831 & B0832)


Assignment Set 2

1. Write a program to demonstrate the concept of stream classes


in Java.
Consider the following simple example program that demonstrates how
the read and write methods can be used :
import java.io.*;
// Displays contents of a file
//(e.g. java Type app.ini)
public class Type
{
public static void main(
String args[]) throws Exception
{
// Open input/output and setup variables
FileReader fr = new FileReader(args[0]);
PrintWriter pw = new PrintWriter(
System.out, true);
char c[] = new char[4096];
int read = 0;
// Read (and print) till end of file

while ((read = fr.read(c)) != -1)


pw.write(c, 0, read);
fr.close();
pw.close();
}
}

The following code fragment from the above program, opens the input
and output streams:
FileReader fr = new FileReader(args[0]);
PrintWriter pw = new PrintWriter(System.out, true);
The program reads the input file and displays its contents until it reaches
an end-of-file condition (-1), as shown here:
while ((read = fr.read(c)) != -1)
pw.write(c, 0, read);
Notice the "(char cbuf[])" version of the read method. This is used here
because in most cases reading a single character at a time can be
approximately five times slower than reading chunks of data (array) at a
time.
2. Write the steps in creating and running applets in Java along with
a sample program to demonstrate the same. Also describe various
ways of running Applets.
A Java applet is an applet delivered to the users in the form of Java bytecode. Java
applets can run in a Web browser using a Java Virtual Machine (JVM), or in Sun's
AppletViewer, a stand-alone tool for testing applets. Java applets were introduced in
the first version of the Java language in 1995. Java applets are usually written in the
Java programming language but they can also be written in other languages that
compile to Java bytecode such as Jython.
Java applets run at a speed that is comparable to (but generally slower than) other
compiled languages such as C++, but many times faster than JavaScript. In addition
they can use 3D hardware acceleration that is available from Java. This makes
applets well suited for non trivial, computation intensive visualizations.

Since Java's bytecode is platform independent, Java applets can be executed by


browsers for many platforms, including Microsoft Windows, Unix, Mac OS and Linux.
It is also trivial to run a Java applet as an application with very little extra code. This
has the advantage of running a Java applet in offline mode without the need for any
Internet browser software and also directly from the development IDE.
ExampleThe following example is made simple enough to illustrate the essential use
of Java applets through its java.applet package. It also uses classes from the Java
Abstract Window Toolkit (AWT) for producing actual output (in this case, the "Hello,
world!" message).

import java.applet.Applet;
import java.awt.*;

// Applet code for the "Hello, world!" example.


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

// This method is mandatory, but can be empty.(i.e.,have no actual code).


public void stop() { }

// Print a message on the screen (x=20, y=10).


public void paint(Graphics g) {
g.drawString("Hello, world!", 20,10);

// Draws a circle on the screen (x=40, y=30).


g.drawArc(40,30,20,20,0,360);
}
}

Additional simple applets are available at Wikiversity.[19]

For compilation, this code is saved on a plain-ASCII file with the same name as the
class and .java extension, i.e. HelloWorld.java. The resulting HelloWorld.class applet
should be placed on the web server and is invoked within an HTML page by using an
<APPLET> or an <OBJECT> tag. For example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>HelloWorld_example.html</TITLE>
</HEAD>
<BODY>
<H1>A Java applet example</H1>
<P>Here it is: <APPLET code="HelloWorld.class" WIDTH="200" HEIGHT="40">
This is where HelloWorld.class runs.</APPLET></P>
</BODY>
</HTML>

4. Describe the theory and practical applications of database


connectivity in Java.
Java provides database programmers some distinct advantages, such as easy object
to relational mapping, database independence and distributed computing. For
languages, such as C++ and Smalltalk, there is a need for tools for mapping their
objects to relational entities. Java provides an alternative to these tools that frees us
from the proprietary interfaces associated with database programming. With the
"write once, compile once, run anywhere" power that JDBC offers us, Java's
database connectivity allows us to concentrate on the translation of relational data
into objects instead of how we can get that data from the database.
A Java database application does not care what its database engine is. No matter
how many times the database engine changes, the application itself need never
change. In addition, a company can build a class library that maps its business

objects to database entities in such a way that applications do not even know
whether or not their objects are being stored in a database.
Java affects the way we distribute and maintain application. Currently a Web
application allows user to download a bunch of flight information as an HTML page.
While viewing the page for a particular flight, suppose someone makes a
reservation for a seat on that flight and this process will not be available to the
viewers as the page is just a copy of data from the database. To view the change
that just occurred, the viewers again have to contact the database to get the latest
data. If we reconstruct the same Web application using Java RMI to retrieve the data
from a single flight object on the server, any number of users can view the data
simultaneously and if there is any reservation or any change taking place,
immediately the changes made to the data will be sent back to all the users and
hence the users can avail the latest data at any time. Thus JDBC can combine with
Java RMI to develop distributed enterprise-scale mission-critical three-tier database
applications.

5. Write about the following properties of Beans with suitable code


snippets:
A) Simple Properties:
A simple property of a JavaBean is an attribute of the bean that can be viewed
and can be changed by other beans. A simple property can be a read-only, a
write-only, or a read-write property, and the simple properties of a bean are
determined by the set and get methods in a beans class, which have the following
syntax:
public void set<Property>(data_type x)
public data_type get<Property>()
If both a set and get method appear that have the same property name and data
type, the bean will have a read-write property of the specified name. If only a get
method appears, the property is read-only; similarly, if only a set method appears,
the property is write-only. For example, suppose that a bean has the following
methods: public void setTitle(String t)
public String getTitle()
Then, the bean has a read-write property named title, and the data type of this
property is a String. When the data type is a Boolean, an is method can be used in

place of a get method. For example, the following two method signatures create a
Boolean property named atHome:
public void setAtHome(boolean b)
public boolean isAtHome()
The name of a property is determined by the method signatures for the property.
The set or get portion of the method name is removed, and the next letter is
decapitalized.
B) Bound Properties:
Bound properties support the PropertyChangeListener (in the API reference
documentation) class. Sometimes when a Bean property changes, another object
might need to be notified of the change, and react to the change. Whenever a
bound property changes, notification of the change is sent to interested listeners.
The accessor methods for a bound property are defined in the same way as those
for simple properties. However, you also need to provide the event listener
registration methods forPropertyChangeListener classes and fire a
PropertyChangeEvent (in the API reference documentation) event to the
PropertyChangeListener objects by calling their propertyChange methods
The convenience PropertyChangeSupport (in the API reference documentation) class
enables your bean to implement these methods. Your bean can inherit changes
from the PropertyChangeSupportclass, or use it as an inner class.
In order to listen for property changes, an object must be able to add and remove
itself from the listener list on the bean containing the bound property. It must also
be able to respond to the event notification method that signals a property change.
The PropertyChangeEvent class encapsulates property change information, and is
sent from the property change event source to each object in the property change
listener list with the propertyChange method.
C) Constrained Properties:
A bean property is constrained if the bean supports the VetoableChangeListener(in
the API reference documentation) and PropertyChangeEvent(in the API reference
documentation) classes, and if the set method for this property throws a
PropertyVetoException(in the API reference documentation).
Constrained properties are more complicated than bound properties because they
also support property change listeners which happen to be vetoers.
The following operations in the setXXX method for the constrained property must be
implemented in this order:

Save the old value in case the change is vetoed. Notify listeners of the new
proposed value, allowing them to veto the change. If no listener vetoes the change
(no exception is thrown), set the property to the new value. The accessor methods
for a constrained property are defined in the same way as those for simple
properties, with the addition that the setXXX method throws a
PropertyVetoException exception. The syntax is as follows:
public void setPropertyName(PropertyType pt)
throws PropertyVetoException {code}

6. Describe the process of creating a table and updating its contents using
JDBC.
Creating Tables and updating:
There is currently no possibility to create tables using the SQL Server interface you
have used for queries.
In general, you can create (and delete) tables and insert/update/delete table
content using JDBC - there is a link below - and check the effect using the SQL
Server query interface. By selecting all information from a table (execute "SELECT *
FROM T" in the 'pubs' database using the query tool - if T is the table you have just
created or updated) you can see whether your commands were successful: if the
table hasn't been created then the system is going to tell you that the object
doesn't exist; if it exists you will see its content (might be empty immediately after
creation).

You can create tables in the database using JDBC:


stmt.executeUpdate("CREATE TABLE BOOKS " +
"(ISBN VARCHAR(15), AUTHOR VARCHAR(20), TITLE VARCHAR(20), PRICE
DECIMAL(3.2), " +
" PRIMARY KEY(ISBN) )");
and you can insert data into this table:
stmt.executeUpdate("INSERT INTO BOOKS " +
" VALUES ('1-234-567', 'Gosling', 'Java', 25.99)");
The suggested attribute type DECIMAL might not be available in all DBMS. If there is
a problem, use FLOAT instead.

7. Explain the importance of CORBA and its applications in running


client server programs.
CORBA is an open standard rather than a proprietary technology. This is important
for a variety of reasons.
First, users can choose an implementation from a variety of CORBA vendors (or
choose one of the freeware implementations). You might think that switching from
one CORBA product to another would involve a lot of work. However, the amount of
work involved is likely to be much less than you might think, particularly if you
follow the practical advice in Chapter 25 about how to increase the portability of
CORBA-based applications. In contrast, if you use a proprietary middleware system
then switching to another proprietary middleware vendor is much more challenging.
Second, the competition between different CORBA vendors helps to keep software
prices down.
Finally, many proprietary middleware technologies are designed with the
assumption that developers will build all their applications using that particular
middleware technology, and so they provide only limited support for integration
with other technologies. In contrast, CORBA was designed with the goal of making it
easy to integrate with other technologies. Indeed, the CORBA specification explicitly
tackles integrations with TMN, SOAP, Microsofts (D)COM and DCE (a middleware
standard that was popular before CORBA). Furthermore, many parts of J2EE borrow
heavily from concepts in CORBA, which makes it relatively easy to integrate J2EE
and CORBA. Some vendors sell gateways between CORBA and J2EE that make such
integration even easier. Several CORBA vendors sell COM-to-CORBA and/or .NET-toCORBA gateways. This provides a very pragmatic solution to organizations that wish
to write GUI applications in, say, Visual Basic on Windows that act as clients to
server applications on a different type of computer, such as UNIX or a mainframe.
The Visual Basic GUI can be written as a COM/.NET client that thinks it is talking to a
COM/.NET server, but in fact communicates with a gateway that forwards on
requests to a CORBA server.

The on-the-wire protocol infrastructure of CORBA ensures that messages between


clients and servers are transmitted in a compact representation. Also, most CORBA
implementations marshal data (that is, convert data from programming-language
types into a binary buffer that can be transmitted) efficiently. Many other
middleware technologies also use a similarly compact format for transmitting data
and have efficient marshaling infrastructure. However, there are some notable
exceptions, as I now discuss.
SOAP uses XML to represent data that is to be transmitted. The verbosity of XML
results in SOAP using much more network bandwidth than CORBA.1 SOAP-based
applications also incur considerable CPU overhead involved in formatting

programming-language types into XML format and later parsing the XML to extract
the embedded programming-languages types.
Some other middleware technologies, such as IBM MQ Series, transmit only binary
data, which is efficient. However, this requires that developers write the marshaling
code that copies programming-language types into the binary buffers prior to
transmission, and the unmarshaling code to extract the programming-language
types from a binary buffer. In contrast, a CORBA IDL compiler generates the
marshaling and unmarshaling code, so that developers do not need to write (and
maintain) such low-level code.

8. Explain the importance, applications and working of Ajax.


IMPORTANCE:

They can use a standard web browser, such as Firefox, Internet Explorer or
Safari, as their only user interface.

They don't force the user to wait for the web server every time the user clicks a
button. This is what "asynchronous" means. For instance, gmail fetches new
email messages in the background ("asynchronously") without forcing the user
to wait. This makes an AJAX application respond much more like a "real"
application on the user's computer, such as Microsoft Outlook.

The Ajax engine works within the Web browser (through JavaScript and the DOM)
to render the Web application and handle any requests that the customer might
have of the Web server. The beauty of it is that because the Ajax engine is
handling the requests, it can hold most information in the engine itself, while
allowing the interaction with the application and the customer to happen as
asynchronously and independently of any interaction with the server.

They use standard JavaScript features (including the unofficial XMLHTTPRequest


standard, pioneered by Microsoft and adopted by Firefox and other browsers) to
fetch data in the background and display different email messages or other data
"on the fly" when the user clicks on appropriate parts of the interface.

Usually they manipulate data in XML format. This allows AJAX applications to
interact easily with server-side code written in a variety of languages, such as
PHP, Perl/CGI, Python and ASP.NET. Using XML isn't absolutely necessary, and in
fact many "AJAX" applications don't -- they use the XMLHTTPRequest object to
send and receive data "on the fly," but they don't actually bother packaging that
data as XML.

Working of Ajax:
Ajax adds a layer to web application communication models. As previously
stated, in traditional web applications communication between the
browser/client and the web server occurred directly between these two

components using HTTP requests. When users/clients request web pages, the
server sends all the HTML and CSS code at once. If the user enters information
into this page and requests more servers, the entire page must be loaded again.
When using Ajax, the page is only loaded once. Any processing or modification
caused by additional user input occurs in real time
In addition to HTML and CSS code, Ajax also downloads JavaScript files. These
three components make up the Ajax engine. So all requests for data from the
server will be sent as JavaScript calls to this engine, which is located as a
communication layer between the browser and the server. The Ajax engine or
layer processes subsequent requests that may change the appearance or
function of the web page. By requesting information from the server
asynchronously, Ajax sends page bits to request services from the server as
needed.
The engine allows these bits or responses to be displayed without reloading the
entire page. This makes web pages and web applications much more responsive
since only the necessary information is communicated between clients and
servers instead of the entire page. This process imitates the responsiveness of
desktop applications. Similarly, Ajax conducts all HTTP requests in the
background, preventing user disruption. Users can continue working while the
page sections are requested and delivered. With Ajax, the user interface is much
more closely connected to application logic.

You might also like