বৃহস্পতিবার, ৬ ডিসেম্বর, ২০১২

Technical important link

  Going from One to a Million Users-->

মঙ্গলবার, ৩ জুলাই, ২০১২

Java Marker Interface

Marker interface is used as a tag to inform a message to the java compiler so that it can add special behaviour to the class implementing it. Java marker interface has no members in it.

Lets take the java.io.Serializable marker interface. It doesnot has any members defined it it. When a java class is to be serialized, you should intimate the java compiler in some way that there is a possibility of serializing this java class. In this scenario, marker interfaces are used. The java class which may be serialized has to implement the java.io.Serializable marker interface. In such way, we are intimating the java compiler.
From java 1.5, the need for marker interface is eliminated by the introduction of the java annotation feature. So, it is wise to use java annotations than the marker interface. It has more feature and advantages than the java marker interface.

Is Runnable a marker interface?

First point, there is no reference or definition about marker interface from Java specification/api. This is yet another inconclusive debate. ‘Marker Interface’ is a term coined by (book / web) authors. Since we don’t have Java’s definition it is left to us to arrive at a decent definition. This is one popular question asked in java interview. My answer to the interviewer, there are better questions ask than this to ask.
“Runnable is not a marker interface”, you might say ‘run’ is used to start a method and this is a special instruction to the JVM.  When you run a java class the java interpreter calls the ‘main’ method, because of this would you say every java class as “marker class”?

‘My’ definition for marker interface

“An interface is called a marker interface when it is provided as a handle by java interpreter to mark a class so that it can provide special behaviour to it at runtime and they do not have any method declarations”.
In the above definition “and they do not have any method declarations” is added because, till now all the marker interfaces provided by java do not have method declarations. I dont think, in future there will be any new marker interfaces added :-)
We cannot create marker interfaces, as you cannot instruct JVM to add special behavior to all classes implementing (directly) that special interface.

Java Marker Interface Examples

  • java.lang.Cloneable
  • java.io.Serializable
  • java.util.EventListener
source: http://javapapers.com/core-java/abstract-and-interface-core-java-2/what-is-a-java-marker-interface/



Java Serialization

Have you ever seen what is inside a serialized object? I will explain you what is java serialization, then provide you with a sample for serialization. Finally most importantly, lets explore what is inside a serialized object and what it means. That is internals of java serialization and how does it works. If you want to have your own implementation of java serialization, this article will provide you with a good platform to launch.

What is Java Serialization?

Primary purpose of java serialization is to write an object into a stream, so that it can be transported through a network and that object can be rebuilt again. When there are two different parties involved, you need a protocol to rebuild the exact same object again. Java serialization API just provides you that. Other ways you can leverage the feature of serialization is, you can use it to perform a deep copy.
Why I used ‘primary purpose’ in the above definition is, sometimes people use java serialization as a replacement for database. Just a placeholder where you can persist an object across sessions. This is not the primary purpose of java serialization. Sometimes, when I interview candidates for Java I hear them saying java serialization is used for storing (to preserve the state) an object and retrieving it. They use it synonymously with database. This is a wrong perception for serialization.

How do you serialize?

When you want to serialize an object, that respective class should implement the marker interface serializable. It just informs the compiler that this java class can be serialized. You can tag properties that should not be serialized as transient. You open a stream and write the object into it. Java API takes care of the serialization protocol and persists the java object in a file in conformance with the protocol. De-serialization is the process of getting the object back from the file to its original form.
Here protocol means, understanding between serializing person and de-serializing person. What will be the contents of file containing the serialized object? This serves as a guideline to de-serialize. Have a look at the following sample and how its serialized file looks.

Sample Source Code for Java Serialization

package com.javapapers.sample;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
class SerializationBox implements Serializable {
  private byte serializableProp = 10;
  public byte getSerializableProp() {
    return serializableProp;
  }
}
public class SerializationSample {
  public static void main(String args[]) throws IOException,
      FileNotFoundException, ClassNotFoundException {
    SerializationBox serialB = new SerializationBox();
    serialize("serial.out", serialB);
    SerializationBox sb = (SerializationBox) deSerialize("serial.out");
    System.out.println(sb.getSerializableProp());
  }
  public static void serialize(String outFile, Object serializableObject)
      throws IOException {
    FileOutputStream fos = new FileOutputStream(outFile);
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    oos.writeObject(serializableObject);
  }
  public static Object deSerialize(String serilizedObject)
      throws FileNotFoundException, IOException, ClassNotFoundException {
    FileInputStream fis = new FileInputStream(serilizedObject);
    ObjectInputStream ois = new ObjectInputStream(fis);
    return ois.readObject();
  }
}

