Thursday, May 28, 2009

Java Server Pages (JSP) in breif

JavaServer Pages (JSP) is a technology based on the Java language and enables the development of dynamic web sites. JSP was developed by Sun Microsystems to allow server side development. JSP files are HTML files with special Tagscontaining Java source code that provide the dynamic content.

JSP source code runs on the web server in the JSP Servlet Engine. The JSP Servlet engine dynamically generates the HTML and sends the HTML output to the client’s web browser.

JSP is based on Java, an objectoriented language. JSP offers a robust platform for web development. JSP code on the server is classed as the implementation. By having a separation of presentation and implementation, designers work only on the presentation and developers concentrate on implementing the application.

JSPs are built on top of SUN’s servlet technology. JSPs are essential an HTML page with special JSP tags embedded. These JSP tags can contain Java code. The JSP file extension is .jsp rather than .htm or .html. The JSP engine parses the .jsp and creates a Java servlet source file. It then compiles the source file into a class file, this is done the first time and this why the JSP is probably slower the first time it is accessed. Any time after this the special compiled servlet is executed and is therefore returns faster.

Read more...

Wednesday, May 27, 2009

WebLogic Server Deployment Modes

Staging Modes in WebLogic Server

Stage mode

The Administration Server copies the archive files from their source location to a location on each of the targeted Managed Servers that deploy the archive. Consider if you deploy a J2EE Application to three servers in a cluster, the Administration Server copies the application archive files to each of the three servers. Each server then deploys the J2EE Application using its local copy of the archive files.

* Stage mode is the default mode when deploying to more than one WebLogic Server instance.

External Stage mode

External stage mode is similar to stage mode, but in that the deployment files must reside locally to each targeted server. Here Administration Server does not automatically copy the deployment files to targeted servers in external stage mode, instead we must manually copy the files, or use a third-party application to copy the files for you.

NoStage mode

The Administration Server does not copy the archive files from their source location. Instead, each targeted server must access the archive files from a single source directory for deployment. If you deploy a J2EE Application to three servers in a cluster, each server must be able to access the same application archive files (from a shared or network-mounted directory) to deploy the application.

* Nostage mode is the default mode when deploying only to the Administration Server (for example, in a single-server domain). You can also select nostage mode if you run a cluster of server instances on the same machine.

Read more...

Thursday, May 21, 2009

Weblogic Server T3 Protocol

T3 is BEA's proprietary protocol. T3 provides a framework for WebLogic Server messages that support for enhancements. These enhancements include abbreviations and features, such as object replacement, that work in the context of WebLogic Server clusters and HTTP and other product tunneling.

Weblogic's implementation of the RMI specification uses a proprietary T3 wire-protocol. javasoft's reference implementation of RMI uses a proprietary protocol called JRMP. weblogic developed T3 because they needed a scalable,efficient protocol for building enterprise-class distributed object systems with java.

T3 is mandated between WebLogic Servers and between programmatic clients and a WebLogic Server cluster. HTTP and IIOP are optional protocols that can be used to communicate between other processes and WebLogic Server. It depends on what you want to do. For example, when you want to communicate between n A browser and WebLogic Server-use HTTP
n An ORB and WebLogic Server-IIOP.

T3 predates Java Object Serialization and RMI, while closely tracking and leveraging these specifications. T3 is a superset of Java Object. Serialization or RMI, anything you can do in Java Object Serialization and RMI can be done over T3.

Read more...

Wednesday, May 20, 2009

Implementing a thread-safe JSP page

We can make a thread-safe JSP by having them implement the SingleThreadModel interface. This is done by adding the below directive within your JSP page.

<%@ page isThreadSafe="false" %>

By this, instead of a single instance of the servlet generated for your JSP page loaded in memory, you will have N instances of the servlet loaded and initialized, with the service method of each instance effectively synchronized. You can typically control the number of instances (N) that are instantiated for all servlets implementing SingleThreadModel through the admin screen for your JSP engine.

More importantly, avoid using the tag for variables. If you do use this tag, then you should set isThreadSafe to true, as mentioned above. Otherwise, all requests to that page will access those variables, causing a nasty race condition.

SingleThreadModel is not recommended for normal use. There are many pitfalls, including the example above of not being able to use . You should try really hard to make them thread-safe the old fashioned way by making them thread-safe.

Read more...

Tuesday, May 19, 2009

Message Driven Bean

What is Message Driven Bean ?

Message driven beans will provide asynchrony to EJB based applications by acting as JMS message consumers. A message bean is associated with a JMS topic or queue and receives JMS messages sent by EJB clients or other beans.

Message driven beans are the latest addition to the family of component bean types defined by the EJB specification. The original bean types include session beans, which contain business logic and maintain a state associated with client sessions, and entity beans, which map objects to persistent data.

