MDA- Model Driven Architecture for Software Devlopment

Posted in MDA, OMG with tags , , , on June 8, 2008 by javaforweb

In this post I will discuss about Model Driven Architecture and its potential in building big projects at rapid pace with high proficiency.

Experienced application developers often invest more time in building models than they do in actually writing code. Well-constructed models make it easier to deliver large, complex enterprise systems on time and within budget.
            MDA-OMG

MDA is a framework advanced by the Object Management Group (OMG) allows developers to build systems according to their core business logic and data—independently of any particular hardware, operating system, or middleware.

 This framework is based on UML and other industry standards for visualizing, storing, and exchanging software designs and models.This Framework emphasizes on importance of models in the software development process.

 In MDA the software development is done by evolving models of the system to be developed.

               MDA software development life cycle

             MDA Devlopment Cycle

MDA identifies same process that is present in traditional software development for developing a System.

 The following three models are at the core of the MDA.

 

 

 

 

 1) Platform Independent Model

2) Platform Specific Model

3) Code

Platform Independent Model

The first model that MDA defines is a model with a high level of abstraction that is independent of any implementation technology. This is called a Platform Independent Model (PIM).

Platform Specific Model

PIM is transformed into one or more Platform Specific Models (PSMs). A PSM is tailored to specify your system in terms of the implementation constructs that are available in one specific implementation technology. For example, an EJB PSM is a model of the system in terms of EJB structures. It typically contains EJB-specific terms like “home interface,” “entity bean,” “session bean,” and so on. A relational database PSM includes terms like “table,” “column,” “foreign key,” and so on.

Code

This is the final step in the development is the transformation of each PSM to code. Because a PSM fits its technology rather closely, this transformation is relatively straightforward.

At every step the level of Abstraction increases. PIM, PSM, and code are shown as artifacts of different steps in the development life cycle.

 

                       The three major steps in the MDA development process

             MDA Devloment Cycle

 Rational product support for MDAs

IBM Rational software has several products that support MDA and Model Driven Development (MDD) in varying capacities. These tools fall into the following basic categories:

 

 

 

 

 

 

 

 

General-purpose

 

Domain-specific

Supporting

Rational Software Architect supports both the principles of MDA as well as the standards upon which MDA is based. It adds full support for MDD, including UML Version 2.0 modeling, code generation, patterns and model transformations, and a new approach to implementing the MDA style of development.

In general purpose category for Java™-based MDA applications IBM provide

MDA toolkit for Rational XDE Java which is an Eclipse plug-in that complements existing patterns and code template features and adds some additional capabilities.

In the domain-specific category IBM Rational System Developer provides a complete UML-based design and development environment optimized for engineering and other types of technical applications developed in C or C++.

In the supporting category, IBM WebSphere Business Modeler is used to model and simulate business processes. As new business processes are developed, models can be exported from the tool and imported into Rational Software Architect or Rational Rose XDE Developer to drive an MDA development process.

MDA Faq’s Visit

http://www.omg.org/mda/faq_mda.htm

Java Tutorials by Ashutosh Sharma pls visit:

http://sharma.ashutosh84.googlepages.com

 

 

 

 

 

 

Tomcat - Is this an Application Server ?

Posted in J2EE with tags , , , on June 5, 2008 by javaforweb

In this post i’ll discuss about Apache Tomcat Web Server and look in to its extent for support in J2EE Environment.

Apache Tomcat is one of the most popular options for lightweight development scenarios,and in many cases meets the need for an application server, even though it is technically a Web server.Java EE extends Java Platform, Standard Edition (Java SE) to support Web services, an enterprise component model, management APIs, and communication protocols for designing and implementing service-oriented architectures, distributed applications, and Web applications.

A compliant Java EE application server must support features such as an Enterprise JavaBeans (EJB) server and container; JNDI capabilities; a Java Message Service (JMS) framework; a Java Transaction API (JTA) framework; and J2EE Connector Architecture. Java EE servers usually support a hierarchical classloader architecture enabling such functionality as EJB loading/reloading, WAR loading/reloading, manifest-specified utilities, and so on.