Exploring Java Serialization

Look at following image. After serializing ‘SerializationBox’ in the above sample code, I opened the output in a hex editor. You can use Notepad++ and hex plugin to open the serialized file.
Let us look at contents byte by byte and find out what they are. It starts with “ac ed”. It is is called STREAM_MAGIC. It is a magic number (java API guys says) that is written to the stream header. It denotes that is start of serialzed content.Serialized Output
Similarly every character has a meaning. Actually the serialized file is more bulkier than you would expect, as it has a huge header the meta information of the classes involved and finally the content. Object Serialization Stream Protocol have a look at chapter 6.4.2 Terminal Symbols and Constants. It gives you list of symbols and constants used in serialization.

Decrypting Serialized Java Object

In the image, I have underline a unit of information in a separate color for you to easily identify.
ac ed – STREAM_MAGIC – denotes start of serialzed content
00 05 – STREAM_VERSION – serialization version
73 – TC_OBJECT – new Object
72 – TC_CLASSDESC – new Class Descriptor
00 26 – length of the class name
63 6f 6d 2e 6a 61 76 61 70 61 70 65 72 73 2e 73 61 6d 70 6c 65 2e 53 65 72 69 61 6c 69 7a 61 74 69 6f 6e 42 6f 78 – class name
57 fc 83 ca 02 85 f0 18 – SerialVersionUID
02 – this object is serializable
00 01 – count of properties in the serialzed class – one property in our example
42 00 10 – private byte
73 65 72 69 61 6c 69 7a 61 62 6c 65 50 72 6f 70 78 70 – property name – serializableProp in our example
0a – 10 the value – This is the persisted value of the property in our sample



courtsy: http://javapapers.com/core-java/java-serialization/

বুধবার, ২৭ জুন, ২০১২

Spring framework interview questions


Spring framework interview questions :


Question1: What is IOC or inversion of control?

Ans: This question is first step towards spring and mostly interviewer starts from this question. As the name implies inversion of control means now we have inverted the control of creating the object from our own using new operator to container or framework
Now it’s the responsibility of container to create object as required.
We maintain one xml file where we configure our components, services, all the classes and their property. We just need to mention which service is needed by which component and container will create the object for us. This concept is known as dependency injection because all object dependency (resources) is injected into it by framework.

Example:
 
        
    
In this example CreateNewStockAccont class contain getter and setter for newBid and container will instantiate newBid and set the value automatically when it is used.


Question 2: Explain Bean-LifeCycle.


Ans: Spring framework is based on IOC so we call it as IOC container also So Beans reside inside the IOC container beans are nothing but Plain old java object (POJO).
Following steps explain their lifecycle inside container.
1. Container will look the bean definition inside configuration file (eg.bean.xml).
2 using reflection container will create the object and if any property is defined inside the bean definition then it will also be set.
3. If the bean implements the BeanNameAware interface, the factory calls setBeanName() passing the bean’s ID.
4. If the bean implements the BeanFactoryAware interface, the factory calls setBeanFactory(), passing an instance of itself.
5. If there are any BeanPostProcessors associated with the bean, their post- ProcessBeforeInitialization () methods will be called before the properties for the Bean are set.
6. If an init-method is specified for the bean, it will be called.
7. If the Bean class implements the DisposableBean interface, then the method destroy() will be called when the Application no longer needs the bean reference.
8. If the Bean definition in the Configuration file contains a 'destroy-method' attribute, then the corresponding method definition in the Bean class will be called.

Question 3: what is Bean Factory, have you used XMLBean factory?

Ans: BeanFactory is factory Pattern which is based on IoC.it is used to make a clear separation between application configuration and dependency from actual code.
XmlBeanFactory is one of the implementation of bean Factory which we have used in our project.
org.springframework.beans.factory.xml.XmlBeanFactory is used to creat bean instance defined in our xml file.

