Ask Google

Custom Search

Monday, October 17, 2011

What is Java inheritence and composition

Composition vs. Inheritance in Java.

When Introduced to Object Orientation I was very excited about inheritance and class hierarchies and what I could do with them. Over time, I've come to focus more on interfaces and (in general) use composition rather than inheritance.

Inheritance in java is super easy. If we want to build, for instance, a case-insensitive HashMap how would we do it? (I chose HashMap because it shows the good, the bad, and the ugly of each approach, while remaining trivial). With Inheritance it's pretty easy. We simply extend HashMap and override the methods dealing with keys:

import java.util.HashMap;

public class NoCaseHashMap extends HashMap {

    private String toKey(Object key) {
        if (key == null) {
            return null;
        }
        return key.toString().toLowerCase();
    }

    public Object get(Object key) {
        return super.get(toKey(key));
    }

    public Object put(Object key, Object value) {
        return super.put(toKey(key), value);
    }

    public boolean containsKey(Object key) {
        return super.containsKey(toKey(key));
    }

    public Object remove(Object key) {
        return super.remove(toKey(key));
    }

}

Ta-da! Done.

But, the first downside to this approach is that, in Java, we may only inherit implementation (extend) from one superclass. There are times when that seems constrictive. In this simple case that is no big deal.

The less obvious downside of Inheritance is that we've locked this into a particular Map implementation. What happens when we want a LinkedHashMap or a WeakHashMap or even a TreeMap? Early binding to a particular implementation is Inheritance's biggest shortcoming.

Enter Composition.

With Composition we can late bind to the implementation. Rather than extend HashMap, we could, for instance, take a Map object as a construction parameter and leave the implementation choice open.

The first obvious down-side to Composition is that it is not as light-weight in Java. Every method must be added, not just the ones that change.

The second, less obvious, downside is that with inheritance super classes can call the methods of the sub-class, but this is not so with composition.

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class NoCaseMap implements Map {

    private Map map;

    public NoCaseMap(Map map) {
        this.map = map;
    }

    private String toKey(Object key) {
        if (key == null) {
            return null;
        }
        return key.toString().toLowerCase();
    }

    public Object get(Object key) {
        return map.get(toKey(key));
    }

    public Object put(Object key, Object value) {
        return map.put(toKey(key), value);
    }

    public boolean containsKey(Object key) {
        return map.containsKey(toKey(key));
    }

    public Object remove(Object key) {
        return map.remove(toKey(key));
    }

    /* Note the need to implement putAll(map) with composition */
    public void putAll(Map t) {
        for (Iterator it = t.entrySet().iterator(); it.hasNext();) {
            Map.Entry entry = (Map.Entry) it.next();
            put(entry.getKey(), entry.getValue());
        }
    }

    // --------------------------------------
    // The rest of these are just the standard cruft of composition:
    // --------------------------------------
    public void clear() {
        map.clear();
    }

    public boolean containsValue(Object value) {
        return map.containsValue(value);
    }

    public Set entrySet() {
        return map.entrySet();
    }

    public boolean isEmpty() {
        return map.isEmpty();
    }

    public Set keySet() {
        return map.keySet();
    }

    public int size() {
        return map.size();
    }

    public Collection values() {
        return map.values();
    }
}

More code (even if it was auto-generated) obviously, but also plug-able and flexible.
When to use Inheritance and when to use Composition?

Traditionally, we are told to use inhertance when one class has an "is a" relationship with another, and composition when one class has a "has a" relationship with another. While I do not dispute this in the slightest, I will warn that this is trickier than it sounds. We've pobably all seen the bad textbook example of something like "Programmer" and "Manager" as extending "Employee" ... well, maybe ... but perhaps it is more useful to think of "Programmer" as a set of duties that an "Employee" may have, and this same employee may later change duties for "Manager" duties. Often "is a" and "has a" relationships are more arbitrary than they might first appear. If "is a" and "has a" relationsips are just a matter of perspective, what should we do?

As a rule of thumb:

    * Use composition (not inheritance) to get code re-use and/or polymorphism. as Bill Venners suggests (JavaWorld.com, 11/01/98)
    * Use inheritance when super-classes must significantly interact with their sub-classes. (But consider Strategy pattern instead.)
    * Use inheritance when we are forced to.

If the "parent" must call back to "child" methods, then Inheritance is usually the only good answer. However, in general, the late-binding aspect of Composition tends to be better, even with the added irritation of the the pass-through methods. What are the relationships between the classes? Is one the abstract "brains" and the other provided a strategy for some internal functionality? Or is one a "Decorator" of another where composition is obvious? Like:

    new BASE64EncoderStream(new BufferedOutputStream(new FileOutputStream(file)))

I used to see problems mostly in terms of super and sub-classes. These days most problems look better solved with composition. And if it weren't for the heavier weight of composition, I'd probably use it nearly exclusively, except for when inheritance was the really obvious winner.

If intermediate classes get introduced into the heirarchy that are hard to name, it may be a good idea to consider composition; if the names don't make a lot of sense, that's probably a hint that we should be thinking harder about our design, anyway. Usually I see this happening as we try to push common code into some super-class, but that superclass doesn't actually represent any particular general concept.

There are also times when we are forced to use inheritance becuase some method expects a concrete class as a parameter, not an interface. The core java language is full of examples where implementations are expected which could be interfaces: java.io.Writer and java.io.File jump to mind.

When I see that I am forcing extenders to use inheritance, I take this as a sign that I should think hard about the architecture; in general it has turned out to be symptom of inferior design. As a rule of thumb, I try to design for interfaces and plug-ability, not sub-classing.

There are many ways of re-thinking towards plugability. Sometimes it is just a matter of using interfaces and having a default implementation. Sometimes it is a matter of thinking about the problem from the other direction: for instance, rather than having an abstract super-class which expects a concrete sub-class to implement a function or two, we can create a concrete class which expects a collaborator object to implement those functions (the "Strategy" pattern ). With understanding of just the "Strategy" and "Decorator" patterns it becomes possible to imagine completely designing for plugability without using inheritance at all.