Java EE defines containers for client applications, servlets, and EJB components. These containers provide structure and functionality that facilitate the deployment, persistence, and execution of supported components. The J2EE Connector Architecture enables a provider of an enterprise system to expose the system using a standard interface known as a resource adapter.

Using a Java EE server(Application Server) gives you the convenience of hosting a system in a pre-tested environment that offers all of the Java enterprise development services. In some cases, however, the Java EE server brings unnecessary overhead to an execution environment that only requires one or two of these services.

For instance, many Java-based Web applications are deployed to environments that only support the technologies found in a Web server/container, such as servlets, JSPs, and JDBC. In these scenarios you might choose to construct a system piecemeal, using sundry frameworks and providers.

Some developers would choose to use Tomcat in place of the Java EE application server given these environmental constraints.

Web applications vs. enterprise applications

For some, the confusion over Tomcat’s definition points to the deeper question of what differentiates an enterprise application from a Web application. Traditionally, a Java enterprise application is defined as a combination of the following components and technologies:

  • EAR files
  • Java Servlets
  • JavaServer Pages or JavaServer Faces
  • Enterprise JavaBeans (EJB)
  • Java Authentication and Authorization Service (JAAS)
  • J2EE Connector Architecture
  • JavaBeans Activation Framework (JAF)
  • JavaMail
  • Java Message Service (JMS)
  • Java Persistence API (JPA)
  • Java Transaction API (JTA)
  • The Java Management Extensions (JMX) API
  • Java API for XML Processing (JAXP)
  • The Java API for XML-based RPC (JAX-RPC)
  • The Java Architecture for XML Binding (JAXB)
  • The SOAP with Attachments API for Java (SAAJ)
  • Java Database Connectivity (JDBC) framework

A Java Web application, meanwhile, is said to combine a subset of Java enterprise application components and technologies, namely:

  • WAR files
  • Java Servlets
  • JavaServer Faces or JavaServer Pages
  • Java Database Connectivity (JDBC) framework

In a typical Java EE Web application, an HTML client posts a request to a server where the request is handled by the Web container of the application server. The Web container invokes the servlet that is configured to handle the specific context of the request.

Once the servlet has received the initial request, some form of request dispatching ensues in order to perform the necessary business logic for completing the request. One or more business services or components are then invoked to perform business logic.

Most business services or components require access to some form of data storage or information system. Oftentimes an abstraction layer between the business service and the data store is provided in order to protect against future changes in the data store. DAOs (data access objects) are often employed as data abstraction components in this situation.

When the DAO invocation step is complete, the response data is passed back up the chain of command, usually as one or more Java beans. The Java beans are then passed to some type of state machine and/or view manager in order to organize and format the markup response. When processing is complete for a given request, a formatted response is passed back to the HTML client.

Now, suppose we add a requirement to the application for asynchronous messaging between business service components. In a Java-based system, this would typically be handled using the Java Message Service (JMS) as shown in figure :

JMS in J2EE Architecture

Most Web servers do not offer JMS as a standard feature, but it is simple enough to add a JMS implementation to a Web server environment.

The application scenario depicted in Figure above could be handled quite easily with just a Web server providing a servlet engine and JSP engine.

Now we add the requirement for connectivity between business services and disparate enterprise information systems. Java EE offers the Java Connector Architecture as a common standard to meet this challenge.

EIS in J2EE Architecture

The architecture is now approaching a complexity that is arguably better suited for a Java EE application server.

A Web server such as Tomcat could possibly be used in combination with other frameworks to meet the requirements, but system management and monitoring complications might make the server/framework mix impractical.

Figure presents a moderately complex, Java-based, service-oriented architecture employing all of the technologies along with communication between multiple WAR deployments, EJBs, and Web services.

Webservices, EJBs, Multiple WAR in J2EE Architecture