BeanFactory factory = new XmlBeanFactory(new FileInputStream("beans.xml"));
Or
ClassPathResource resorce = new ClassPathResource("beans.xml");
XmlBeanFactory factory = new XmlBeanFactory(resorce);

Question 4: what are the difference between BeanFactory and ApplicationContext in spring?
Ans: This one is very popular spring interview question and often asks in entry level interview. ApplicationContext is preferred way of using spring because of functionality provided by it and interviewer wanted to check whether you are familiar with it or not.



ApplicationContext.


BeanFactory
Here we can have more than one config files possible
In this only one config file or .xml file
Application contexts can publish events to beans that are registered as listeners
Doesn’t support.
Support internationalization (I18N) messages
It’s not
Support application lifecycle events, and validation.
Doesn’t support.
Support  many enterprise services such JNDI access, EJB integration, remoting
Doesn’t support.



Question 5: What are different modules in spring?

Ans: spring have seven core modules
1.      The Core container module
2.      Application context module
3.      AOP module (Aspect Oriented Programming)
4.      JDBC abstraction and DAO module
5.      O/R mapping integration module (Object/Relational)
6.      Web module

রবিবার, ২৪ জুন, ২০১২

Mobile app for non native


They can be categorized into three groups:

1.  Use another language and compiles a native app in one or more platforms.
  • Titanium Appcelerator (html/js/css -> iPhone/Android/Blackberry)
  • Ansca Mobile (ActionScript, Lua -> iPhone/Android)

2. Embed your native platform language to expose certain native features to web app.
  • PhoneGap
  • QuickConnect

3.  Create Touch device optimized/native look and feel web apps.
  • Sencha
  • jQTouch
  • xui
  • PastryKit
  • jQuery Mobile

সোমবার, ১৮ জুন, ২০১২

Forward vs Redirect in servlet

Forward vs Redirect in servlet

 Forward

    * a forward is performed internally by the servlet
    * the browser is completely unaware that it has taken place, so its original URL remains intact
    * any browser reload of the resulting page will simple repeat the original request, with the original URL

Redirect

    * a redirect is a two step process, where the web application instructs the browser to fetch a second URL, which differs from the original
    * a browser reload of the second URL will not repeat the original request, but will rather fetch the second URL
    * redirect is marginally slower than a forward, since it requires two browser requests, not one
    * objects placed in the original request scope are not available to the second request

বৃহস্পতিবার, ২৬ এপ্রিল, ২০১২

Spring 3 MVC - DynamicJasper Integration Tutorial

http://krams915.blogspot.com/2010/12/spring-3-mvc-dynamic-jasper-integration.html

মঙ্গলবার, ১৭ এপ্রিল, ২০১২

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

problem: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

probable solution for linux :
1. sudo /etc/init.d/mysqld start
2. mysql -u username -p
(then password)

সোমবার, ১৬ এপ্রিল, ২০১২

InnoDB vs MyISAM on MySQL

MySQL know that MyISAM and InnoDB are the two most-common database engines available with the popular open-source database provider

MyISAM

Let's start with MyISAM since it is the default engine with MySQL. MyISAM is based on the older but proven ISAM code but has been extended to be fully-featured while retaining the reliability. Data in MyISAM tables is split between three different files on the disk. One for the table format, another for the data, and lastly a third for the indexes.

The maximum number of rows supported amounts to somewhere around ~4.295E+09 and can have up to 64 indexed fields per table. Both of these limits can be greatly increased by compiling a special version of MySQL.

Text/Blob fields are able to be fully-indexed which is of great importance to search functions.

Much more technical information can be found on MySQL's MyISAM Manual Page.

InnoDB

InnoDB is relatively newer so the scene than MyISAM is so people are still weary about its use in environments than run fine under MyISAM. InnoDB is transaction-safe meaning data-integrity is maintained throughout the entire query process. InnoDB also provides row-locking, as opposed to table-locking, meaning while one query is busy updating or inserting a row, another query can update a different row at the same time. These features increase multi-user concurrency and performance.

Another great feature InnoDB boasts is the ability to use foreign-key constraints. FK constraints allows developers to ensure that inserted data referencing another table remains valid. For example, if you had an authors table and a books table and you wanted to insert a new book while referencing the author. The author would have to exist in the authors table before inserting them in the books table because a foreign key was specified in the books table. At the same time you would not be able to delete an author from the authors table if they had any entries associated with them in the books table.