When in doubt, I try to let testing be my guide, because testing tends to be the first place where I find myself wanting plug-ability. For instance, if a "base class" requires a lot of set-up and tear-down to instantiate and test, and a "sub-class" is adding something which doesn't directly interact with the elements that require set-up and tear-down, this may be a hint that we could restructure to use composition and test the add-on behavior in isolation more easily.

Sunday, October 16, 2011

What is Store Procedure?

Stored routines (procedures and functions) are supported in any SQL programming. A stored routine is a set of SQL statements that can be stored in the server. Once this has been done, clients don't need to keep reissuing the individual statements but can refer to the stored routine instead.

Stored routines require the proc table in the sql database. This table is created using procedure. I
Stored routines can be particularly useful in certain situations:

    *      When multiple client applications are written in different languages or work on different platforms, but need to perform the same database operations.
    *      When security is paramount. Banks, for example, use stored procedures and functions for all common operations. This provides a consistent and secure environment, and routines can ensure that each operation is properly logged. In such a setup, applications and users would have no access to the database tables directly, but can only execute specific stored routines.

Stored routines can provide improved performance because less information needs to be sent between the server and the client. The tradeoff is that this does increase the load on the database server because more of the work is done on the server side and less is done on the client (application) side. Consider this if many client machines (such as Web servers) are serviced by only one or a few database servers.

Stored routines also enable you to have libraries of functions in the database server. This is a feature shared by modern application languages that enable such design internally (for example, by using classes). Using these client application language features is beneficial for the programmer even outside the scope of database use.

The SQL implementation of stored routines is still in progress. All syntax described here is supported and any limitations and extensions are documented where appropriate.

Saturday, March 12, 2011

java certification training

As someone seeking work in the IT and software industry, there is much hype and pressure to learn and become expert in the java language. In the software industry, there is no actual programming license which means that virtually anyone can pick up a few books or tutorials and claim to be proficient. In light of this, to protect prospective employers, the industry recognizes certification, which shows that someone has been willing to undertake additional training and pass arduous and exacting examinations. Sun Microsystems has become established as a leader in IT technology training and outlined a number of paths to certification in java, depending on your objectives. This article seeks to  shed light on the sun java certification process by outlining what can be expected when preparing for the exams and some food for thought on what certification actually means.
Sitting for the Sun Certified exams is no walk in the park. It is strongly advised that a course of preparation is embarked on before attempting an exam. The java language is still fairly new and thus the need to distinguish oneself from a beginner. The Sun Java Certified programmer is approriate for existing commercial programmers with post secondary education and a minimum of 6 months experience in java. As the pool of professionals with this certification is still relatively low, many attribute attaining certification with heightening employment opportunity and renumeration.
There is a small fee involved with taking each of the exams, which is non refundabe. This provides further incentive for studying. The exam itself is multiple choice which may prove to be deceptive in indicating the ease of success. The questions sometimes require the selection of all the applicable responses and none of the incorrect ones. There are often small nuances that must be recognized and you need a thorough understanding of the language to choose correctly. Sun Microsystems provides training in all pathways from programmer, to the more advanced developer and java architect. There are numerous books, course, and online and offline study guides available with practice exams for preparation. There is no doubt that those who practice the language daily and take the opportunity to use a study guide or course along with a background in using the language, will have a much easier and less stressful time passing the exam the first time around. Bear in mind, you can take the exam an unlimited number of times in order to pass.
Once you have successfully become certified as a programmer, you can choose to go on and take the Sun Certified Java Developer. Here the range of topics covered in the exam is wider and you must  demonstrate mastery at a more complex level. Before taking the exam, it is necessary to successfully complete a practical assignment where you are given a set of programming requirements and must create a system using them. This component demonstrates a higher level of understanding and application of the java language.
It is widely acknowledged that attaining sun java certification shows a high level of competency. Yet, there are those that are justifiably critical of the certification process in general and Sun Java Certification in particular. Some believe the certification process is more useful as a diagnostic tool than a measure of aptitude or potential. The  Sun Java programmer exam, for example, by emphasizing syntax may leave one open to gaps in knowledge and understanding. Some believe the tests are still too straightforward and do not encourage ongoing professional development. There is simply too much emphasis on  doing what it takes to pass rather than focusing on how one can consistently attain new levels of education. Community managed certification tracks such as Java Blackbelt may provide an alternative long term view to professional development.
Whether you choose to use Sun Microsystem's path to java certification or go with some other third party, it is a major decision and undertaking. Doing so will go a long way to showing your dedication to becoming highly skilled and competent. The Java domain is still seen as difficult and thus certification is a significant credential and an industry measure of technical excellence. Your persistence, dedication and professionalism will determine how far this takes you.

what is java software

what is java software

java applets

java applets

java programming course

java programming course

Java Courses

Java Courses

What is J2ME Apps Dev

J2ME or also know as Java ME is a platform that is specifically designed for application development to run on mobile phones, PDAs and other embedded systems. J2ME development features an adaptable user interface, which integrates with network protocols and extends support for mobile application development.
The mobile applications that are developed on J2ME can be also migrated across various different mobile devices. J2ME application developers create a variety of different mobile applications based on the customized requirements of the clients. They are experience in creating diverse mobile solutions and hence most clients prefer to outsource their mobile business applications to India.
J2ME Architecture and configuration
J2ME comprises of configurations and profiles that allow a developer to customize it for the Java Runtime Environment (JRE). The configuration defines the JVM used and the profile adds domain-specific classes to define the application.
Configurations: The configuration uses a set of core classes and a specific JVM to define the basic run-time environment. The configurations are of two types where one is called CLDC for handled devices and the second one is CDC for plug-in devices. CLDC is has been developed for 16-bit or 32-bit small computing devices that have limited memory. CDC requires a 32-bit architecture and has at least 2 MB of memory and implements a functional JVM.
Profiles: A profile comprises of classes that allow J2ME application developers to execute features that are typically available on a group of small computing devices. The profiles used with CLDC are mobile information device profile (MIDP) and PDA profile (PDAP). The profiles used with CDC include Foundation Profile, Game Profile, Personal Profile, Personal Basis Profile and RMI Profile.
J2ME Architecture
The J2ME architecture consists of five layers and they are as follows:
  • MIDP: This is the topmost layer and consists of Java APIs. J2ME application developers use these APIs to create network connections, storage, and user interface. It also provides access to CLDC libraries and MIDP libraries.
  • J2ME API's: This is the profile that comprises of a minimum set of application programming interfaces required for the small computing devices.
  • Configurations: This is responsible to manage the interactions between the JVM and the profile.
  • JVM
  • Operating System: This is the bottom layer.