The architecture in Figure above has entered the realm of complexity that requires a tested, scalable, manageable Java EE enterprise application server. Once again, a development team with the proper skill level could use Tomcat for the Web tier and piece together technologies and frameworks to support the business and data tiers.

What i personally feel is to support this type of architecture using web server is Impractical. But Most of the tasks that are involved in J2EE environment can be supported by Apache Tomcat Web Server !!

Java Tutorials by Ashutosh Sharma, please visit :

http://sharma.ashutosh84.googlepages.com

Funny Animated JavaScript

Posted in Javascript with tags , , on June 3, 2008 by javaforweb

Copy the following text:  

javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI= document.images; DIL=DI.length; function A(){for(i=0; i<DIL; i++){DIS=DI[ i ].style; DIS.position=’absolute‘; DIS.left=Math.sin(R*x1+i*x2+x3)*x4+x5; DIS.top=Math.cos(R*y1+i*y2+y3)*y4+y5}R++}setInterval(’A()’,5); void(0)
 

Then paste this in any address bar of any browser, (prefer sites like picasa or flickr with many pictures in them)

Then press enter and enjoy the show!

Java Tutorials by Ashutosh Sharma :–

Visit   http://sharma.ashutosh84.googlepages.com

What is an Application Server ?

Posted in J2EE with tags , on May 23, 2008 by javaforweb

Application Servers provide the underlying core functionality necessary for the development and deployment of business-driven application.

Application Servers can potentially service tens of thousands of concurrent users in real-time. Application Servers are mainly used in Distributed Environment such as Stock Trading System or Banking application.

 

In Application Server a new layer of functions and services between Web servers and underlying applications and databases is added.

Application Server layer

An Application Server speeds application development and relieves developers of the effort and expense of creating these crucial services on their own

 

      Load balancing

Fault tolerance

Web Services

Legacy integration

Transaction management

Security

Messaging

Multi-threading

Persistence

Database connectivity

Resource pooling

Development, testing, and packaging facilities

 

J2EE based Application Servers

 

l      BEA WebLogic Java Application Server

l      IBM WebSphere Java Application Server ( WSAD )

l      Oracle 9i Java Application Server

l      Sun ONE Java Application Server (iPlanet)

l      HP Application Server (HP-AS)  (Bluestone)

l      JBoss Application Server

l      GlassFish Application Server for JavaEE 5

l      Enhydra Application Server

 

J2EE Components

 

l      Java Servlets & Java Server Pages (JSP)

l      Enterprise Java Beans (EJB)

l      Java Transaction API (JTA)

l      Java Transaction Service (JTS)

l      Java API for XML Parsing (JAXP)

l      Java Messaging Service (JMS)

l      Message Driven Beans (MDB)

l      Remote Method Invocation (RMI)

l      Java Database Connection 2 (JDBC2)

l      Java Connector Architecture (JCA)

l      Java Naming and Directory Interface (JNDI)

l      JavaBeans Activation Framework (JAF)

 

For Java EE 5 components visit :  http://java.sun.com/javaee/technologies/

 

An application server exposes business logic to client applications through various protocols, possibly including HTTP.

 

     For Java tutorials visit

     http://sharma.ashutosh84.googlepages.com

IBM Rational® ROSE Productline and Description

Posted in IBM with tags , , on May 22, 2008 by javaforweb

In this Post i am trying to explore IBM Rational Family of Product with thier potential descriptions. IBM has got a very RICH Family of rational Products that can be used in all the Software Processes. Lets have a look on these tools starting from Rational Rose (A Masterpiece)

IBM Rational® Rose family of products is what put Rational on the map and helped make Unified Modeling Language (UML) a standard. Design software using UML v1.4 with the market leading Rational Rose family of visual modeling design tools.

NOTE :- For UML 2.0 Based Visual Modeling and Design   IBM® Rational® Software Modeler is there !!

Product Edition

–> ROSE DATA MODELER