Because of its row-locking feature InnoDB is said to thrive in high load environments. Its CPU efficiency is probably not matched by any other disk-based relational database engine.

Comparison

MyISAM in most cases will be faster than InnoDB for run of the mill sort of work. Selecting, updating and inserting are all very speedy under normal circumstances. It is the default engine chosen by the MySQL development team which speaks to its integrity, reliability, and performance.

InnoDB, has emerged with some nifty features and created a niche for itself very quickly. Boasting features like row-level locking, transaction-safe queries, and relational table design are all very temping. The first two features really shine in a table that is constantly getting hammered like a logs, or search engine-type table. Since queries happen in the blink of an eye (faster actually) table-level locking(MyISAM) is sufficient in most other normal cases.

InnoDB recovers from a crash or other unexpected shutdown by replaying its logs. MyISAM must fully scan and repair or rebuild any indexes or possibly tables which had been updated but not fully flushed to disk.

Decision Matrix

Is your table is going to be inserted, deleted, and updated much much more than it is going to be selected?
InnoDB
If you need full-text search MyISAM
If you prefer/require relational database design InnoDB
Is disk-space or ram an issue? MyISAM
In Doubt? MyISAM

There is no winner.

REMEMBER! It's OK to mix table types in the same database! In fact it's recommended and frequently required. However, it is important to note that if you are having performance issues when joining the two types, try converting one to the other and see if that fixes it. This issue does not happen often but it has been reported.

রবিবার, ১৫ এপ্রিল, ২০১২


Setup ant file ..... more

Here I write something about build script file......

I used one build.propeties and build.xml file. Both file are in same directory in project folder.

My ant file expect above project structure(that is shown above):


setting information about tomcat server on build.properties:

tomcat.home=/usr/local/tomcat6
deploy.path=${tomcat.home}/webapps
appContext={your project name}

On build.xml:

<?xml version="1.0" encoding="UTF-8"?>

<project name="birth-certificate" default="deploy" basedir=".">

<description>
birth certificate
</description>

<property file="build.properties"/>
<property name="src.dir" location="${basedir}/src"/>
<property name="web.dir" location="${basedir}/web"/>
<property name="lib.dir" location="${basedir}/lib"/>
<property name="props.dir" location="${basedir}/props"/>
<property name="i18n.dir" location="${basedir}/i18n"/>

<property name="build.dir" location="/tmp/build"/>
<property name="classes.dir" location="${build.dir}/WEB-INF/classes"/>
<property name="dist.dir" location="${basedir}/dist"/>

<property name="tomcat.lib" value="${tomcat.home}/lib"/>

<path id="classpath">
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>

<fileset dir="${tomcat.lib}">
<include name="*.jar"/>
</fileset>
</path>


<target name="init">
<tstamp>
<format property="build.tstamp" pattern="yyyy-MM-dd HH:mm:ss"/>
</tstamp>
<echo message="Build timestamp: ${build.tstamp}"/>
<mkdir dir="${classes.dir}"/>
</target>

<target name="resources" depends="init" description="prepare deployment resources">
<copy todir="${build.dir}">
<fileset dir="${web.dir}"/>
</copy>

<mkdir dir="${build.dir}/WEB-INF/lib"/>

<copy todir="${build.dir}/WEB-INF/lib">
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
</copy>

<copy todir="${classes.dir}">
<fileset dir="${props.dir}"/>
<fileset dir="${i18n.dir}"/>
</copy>
</target>


<target name="compile" depends="init">
<javac destdir="${classes.dir}"
classpathref="classpath"
srcdir="${src.dir}"
debug="on"
includeantruntime="false"/>
</target>

<target name="clean">
<delete dir="${build.dir}"/>
</target>

<target name="build" depends="clean, resources, compile"/>

<target name="start">
<exec executable="${tomcat.home}/bin/catalina.sh">
<arg value="start"/>
</exec>
</target>

<target name="stop">
<exec executable="${tomcat.home}/bin/catalina.sh">
<arg value="stop"/>
</exec>
</target>