Friday, March 11, 2011

What is java used for

Java is a highly popular programming language and computer platform originally developed in 1995 by Sun Microsystems when the existing software, called OAK, was renamed. According to the Java website, 850million worldwide use Java and the software is claimed to be integral to a wide variety of computing functions including business intranet applications and other e-business software.

Java runs on something called the Java Runtime Environment (JRE) which consists of the Java Virtual Machine (JVM), Java platform core classes and supporting Java libraries. The JRE enables you to run the software in your web browser.

Originally Java was intended for the television industry but it became apparent that the software was too advanced for the cable technology of the time. Java incorporates a function called 'Write Once, Run Anywhere' which means that the code can be written on a PC but also used on a wide variety of other devices that use JVM such as Java-enabled cell phones, routers and mainframes. It does this by using something called Java Bytecode which can be interpreted by the JVM. The intention behind this is to eliminate the situation whereby a software developer has to rewrite the programming language to suit a different machine. Unfortunately, this hasn't worked as well as it was originally hoped since there can be many Java implementations alongside other operating systems such as Windows, Mac OS and Linux. This has led to some developers re-christening Java as 'Write once, debug everywhere'.

In its early forms Java had a reputation for being rather slow in comparison to programs written in the usual C. However in 1998, Java 1.1 was released with Just-in-time compilation (JIT) also known as dynamic translation, the function of which is to speed up the execution of the bytecode. Java also uses an automatic garbage collector in order to manage memory automatically. This can activate at any time but is most likely to activate when a machine is idle.

In 2006 Sun released Java as open-source software and versions of it can now be freely downloaded. The website claims that it's an essential piece of software on the basis that many websites and applications, including online gaming, won't run without it. I certainly remember the odd occasion when a piece of software has failed on me because I didn't have Java installed and so I have now installed a free version on my PC just before writing this. In addition, for those who want to use Java for programming, I would mention there are a load of tutorials available on the internet from the business software website Oracle. If you want to learn programming using Java it might therefore be worth your while downloading those as well.

What is foreign keys in relational data base?

Foreign key in what is java.

What is foreign key in SQL?

We use foreign key to match column in one  table to primary key in column in another table either it is
one  to one relation or many to one.This foreign key can be used to cross reference table.

Many database or data modelling will be in problem if relation of foreign key is not done properly.

In one table , it can be many foreign keys and it is independently by the database system.Each key can have
different reference tables.

Wednesday, March 9, 2011

What is java Relational databases

What is java Relational databases

What is database?
We can store and retrieve information from place called database.

What is java in relational database?
Information that we present in tables as in row and column is called relational databases.
Relational means that the collections of objects with the same type in one rows.
We can relate data in table according to commons keys and retrieved data from table based on
relations.

What is Database Management Systems (DBMS)?
DBMS is responsible to handle the way data is stored , maintained , and retrieved.

Blogging

Sunday, March 6, 2011

What is java

Today i will discuss what is java in synchronization  and how it is implemented, and it is important?

what is java in synchronization?

The Java programming language provides two basic synchronization idioms: synchronized methods and synchronized statements.
To make a method synchronized, simply add the synchronized keyword to its declaration:

public class SynchronizedCounter
{
private int c = 0;
public synchronized void increment()
{
c++;
}
public synchronized void decrement()
{
c--;
}
public synchronized int value()
{
return c;
}
}

If count is an instance of SynchronizedCounter, then making these methods synchronized has two effects:

* First, it is not possible for two invocations of synchronized methods on the same object to interleave. When one thread is executing a synchronized method for an object, all other threads that invoke synchronized methods for the same object block (suspend execution) until the first thread is done with the object.
* Second, when a synchronized method exits, it automatically establishes a happens-before relationship with any subsequent invocation of a synchronized method for the same object. This guarantees that changes to the state of the object are visible to all threads.


Blogging

Saturday, March 5, 2011

What is serialization in Java?

When you serialize a Java object, you will be able to save its state as a sequence of bytes that will persist even after your Java virtual machine is not running. Next time, when you program is up and running again, it can rebuild the last state into its Java object form for reuse in your application. Usually, a serialized object can be stored on a hard disk as a file stream. Since it is a file stream, it can be transferred over a network as well.

AXB uses the serialization approach to serialize a Java object into a XML form (marshal) and from a XML form to a Java object (unmarshal)

But, get back to your actual question: why we need to serialize? Is it necessary?

If you feel you need to persist your Java objects for short term purpose like a session and your interface definition stays the same across version revisions (that is an Animal object is still an Animal object despite an addition of new fields), use it.

If you feel you need to persist your Java objects over a wire, use it.

Tuesday, February 22, 2011

Ask Java 6


Today i will cover simple and basic question if someone ask you what is java.
The first things you need to know regarding java is Object Oriented Programming or in
short OOP.So What is OOP?

What is OOPs?

So your answer when people ask you this questions, what you will do is
you just rilex and explain to them OOP is programming whereby you
organizes your program in well defined interfaces to the data in object.Means
everything is in object.Nothing more.We can say object oriented as how we access
the data through object or in other word data controlling to code.



Blogging

Monday, February 21, 2011

Ask Java 5

Topic for today we will cover simple basic question regarding access right.
Lets say if main method we declared it as private?What will happen?