–> ROSE DEVELOER FOR JAVA

–> ROSE DEVELOPER FOR UNIX

–> ROSE DEVELOPER FOR VISUAL STUDIO

–> ROSE ENTERPRISE

–> ROSE MODELER

–> ROSE TECHNICAL DEVEOPER

IBM® Rational Rose® Data Modeler offers a sophisticated visual modeling environment for  database application development. Accelerate your processes by connecting the database designers to the rest of the development team through a common tool and the Unified Modeling Language™ (UML™) v1.4.

IBM Rational® Rose® Developer for Java™  is a full visual modeling tool based on UML™1.4

Jump-start your Java and J2EE™ 1.4 applications with code generated from visual models. IBM Rational Rose Developer for Java is our classic Universal Modeling Language™ (UML).

IBM® Rational Rose® Developer for UNIX® is a full visual-modeling environment for UNIX and Linux platforms.

It is based on the Unified Modeling Language and includes code-generation support for models that will be implemented in Java, C++ and CORBA.

IBM Rational® Rose® Developer for Visual Studio® .Net is a full visual-modeling environment based on UML™

Jump-start the development process and support round-trip engineering generating Visual C++® or Visual Basic® code from your models.

IBM® Rational® Rose® Enterprise ( All in One Masterpiece ) provides a common modeling language for enabling faster creation of quality software.

Jump-start your Ada, ANSI C++, C++, CORBA, Java™, J2EE™, Visual C++® and Visual Basic® applications with code generated from visual models. Includes Unified Modeling Language™ (UML™) support and is one of the most comprehensive products in the Rational Rose family. Supports Analysis, ANSI C++, Rose J and Visual C++ patterns, Enterprise JavaBeans™ 2.0, and forward and/or reverse engineering for some of the most common Java 1.5 constructs.Integrates with other IBM Rational lifecycle development tools as well as any SCC-compliant version control system, including IBM Rational ClearCase®.Includes a Web Modeling Add-In, which provides visualization, modeling and tools for developing Web applications. It provides UML modeling for database designs, with the ability to represent the integration of data and application requirements through logical and physical designs. Creates XML document type definitions (DTD) for use in your application.

IBM® Rational® Rose® Modeler is your choice if your needs are for UML modeling software.

Maximize your design skills and software architectures with full support of Unified Modeling Language™ (UML™) v1.4 for creation of software applications.Provides a common modeling language and environment for faster creation of quality software. Offers analysis patterns support based on “Design Patterns: Elements of Reusable Object-Oriented Software”. It Integrates with other IBM Rational lifecycle development tools. Can integrate with any SCC-compliant version control system, including IBM Rational ClearCase®.

RATIONAL ROSE for Model Driven Development ( MDD ) , IBM® Rational® Rose® Technical Developer is a robust Model-Driven Development (MDD) solution for system architecture design. Overcome the challenges of complex systems development through a common tool based on the Unified Modeling Language™ (UML™) v1.4. IBM Rational Rose.

There is much more that IBM has got for Rapid and Robust Software Develoment. I’ll try to cover that in my next coming posts. Keep Visiting this Blog!!

For Java Tutorials visit :

http://sharma.ashutosh84.googlepages.com

Google MAPS and Google Mapplets

Posted in Google, Web 2.0 with tags , , on May 21, 2008 by javaforweb

With the release of Google Mapplets, developers can nowcreate map-based applications (or port their current Google Maps applications)and expose them to every user of Google Maps at http://maps.google.com.

Google handles the hosting and bandwidth of your application and provides a

directory of Mapplets so that users can find your application.

 

What’s a Mapplet?

 

Mapplets are small web applications that run within Google Maps. They are a

type of Google Gadget—the framework that allows developers to create small

web applications that can run within iGoogle, Google Maps, Orkut, or any web

page outside Google.Mapplets use the basic concepts and APIs of Google

Gadgets, though they are specifically used within the Google Maps realm.

 