Unlike entity beans and session beans, message beans do not have home or remote interfaces. Instead, message driven beans are instantiated by the container as required. Like stateless session beans, message beans maintain no client-specific state, allowing the container to optimally manage a pool of message-bean instances. Clients send JMS messages to message beans in exactly the same manner as they would send messages to any other JMS destination. This similarity is a fundamental design goal of the JMS capabilities of the new specification.

To receive JMS messages, message driven beans implement the javax.jms.MessageListener interface, which defines a single "onMessage()" method. When a message arrives, the container ensures that a message bean corresponding to the message topic/queue exists (instantiating it if necessary), and calls its onMessage method passing the client's message as the single argument. The message bean's implementation of this method contains the business logic required to process the message. Session beans and entity beans are not allowed to function as message beans.

Read more...

Thursday, May 14, 2009

Advanced Ajax: Architecture and Best Practices eBook

Advanced Ajax: Architecture and Best Practices is the definitive guide to building business-critical, production-quality Web applications with Ajax. Shawn M. Lauriat systematically addresses the design, architecture, and development issues associated with Ajax, offering proven patterns and robust code examples available in no other book. You’ll find best practices for addressing the full spectrum of issues enterprise Ajax developers face: scalability, performance, security, reliability, flexibility, maintainability, and reusability.

  • Planning Ajax interfaces for simplicity, clarity, and intuitiveness
  • Creating scalable, maintainable architectures for client-side JavaScript
  • Using the latest tools to profile, validate, and debug client-side code
  • Architecting the server side for security and functionality, while restricting loaded data, objects, and actions to current requests
  • Protecting against the most widespread and significant Ajax security risks
  • Optimizing every component of an Ajax application, from server-side scripts to database interactions
  • Introducing cutting-edge Ajax: game development, Ajax with canvas, and Ajax for enterprise applications
Writing for experienced Web developers, Lauriat delivers fresh ideas and elegant solutions: meaty technical content, presented with exceptional clarity. Among the many topics he covers in unprecedented depth: cleanly implementing JavaScript custom events to reduce coupling and to enhance flexibility; overcoming Ajax’s traditional accessibility limitations; reducing network latency through compression and other techniques; and much more. Coverage includes.

-Shawn M. Lauria

Read more...

Wednesday, May 13, 2009

Servlet Container

A servlet is managed by a servlet container also referred to as Servlet Engine. The servlet container is a compiled, executable program.

The container is the intermediary between the application (web server) and the servlets in the container.The container loads, initializes, and executes the servlets. When a request arrives, the container maps the request to a servlet, translates the request and then passes the request to the servlet. The servlet processes the request and produces a response.The container translates the response into the network format, then sends the response back to the Web server.

The servlet container together with the web server (or application server) provides the HTTP interface to the world. It is also possible for a servlet container to run stand alone (without web server) or to even run on another host than the web server. When a request is received by the servlet container, it decides what servlet to call in accordance with a configuration file. The servlet Container calls the servlet's service() method and passes an instance of ServletRequest and ServletResponse. Depending on the request's method (mostly GET and POST), service calls doGet() or doPost().

These passed instances can be used by the servlet to find out who the remote user is, if and what HTTP POST parameters have been set and other characteristics. The servlet container is responsible for loading and instantiating the servlets and then calling init().

The container is designed to perform well while serving large numbers of requests. A container can hold any number of active servlets, filters, and listeners. Both the container and the objects in the container are multithreaded. The container creates and manages threads as necessary to handle incoming requests. The container handles multiple requests concurrently, and more than one thread may enter an object at a time. Therefore, each object within a container must be threadsafe.

A servlet container can manage any number of distinct applications. An application consists of any number of servlets, filters, listeners, and static Web pages. A set of components working together is a Web applicatio

Read more...

Tuesday, May 12, 2009

Ajax For Dummies eBook

Ajax is short for "Asynchronous JavaScript" Even if you weren't intimidated before, that tidbit is probably enough to make you reach for the Excedrin. Just reach for Ajax For Dummies instead. With screen shots, actual code and explanations, and live Web sites where you can see Ajax applications doing their thing, it will have you using Ajax to create Web applications that look an act like desktop applications in no time. With Ajax, you can speed up and clean up your Web applications. Shoppers at your online store can fill their carts without waiting for multiple page refreshes. Searchers on your sites can get instant results on the same page.

Major Web players are already using Ajax to create a new generation of Web applications, including Google (Ajax is behind Google Maps, Google Suggest, and Google Groups), Amazon, and Yahoo. Topics covered include creating JavaScript effects, styling with CSS, using the XMLHttpRequest object to fetch data, working with Ajax design patterns, harnessing Ajax toolkits, and server-side scripting with PHP and JSP.