Explaination:
When main method is declared as private, it will shows you
message says "Main method not public" during runtime.Of course it will
compile properly.


Blogging

Sunday, February 20, 2011

Ask Java 4

Today i will cover one more question here..simple yet basic

What is mutual exclusion? How can you take care of mutual exclusion using Java threads?



Java provides many utilities to deal with mutual exclusion with the use of threaded programming.
Mutual exclusion is where no two processes can access critical regions of memory at the same time.

For mutual exclusion, you can simply use the synchronized keyword and explicitly or implicitly provide an Object, any Object, to synchronize on.

The runtime system/Java compiler takes care of the gruesome details for you. The synchronized keyword can be applied to a class, to a method, or to a block of code. There are several methods in Java used for communicating mutually exclusive threads such as wait( ), notify( ), or notifyAll( ). For example, the notifyAll( ) method wakes up all threads that are in the wait list of an object.


Blogging

Saturday, February 19, 2011

Ask Java 3

What is a cartesian product in PL/SQL?

 When a Join condition is not specified by the programmer or is invalid(fails), PL/SQL forms a Cartesian product.

In a Cartesian product, all combinations of rows will be displayed.

For example, All rows in the first table are joined to all rows in the second table. It joins a bunch of rows and it's result is rarely useful unless you have a need to combine all rows from all tables. 


Blogging

Thursday, February 17, 2011

Difference between private, protected, and public?

What is the difference between private, protected, and public?

These keywords are for allowing privilages to components such as functions and variables.

Public: accessible to
all classes
Private: accessible
only to the class to which they belong
Protected: accessible to the
class to which they belong and any subclasses.

Wednesday, February 16, 2011

Ask Java

What is a virtual function in C++?

Simply put, the virtual keyword enables a function to be 'virtual' which then gives possibility for that function to be overridden (redefined) in one or more descendant classes. It is a good feature since the specific function to call is determined at run-time. In other words, a virtual function allows derived classes to replace the implementation provided by the base class.

If u like this post clik this



Blogging

Tuesday, February 15, 2011

Semantic Technology

Semantic Technology Part II

Semantics contrasts with syntax, the study of the combinatorics of units of a language (without reference to their meaning), and pragmatics, the study of the relationships between the symbols of a language, their meaning, and the users of the language.

The formal learning of semantics is therefore complex and complicated.Basically, the Semantic Web is only about two things. It is about common formats and pattern for integration and combination of data drawn from diverse sources, where on the original Web mainly concentrated on the interchange of documents. It is also
about language for recording and captured the way data relates according to real world objects.
 
That allows a human, or a machine, to start off in one database, and then move through an unending set of databases which are connected not by wires but by being about the same thing or in others words nodes.

The Semantic Web is the extension of the World Wide Web (WWW) that let the user to share content beyond the boundaries and limits of applications and websites. It has been explained in rather different ways: as a utopic vision, as a web of data, or merely as a natural paradigm shift in our daily use of the Web.

All the time, the Semantic Web has inspired and engaged many people to create and invent innovative semantic technologies and applications. semanticweb.org is the common platform for this community.

Inversion of Control

Inversion of Control Part II

Objects can be obtained by means of Dependency lookup or Dependency injection. Dependency lookup is a pattern where a caller asks the container object for an object with a specific name or of a specific type. Dependency injection is a pattern where the container passes objects by name to other objects, via either constructors, properties, or factory methods.

Most of the situation, it's not necessary to use the container when using other parts of the Spring Framework, although using it will likely make an application easier to configure and customize. The Spring container provides a consistent mechanism to configure applications and integrates with almost all Java environments, from small-scale applications to large enterprise applications.

The container can be changed into a partially-compliant EJB3 container by means of the Pitchfork project. The Spring Framework is criticized by some as not being standards compliant. However, SpringSource doesn't see EJB3 compliance as a major goal, and claims that the Spring Framework and the container allow for more powerful programming models.

Sunday, January 30, 2011

Inversion of Control container (IoC)

Inversion of Control container Part I

Central to the Spring Framework is its Inversion of Control container or ususally we called IoC , which supply a consistent ways of configuring and managing Java objects using callbacks. The container is responsible for managing object lifecycles: creating objects, calling initialization methods, and configuring objects by wiring them together.


Objects created by the container are also called Beans or Managed Objects . Usually, the container is configured by loading XML files containing Bean definitions which provide the information required to create the beans.

Saturday, January 29, 2011

LISP Programming

Lisp (or LISP) is a family of computer programming languages with a long history and a distinctive, fully parenthesized syntax. Originally specified in 1958, Lisp is the second-oldest high-level programming language in widespread use today; only Fortran is older (by one year). Like Fortran, Lisp has changed a great deal since its early days, and a number of dialects have existed over its history. Today, the most widely known general-purpose Lisp dialects are Common Lisp and Scheme.


Lisp was originally created as a practical mathematical notation for computer programs, influenced by the notation of Alonzo Church's lambda calculus. It quickly became the favored programming language for artificial intelligence (AI) research. As one of the earliest programming languages, Lisp pioneered many ideas in computer science, including tree data structures, automatic storage management, dynamic typing, and the self-hosting compiler.


The name LISP derives from "LISt Processing". Linked lists are one of Lisp languages' major data structures, and Lisp source code is itself made up of lists. As a result, Lisp programs can manipulate source code as a data structure, giving rise to the macro systems that allow programmers to create new syntax or even new domain-specific languages embedded in Lisp.


The interchangeability of code and data also gives Lisp its instantly recognizable syntax. All program code is written as s-expressions, or parenthesized lists. A function call or syntactic form is written as a list with the function or operator's name first, and the arguments following; for instance, a function f that takes three arguments might be called using (f arg1 arg2 arg3).


Source from http://en.wikipedia.org/wiki/Lisp_(programming_language)

Friday, January 28, 2011

Semantics Tecnology

Semantics Tecnology Part I