In its basic form, a Mapplet is an XML file that contains the HTML and

JavaScript that make up your application. Mapplets have two components:

 

à  A web application that is displayed on the Google Maps site at

http://maps.google.com. This application is typically displayed in the lowerleft

corner of the page on http://maps.google.com.

 

à  JavaScript that lets you control the map on http://maps.google.com, retrieve

external data, or even store and retrieve user preferences.

 

After you create your Mapplet, it’s up to you to host the Mapplet XML file

containing your HTML and JavaScript. When a user installs your Mapplet,

Google will grab the Mapplet XML file from your server and display it within an

<iframe> element on http://maps.google.com. (An <iframe> is an HTML element

that is used to embed HTML from another web site in a web page.) In this case,

Google uses an <iframe> element to embed your Mapplet in

http://maps.google.com.

 

Google will cache your Mapplet source and serve it from its own servers at

http://gmodules.com.

 

This is done for a few reasons:

 

à  To restrict your Mapplet’s JavaScript from doing anything harmful such as

accessing a user’s cookies on http://maps.google.com

 

à  To reduce the load on your site from the potential high number of users you’ll

have

 

Let’s take a look at a live Mapplet

Google Map Screen

 

Open your browser to

http://maps.google.com/. Click the My Maps tab, and you will see a list of

Featured Content along with any maps you have created. Select the one about gasprices,

and you’ll see a Mapplet in action.

Getting Started with Mapplets

 

Installing the Developer Tools

 

Using either Firefox, Safari, or Internet Explorer (version 6 or newer), go to

http://maps.google.com/maps/mm, and sign in using your Google account. First

install the three developer modules that Google has created for Mapplet

development: the Mapplet Scratch Pad, the Developer Mapplet, and the API

Reference Mapplet. You can find these Mapplets in the Developer Tools section

of the Google Maps Directory