Author: Steve, Ph.D. Holzner

Read more...

Monday, May 11, 2009

Java Programming with Oracle JDBC eBook

JDBC is the key Java technology for relational database access. Oracle is arguably the most widely used relational database platform in the world. In this book, Donald Bales brings these two technologies together, and shows you how to leverage the full power of Oracle's implementation of JDBC.

This can be one of the most frustrating areas for programmers new to JDBC, and Donald covers it well with detailed information and examples showing how to make database connections from applications, applets, Servlets, and even from Java programs running within the database itself. Next comes thorough coverage of JDBC's relational SQL features. shows you how to use JPublisher and JDBC to work seamlessly with Oracle database objects from within Java programs. You'll also learn how to access nested tables and arrays using JDBC. Donald concludes the book with a discussion of transaction management, locking, concurrency, and performance--topics that every professional JDBC programmer must be familiar with. If you write Java programs to run against an Oracle database, this book is a must-have.


Author: Donald Bales

Read more...

Friday, May 8, 2009

Java Static Modifier

Static Modifier in Java:

In java we can have a Static Block, Static Variable, Static Method. Static modifier specifies that a variable or method is the same for all objects of a particular class. Some times we need a common variable or method for all objects of a part icular class. Typically, new variables are allocated for each instance of a class.

Variable declared as being static is only allocated once, regardless of how many objects are instantiated and all instantiated objects share the same instance of the static variable.
Similarly, a static method is one whose implementation is exactly the same for all objects of a part icular class. Static methods have access only to static variables.

Example of a static member variable and a static method:

static int refCount;
static int getRefCount() {
return refCount;
}
A beneficial side effect of static members is that they can be accessed without having to create an instance of a class. Static method or a variable is not attached to a particular object, but rather to the class as a whole. They are allocated when the class is loaded.

A static initializer block resembles a method with no name, no arguments, and no return type. It doesn't need a name, because there is no need to refer to it from outside the class definition. The code in a static initializer block is executed by the virtual machine when the class is loaded.

Example of a Static Block
static{
date1 = new Date();
for(int count = 0; count <>
var = var+1;
}
Static blocks are blocks defined within the body of a class using the static keyword but which are not inside any other blocks.

Read more...

Thursday, May 7, 2009

Java Access Modifiers

Access Modifiers in Java

Access to variables and methods in Java classes is accomplished through access modifiers. Access modifiers define varying levels of access between class members and the outside world (other objects). Access modifiers are declared immediately before the type of a member variable or the return type of a method.

There are four access modifiers in java :

  • default
  • public
  • protected
  • private
Access modifiers affect the visibility not only of class members, but also of classes themselves.

Default Access Modifier

The default access modifier specifies that only classes in the same package can have access to a class's variables and methods. Class members with default access have a visibility limited to other classes within the same package. There is no actual keyword for declaring the default access modifier, it is applied by default in the absence of an access modifier.

Code for default access variable and member:
long length;
void getLength() {
return length;
}
Notice that neither the member variable nor the method supplies an access modifier, so each
takes on the default access modifier implicitly.

public Access Modifier

The public access modifier specifies that class variables and methods are accessible to anyone, both inside and outside the class. This means that public class members have global
visibility and can be accessed by any other object.

Sample Code for public member variables:
public int count;
public boolean valid;
protected Access Modifier

The protected access modifier specifies that class members are accessible only to methods in that class and subclasses of that class. This means that protected class members have visibility limited to subclasses.

Sample code for protected variable and a protected method :
protected char Name;
protected char getName() {
return Name;
}
The private Access Modifier

The private access modifier is the most restrictive; it specifies that class members are accessible only by the class in which they are defined. This means that no other class has access to private class members, even subclasses.

Code example for private member variables:
private String firstName;
private double Value;
Access to classes, constructors, methods and fields are regulated using access modifiers. Access modifiers in Java determine the visibility and the scope of the Java elements.

Read more...

Wednesday, May 6, 2009

Java code to get the Users IP Address

Java Program to get the Users IP Address

This following code shows how to obtain the IP address of the user that calls the server. The Request object has a few methods to get information about the call and about the caller, and one of them is named getRemoteAddr() which returns the IP address of the calling computer.

The below example will print the IP address of the user on a blank html-page.

import java.io.*;
import java.util.Enumeration;
import javax.servlet.*;
import javax.servlet.http.*;

public class ExampleServlet extends HttpServlet {

protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
printPageStart(out);

//Funtion to Print out the IP address of the caller
out.println(request.getRemoteAddr());
}
}

Read more...

Tuesday, May 5, 2009

Java code to list all the available Locales

While implementing Internationalization (I18N) concept, there will be a requirement to find the Locales.Check the following java code to list all the available Locales

Locale[] locales = Locale.getAvailableLocales();