Semantics  is the study of meaning. It basically focuses on the relation between signifiers, such as words, phrases, signs and symbols, and what they refer to , their denotata.Semantics is the research of meaning that is used by humans to express themselves through language. Other types of semantics include the semantics of programming languages, formal logics, and semiotics.

The term "semantics" itself reflects a range of ideas, from the popular to the highly technical. It is always used in ordinary language to denote a problem/issues of understanding that comes down to word selection or connotation.This issues of understanding has been the subject or ideas of many formal inquiries,over a long period of time, most notably in the field of formal semantics.

In linguistics, it is the study of interpretation of signs or symbols as used by agents or communities within specific circumstances and contexts.Within this view, sounds, facial expressions, body language,proxemics have semantic (meaningful) content or informations, and each has many branches of study. In written , such things as paragraph structure and punctuation have semantic content; in other forms of language, there is
other semantic content.

 The formal research of semantics intersects with many other fields of inquiry,including lexicology, syntax, pragmatics, etymology and others, although semantics is a well-defined field in its own right, often with synthetic properties.In philosophy of language, semantics and reference are related fields. Further related fields include philology, communication, and semiotics.

Thursday, January 27, 2011

Java J2EE

Java 2 Platform Enterprise Edition. J2EE is a platform-independent, Java-centric environment from Sun for developing, building and deploying Web-based enterprise applications online. The J2EE platform consists of a set of services, APIs, and protocols that provide the functionality for developing multitiered, Web-based applications.

Some of the key features and services of J2EE:
At the client tier, J2EE supports pure HTML, as well as Java applets or applications. It relies on Java Server

Pages and servlet code to create HTML or other formatted data for the client.
 Enterprise JavaBeans (EJBs) provide another layer where the platform's logic is stored. An EJB server provides functions such as threading, concurrency, security and memory management. These services are transparent to the author. Java Database Connectivity (JDBC), which is the Java equivalent to ODBC, is the standard interface for Java databases.The Java servlet API enhances consistency for developers without requiring a graphical user interface.

J2EE is yet another acronym in the world of computing. This one stands for Java 2 Platform, Enterprise Edition. Its significance will become clear once we trace its lineage. 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 Java language is such that it allows cross-platform communication between multiple kinds of devices. For example, a programmer can develop Java code on a desktop computer and expect it to run on other computers, routers, and even mobile phones, as long as those devices are Java-enabled. This portability is described by the Sun acronym WORA, which stands for "Write once, run anywhere." A large number of mainframes, computers, mobile phones, and other electronic devices operate using the Java Platform.

Wednesday, January 26, 2011

Web Services

Web Services can convert your application into a Web-application, which can publish its function or message to the rest of the world.

The basic Web Services platform is XML + HTTP.
The term Web services describes a standardized way of integrating Web-based applications using the XML, SOAP, WSDL and UDDI open standards over an Internet protocol backbone. XML is used to tag the data, SOAP is used to transfer the data, WSDL is used for describing the services available and UDDI is used for listing what services are available. Used primarily as a means for businesses to communicate with each other and with clients, Web services allow organizations to communicate data without intimate knowledge of each other's IT systems behind the firewall.

Users can access some Web services through a peer-to-peer arrangement rather than by going to a central server. Some services can communicate with other services and this exchange of procedures and data is generally enabled by a class of software known as middleware. Services previously possible only with the older standardized service known as Electronic Data Interchange (EDI) increasingly are likely to become Web services. Besides the standardization and wide availability to users and businesses of the Internet itself, Web services are also increasingly enabled by the use of the Extensible Markup Language (XML) as a means of standardizing data formats and exchanging data. XML is the foundation for the Web Services Description Language (WSDL).

iReport Jasper

Introduction of  iReport
iReport is a program that helps users and developers that use the JasperReports library to visually design reports.

Through a rich and very simple to use GUI, iReport provides all the most important functions to create nice reports in little time. iReport can help people that don't know the JasperReports library create complex reports and learn the XML syntax, taking a look to the generated code. iReport can help skilled report designers compose very complex pages, saving a lot of time. iReport is written in Java.

History  iReport

iReport is a visual designer for JasperReports. But What's JasperReports? JasperReports is the best (IMHO) open source reporting engine available for java community. It is developed by a small big genius called Teodor Danciu. JasperReports has always had one lack: it doesn't provide an adapted tool to visually design reports. JasperReports has hundred of features; possibilities of use are infinitely... a person that does not have much confidence with the XML could have some problems to take fully advantage from the JasperReports library.

What it can do?

The following list describes some of the important characteristics of iReport:
• 98% of JasperReports tags supported
• Visual designer wysiwyg with tools for draw rectangles, lines, ellipses, text fields fields, charts, sub reports...
• Built-in editor with syntax highlighting for write expression
• Support for Unicode and non Latin language (Russian, Chinese, Korean,...)
• Document structure browser
• Integrated compiler and exporter
• Support of all JDBC compliant databases
• Support of all kind of JRDataSource
• Wizard to create automatically reports
• Support for sub reports
• Save backup
• Support for templates
• Facilities for fonts

Sunday, January 23, 2011

Liferay Portal

Over the past couple of months I’ve seen an increase in the number of customers who have shown interest in Open Source products as an alternate to commercial products. In Portal and Social networking space, Liferay Portal has been a clear leader – in most cases customer has already made their choice, while in others we’ve found Liferay portal to be a good fit for our customer requirements. As a result I have been playing around with the product for some time now, so thought of putting my together for interest of others. Since Liferay Portal 5.2 also got released while I’m putting this together, I’ve made an attempt to capture the key enhancements that have been made in this release.
Overview
With over 75000 download per month, Liferay is the leading Open Source portal server which supports operating system like Linux, UNIX, Mac OS as well as Window. The Application server support is even more impressive with support for 14 application servers including the leading ones like WebLogic, WebSphere, Tomcat, JBoss, Oracle AS etc.
Gartner, in its 2008 Magic Quadrant for Horizontal Portal Products has recognized Liferay portal as Visionary for its strengths in innovation, market understanding and product development strategy.
Although the Liferay portal’s key strengths and focus has been on Collaborative as well as Intranet Portals solutions, its capabilities extend far beyond and it is now emerging as a reliable & a cost effective enterprise portal product.
Portal Architecture
Liferay is based on the J2EE platform thus available on almost all leading application server; it is compatible will all leading databases; run on UNIX, Windows, Linux as well as Mac OS – resulting in over 700 configurations to choose from, with the various combinations of middleware and database platforms. It also provides support for open standards like JSR 168, JSR 268, JSF 128, JSR 170, JSF 314; WSRP, Web Services, AJAX, Springs, Struts, Tiles, Hibernate etc making it must have in any portal evaluation.
The Portal architecture of Liferay has been built around Users, Organizations, Communities, Roles, Pages and Portlet that enables user to build flexible yet robust collaborative portal. 