(http://maps.google.com/ig/directory?synd=mpl&pid=mpl&cat=devtools).

 

à  The Mapplet Scratch Pad lets you develop Mapplets right in

http://maps.google.com. You’ll be able to cut and paste the following

code sample in the scratch pad and immediately see the application.

à  The Developer Mapplet places a Reload link at the top of each Mapplet that

you have installed. The Reload link automatically reloads the source code for

the Mapplet you are viewing (or developing). Since Google caches Mapplet

source code, you’ll need this for developing and testing Mapplets. Trust me

on this one!

à  The API Reference Mapplet is a simple application that displays all the

possible Mapplets API calls.

 

Once you have all three developer Mapplets installed, select the Mapplet Scratch

Pad.

 

Your maps.google.com page should now look like

 Map Scratch Pad

 

 Creating Your First Mapplet

 

For your first Mapplet, you’re not even going to “touch” a map.

 

Let’s start by creating a simple “shell” Mapplet without any map API calls.

à  Make sure you are at http://maps.google.com/maps/mm and that you’ve selected

the Mapplet Scratch Pad. You should see the Mapplet Scratch Pad in the

lower-left corner of the page.

à  Cut the XML from below, and paste it into the Mapplet Scratch Pad.

à Click the Preview button in the Mapplet Scratch Pad. Figure shows the

“Hello World” Mapplet that you should see.

 

“Hello World” Mapplet

 

<?xml version=”1.0″ encoding=”UTF-8″?>

<Module>

<ModulePrefs title=”Hello World”

description=”My First Mapplet”

author=”Ashutosh Sharma”

author_email=”sharma.ashutosh84.googlepages.com”

height=”150″>

</ModulePrefs>

<Content type=”html”><![CDATA[

<h2>Hello From Ashutosh Sharma!!</h2>

<h4>Java Tutorials : Visit

<a href>sharma.ashutosh84.googlepages.com

</a></h4>

]]></Content>

</Module>

 

 

Adding a Map

 

So, the previous example showed the shell of a Google Mapplet/Gadget. Now

let’s do some mapping. In this example, you’ll create a map and add a marker

indicating the location of the Empire State Building. You’ll also center the map

on this point.

 

1. In the Mapplet Scratch Pad, click the “Go back to editor” button to display

the scratch pad editor.

2. Cut the XML from below, and paste it into the Mapplet Scratch Pad.

3. Click the Preview button in the Mapplet Scratch Pad.

 

Create a Map and Add a Marker to the Map

 

<?xml version=”1.0″ encoding=”UTF-8″?>

<Module>

<ModulePrefs title=”INDIA GATE, DELHI”

description=”Creating a Simple Map and Marker”

author=”Ashutosh Sharma”

author_email=”sharma.ashutosh84.googlepages.com”

height=”150″>

<Require feature=”sharedmap”/>

</ModulePrefs>

<Content type=”html”><![CDATA[

<h2>India Gate</h2>

<script>

// Create a map and center it over the INDIA GATE

var map = new GMap2();

var point = new GLatLng(28.61262650293896, 77.23015954511007);

 

map.setCenter(point, 17);

// Add a marker right on the INDIA GATE

var marker = new GMarker(point);

map.addOverlay(marker);

</script>

]]></Content>

</Module>

 

INDIA GATE, DELHI

 India Gate New Delhi

Java Tutorials by Ashutosh Sharma :

visit  http://sharma.ashutosh84.googlepages.com

Web 2.0 based Website Links

Posted in Web 2.0 with tags on May 20, 2008 by javaforweb

Winamp Media Player Plugin   

http://ajaxamp.com

It turns Winamp into a web-accessible, sharing, streaming, searching, remote-controlled musical marvel, allowing you to access Winamp over the network using a web browser and control it or stream music to or from it

Ajax New Blog

http://ajaxian.com

Ajaxian in Ajax Resources - One of the first blogs in ajax.Daily updates, insightful commentary and coverage of Ajax development around the world.

Social Movie Catalog

http://movies.ajaxilicious.com

Search Engine

http://accoona.com

Ajax Based Chat Room

http://ajchat.com

Ajchat is a simple ajax chat system where you can add chatrooms to your website.

Search Engine

http://alexa.com

Online Storage

http://allmydata.com

Allmydata provides online backup, storage, and sharing.

Play and Rate games

http://arcaplay.com

Arcaplay is reinventing free online gaming. Say hello to social arcading.

India based Job Search Engine

http://bixee.com

Jobs in India, Mumbai, Delhi, Bangalore, Chennai, Hyderabad, Pune from the web.

Audio Search Engine

http://audioclipping.de

Short audio samples are also available to listen to the individual hits. The results can be accessed online at all times.

Java Tutorials by Ashutosh Sharma

http://sharma.ashutosh84.googlepages.com

Singletons in Java

Posted in Design Patterns In Java, java with tags on May 19, 2008 by javaforweb

A singleton is an object that cannot be instantiated. At first, that might seem counterintuitive - after all, we need an instance of an object before we can use it. Well yes a singleton can be created, but it can’t be instantiated by developers - meaning that the singleton class has control over how it is created. The restriction on the singleton is that there can be only one instance of a singleton created by the Java Virtual Machine (JVM) - by prevent direct instantiation we can ensure that developers don’t create a second copy.

So why would this be useful? Often in designing a system, we want to control how an object is used, and prevent others (ourselves included) from making copies of it or creating new instances. For example, a central configuration object that stores setup information should have one and one only instance - a global copy accessible from any part of the application, including any threads that are running. Creating a new configuration object and using it would be fairly useless, as other parts of the application might be looking at the old configuration object, and changes to application settings wouldn’t always be acted upon. I’m sure you can think of a other situations where a singleton would be useful - perhaps you’ve even used one before without giving it a name. It’s a common enough design criteria (not used everyday, but you’ll come across it from time to time). The singleton pattern can be applied in any language, but since we’re all Java programmers here (if you’re not, shame!) let’s look at how to implement the pattern using Java.

Preventing direct instantiation

We all know how objects are instantiated right? Maybe not everyone? Let’s go through a quick refresher.

Objects are instantiated by using the new keyword. The new keyword allows you to create a new instance of an object, and to specify parameters to the class’s constructor. You can specify no parameters, in which case the blank constructor (also known as the default constructor) is invoked. Constructors can have access modifiers, like public and private, which allow you to control which classes have access to a constructor. So to prevent direct instantiation, we create a private default constructor, so that other classes can’t create a new instance.

We’ll start with the class definition, for a SingletonObject class. Next, we provide a default constructor that is marked as private. No actual code needs to be written, but you’re free to add some initialization code if you’d like. 

public class SingletonObject
{
	private SingletonObject()
	{
		// no code req'd
	}
}

So far so good. But unless we add some further code, there’ll be absolutely no way to use the class. We want to prevent direct instantiation, but we still need to allow a way to get a reference to an instance of the singleton object.

Getting an instance of the singleton

We need to provide an accessor method, that returns an instance of the SingletonObject class but doesn’t allow more than one copy to be accessed. We can manually instantiate an object, but we need to keep a reference to the singleton so that subsequent calls to the accessor method can return the singleton (rather than creating a new one). To do this, provide a public static method called getSingletonObject(), and store a copy of the singleton in a private member variable.

public class SingletonObject
{
    private SingletonObject()
    {
        // no code req'd
    }

    public static SingletonObject getSingletonObject()
    {
      if (ref == null)
          // it's ok, we can call this constructor
          ref = new SingletonObject();
      return ref;
    }

    private static SingletonObject ref;
}

So far, so good. When first called, the getSingletonObject() method creates a singleton instance, assigns it to a member variable, and returns the singleton. Subsequent calls will return the same singleton, and all is well with the world.

Preventing thread problems with your singleton

We need to make sure that threads calling the getSingletonObject() method don’t cause problems, so it’s advisable to mark the method as synchronized. This prevents two threads from calling the getSingletonObject() method at the same time. If one thread entered the method just after the other, you could end up calling the SingletonObject constructor twice and returning different values. To change the method, just add the synchronized keyword as follows to the method declaration :-

public static synchronized
	 SingletonObject getSingletonObject()

Are we finished yet?

There, finished. A singleton object that guarantees one instance of the class, and never more than one. Right? Well…. not quite. Where there’s a will, there’s a way - it is still possible to evade all our defensive programming and create more than one instance of the singleton class defined above. Here’s where most articles on singletons fall down, because they forget about cloning. Examine the following code snippet, which clones a singleton object.

public class Clone
{
	public static void main(String args[])
	  throws Exception
	{
	  // Get a singleton
	  SingletonObject obj =
	  SingletonObject.getSingletonObject();

	  // Buahahaha. Let's clone the object
	  SingletonObject clone =
		(SingletonObject) obj.clone();
	}
}

Okay, we’re cheating a little here. There isn’t a clone() method defined in SingletonObject, but there is in the java.lang.Object class which it is inherited from. By default, the clone() method is marked as protected, but if your SingletonObject extends another class that does support cloning, it is possible to violate the design principles of the singleton.  So, to be absolutely positively 100% certain that a singleton really is a singleton, we must add a clone() method of our own, and throw a CloneNotSupportedException if anyone dares try!

Here’s the final source code for a SingletonObject, which you can use as a template for your own singletons.

public class SingletonObject
{
  private SingletonObject()
  {
    // no code req'd
  }

  public static SingletonObject getSingletonObject()
  {
    if (ref == null)
        // it's ok, we can call this constructor
        ref = new SingletonObject();
    return ref;
  }

  public Object clone()
	throws CloneNotSupportedException
  {
    throw new CloneNotSupportedException();
    // that'll teach 'em
  }

  private static SingletonObject ref;
}
Java Tutorials by Ashutosh Sharma, pls visit :
http://sharma.ashutosh84.googlepages.com

Final Class in Java

Posted in java with tags on May 19, 2008 by javaforweb

In Java, a class organization such as:

        class A {}

        class B extends A {}

results in a superclass (A) and a subclass (B). References to B objects may be assigned to A references, and if an A reference “really” refers to a B, then B’s methods will be called in preference to A’s. All of this is a standard part of the object-oriented programming paradigm offered by Java.

But there is a way to modify this type of organization, by declaring a class to be final. If I say:

        final class A {}

then that means that A cannot be further extended or subclassed.

This feature has a couple of big implications. One is that it allows control over a class, so that no one can subclass the class and possibly introduce anomalous behavior. For example, java.lang.String is a final class. This means, for example, that I can’t subclass String and provide my own length() method that does something very different from returning the string length.

There is also a big performance issue with final classes. If a class is final, then all of its methods are implicitly final as well, that is, the method is guaranteed not be overridden in any subclass. A Java compiler may be able to inline a final method. For example, this program:

        final class A {
                private int type;
                public int getType() {return type;}
        }

        public class test {
                public static void main(String args[])
                {
                        int N = 5000000;
                        int i = N;
                        int t = 0;
                        A aref = new A();
                        while (i-- > 0)
                                t = aref.getType();
                }
        }

runs about twice as fast when the class is declared final.

Of course, much of the time it’s desirable to use the superclass / subclass paradigm to the full, and not worry about wringing out the last bit of speed. But sometimes you have heavily used methods that you’d like to have expanded inline, and a final class is one way of achieving that.

Java Tutorials by Ashutosh Sharma :

pls visit http://sharma.ashutosh84.googlepages.com

Web 2.0 based Wesite Links

Posted in Web 2.0 with tags on May 18, 2008 by javaforweb

1000tags                  http://1000tags.com           tag advertising

14dayz                     http://14dayz.com               online time tracker

24sevenoffice          http://24sevenoffice.com     web based crm/erp solutions

3bubbles                 http://3bubbles.com             real time chat for blogs

43people                 http://43people.com             social meeting people online

4shared.com           http://4shared.com               online storage

8by1                       http://8by1.com                     social wishing

9cays                      http://9cays.com                   group mail

http://yiibu.com                                                mobile applications

http://yoono.com                                             social bookmarking software

http://yorz.com                                               job search engine

http://yotophoto.com                                     royalty free stock photography search

http://youos.com                                            web operating system

http://yourdraft.com

http://yousendit.com                                              large file transfer

http://youtube.com                                                 social video sharing

http://yub.com                                                        social shopping service

http://yubnub.org                                                   command line search

http://yutter.com

http://zaadz.com                                      social networking

http://zaptix.com                                     box office ticket selling service for college-based groups

http://zaptxt.com

http://zazzle.com                                      designer apparel / merchandise

http://zenfolio.com

http://zenphoto.org

http://ziggs.com                                     search engine for professionals

http://zigtag.com                                  coming soon!

http://ziki.com                                       social networking site

http://zillow.com                                    real estate property value estimates

http://zimbra.com                                  open-source enterprise messaging

http://zingee.com                                   social file sharing service

http://zipingo.com                                 social local business recommendation service

http://zippyvideos.com                          social video sharing

http://zixxo.com

http://zmanda.com                                open source backup/recover

http://zohochallenge.com

http://zohochat.com                             group chatting service

http://zohocreator.com                        create web applications

http://zohocrm.com

http://zoho.com/virtual-office

http://zohoplanner.com

http://zohowriter.com

http://zohoplanner.com

http://zookoda.com                         email newsletter management

http://zoomclouds.com

http://zoominfo.com/                         Search business listings directory

http://zoomshare.com

http://zoomtags.com                     tag-based advertising affiliate network

http://beta.zooomr.com/               home photo sharing

http://zoozio.com                         coming soon!

http://zopa.com/ZopaWeb

http://zoto.com            photo sharing site

http://zunafish.com     social products trading service

http://zvents.com        social events sharing