<target name="remove-deployment">
<delete file="${deploy.path}/${appContext}.war"/>
<delete dir="${deploy.path}/${appContext}"/>
</target>

<target name="undeploy" depends="stop, remove-deployment, start" description="UnDeploy Application"/>

<target name="copy-war" depends="clean, build">
<copy todir="${deploy.path}" file="${dist.dir}/${appContext}.war"/>
</target>

<target name="war" depends="clean, build">
<mkdir dir="${dist.dir}"/>
<war destfile="${dist.dir}/${appContext}.war" webxml="${build.dir}/WEB-INF/web.xml">
<fileset dir="${build.dir}"/>
</war>
</target>

<target name="copy" depends="clean, build">
<copy todir="${deploy.path}/${appContext}">
<fileset dir="${build.dir}"/>
</copy>
</target>

<target name="deploy-war" depends="stop, copy-war, start"/>

<target name="deploy" depends="stop, copy, start"/>


<!--=============================build some extra features===========================-->

<target name="static" description="Copy JSP files and Static contents">
<copy todir="${deploy.path}/${appContext}">
<fileset dir="${web.dir}">
<include name="**/*.jsp"/>
</fileset>
</copy>

<copy todir="${deploy.path}/${appContext}/css">
<fileset dir="${web.dir}/css"/>
</copy>

<copy todir="${deploy.path}/${appContext}/images">
<fileset dir="${web.dir}/images"/>
</copy>

<copy todir="${deploy.path}/${appContext}/js">
<fileset dir="${web.dir}/js"/>
</copy>
</target>


<target name="debug">
<exec executable="${tomcat.home}/bin/catalina.sh">
<arg value="jpda"/>
<arg value="start"/>
</exec>
</target>
</project>

রবিবার, ৮ এপ্রিল, ২০১২

fibonacci number

public class FibonacciNo {
public FibonacciNo() {
calculate(10);
System.out.println("\n recursive fibo "+ fibo(10));
}

private void calculate(int limit) {
int[] tempArray = new int[limit+2];
tempArray[0] = 0;
tempArray[1] = 1;
for(int i =1 ;i<=limit;i++){
tempArray[i+1] = tempArray[i-1] + tempArray[i];
}
for(int i=0;i<=limit;i++){
System.out.print(tempArray[i]+" ");
}
}

private int fibo(int n){
if(n==0) return 0;
if(n==1) return 1;
return fibo(n - 1)+ fibo(n - 2);
}


public static void main(String[] a) {
new FibonacciNo();
}
}

factoiral number

/**
* User: shohan
* Date: 4/8/12
*/
public class FactorialNo {

public FactorialNo() {

int result = calculateFactorialNo(10);
System.out.println("normal result : "+result);
System.out.println("recursive result : "+calculate(10));

}

private int calculateFactorialNo(int i) {
int result = 1;
for (int j = 1; j <= i; j++) {
result *= j;
}
return result;
}

private int calculate(int n){
if(n==0) return 1;
return n*calculate((n-1));
}

public static void main(String [] arg){
new FactorialNo();
}
}

Multiple div in one div

<html>
<style type="text/css">
div
{
margin:10 10 10 10;
border:1px solid;
border-radius:25px;
-moz-border-radius:5px;
}
.test{
width:200px;
}
a{
text-decoration:none
}
.subMain{
width:250px;
padding:5px;

}
</style>
<body>


<div style="float:left; width: 600px;">

<div style="float:left; border:0px; width= 500px;">
<div class="subMain"style="float:left">dddd dfdfd fdfsdf s fsdfsdf sdfsdfsdfsdfsdf sfsdfsd sfsdfd sdfsdfd<a href="#">more...</a></div>
<div class="subMain"style="float:right">dddd dfdfd fdfsdf s fsdfsdf sdfsdfsdfsdfsdf sfsdfsd sfsdfd sdfsdfd<a href="#">More...</a></div>
</div>
<div style="float:left; border:0px;">
<div class="subMain"style="float:left">dddd dfdfd fdfsdf s fsdfsdf sdfsdfsdfsdfsdf sfsdfsd sfsdfd sdfsdfddddd dfdfd fdfsdf s fsdfsdf sdfsdfsdfsdfsdf sfsdfsd sfsdfd sdfsdfd<a href="#">More...</a></div>
<div class="subMain"style="float:right">dddd dfdfd fdfsdf s fsdfsdf sdfsdfsdfsdfsdf sfsdfsd sfsdfd sdfsdfddddd dfdfd fdfsdf s fsdfsdf sdfsdfsdfsdfsdf sfsdfsd sfsdfd sdfsdfddddddfdf dfsdfdf<a href="#">More...</a></div>
</div>