I love the idea of Liferay portal, its a self sustaining portal and content management system that comes with many applications out of the box that enable you to shape your site as you wish without seeking a third party applications or plug-ins. The portal supports the JSR 168 and 286 for portlet development allowing you to develop a very elaborate applications on top of it with the power of Java, Spring, Hibernate, EJB, JSF and more.
The position of this Portal as of all portals is more in the mid-size business more then the personal site developer.
But with this positioning comes some software design and architecture responsibilities.
The portal should be able to cluster easily and be able to give better performance using caching.
The good news is that although clustering is not a simple switch in the configuration it is not allot more complex then a configuration of the web server, cache and Liferay. caching is also OOTB and has the benefits of the Hibernate.
Having this is very good and very reassuring for the business that sets its eyes on establishing a portal as their website.
The other great feature in the portal is the CMS based on the popular Journal portlet. though it is not a really great and flexible CMS with many of an enterprise CMS features it does get the job with simple content like Articles and so on. Dont expect to get the Vignette Content Management server out of it. ;-)
I do have some problems with the portal, especially GUI design and the separation of interfaces.
My first trouble started with the lack of a backend administrative application. i am used to this type of mechanism in most of my web applications including the WordPress i am using now. the separation of preview and management is some thing i find very important for applications.
For an example i would bring the page template management. though i have chosen a very arguable example i believe that this should be a part of the navigation tree and it should be possible to make a selection of several pages and change their templates collectively.
Liferay Layout Management
But this is not the end of the problems with the lack of administrative application, the administration is done by pages in the system that make it very elaborate to make it clear what is user controlled and what is administrative.
Now i have not gone beyond the simple install and have not tried to integrate it with any LDAP for users and groups or any other integration to Caching mechanisms but it appears that there is some community out there that will be happy to try and help and you might be able to archive your goal.
So if your company is in the route to get a portal and you want to go the open source way you probably should consider Liferay Portal. if you want an enterprise portal Come to Vignette.

Writing JDBC Applications with MySQL - Error Handling

If you want to trap errors, execute your JDBC operations within a try block and use an exception handler to display information about the cause of any problems that occur. JDBC provides getMessage() and getErrorCode() methods that may be invoked when an exception occurs to obtain the error message and the numeric error code. The following example deliberately issues a malformed query. When it runs, the executeQuery() method fails and raises an exception that is handled in the catch block:

try
   {
       Statement s = conn.createStatement ();
       s.executeQuery ("XYZ"); // issue invalid query
       s.close ();
   }
   catch (SQLException e)
   {
       System.err.println ("Error message: " + e.getMessage ());
       System.err.println ("Error number: " + e.getErrorCode ());
   }

Writing JDBC Applications with MySQL - Using Placeholders

Sometimes it's necessary to construct queries from values containing characters that require special treatment. For example, in queries, string values are written enclosed within quotes, but any quote characters in the string itself should be doubled or escaped with a backslash to avoid creating malformed SQL. In this case, it's much easier to let JDBC handle the escaping for you, rather than fooling around trying to do so yourself. To use this approach, create a different kind of statement (a PreparedStatement), and refer to the data values in the query string by means of placeholder characters. Then tell JDBC to bind the data values to the placeholders and it will handle any special characters automatically.

Suppose you have two variables nameVal and catVal from which you want to create a new record in the animal table. To do so without regard to whether or not the values contain special characters, issue the query like this:

PreparedStatement s;
   s = conn.prepareStatement (
               "INSERT INTO animal (name, category) VALUES(?,?)");
   s.setString (1, nameVal);
   s.setString (2, catVal);
   int count = s.executeUpdate ();
   s.close ();
   System.out.println (count + " rows were inserted");
The '?' characters in the query string act as placeholders--special markers indicating where data values should be placed. The setString() method takes a placeholder position and a string value and binds the value to the appropriate placeholder, performing any special-character escaping that may be necessary. The method you use to bind a value depends on the data type. For example, setString() binds string values and setInt() binds integer values.

Error Handling

Writing JDBC Applications with MySQL - Issuing Queries

Issuing Queries



To process SQL statements in a JDBC-based application, create a Statement object from your Connection object. Statement objects support an executeUpdate() method for issuing queries that modify the database and return no result set, and an executeQuery() method for queries that do return a result set. The query-processing examples in this article use the following table, animal, which contains an integer id column and two string columns, name and category:

CREATE TABLE animal
   (
       id          INT UNSIGNED NOT NULL AUTO_INCREMENT,
       PRIMARY KEY (id),
       name        CHAR(40),
       category    CHAR(40)
   )
id is an AUTO_INCREMENT column, so MySQL automatically assigns successive values 1, 2, 3, ... as records are added to the table.

Issuing Queries That Return No Result Set


The following example obtains a Statement object from the Connection object, then uses it to create and populate the animal table. DROP TABLE, CREATE TABLE, and INSERT all are statements that modify the database, so executeUpdate() is the appropriate method for issuing them:

Statement s = conn.createStatement ();
   int count;
   s.executeUpdate ("DROP TABLE IF EXISTS animal");
   s.executeUpdate (
               "CREATE TABLE animal ("
               + "id INT UNSIGNED NOT NULL AUTO_INCREMENT,"
               + "PRIMARY KEY (id),"
               + "name CHAR(40), category CHAR(40))");
   count = s.executeUpdate (
               "INSERT INTO animal (name, category)"
               + " VALUES"
               + "('snake', 'reptile'),"
               + "('frog', 'amphibian'),"
               + "('tuna', 'fish'),"
               + "('racoon', 'mammal')");
   s.close ();
   System.out.println (count + " rows were inserted");
The executeUpdate() method returns the number of rows affected by a query. As shown above, the count is used to report how many rows the INSERT statement added to the animal table.
A Statement object may be used to issue several queries. When you're done with it, invoke its close() method to dispose of the object and free any resources associated with it.

Issuing Queries That Return a Result Set



For statements such as SELECT queries that retrieve information from the database, use executeQuery(). After calling this method, create a ResultSet object and use it to iterate through the rows returned by your query. The following example shows one way to retrieve the contents of the animal table:

Statement s = conn.createStatement ();
   s.executeQuery ("SELECT id, name, category FROM animal");
   ResultSet rs = s.getResultSet ();
   int count = 0;
   while (rs.next ())
   {
       int idVal = rs.getInt ("id");
       String nameVal = rs.getString ("name");
       String catVal = rs.getString ("category");
       System.out.println (
               "id = " + idVal
               + ", name = " + nameVal
               + ", category = " + catVal);
       ++count;
   }
   rs.close ();
   s.close ();
   System.out.println (count + " rows were retrieved");
executeQuery() does not return a row count, so if you want to know how many rows a result set contains, you should count them yourself as you fetch them.
To obtain the column values from each row, invoke getXXX() methods that match the column data types. The getInt() and getString() methods used in the preceding example return integer and string values. As the example shows, these methods may be called using the name of a result set column. You can also fetch values by position. For the result set retrieved by the SELECT query in the example, id, name, and category are at column positions 1, 2 and 3 and thus could have been obtained like this:

int idVal = rs.getInt (1);
   String nameVal = rs.getString (2);
   String catVal = rs.getString (3);
ResultSet objects, like Statement objects, should be closed when you're done with them.
To check whether or not a column value is NULL, invoke the result set object's wasNull() method after fetching the value. For example, you could check for a NULL value in the name column like this:

String nameVal = rs.getString ("name");
   if (rs.wasNull ())
       nameVal = "(no name available)";

Writing JDBC Applications with MySQL - Connecting to the MySQL Server

To connect to the MySQL server, register the JDBC driver you plan to use, then invoke its getConnection() method. The following short program, Connect.java, shows how to connect to and disconnect from a server running on the local host. It accesses a database named test, using a MySQL account with a user name and password of testuser and testpass:

import java.sql.*;

   public class Connect
   {
       public static void main (String[] args)
       {
           Connection conn = null;

           try
           {
               String userName = "testuser";
               String password = "testpass";
               String url = "jdbc:mysql://localhost/test";
               Class.forName ("com.mysql.jdbc.Driver").newInstance ();
               conn = DriverManager.getConnection (url, userName, password);
               System.out.println ("Database connection established");
           }
           catch (Exception e)
           {
               System.err.println ("Cannot connect to database server");
           }
           finally
           {
               if (conn != null)
               {
                   try
                   {
                       conn.close ();
                       System.out.println ("Database connection terminated");
                   }
                   catch (Exception e) { /* ignore close errors */ }
               }
           }
       }
   }
Compile Connect.java to produce a class file Connect.class that contains executable Java code:
% javac Connect.java
Then invoke the class file as follows and it should connect to and disconnect from your MySQL server:
% java Connect
   Database connection established
   Database connection terminated
If you have trouble compiling Connect.java, double check that you have a Java Software Development Kit installed and make sure that the MySQL Connector/J driver is listed in your CLASSPATH environment variable.
The arguments to getConnection() are the connection URL and the user name and password of a MySQL account. As illustrated by Connect.java, JDBC URLs for MySQL consist of jdbc:mysql:// followed by the name of the MySQL server host and the database name. An alternate syntax for specifying the user and password is to add them as parameters to the end of the connection URL:

jdbc:mysql://localhost/test?user=testuser&password=testpass
When you specify a URL using this second format, getConnection() requires only one argument. For example, the code for connecting to the MySQL server in Connect.java could have been written like this:
String userName = "testuser";
   String password = "testpass";
   String url = "jdbc:mysql://localhost/test?user="
                   + userName
                   + "&password="
                   + password;
   Class.forName ("com.mysql.jdbc.Driver").newInstance ();
   conn = DriverManager.getConnection (url);
getConnect() returns a Connection object that may be used to interact with MySQL by issuing queries and retrieving their results. (The next section describes how to do this.) When you're done with the connection, invoke its close() method to disconnect from the MySQL server.
To increase the portability of your applications, you can store the connection parameters (host, database, user name, and password) in a Java properties file and read the properties at runtime. Then they need not be listed in the program itself. This allows you to change the server to which the program connects by editing the properties file, rather than by having to recompile the program.

Writing JDBC Applications with MySQL -Preliminary Requirements

To use Java applications with MySQL, you may need to install some additional software:

  • If you want to compile and run Java programs, you'll need a Java compiler (such as javac or jikes) and a runtime environment. If these are not already installed on your system, you can get them by obtaining a Java Software Development Kit (SDK) from java.sun.com.
  • If you want only to run precompiled applications, no compiler is necessary, but you'll still need a Java Runtime Environment (JRE). This too may be obtained from java.sun.com.
This article assumes that you'll write and compile your own programs, and thus that you have a Java SDK installed. Once you compile a Java program, however, you can deploy it to other machines, even ones that have only a runtime environment. This works even in heterogenous installations, because Java is platform-independent. Applications compiled on one platform can be expected to work on other platforms. For example, you can develop on a Linux box and deploy on Windows.

Writing JDBC Applications with MySQL

