doc - Angelfire

advertisement
ASSIGNMENT FOR
SOFTWARE ENGINEERING
J2EE
INTRODUCTION TO J2EE:
J2EE is yet another acronym in the world of computing. This one stands for Java 2
Platform, Enterprise Edition. First of all, Java is a programming language developed by Sun
Microsystems, one of the giants of the industry. The Java Platform is a virtual machine, a
processor look-alike that translates computerized instructions into functions.
The 2 in the acronym J2EE stands for Version 2. As with many software
applications, J2EE is Java Platform Version 2. Actually, the number 2 is often dropped
nowadays, so J2EE becomes Java EE. Traditionally, though, it's still J2EE. One prime
benefit of the J2EE, despite the assumption of such a powerful set of source code, is that
it is available for free. You can download it right now from the Sun Microsystems website.
Third-party open-source tools are available to help you as well, including Apache Tomcat
and JBoss. Unless you are running your own multiple-workstation server system or
mainframe, however, you are unlikely to encounter or have a need for J2EE. Still, it's good
to know what such things stand for.
Multitiered Applications
J2EE Components
J2EE applications are made up of components. A J2EE component is a selfcontained functional software unit that is assembled into a J2EE application with
its related classes and files and that communicates with other components. The
J2EE specification defines the following J2EE components:



Application clients and applets are components that run on the client.
Java Servlet and JavaServer Pages (JSP ) technology components are
web components that run on the server.
Enterprise JavaBeans (EJB ) components (enterprise beans) are business
components that run on the server.
J2EE components are written in the Java programming language and are compiled in
the same way as any program in the language. The difference between J2EE
components and "standard" Java classes is that J2EE components are assembled
into a J2EE application, are verified to be well formed and in compliance with the
J2EE specification, and are deployed to production, where they are run and
managed by the J2EE server.
J2EE Clients
A J2EE client can be a web client or an application client.
Web Clients
A web client consists of two parts: (1) dynamic web pages containing various types
of markup language (HTML, XML, and so on), which are generated by web
components running in the web tier, and (2) a web browser, which renders the pages
received from the server.
A web client is sometimes called a thin client. Thin clients usually do not query
databases, execute complex business rules, or connect to legacy applications. When
you use a thin client, such heavyweight operations are off-loaded to enterprise
beans executing on the J2EE server, where they can leverage the security, speed,
services, and reliability of J2EE server-side technologies.
Applets
A web page received from the web tier can include an embedded applet. An applet
is a small client application written in the Java programming language that executes
in the Java virtual machine installed in the web browser. However, client systems
will likely need the Java Plug-in and possibly a security policy file in order for the
applet to successfully execute in the web browser.
Web components are the preferred API for creating a web client program
because no plug-ins or security policy files are needed on the client systems. Also,
web components enable cleaner and more modular application design because they
provide a way to separate applications programming from web page design.
Personnel involved in web page design thus do not need to understand Java
programming language syntax to do their jobs.
Application Clients
An application client runs on a client machine and provides a way for users to
handle tasks that require a richer user interface than can be provided by a markup
language. It typically has a graphical user interface (GUI) created from the Swing
or the Abstract Window Toolkit (AWT) API, but a command-line interface is
certainly possible.
Application clients directly access enterprise beans running in the business tier.
However, if application requirements warrant it, an application client can open an
HTTP connection to establish communication with a servlet running iJ2EE Server
Communications
The client communicates with the business tier running on the J2EE server
either directly or, as in the case of a client running in a browser, by going through
JSP pages or servlets running in the web tier.
Your J2EE application uses a thin browser-based client or thick application
client. In deciding which one to use, you should be aware of the trade-offs between
keeping functionality on the client and close to the user (thick client) and offloading as much functionality as possible to the server (thin client). The more
functionality you off-load to the server, the easier it is to distribute, deploy, and
manage the application; however, keeping more functionality on the client can make
for a better perceived user experience.
N THE WEB TIER. J2EE APPLICATIONS
Java 2 Enterprise Edition introduces the concept of J2EE applications. A J2EE
application contains J2EE modules, which could be web applications, EJBs and application
clients. It also contains meta-information about the application as well as shared libraries. You
can also say that a J2EE application is a set of J2EE modules with some added glue that binds
them together into a complete integrated application. The shape of a J2EE application is a
single Java Archive file with the .ear filename extension.
GENERATING PRIME NUMBERS
A prime number is an integer greater than 1, with only itself and
1 as divisors. The first few primes are 2, 3, 5, 7, 11, and 13.
This tip examines two ways of generating primes. The first
approach works for relatively small (32-bit) prime numbers. The
second uses the BigInteger class to generate large primes
(typically hundreds or thousands of digits).
Here's an example of where prime numbers are used. Suppose that
you're working on a custom hash table scheme. You know that there
will be about 1000 entries in the table, and you want the table
to be no more than two thirds full, relative to the number of
slots available. This implies a table size of 1500. A common hash
table algorithm uses a table size that's prime, in order to
reduce the number of collisions. So you need to find a prime
number with a value near 1500. How can you do this? Here's one
way:
public class PrimeDemo1 {
// check whether a number is prime
static boolean isPrime(int n) {
// 2 is the smallest prime
if (n <= 2) {
return n == 2;
}
// even numbers other than 2 are not prime
if (n % 2 == 0) {
return false;
}
// check odd divisors from 3
// to the square root of n
for (int i = 3, end = (int)Math.sqrt(n);
i <= end; i += 2) {
if (n % i == 0) {
return false;
}
}
}
return true;
// find the smallest prime >= n
static int getPrime(int n) {
while (!isPrime(n)) {
n++;
}
return n;
}
}
public static void main(String args[]) {
System.out.println(getPrime(1500));
}
The PrimeDemo1 program defines an isPrime method. The method
handles the special case of 2 (which is prime). It then screens
out other positive even numbers (which are not prime, because
they have 2 as a divisor). The isPrime method then tries odd
divisors starting at 3 and going up to the square root of the
number.
The output of the program is:
1511
that is, 1511 is the smallest prime of value 1500 or above.
Given this background, how do you actually generate a big prime?
Here's a simple example:
import java.math.BigInteger;
import java.util.Random;
public class PrimeDemo2 {
public static void main(String args[]) {
Random rnd = new Random(0);
//
//
//
//
obtain a 100-bit probable prime,
with the probability that the number
is composite at less than
1 in 2 to the 100th power
BigInteger prime =
BigInteger.probablePrime(100, rnd);
}
}
System.out.println(prime);
This program generates a 100-bit prime, using the passed-in
Random object as a source of random values. The output of the
program is:
689572171629632424814677540353
BY
SHABANA S.
Download