</div>
</body>
</html>

বৃহস্পতিবার, ৫ এপ্রিল, ২০১২

Balsamiq Mockups

http://www.douban.com/group/topic/21967889/

Prime Number genrator

public class PrimeNo {

public PrimeNo() {
int givenNo = 9234563;

boolean isPrime = checkPrimeNumber(givenNo);

boolean isPrimeEfficient = getPrimeNumber(givenNo, getDivisorsArray(givenNo));

System.out.println(isPrime);
System.out.println("efficient");
System.out.println(isPrimeEfficient);

}



private boolean getPrimeNumber(int givenNo, int[] divisorsArray) {
if (givenNo == 2) return true;
if (givenNo > 2 && givenNo % 2 != 0) {
if (divisorsArray.length != 0) {
for (int j = 3; j <= divisorsArray.length; j++) {
if (givenNo % j == 0) {
return false;
}
}
}
return true;
}
return false;
}

public static void main(String arg[]) {
new PrimeNo();
}

private int[] getDivisorsArray(int givenNo) {

int sqrt = (int) Math.sqrt(givenNo);
int[] tempArray = new int[sqrt];
int count = 0;
for (int i = 3; i < sqrt; i++) {
if (checkPrimeNumber(i)) {
tempArray[count++] = i;
}
}

return tempArray;
}

private boolean checkPrimeNumber(int i) {
if (i == 2) return true;
if (i > 1 && i % 2 != 0) {
for (int j = 3; j <= Math.sqrt(i); j++) {
if (i % j == 0) {
return false;
}
}
return true;
}
return false;
}
}

বুধবার, ৪ এপ্রিল, ২০১২

বৃহস্পতিবার, ৮ মার্চ, ২০১২

sencha touch

http://www.slideshare.net/senchainc/structuring-your-sencha-touch-application

রবিবার, ১২ ফেব্রুয়ারী, ২০১২

ABCD on seam

Seam Framework is one of the most successful integration frameworks that joins together multiple software components.

Integration is one of the hardest problems in enterprise application development. A
multitier application is typically made up of many components, such as transactional services, security, data persistence, asynchronous messaging, UI rendering, etc. Those components are developed in different frameworks and libraries; they often have different programming models and scalability characteristics. The need to make those components work with each other has given rise to integration frameworks.Seam integrates a number of other leading open source frameworks, such as jBPM, JBoss Rules (a.k.a. Drools), iText, and Spring.


The core framework of JEE 5.0 are:
1. EJB 3.0
2. JSF 1.2

(EJB 3.0 converts POJO into business service object and database persistence object)
(JSF is MVC component framework)
In JEE uses both EJB for business logic and JSF for front end.
Complementary to each others and designed as separate framework, each with its own philosophy.they are not aware of each other at the framework level.To make EJB3 and JSF work together, you need artificial facade objects.Gluing
those technologies together is part of Seam’s responsibilities.
Seam collapses the artificial layer between EJB3 and JSF and provides a consistent,
annotation-based approach to integrate .It provides a consistent,annotation-based approach to integrate EJB3 and JSF.

JSF is that it relies too much on HTTP POST and hard to bookmark a JSF web page and then get it via HTTP GET but Seam is solve the problem.


With Seam, there are no more DTOs to write, lazy loading just works, and
ORM performance can be greatly improved because the extended persistence context acts as a natural cache to reduce database roundtrips.


Seam was designed for stateful web applications.


Furthermore, database caches and transactions can be automatically tied with the appli-cation state in Seam. Seam automatically holds database updates in memory and commits to the database only at the end of a conversation.

Seam is fully optimized for Web 2.0 applications.

Seam wires POJO components together using a popular design pattern known as depen-dency injection (DI)
.

Writing a Seam web application is conceptually very simple. You only need to code
the following components:

• Entity objects that represent the data model. These entity objects could be entity
beans in the Java Persistence API (JPA, a.k.a. EJB3 persistence) or Hibernate POJOs.
They are automatically mapped to relational database tables.

• JSF web pages that display the user interface. These pages capture user input via
forms and display the data. The data fields on the page are mapped to the backend
data model via the JSF Expression Language (EL).

• EJB3 session beans or annotated Seam POJOs that act as UI event handlers for the
JSF web pages. They update the data model based on the user input.


Seam manages all these components and automatically injects them into the right pages or objects at runtime. For instance, when the user clicks a button to submit a JSF form, Seam automatically parses the form fields and constructs an entity bean. Then Seam passes the entity bean into the event handler session bean, which Seam also creates, for processing. You do not need to manage component lifecycles and relationships between components in your code. There is no boilerplate code and no XML file for dependency management.

Dependency bijection:

Seam wires POJO components together using a popular design pattern known as depen-dency injection (DI). Under this pattern, the Seam framework manages the lifecycle of all the components. When a component needs to use another, it declares this dependency to Seam using annotations. Seam determines where to get this dependent component based on the application’s current state and “injects” it into the asking component.

Expanding on the dependency injection concept, a Seam component A can also create another component B and “outject” the created component B back to Seam for other components, such as C, to use later.
In Seam terms, we call this dependency bijection.

Convention over Configuration

The idea is to have a set of common-sense default behaviors for the components (i.e., the convention). The developer needs to configure the component explicitly only when the desired behavior is not the default.
Overall, the configuration metadata in Seam is much simpler than in competing Java frameworks.




Seam designers recognize that XML is well suited to specifying web application pageflows or defining business process workflows. The XML file enables us to centrally manage the workflow for the entire application, as opposed to scattering the information around in Java source files.




@Entity
@Name("person")
public class Person implements Serializable {

private long id;
private String name;

@Id @GeneratedValue
public long getId() { return id;}

public void setId(long id) { this.id = id; }

public String getName() { return name; }

public void setName(String name) {
this.name = name;
}

}


The @Entity annotation tells the container to map this class to a relational
database table, with each property a column in the table.
The most important annotation in the Person class is the @Name annotation. It specifies the string name the Person bean should be registered by under Seam. In other Seam components (e.g., JSF web pages and session beans), you can reference the managed Person bean using the person name.


In the JSF page, we use the Person bean to back the form’s input text field. The
#{person.name} symbol refers to the name property on the Seam component named
person, which is an instance of the Person entity bean as we just discussed. The #{...} notation to reference Java objects is called JSF Expression Language (EL). It is widely used in Seam.


<h:form>
Please enter your name:<br/>
<h:inputText value="#{person.name}" size="15"/><br/>
<h:commandButton type="submit" value="Say Hello"
action="#{manager.sayHello}"/>
</h:form>






The manager component in Seam is the ManagerAction session bean, identified by the @Name annotation on the class. Notice that we use the @Stateful annotation here as Seam works best with stateful session beans (for details, refer to the end of this section). The ManagerAction class has a person field with the @In annotation.