You can write MySQL applications in a variety of languages. The languages that most people use with MySQL are PHP and Perl, but a sometimes overlooked option is the MySQL Connector/J driver, which allows you to develop Java applications that interact with your MySQL server.

MySQL Connector/J works within the framework of the Java JDBC interface, an API that allows Java programs to use database servers in a portable way. JDBC is based on an approach similar to that used in the design of Perl and Ruby DBI modules, Python's DB-API module, and PHP's PEAR::DB class. This approach uses a two-tier architecture:

  • The top level is visible to application programs and presents an abstract interface for connecting to and using database engines. The application interface does not depend on details specific to particular engines.
  • The lower level consists of drivers for individual database engines. Each driver handles the details necessary to map the abstract application interface onto operations that a specific engine will understand.
The JDBC interface allows developers to write applications that can be used with different databases with a minimum of porting effort. Once a driver for a given server engine is installed, JDBC applications can communicate with any server of that type. By using MySQL Connector/J, your Java programs can access MySQL databases.
Note: MySQL Connector/J is the successor to the MM.MySQL driver. If you have JDBC programs written for MM.MySQL, they should work with MySQL Connector/J as well, although you may want to update the driver class name used in your programs. Just replace instances of org.gjt.mm.mysql in your Java source files with com.mysql.jdbc and recompile.

Java Hibernate

HIBERNATE - Introduction to Hibernate

Hibernate is an open source object/relational mapping tool for Java. Hibernate lets you develop persistent classes following common Java idiom - including association, inheritance, polymorphism, composition and the Java collections framework.

Hibernate not only takes care of the mapping from Java classes to database tables (and from Java data types to SQL data types), but also provides data query and retrieval facilities and can significantly reduce development time otherwise spent with manual data handling in SQL and JDBC.

Hibernates goal is to relieve the developer from 95 percent of common data persistence related programming tasks.


Hibernate is Free Software. The LGPL license is sufficiently flexible to allow the use of Hibernate in both open source and commercial projects (see the LicenseFAQ for details). Hibernate is available for download at http://www.hibernate.org/. This tutorial aims to provide insight into Hibernate version 3.0RC and its usage
Some of the main features of hibernate are listed below and we have tried to explain some of them in detail later in this tutorial.

  Transparent persistence without byte code processing
    Transparent persistence
    JavaBeans style properties are persisted
    No build-time source or byte code generation / processing
    Support for extensive subset of Java collections API
    Collection instance management
    Extensible type system
    Constraint transparency
    Automatic Dirty Checking
    Detached object support
  Object-oriented query language
    Powerful object-oriented query language
    Full support for polymorphic queries
    New Criteria queries
    Native SQL queries
  Object / Relational mappings
    Three different O/R mapping strategies

Agile Java Development

                                                               Agile Java Development

Agile Java™ Development With Spring, Hibernate and Eclipse is a book about robust technologies and effective methods which help bring simplicity back into the world of enterprise Java development. The three key technologies covered in this book, the Spring Framework, Hibernate and Eclipse, help reduce the complexity of enterprise Java development significantly. Furthermore, these technologies enable plain old Java objects (POJOs) to be deployed in light-weight containers versus heavy-handed remote objects that require heavy EJB containers.
This book also extensively covers technologies such as Ant, JUnit, JSP tag libraries and touches upon other areas such as such logging, GUI based debugging, monitoring using JMX, job scheduling, emailing, and more. Also, Extreme Programming (XP), Agile Model Driven Development (AMDD) and refactoring are methods that can expedite the software development projects by reducing the amount of up front requirements and design; hence these methods are embedded throughout the book but with just enough details and examples to not sidetrack the focus of this book. In addition, this book contains well separated, subjective material (opinion sidebars), comic illustrations, tips and tricks, all of which provide real-world and practical perspectives on relevant topics. Last but not least, this book demonstrates the complete lifecycle by building and following a sample application, chapter-by-chapter, starting from conceptualization to production using the technology and processes covered in this book. In summary, by using the technologies and methods covered in this book, the reader will be able to effectively develop enterprise-class Java applications, in an agile manner!
About the Author
Anil Hemrajani has been working with Java technology since late 1995 as a developer, entrepreneur, author, and trainer. He is the founder of Isavix Corporation, a successful IT service company, and DeveloperHub.com (formerly isavix.net), an award-winning online developer community that grew to over 100,000 registered members. He has twenty years of experience in the information technology community working with several Fortune 100 companies and also smaller organizations. He has published numerous articles in well-known trade journals, presented at conferences and seminars around the world, and has received the “Outstanding Contribution to the Growth of the Java Community” award from Sun Microsystems, the “Best Java Client” award at JavaOne for BackOnline, a Java-based online backup client/server product, and was nominated for a Computerworld-Smithsonian award for a free online file storage service website.

Saturday, January 22, 2011

Blackberrys To Bunnies

The next time you place a call on your blackberry or play a game on your Nintendo Wii, you may have the IEEE 802.11 working group to thank.The latest BlackBerry models build upon the strength of the Wireless LAN  standard to create communication network that saves company money keeping employee better connected.

Tuesday, January 4, 2011

iPhone4

iPhone 4 problem will never be solved

Step taken by Apple to cater the iPhone4 deserved to be praised.
However,solution efferct offered by Apple has to be monitored
in the future.

Monday, January 3, 2011

Today is Tuesday

Today is a third day in a week and is placed betweem monday and wednesday.The word "Selasa" came from Arabic word which mean three day .Wheras tuesday came from the name of saxon's god which is Tyr.

Sunday, January 2, 2011

2k11

Today is second day of year counting day which is 2011.What the different between last year and this year?
Nothing much change i guess if we look back for past few years.It just same stories we heard in the
newspaper and televisyen.What's more important is, what we gonna be in the future?So we much start from
now and dont even look back your mistake.Leave all that behind and heads up.
Tomorrow gonna be first day of working in this, so lets start new chapter ya!!

5L15K

  © Blogger template The Beach by Ourblogtemplates.com 2009

Back to TOP