for (int i=0; i
// Get the two letter language code
String language = locales[i].getLanguage();

// Get the two letter country code;
String country = locales[i].getCountry();


// Get localized name suitable for display
String locName = locales[i].getDisplayName();
}

Read more...

Monday, May 4, 2009

Java Object Serialization

Serialization in Java :

Serialization is the process of converting a set of object instances that contain references to each other into a linear stream of bytes, which can then be sent through a socket, stored to a file, or simply manipulated as a stream of data. Serialization involves saving the current state of an object to a stream, and restoring an equivalent object from that stream.

Serialization is the mechanism used by RMI to pass objects between JVMs, either as arguments in a method invocation from a client to a server or as return values from a method invocation.

For an object to be serialized, it must be an instance of a class that implements either the Serializable or Externalizable interface. Both interfaces only permit the saving of data associated with an object's variables.

The Serializable interface relies on the Java runtime default mechanism to save an object's state. Writing an object is done via the writeObject() method in the ObjectOutputStream class or the ObjectOutput interface.

The Externalizable interface specifies that the implementing class will handle the serialization on its own, instead of relying on the default runtime mechanism.

Classes ObjectInputStream and ObjectOutputStream, which respectively implement the ObjectInput and ObjectOutput interfaces, enable entire objects to be read from or written to a stream (possibly a file). To use serialization with files, we initialize ObjectInputStream and ObjectOutputStream objects with stream objects that read from and write to files—objects of classes FileInputStream and FileOutputStream, respectively.

Initializing stream objects with other stream objects in this manner is sometimes called wrapping—the new stream object being created wraps the stream object specified as a constructor argument. To wrap a FileInputStream in an ObjectInputStream, for instance, we pass the FileInputStream object to the ObjectInputStream’s constructor.

The ObjectOutput interface contains method writeObject, which takes an Object that implements interface Serializable (discussed shortly) as an argument and writes its information to an OutputStream. Correspondingly, the ObjectInput interface contains method readObject, which reads and returns a reference to an Object from an InputStream. After an object has been read, its reference can be cast to the object’s actual type.

The object to be serialized must implement java.io.Serializable. This example serializes a javax.swing.JButton object.


Object object = new javax.swing.JButton("push me");

try {
// Serialize to a file
ObjectOutput out = new ObjectOutputStream(new FileOutputStream("filename.ser"));
out.writeObject(object);
out.close();

// Serialize to a byte array
ByteArrayOutputStream bos = new ByteArrayOutputStream() ;
out = new ObjectOutputStream(bos) ;
out.writeObject(object);
out.close();

// Get the bytes of the serialized object
byte[] buf = bos.toByteArray();
} catch (IOException e)
{
}


Object serialization is performed with byte-based streams, so the sequential files created and manipulated will be binary files. Recall that binary files cannot be viewed in standard text editors.

Read more...

Sunday, May 3, 2009

Java Code to Generate a Random Number


Sample Java Code to Generate a Random Number:

Some times in Projects or Applications, there will be a requirement to generate a Random Number for this we can use the following code.

Random rand = new Random();

// Random integers
int i = rand.nextInt();
// Continually call nextInt() for more random integers

// Random integers ranging from from 0 to n
int n = 10;
i = rand.nextInt(n+1);

// Random bytes
byte[] bytes = new byte[5];
rand.nextBytes(bytes);

// Other primitive types
boolean b = rand.nextBoolean();
long l = rand.nextLong();
float f = rand.nextFloat(); // 0.0 <= f < 1.0
double d = rand.nextDouble(); // 0.0 <= d < 1.0

// Create two random number generators with same seed
long seed = rand.nextLong();
rand = new Random(seed);
Random rand2 = new Random(seed);


Read more...

Saturday, May 2, 2009

Java Methods for Financial Engineering eBook


Java Methods for Financial Engineering: Applications in Finance and Investment eBook :

In order to build a successful, Java-based application it is important to have a clear understanding of the principles underlying the various financial models. Those models guide the application designer in choosing the most appropriate Java data structures and implementation strategy.

This book describes the principles of model building in financial engineering and explains those models as designs and working implementations for Java-based applications.

Throughout the book a series of packaged classes are developed to address a wide range of financial applications. Java methods are designed and implemented based on the most widely used models in financial engineering and investment practice. The classes and methods are explained and designed in a way which allows the financial engineer complete flexibility. The classes can be used as off-the-shelf working solutions or the innovative developer can re-arrange and modify meth
ods                                                        to create new products
 
                                                                                           Author: Philip Barker

                               
Download Java Methods for Financial Engineering eBook

Read more...
Blog Widget by LinkWithin

JS-Kit Comments

  © Blogger template Newspaper III by Ourblogtemplates.com 2008

Back to TOP