@Stateful
@Name("manager")
public class ManagerAction implements Manager {
@In
private Person person;










//////////////////////////

Statefull framework

The real jewel of Seam is its support for sophisticated application state management that is not available in any other web application framework today.
The state management facilities in Seam are independent of JSF or EJB.

lazy loading:
When the framework loads an object from the relational database, it does not necessarily load all its associated objects.

If the web presentation layer attempts to lazy-
load associated objects after Spring returns, an exception will be thrown




To avoid the nasty lazy loading exceptions, developers have to work around the
framework using hacks such as Data Transfer Objects (DTOs) or messing with
the database queries or schema.a Seam component keeps the persistence context valid from the time
when an HTTP request is submitted to the time when the response page is fully renderedWe can pass
entity objects (i.e., EJB3 entity beans) directly across the business layer and the presen-
tation layer without the need to wrap them in DTO



Here is a list of stateful contexts in Seam:
stateless Components in this context are completely stateless and do not hold any
state data of their own.
event This is the narrowest stateful context in Seam. Components in this context
maintain their state throughout the processing of a single JSF request.
page Components in this context are tied to a specific page. You can have access to
these components from all events emitted from that page.
conversation In Seam, a conversation is a series of web requests to accomplish a
certain task (e.g., to check out the shopping cart). Components tied to a conversation
context maintain their state throughout the conversation. The conversation context
is the most important context in Seam; it is discussed in more detail in Chapter 8.
session Components in the session context are managed in an HTTP session object.
They maintain their state until the session expires. You can have multiple
conversations in a session.
business process This context holds stateful components associated with a long-
running business process managed in the JBoss jBPM (Business Process Manager)
engine. While all the previously discussed contexts manage stateful components
for a single web user, the business process components can span across several
users. We will explore this in more detail in Chapter 24.
application This is a global context that holds static information. There is no concept of web users in this context.




























রবিবার, ২২ জানুয়ারী, ২০১২

CSS important link

1.Page Layout Samples-->

মঙ্গলবার, ১৭ জানুয়ারী, ২০১২

vps

http://www.web24.com.au/vps/204/linux_vps.html

বুধবার, ১১ জানুয়ারী, ২০১২

What are the difference between DDL, DML and DCL

Data Definition Language (DDL): ~ statements are used to define the database structure or schema.
  1. CREATE - to create objects in the database
  2. ALTER - alters the structure of the database
  3. DROP - delete objects from the database
  4. TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed
  5. COMMENT - add comments to the data dictionary
  6. RENAME - rename an object

Data Manipulation Language (DML):~ statements are used for managing data within schema objects.
  1. SELECT - retrieve data from the a database
  2. INSERT - insert data into a table
  3. UPDATE - updates existing data within a table
  4. DELETE - deletes all records from a table, the space for the records remain
  5. MERGE - UPSERT operation (insert or update)
  6. CALL - call a PL/SQL or Java subprogram
  7. EXPLAIN PLAN - explain access path to data
  8. LOCK TABLE - control concurrency

Data Control Language (DCL): ~is used to control the data between different user accounts.
  1. GRANT - gives user's access privileges to database
  2. REVOKE - withdraw access privileges given with the GRANT command

Transaction Control (TCL): ~ is used to manage the changes made by DML statements. It allows statements to be grouped together into logical transactions.
  1. COMMIT - save work done
  2. SAVEPOINT - identify a point in a transaction to which you can later roll back
  3. ROLLBACK - restore database to original since the last COMMIT
  4. SET TRANSACTION - Change transaction options like isolation level and what rollback segment to use

Keys in Database

Primary key:-  The attribute or combination of attributes
that uniquely identifies a row or record.

Foreign Key:- an attribute or combination of attribute in a
table whose value match a primary key in another table.

Composite key:- A primary key that consistsof two or more
attributes is known as composite key

candidate key:- is a column in a table which has the
ability to become a primary key.

Alternate Key:- Any of the candidate keys that is not part
of the primary key is called an alternate key.

বৃহস্পতিবার, ৫ জানুয়ারী, ২০১২

Top 15 Open source alternative to Microsoft products

Operating System Windows Ubuntu
Email Server Exchange Server Zimbra
Email Client Outlook Thunderbird
Browser Internet Explorer Firefox / Chrome
Directory Service / Identity Management Active Directory Open LDAP
Database SQL Server MySQL
Enterprise Search Fast Solr
Office Suite MS Office Open office / LibreOffice
Source code Management Visual source safe / Team foundation Git / Subversion
Web browser IIS Apache
Integrated Development Environment Visual studio Eclipse / Netbeans
Mobile OS Windows Mobile Android
Media player Windows Media Player VLC Media player / Zinf
UML and Network diagram tools Visio Dia / Star UML
Enterprise Content Management System Sharepoint Alfresco / Liferay

Java Final Keyword

  • A java variable can be declared using the keyword final. Then the final variable can be assigned only once.
  • A variable that is declared as final and not initialized is called a blank final variable. A blank final variable forces the constructors to initialise it.
  • Java classes declared as final cannot be extended. Restricting inheritance!
  • Methods declared as final cannot be overridden. In methods private is equal to final, but in variables it is not.
  • final parameters – values of the parameters cannot be changed after initialization. Do a small java exercise to find out the implications of final parameters in method overriding.
  • Java local classes can only reference local variables and parameters that are declared as final.
  • A visible advantage of declaring a java variable as static final is, the compiled java class results in faster performance.