<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Tech Passion</title>
	<atom:link href="http://techpassion.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://techpassion.wordpress.com</link>
	<description>Articles, Tutorials, Interview Questions on Java, J2EE, Open Source Java Frameworks (Struts, Struts2, Spring, Hibernate, MyFaces), Javascript Libraries, CSS</description>
	<lastBuildDate>Thu, 16 Jul 2009 01:39:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='techpassion.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Tech Passion</title>
		<link>http://techpassion.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://techpassion.wordpress.com/osd.xml" title="Tech Passion" />
	<atom:link rel='hub' href='http://techpassion.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Java Collection Questions</title>
		<link>http://techpassion.wordpress.com/2009/07/13/java-collection-questions/</link>
		<comments>http://techpassion.wordpress.com/2009/07/13/java-collection-questions/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 01:13:07 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[Core Java]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://techpassion.wordpress.com/?p=111</guid>
		<description><![CDATA[1.) What are the differences between ArrayList and LinkedList? Answer An ArrayList is a List implementation backed by a Java array, similar to the Vector class. As the number of elements in the collection increases, the internal array grows to fit them. If there are lots of growth periods, performance degrades as the old array [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techpassion.wordpress.com&amp;blog=5988916&amp;post=111&amp;subd=techpassion&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-family:Verdana,Arial,Helvetica;font-size:x-small;"><strong>1.) What are the differences between ArrayList and LinkedList? </strong></span></p>
<p><span style="font-family:Verdana,Arial,Helvetica;font-size:x-small;"> <strong>Answer</strong> </span><br />
<span style="font-family:Verdana,Arial,Helvetica;font-size:x-small;"> An ArrayList is a List implementation backed by a Java array, similar to the Vector class. As the number of elements in the collection increases, the internal array grows to fit them. If there are lots of growth periods, performance degrades as the old array needs to be copied into the new array. However, random access is very quick as it uses an array index to access.</span></p>
<p><span style="font-family:Verdana,Arial,Helvetica;font-size:x-small;"> With a LinkedList, the List implementation is backed by a doubly linked list data structure, allowing easy inserts/deletions anywhere in the structure, but really slow random accesses as the access must start at an end to get to the specific position.</span></p>
<p><span style="font-family:Verdana,Arial,Helvetica;font-size:x-small;">Which you use really depends on the type of operations you need to support. </span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/techpassion.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/techpassion.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/techpassion.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/techpassion.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/techpassion.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/techpassion.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/techpassion.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/techpassion.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/techpassion.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/techpassion.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/techpassion.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/techpassion.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/techpassion.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/techpassion.wordpress.com/111/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techpassion.wordpress.com&amp;blog=5988916&amp;post=111&amp;subd=techpassion&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://techpassion.wordpress.com/2009/07/13/java-collection-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9eea02dca209112818f5a9ee1f48cb3e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Admin</media:title>
		</media:content>
	</item>
		<item>
		<title>Garbage collection tuning in Java 5.0</title>
		<link>http://techpassion.wordpress.com/2009/06/03/garbage-collection-tuning-in-java-5-0-is-a-breath-of-fresh-air-by-peter-v-mikhalenko/</link>
		<comments>http://techpassion.wordpress.com/2009/06/03/garbage-collection-tuning-in-java-5-0-is-a-breath-of-fresh-air-by-peter-v-mikhalenko/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 17:22:07 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[Core Java]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://techpassion.wordpress.com/?p=105</guid>
		<description><![CDATA[Takeaway: Garbage collection can become a bottleneck in different applications depending on the requirements of the applications. Peter V. Mikhalenko offers a review of Java 5.0 capabilities in the tuning of garbage collection, and explains how you can minimize the impact of garbage collection.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techpassion.wordpress.com&amp;blog=5988916&amp;post=105&amp;subd=techpassion&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Written by Peter V. Mikhalenko<br />
Peter V. Mikhalenko is a Sun certified professional who works for Deutsche Bank as business consultant.</p>
<p>Memory management is a major factor that affects software application performance. More time is usually spent allocating and deallocating memory than performing actual data computation.</p>
<p>While C++ offers direct control over when memory is allocated and freed up, Java attempts to abstract memory management by using garbage collection to reclaim memory that the program no longer needs. However, the &#8220;pause&#8221; associated with garbage collection has been the central argument against using Java when real-time performance is required.</p>
<p>Garbage collection is typically a periodic process that pauses normal program execution to analyze object references and reclaim memory that was allocated but can no longer be accessed by reference. In large Java applications, the pause for garbage collection can last several seconds, which is enough time to disrupt any type of real-time communication or control system.</p>
<p>Consequently, the memory abstraction provided by garbage collection requires some developers to think more carefully about memory management. Even though Java does not provide the same level of control over memory deallocations as C++, programming patterns can still make a huge difference in the memory performance of Java applications.</p>
<p>In this article, I will briefly review Java 5.0 capabilities in the tuning of garbage collection.<br />
Principles of garbage collection in Java 5.0</p>
<p>The goal of a new Java 1.5 feature called ergonomics is to provide good performance from the JVM with a minimum of command-line tuning. Ergonomics attempts to match the best selection of proper garbage collector, heap size, and runtime compiler for an application.</p>
<p>When does the choice of a garbage collector matter to the user? For many applications, it doesn&#8217;t matter. That is, the application can perform within its specifications in the presence of garbage collection with pauses of modest frequency and duration. An example where this is not the case would be a large application that scales well to a large number of threads, processors, sockets, and a lot of memory.</p>
<p>An object is considered garbage when it can no longer be reached from any pointer in the running program. The most straightforward garbage collection algorithms simply iterate over every reachable object. Any objects left over are then considered garbage. The time this approach takes is proportional to the number of live objects, which is prohibitive for large applications maintaining lots of live data.</p>
<p>Starting with Java 2, the virtual machine incorporated a number of different garbage collection algorithms that are combined using generational collection. While naive garbage collection examines every live object in the heap, generational collection exploits several empirically observed properties of most applications to avoid extra work. The most important of these observed properties is so-called infant mortality. There are a plenty of objects that &#8220;have died&#8221; soon after being allocated. Iterator objects, for example, are often alive for the duration of a single loop. To optimize for this scenario, memory is managed in generations, or memory pools holding objects of different ages. Garbage collection occurs in each generation when the generation fills up. Objects are allocated in a generation for younger objects or the young generation, and most objects die there because of infant mortality.</p>
<p>If the garbage collector has become a bottleneck, you may wish to customize the generation sizes. Check the verbose garbage collector output, and then explore the sensitivity of your individual performance metric to the garbage collector parameters.</p>
<p>At initialization, a maximum address space is virtually reserved but not allocated to physical memory unless it is needed. The complete address space reserved for object memory can be divided into the young and tenured generations. The young generation consists of eden plus two survivor spaces. Objects are initially allocated in eden. One survivor space is empty at any time and serves as a destination of the next, copying collection of any live objects in eden and the other survivor space. Objects are copied between survivor spaces in this way until they are old enough to be tenured, or copied to the tenured generation. A third generation closely related to tenured is the permanent generation. This generation is special because it holds data needed by the virtual machine to describe objects that do not have an equivalent at the Java language level. For example, objects describing classes and methods are stored in the permanent generation.<br />
Performance considerations</p>
<p>There are two metrics of performance of a Java application (and garbage collection in particular): throughput and pauses. Throughput is the percentage of total time not spent in garbage collection, considered over long periods of time. Throughput includes time spent in allocation (but tuning for speed of allocation is generally not needed). Pauses are the times when an application appears unresponsive because garbage collection is occurring.</p>
<p>Some users are sensitive to other considerations as well. For instance, footprint is the working set of a process, measured in pages and cache lines. On systems with limited physical memory or many processes, footprint may dictate scalability. Promptness is the time between when an object becomes dead and when the memory becomes available; this is an important consideration for distributed systems, including remote method invocation (RMI).</p>
<p>In general, a particular generation sizing chooses a trade off between these considerations. For example, a very large young generation may maximize throughput, but it does so at the expense of footprint, promptness, and pause times. You can minimize young generation pauses by using a small young generation at the expense of throughput.</p>
<p>When you want to improve the performance of your application with larger numbers of processors, you should use the throughput collector. You can enable the throughput collector by using the command-line flag -XX:+UseParallelGC. You can control the number of garbage collector threads with the ParallelGCThreads command-line option -XX:ParallelGCThreads=. The maximum pause time goals are specified with the command-line flag -XX:MaxGCPauseMillis=. This is interpreted as a hint to the throughput collector that pause times of  milliseconds or less are desired. There are plenty of generation sizes adjustment options such as -XX:YoungGenerationSizeIncrement= for the young generation and -XX:TenuredGenerationSizeIncrement= for the tenured generation.</p>
<p>If your application would benefit from shorter garbage collector pauses and can afford to share processor resources with the garbage collector when the application is running, I suggest using the concurrent low pause collector. A concurrent collection will start if the occupancy of the tenured generation grows above the initiating occupancy (i.e., the percentage of the current heap that is used before a concurrent collection is started). The initiating occupancy by default is set to about 68%. You can set it with the parameter -XX:CMSInitiatingOccupancyFraction= where  is a percentage of the current tenured generation size. You can use the concurrent collector in a mode in which the concurrent phases are done incrementally. This mode (referred to here as &#8220;i-cms&#8221;) divides the work done concurrently by the collector into small chunks of time, which are scheduled between young generation collections. This feature is useful when applications that need the low pause times provided by the concurrent collector are run on machines with small numbers of processors.<br />
Fine-tuning garbage collection</p>
<p>The command-line argument -verbose:gc prints information at every collection. If it is switched on, you will see similar output at every garbage collection. For example:</p>
<p>[GC 325407K-&gt;83000K(776768K), 0.2300771 secs] </p>
<p>[GC 325816K-&gt;83372K(776768K), 0.2454258 secs] </p>
<p>[Full GC 267628K-&gt;83769K(776768K), 1.8479984 secs]</p>
<p>There are two minor collections and one major one (Full GC). The flag -XX:+PrintGCDetails prints additional information about the collections. The flag -XX:+PrintGCTimeStamps will additionally print a timestamp at the start of each collection. Listing A is what you will see when both flags are set.</p>
<p>Additionally, the information is shown for a major collection delineated by Tenured. The tenured generation usage was reduced here to about 10% and took approximately 0.13 seconds.</p>
<p>A number of parameters affect generation size. At initialization of the virtual machine, the entire space for the heap is reserved. You can specify the size of the space reserved with the -Xmx option. If the value of the -Xms parameter is smaller than the value of the -Xmx parameter, not all of the reserved space is immediately committed to the virtual machine. The different parts of the heap (permanent generation, tenured generation, and young generation) can grow to the limit of the virtual space as needed.</p>
<p>By default, the virtual machine grows or shrinks the heap at each collection to try to keep the proportion of free space to live objects at each collection within a specific range. This target range is set as a percentage by the parameters -XX:MinHeapFreeRatio= and -XX:MaxHeapFreeRatio=, and the total size is bounded below by -Xms and above by -Xmx. Unless you have problems with pauses, try granting as much memory as possible to the virtual machine. The default size (64MB) is often too small. You can find descriptions of other VM options on Sun&#8217;s Web site.</p>
<p>You can also set a proportion of the heap dedicated to the young generation. The bigger the young generation, the less often minor collections occur. However, for a bounded heap size, a larger young generation implies a smaller tenured generation, which will increase the frequency of major collections. The optimal choice depends on the lifetime distribution of the objects allocated by the application. The young generation size is controlled by NewRatio. For example, setting -XX:NewRatio=3 means that the ratio between the young and tenured generation is 1:3. If desired, the parameter SurvivorRatio can be used to tune the size of the survivor spaces, but this is often not as important for performance. For example, -XX:SurvivorRatio=6 sets the ratio between each survivor space and eden to 1:6. Unless you find problems with excessive major collection or pause times, grant plenty of memory to the young generation.</p>
<p>Java 5.0 has implemented three different garbage collectors. The throughput collector uses a parallel version of the young generation collector. It is used if the -XX:+UseParallelGC option is passed on the command line. The concurrent low pause collector is used if the -Xincgc or -XX:+UseConcMarkSweepGC option is passed on the command line. In this case, the application is paused for short periods during the collection. The incremental low pause collector is used only if -XX:+UseTrainGC is passed on the command line. It will not be supported in future releases, but if you want more information, please see Sun&#8217;s documentation on using this collector. (Note: Do not use -XX:+UseParallelGC with -XX:+UseConcMarkSweepGC.)<br />
Conclusion</p>
<p>Garbage collection can become a bottleneck in different applications depending on the requirements of the applications. By understanding the requirements of the application and the garbage collection options, it is possible to minimize the impact of garbage collection.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/techpassion.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/techpassion.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/techpassion.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/techpassion.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/techpassion.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/techpassion.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/techpassion.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/techpassion.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/techpassion.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/techpassion.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/techpassion.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/techpassion.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/techpassion.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/techpassion.wordpress.com/105/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techpassion.wordpress.com&amp;blog=5988916&amp;post=105&amp;subd=techpassion&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://techpassion.wordpress.com/2009/06/03/garbage-collection-tuning-in-java-5-0-is-a-breath-of-fresh-air-by-peter-v-mikhalenko/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9eea02dca209112818f5a9ee1f48cb3e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Admin</media:title>
		</media:content>
	</item>
		<item>
		<title>Difference between Struts and Struts2(Webwork + Struts)</title>
		<link>http://techpassion.wordpress.com/2009/06/02/difference-between-struts-and-struts2webwork-struts/</link>
		<comments>http://techpassion.wordpress.com/2009/06/02/difference-between-struts-and-struts2webwork-struts/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 23:45:22 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[Struts Framework]]></category>
		<category><![CDATA[Struts]]></category>
		<category><![CDATA[Struts2]]></category>

		<guid isPermaLink="false">http://techpassion.wordpress.com/?p=95</guid>
		<description><![CDATA[1.  Servlet Dependency: Actions in Struts1 have dependencies on the servlet API since the HttpServletRequest and HttpServletResponse objects are passed to the execute method when an Action is invoked but in case of Struts 2, Actions are not container dependent because they are made simple POJOs. In struts 2, the servlet contexts are represented as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techpassion.wordpress.com&amp;blog=5988916&amp;post=95&amp;subd=techpassion&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>1.  Servlet Dependency:</strong><br />
Actions in Struts1 have dependencies on the servlet API since the HttpServletRequest and HttpServletResponse objects are passed to the execute method when an Action is invoked but in case of Struts 2, Actions are not container dependent because they are made simple POJOs. In struts 2, the servlet contexts are represented as simple Maps which allows actions to be tested in isolation. Struts 2 Actions can access the original request and response, if required. However, other architectural elements reduce or eliminate<br />
the need to access the HttpServetRequest or HttpServletResponse directly.</p>
<p><strong>2.  Action classes</strong><br />
Programming the abstract classes instead of interfaces is one of design issues of struts1 framework that has been resolved in the struts 2 framework. Struts1 Action classes needs to extend framework dependent abstract base class. But in case of Struts 2 Action class may or may not implement interfaces to enable optional and custom services. In case of Struts 2 , Actions are not container dependent because they are made simple POJOs. Struts 2 provides a base ActionSupport class to implement commonly used interfaces. Albeit, the Action interface is<br />
not required. Any POJO object with an execute signature can be used as an Struts 2 Action object.<br />
<strong></strong></p>
<p><strong>3.  Validation</strong></p>
<p>Struts1 and Struts 2 both supports the manual validation via a validate method. Struts1 uses validate method on the ActionForm, or validates through an extension to the Commons Validator. However, Struts 2 supports manual validation via the validate method and the XWork Validation framework. The Xwork Validation Framework supports chaining validation into sub-properties using the validations defined for the<br />
properties class type and the validation context.</p>
<p><strong><br />
4.  Threading Model</strong><br />
In Struts1, Action resources must be thread-safe or synchronized. So Actions are singletons and thread-safe, there should only be one instance of a class to handle all requests for that Action. The singleton strategy places restrictions on what can be done with Struts1 Actions and<br />
requires extra care to develop. However in case of Struts2, Action objects are instantiated for each request, so there are no thread-safety issues. (In practice, servlet containers generate many throw-away objects per request, and one more object does not impose a performance penalty<br />
or impact garbage collection.)</p>
<p><strong><br />
5.  Testability</strong><br />
Testing Struts1 applications are a bit complex. A major hurdle to test Struts1 Actions is that the execute method because it exposes the Servlet API. A third-party extension, Struts TestCase, offers a set of mock object for Struts1. But the Struts 2 Actions can be tested by instantiating the Action, setting properties and invoking methods. Dependency Injection support also makes testing simpler. Actions in struts2 are simple POJOs and are framework independent,  hence testability is quite easy in struts2.<br />
<strong></strong></p>
<p><strong>6.  Harvesting Input</strong><br />
Struts1 uses an ActionForm object to capture input. And all ActionForms needs to extend a framework dependent base class. JavaBeans cannot be used as ActionForms, so the developers have to create redundant classes to capture input. However Struts 2 uses Action properties (as input<br />
properties independent of underlying framework) that eliminates the need for a second input object, hence reduces redundancy. Additionally in struts2, Action properties can be accessed from the web page via the taglibs. Struts 2 also supports the ActionForm pattern, as well as POJO form objects and POJO Actions. Even rich object types, including business or domain objects, can be used as input/output objects.</p>
<p><strong><br />
7.  Expression Language</strong><br />
Struts1 integrates with JSTL, so it uses the JSTL-EL. The struts1 EL has basic object graph traversal, but relatively weak collection and indexed property support. Struts 2 can also use JSTL, however it supports a more powerful and flexible expression language called &#8220;Object Graph Notation Language&#8221; (OGNL).<br />
<strong></strong></p>
<p><strong>8.  Binding values into views</strong><br />
In the view section, Struts1 uses the standard JSP mechanism to bind objects (processed from the model section) into the page context to access. However Struts 2 uses a &#8220;ValueStack&#8221; technology so that the taglibs can access values without coupling your view to the object type it is rendering. The ValueStack strategy allows the reuse of views across a range of types which may have the same property name but different property types.<br />
<strong></strong></p>
<p><strong>9.  Type Conversion</strong><br />
Usually, Struts1 ActionForm properties are all Strings. Struts1 uses Commons-Beanutils for type conversion. These type converters are per-class and not configurable per instance. However Struts 2 uses OGNL for type conversion. The framework includes converters for basic and common<br />
object types and primitives.<br />
<strong></strong></p>
<p><strong>10.  Control Of Action Execution</strong><br />
Struts1 supports separate Request Processor (lifecycles) for each module, but all the Actions in a module must share the same lifecycle. However Struts 2 supports creating different lifecycles on a per Action basis via Interceptor Stacks. Custom stacks can be created and used with<br />
different Actions as needed.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/techpassion.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/techpassion.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/techpassion.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/techpassion.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/techpassion.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/techpassion.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/techpassion.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/techpassion.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/techpassion.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/techpassion.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/techpassion.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/techpassion.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/techpassion.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/techpassion.wordpress.com/95/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techpassion.wordpress.com&amp;blog=5988916&amp;post=95&amp;subd=techpassion&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://techpassion.wordpress.com/2009/06/02/difference-between-struts-and-struts2webwork-struts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9eea02dca209112818f5a9ee1f48cb3e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Admin</media:title>
		</media:content>
	</item>
		<item>
		<title>SOA interview questions</title>
		<link>http://techpassion.wordpress.com/2009/06/02/soa-interview-questions/</link>
		<comments>http://techpassion.wordpress.com/2009/06/02/soa-interview-questions/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 23:21:03 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[SOA ESB Web Services]]></category>
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://techpassion.wordpress.com/?p=92</guid>
		<description><![CDATA[What are the main benefits of SOA ? SOA helps create greater alignment between IT and line of business while generating more flexibility - IT flexibility to support greater business flexibility. Your business processes are changing faster and faster and global competition requires the flexibility that SOA can provide. SOA can help you get better [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techpassion.wordpress.com&amp;blog=5988916&amp;post=92&amp;subd=techpassion&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong><span style="font-size:12px;"><span style="font-family:Verdana;"><span style="color:#ff0000;">What are the main benefits of SOA ?<br />
</span></span></span></strong><span style="font-size:12px;"><span style="font-family:Verdana;"><br />
SOA helps create greater alignment between IT and line of business while generating more <strong>flexibility </strong>- IT flexibility to support greater business flexibility. Your business processes are changing faster and faster and global competition requires the flexibility that SOA can provide.<br />
SOA can help you get better reuse out of your existing IT investments as well as the new services you&#8217;re developing today. SOA makes integration of your IT investments easier by making use of well-defined interfaces between services. SOA also provides an architectural model for integrating business partners’, customers’ and suppliers’ services into an enterprise’s business processes. This reduces cost and improves customer satisfaction</span></span></p>
<p><span style="font-size:12px;"><span style="font-family:Verdana;"><span style="color:#ff0000;"><strong>What is a reusable Service?</p>
<p></strong></span>It is an autonomous, reusable, discoverable, stateless functionality that has the necessary granularity, and can be part of a composite application or a composite service.<br />
A reusable service should be identified with a business activity described by the service specifications (<strong>design-time contract</strong>).</p>
<p>A service&#8217;s constraints, including security, QoS, SLA, usage policies, may be defined by multiple run-time contracts, multiple interfaces (the WSDL for a SOAP Web Service), and multiple implementations (the code).</p>
<p>A reusable service should be governed at the enterprise level throughout its entire lifecycle, from design-time through run-time. Its reuse should be promoted through a prescriptive process, and that reuse should be measured.</span></span></p>
<p><span style="font-size:12px;"><span style="font-family:Verdana;"><span style="color:#ff0000;"><strong>Talking about Service identification, which approach between top-down and bottom-up methodologies encourages re-use and mantainance ?</p>
<p></strong></span>Since the <strong>top-down approach is business-driven </strong>it can be practical to separate the different concerns of business and IT on different plans, providing a common ground in between. So in most situations it the most appropriate if you want to improve reuse and ROI in the medium/long term. Anyway </span></span></p>
<p><span style="font-size:12px;"><span style="font-family:Verdana;"><strong><span style="color:#ff0000;">How can you achieve loose coupling in a soa ?<br />
</span></strong><br />
One strategy for achieving loose coupling is to use the service interface (the WSDL for a SOAP Web Service) to limit this dependency, <strong>hiding the service implementation from the consumer</strong>. Loose coupling can be addressed by encapsulating the service functionalities in a manner that limits the impact of changes to the implementation on the service interface. However, at some point you will need to change the interface and manage versioning without impacting service consumers, in addition to managing multiple security constraints, multiple transports, and other considerations</span></span></p>
<p><span style="font-size:12px;"><span style="font-family:Verdana;"><strong><span style="color:#ff0000;">Do you recall any pattern which could be use to leverage loose coupling ?<br />
</span><br />
</strong>The <strong>Mediation </strong>pattern, using an enterprise service bus (ESB), will help in achieving this.<br />
Mediation will take loose coupling to the highest level. It will establish independence between consumers and providers on all levels, including message formats, message types (including SOAP, REST, XML, binary) and transport protocols (including HTTP, HTTPS, JMS).<br />
Architecturally speaking this means the separation of concerns between consumers and providers on the transport, message type, and message format levels. </span></span></p>
<p><span style="font-size:12px;"><span style="font-family:Verdana;"><span style="color:#ff0000;"><strong>The Service of a SOA should be engineered as stateless or stateful ?<br />
</strong></span><br />
Service should be <strong>stateless</strong>. It may have a context within its stateless execution, but it will not have an intermediary state waiting for an event or a call-back. The retention of state-related data must not extend beyond a request/response on a service. This is because state management consumes a lot of resources, and this can affect the scalability and availability that are required for a reusable service.</span></span></p>
<p><span style="font-size:12px;"><span style="font-family:Verdana;"><span style="color:#ff0000;"><strong>What is composition of a Service ?</p>
<p></strong></span>Composition is the process by which <strong>services are combined to produce composite applications or composite services</strong>. A composite application consists of the aggregation of services to produce an enterprise portal or enterprise process. A composite service consists of an aggregation of services that produces another reusable service. It&#8217;s just like combining electronic components to create a computer motherboard, and then using that motherboard in a computer. Think of the motherboard as a reusable composite service that is a component of the computer, and of the computer as the composite application. </span></span></p>
<p><span style="font-size:12px;"><span style="font-family:Verdana;"><span style="color:#ff0000;"><strong>How do I integrate my Legacy applications with SOA ?<br />
</strong></span><br />
Legacy applications are frequently at the core of your IT environment. With the right skills and tools, you need to identify discrete elements within your legacy applications and &#8220;wrap&#8221; them in standards-based interfaces and use them as services within your SOA. </span></span></p>
<p><span style="font-size:12px;"><span style="font-family:Verdana;"><span style="color:#ff0000;"><strong>How does the ESB fits in this picture ?<br />
</strong></span><br />
The Enterprise Service Bus is a core element of any SOA. ESBs provide the &#8220;any to any&#8221; connectivity between services within your own company, and beyond your business to connect to your trading partners. But SOA does not stop at just implementing an ESB. Depending on what your goals are, you may want to use an ESB to connect other services within your SOA such as information services, interaction services and business process management services. Additionally, you will need to consider development services and IT service management services. The SOA reference architecture can help you lay out an SOA environment that meets your needs and priorities. The ESB is part of this reference architecture and provides the backbone of an SOA but it should not be considered an SOA by itself.</span></span></p>
<p><strong><span style="font-size:12px;"><span style="font-family:Verdana;"><span style="color:#ff0000;">What are the common pitfalls of SOA ?<br />
</span></span></span></strong><span style="font-size:12px;"><span style="font-family:Verdana;"><br />
One of the most common pitfalls is to view SOA as an end, rather than a means to an end. Developers who focus on building an SOA solution rather than solving a specific business problem are more likely to create complex, unmanageable, and unnecessary interconnections between IT resources.</span></span></p>
<p><span style="font-size:12px;"><span style="font-family:Verdana;">Another common pitfall is to try to solve multiple problems at once, rather than solving small pieces of the problem. Taking a top-down approach—starting with major organization-wide infrastructure investments—often fails either to show results in a relevant timeframe or to offer a compelling return on investment. </span></span></p>
<h2><span style="font-size:12px;"><span style="font-family:Verdana;"><span style="color:#ff0000;"><strong>What&#8217;s the difference between services and components?</strong></span></span></span></h2>
<p><span style="font-size:12px;"><span style="font-family:Verdana;">Services are logical grouping of components to achieve business functionality. Components are implementation approaches to make a service. The components can be in JAVA, C#, C++ but the services will be exposed in a general format like Web Services. </span></span></p>
<h2><span style="font-size:12px;"><span style="font-family:Verdana;"><span style="color:#ff0000;"><strong>What are ends, contract, address, and bindings?</strong></span></span></span></h2>
<p><span style="font-size:12px;"><span style="font-family:Verdana;">These three terminologies on which SOA service stands. Every service must expose one or more ends by which the service can be available to the client. End consists of three important things where, what and how:-</span></span></p>
<p><span style="font-size:12px;"><span style="font-family:Verdana;"><strong>Contract</strong> is an agreement between two or more parties. It defines the protocol how client should communicate with your service. Technically, it describes parameters and return values for a method. </span></span></p>
<p><span style="font-size:12px;"><span style="font-family:Verdana;">An <strong>Address</strong> indicates where we can find this service. Address is a URL, which points to the location of the service. </span></span></p>
<p><span style="font-size:12px;"><span style="font-family:Verdana;"><strong>Bindings</strong> determine how this end can be accessed. It determines how communications is done. For instance, you expose your service, which can be accessed using SOAP over HTTP or BINARY over TCP. So for each of these communications medium two bindings will be created.<br />
Below figure, show the three main components of end. You can see the stock ticker is the service class, which has an end hosted on </span></span><a href="http://www.soa.com/"><span style="font-size:12px;"><span style="font-family:Verdana;">www.soa.com</span></span></a><span style="font-size:12px;"><span style="font-family:Verdana;"> with HTTP and TCP binding support and using Stock Ticker interface type.</span></span></p>
<h2><img src="http://www.mastertheboss.com/images/stories/esb/soa1.jpg" border="0" alt="soa interview questions" /></h2>
<p><span style="font-size:12px;"><span style="font-family:Verdana;"><span style="color:#ff0000;"><strong>The concept of SOA is nothing new, however why everyone started to talk about SOA only in the last years ?</p>
<p></strong></span>Yes I agree the basic concept of SOA aren&#8217;t new, however some technology technology changes in the last 10 years made service-oriented architecture more practical and applicable to more organizations than it was previously. Among this:</span></span></p>
<ul>
<li><span style="font-size:12px;"><span style="font-family:Verdana;">Universally-accepted industry standards such as XML, its many variants, and Web-services standards have contributed to the renewed interest in SOA.<br />
</span></span></li>
<li><span style="font-size:12px;"><span style="font-family:Verdana;">Data governance frameworks, which are important to a successful SOA implementation, have well test and refined over the years.<br />
</span></span></li>
<li><span style="font-size:12px;"><span style="font-family:Verdana;">A variety of enabling technologies and tools (e.g., modeling, development, infrastructure/middleware, management, and testing) have matured.<br />
</span></span></li>
</ul>
<p><span style="font-size:12px;"><span style="font-family:Verdana;">Understanding of business and business strategies has grown, shifting attention from technology to the people, cultural changes, and process that are key business success factors.</p>
<p><span style="color:#ff0000;"><strong>What is the most important skill you need to adopt SOA ? technical or cultural ?<br />
</strong></span><strong><br />
Surely cultural</strong>. SOA does require people to think of business and technology differently. Instead of thinking of technology first (e.g., If we implement this system, what kinds of things can we do with it?), practitioners must first think in terms of business functions, or services (e.g., My company does these business functions, so how can I set up my IT system to do those things for me most efficiently?).It is expected that adoption of SOA will change business IT departments, creating service-oriented (instead of technology-oriented) IT organizations. </span></span></p>
<h2><span style="font-size:12px;"><span style="font-family:Verdana;"><span style="color:#ff0000;"><strong>Is SOA really needed on your opinion?</strong></span></span></span></h2>
<p><span style="font-size:12px;"><span style="font-family:Verdana;">SOA is not for everyone. While SOA delivers significant benefits and cost savings, SOA does require disciplined enforcement of centralized governance principals to be successful. For some organizations, the cost of developing and enforcing these principals may be higher than the benefits realized, and therefore not a sound initiative.</span></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/techpassion.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/techpassion.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/techpassion.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/techpassion.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/techpassion.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/techpassion.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/techpassion.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/techpassion.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/techpassion.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/techpassion.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/techpassion.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/techpassion.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/techpassion.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/techpassion.wordpress.com/92/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techpassion.wordpress.com&amp;blog=5988916&amp;post=92&amp;subd=techpassion&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://techpassion.wordpress.com/2009/06/02/soa-interview-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9eea02dca209112818f5a9ee1f48cb3e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Admin</media:title>
		</media:content>

		<media:content url="http://www.mastertheboss.com/images/stories/esb/soa1.jpg" medium="image">
			<media:title type="html">soa interview questions</media:title>
		</media:content>
	</item>
		<item>
		<title>JBoss Seam tutorial</title>
		<link>http://techpassion.wordpress.com/2009/06/02/jboss-seam-tutorial/</link>
		<comments>http://techpassion.wordpress.com/2009/06/02/jboss-seam-tutorial/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 23:15:26 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[JBoss Seam Framework]]></category>
		<category><![CDATA[JBossSeam]]></category>

		<guid isPermaLink="false">http://techpassion.wordpress.com/?p=90</guid>
		<description><![CDATA[To be useful, your application has to be a multitiered application that uses specific components for the presentation, business, and persistence tiers. If you have already developed one multitiered application you know that lots of time is devoted to writing lots of &#8220;glue&#8221; code in order to connect your tier. Starting from the presentation layer, in your [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techpassion.wordpress.com&amp;blog=5988916&amp;post=90&amp;subd=techpassion&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-family:Tahoma;">To be useful, your application has to be a multitiered application that uses specific components for the presentation, business, and persistence tiers.<br />
If you have already developed one multitiered application you know that lots of time is devoted to writing lots of &#8220;glue&#8221; code in order to connect your tier. </span><br />
<span style="font-size:12px;"><span style="font-family:Tahoma;">Starting from the presentation layer, in your forms  you&#8217;ll reference your JSF Beans, your JSF Beans will  in turn reference your Business classes, your Business classes will call your EJB maybe passing some wrapper Java Bean classes, your EJB will finally reach your DAO layer and do datapersistence.</p>
<p>So how can <strong>JBoss Seam </strong>help me ? I guess you already have asked yourself: why cannot I reference my EJB directly from my JSP page ?</p>
<p>Let me tell you, Seam it&#8217;s not only about this, but the same way when you want to conquer a location in a battle you need a bridgehead, so that&#8217;s your bridgehead.<br />
Imagine how beatiful would be if in your JSP form you could reference directly your Entity Beans field, you push &#8220;Submit&#8221; and the data goes straight on the DB.<br />
Imagine next if you need to query the data, simply reference your Session Bean doQuery Method. </span></span></p>
<p><span style="font-size:12px;"><span style="font-family:Tahoma;">Seam achieves this by eliminating the need for &#8220;plumbing&#8221; code. Essentially, we are allowing Seam to handle the plumbing and to have the business logic interact with the JSF pages themselves. One of the nice things about Seam is that even if you already have code you want to use, you will be able to<br />
keep your existing EJBs and JSF pages, thus being able to maintain a mixed environment if you choose.</span></span></p>
<p><span style="font-size:12px;"><span style="font-family:Tahoma;"><img src="http://www.mastertheboss.com/images/emo/what.png" alt="jboss seam tutorial" align="right" />How can Seam do it ? to keep it simple, Seam <strong>uses Interceptors</strong> at all layer levels. By using  interceptors you&#8217;re allowed to use Seam specific annotations into already-existing classes. This will cut drammatically the time needed to develop &#8220;glue&#8221; code and leaving more time to spend actually developing the business functionality.</span></span></p>
<p><span style="font-size:12px;"><span style="font-family:Tahoma;"></p>
<p>So let&#8217;s get how hands dirty, first of all download Seam from the distribution:</span></span></p>
<p><a href="http://www.seamframework.org/Download">http://www.seamframework.org/Download</a></p>
<p><span style="font-family:Tahoma;">In this release we will use the stable 2.0.3 CR1 release. Now let&#8217;s see first in detail how to configure Seam Listeners.</span></p>
<h2>I ) web.xml &#8211; <span style="color:#ff0000;">Seam Servlet Listener</span></h2>
<p><span style="font-family:Tahoma;">In order to initialize the Seam core services and to correctly manage some Seam contexts that are in common with standard web container contexts, you have to install the Seam servlet listener in your web.xml deployment descriptor:</span><br />
<span style="color:#006600;"><span style="font-family:Courier New;">&lt;web-app&gt;<br />
. . .<br />
&lt;listener&gt;<br />
&lt;listener-class&gt;<strong><span style="color:#000000;">org.jboss.seam.servlet.SeamListener</span></strong>&lt;/listener-class&gt;<br />
&lt;/listener&gt;<br />
. . .<br />
&lt;/web-app&gt;</span></span><br />
Ok, that&#8217;s one, let&#8217;s go on.</p>
<h2>II ) faces-config.xml &#8211; <span style="color:#ff0000;">JSF Phase Listener</span></h2>
<p><span style="font-family:Tahoma;">At the heart of Seam&#8217;s component and context services is the Seam JSF phase listener. It receives events from the JSF runtime during request processing, allowing Seam to keep its various contexts in their proper state, among other things.</p>
<p>The Seam phase listener is installed in your <strong>faces-config.xml </strong>file:<br />
</span><br />
<span style="color:#006600;"><span style="font-family:Courier New;">&lt;faces-config&gt;<br />
. . .<br />
&lt;lifecycle&gt;<br />
&lt;phase-listener&gt;<strong><span style="color:#000000;">org.jboss.seam.jsf.SeamPhaseListener</span></strong>&lt;/phase-listener&gt;<br />
&lt;/lifecycle&gt;<br />
. . .<br />
&lt;/faces-config&gt;</span></span></p>
<h2>III ) ejb-jar.xml - <span style="color:#ff0000;">EJB Seam Interceptor</span></h2>
<p><span style="font-family:Tahoma;">The last tier that needs Seam glue is the EJB-tier. Here we&#8217;ll use the old  ejb-jar.xml. (Thought you got rid of it, isn&#8217;t it ?)  Here we just define SeamInterceptor for all the EJBs but of course you could choose to use it only for a subset of them.</span></p>
<p><span style="color:#006600;"><span><span style="font-family:Courier New;">&lt;ejb-jar&gt;<br />
. . .<br />
&lt;assembly-descriptor&gt;<br />
&lt;interceptors&gt;<br />
&lt;interceptor&gt;<br />
&lt;interceptor-class&gt;<br />
<strong><span style="color:#000000;">org.jboss.seam.ejb.SeamInterceptor</span></strong><br />
&lt;/interceptor-class&gt;<br />
&lt;/interceptor&gt;<br />
&lt;/interceptors&gt;<br />
&lt;interceptor-binding&gt;<br />
&lt;ejb-name&gt;*&lt;/ejb-name&gt;<br />
&lt;interceptor-class&gt;<br />
<strong><span style="color:#000000;">org.jboss.seam.ejb.SeamInterceptor</span><br />
</strong> &lt;/interceptor-class&gt;<br />
&lt;/interceptor-binding&gt;<br />
&lt;/assembly-descriptor&gt;<br />
. . .<br />
&lt;/ejb-jar&gt;</span></span></span></p>
<p><span style="font-family:Tahoma;">The Seam interceptor allows EJB components to be used as Seam components, by &#8220;plugging&#8221; them into the Seam component life cycle when you annotate your EJBs with the Seam @Name annotation.</span></p>
<h2>JNDI pattern : Seam&#8217;s components.xml</h2>
<p><span style="font-family:Tahoma;">In order for Seam to work  with the EJB container, you need to include an entry for Seam&#8217;s core initialization component, and this entry needs to include a setting for the JNDI pattern that Seam should use to find your application&#8217;s EJB components in the JNDI services of the application server.<br />
The following example shows how this setting is provided for the JBoss application<br />
server</span></p>
<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;<br />
&lt;components xmlns=&#8221;<a href="http://jboss.com/products/seam/components">http://jboss.com/products/seam/components</a>&#8220;<br />
xmlns:core=&#8221;<a href="http://jboss.com/products/seam/core">http://jboss.com/products/seam/core</a>&#8220;<br />
xmlns:xsi=&#8221;<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>&#8220;<br />
xsi:schemaLocation=<br />
&#8220;<a href="http://jboss.com/products/seam/core">http://jboss.com/products/seam/core</a> <a href="http://jboss.com/products/seam/core-2.0.xsd">http://jboss.com/products/seam/core-2.0.xsd</a><br />
<a href="http://jboss.com/products/seam/components">http://jboss.com/products/seam/components</a> <a href="http://jboss.com/products/seam/components-2.0.xsd">http://jboss.com/products/seam/components-2.0.xsd</a>&#8220;&gt;</p>
<p>&lt;core:init jndi-pattern=&#8221;@jndiPattern@&#8221;/&gt;</p>
<p>&lt;/components&gt;</p>
<h2>Seam Registration Example reloaded</h2>
<p><span style="font-family:Tahoma;">Here we&#8217;ll use on example application provided with Seam distribution but we&#8217;ll add a few additions to make it more interesting. The example is located under the &#8220;registration&#8221; example folder. Let&#8217;s start from the Home page, register.xhtml</span></p>
<p><span style="color:#006600;"> &lt;f:view&gt;<br />
&lt;h:form&gt;<br />
&lt;s:validateAll&gt;<br />
&lt;h:panelGrid columns=&#8221;2&#8243;&gt;<br />
<span style="color:#000000;">Username:</span> &lt;h:inputText <span style="color:#ff6600;">value</span>=&#8221;<span style="color:#0000ff;">#{user.username}</span>&#8221; <span style="color:#ff6600;">required</span>=&#8221;true&#8221;/&gt;<br />
<span style="color:#000000;">Real Name:</span> &lt;h:inputText <span style="color:#ff6600;">value</span>=&#8221;<span style="color:#0000ff;">#{user.name}</span>&#8221; <span style="color:#ff6600;">required</span>=&#8221;true&#8221;/&gt;<br />
<span style="color:#000000;">Password: </span>&lt;h:inputSecret <span style="color:#ff6600;">value</span>=&#8221;<span style="color:#0000ff;">#{user.password}</span>&#8221; <span style="color:#ff6600;">required</span>=&#8221;true&#8221;/&gt;<br />
&lt;/h:panelGrid&gt;<br />
&lt;/s:validateAll&gt;<br />
&lt;h:messages/&gt;<br />
&lt;h:commandButton value=&#8221;Register&#8221; <span style="color:#ff6600;">action</span>=&#8221;<span style="color:#0000ff;">#{register.registerUser}</span>&#8220;/&gt;<br />
&lt;/h:form&gt;<br />
&lt;/f:view&gt;</span></p>
<p><span style="font-family:Tahoma;">Well if you&#8217;re practical with JSF you&#8217;ll notice nothing strange except..how does JSF resolves the &#8220;user&#8221; and &#8220;register&#8221; fields ? You say in a configuration file ? wrong answer!. <strong>JBoss Seam</strong> uses , as well as EJB 3.0, a lot of annotations. Let&#8217;s see our User Entity Bean and you&#8217;ll understand better: </span></p>
<div>
<div>
<div><a href="http://www.mastertheboss.com/seam/63-jboss-seam-tutorial-1.html#">view plain</a><a href="http://www.mastertheboss.com/seam/63-jboss-seam-tutorial-1.html#">copy to clipboard</a><a href="http://www.mastertheboss.com/seam/63-jboss-seam-tutorial-1.html#">print</a><a href="http://www.mastertheboss.com/seam/63-jboss-seam-tutorial-1.html#">?</a></div>
</div>
<ol>
<li><span><span>package</span><span> org.jboss.seam.example.registration; </span></span></li>
<li><span> </span></li>
<li><span><span>import</span><span> </span><span>static</span><span> org.jboss.seam.ScopeType.SESSION; </span></span></li>
<li><span> </span></li>
<li><span><span>import</span><span> java.io.Serializable; </span></span></li>
<li><span> </span></li>
<li><span><span>import</span><span> javax.persistence.Entity; </span></span></li>
<li><span><span>import</span><span> javax.persistence.Id; </span></span></li>
<li><span><span>import</span><span> javax.persistence.Table; </span></span></li>
<li><span> </span></li>
<li><span><span>import</span><span> org.hibernate.validator.Length; </span></span></li>
<li><span><span>import</span><span> org.hibernate.validator.NotNull; </span></span></li>
<li><span><span>import</span><span> org.jboss.seam.annotations.Name; </span></span></li>
<li><span><span>import</span><span> org.jboss.seam.annotations.Scope; </span></span></li>
<li><span> </span></li>
<li><span><span>@Entity</span><span> </span></span></li>
<li><span><span>@Name</span><span>(</span><span>&#8220;user&#8221;</span><span>) </span></span></li>
<li><span><span>@Scope</span><span>(SESSION) </span></span></li>
<li><span><span>@Table</span><span>(name=</span><span>&#8220;users&#8221;</span><span>) </span></span></li>
<li><span><span>public</span><span> </span><span>class</span><span> User </span><span>implements</span><span> Serializable </span></span></li>
<li><span>{ </span></li>
<li><span> <span>private</span><span> </span><span>static</span><span> </span><span>final</span><span> </span><span>long</span><span> serialVersionUID = 1881413500711441951L; </span></span></li>
<li><span> </span></li>
<li><span> <span>private</span><span> String username; </span></span></li>
<li><span> <span>private</span><span> String password; </span></span></li>
<li><span> <span>private</span><span> String name; </span></span></li>
<li><span> </span></li>
<li><span> <span>public</span><span> User(String name, String password, String username) </span></span></li>
<li><span> { </span></li>
<li><span> <span>this</span><span>.name = name; </span></span></li>
<li><span> <span>this</span><span>.password = password; </span></span></li>
<li><span> <span>this</span><span>.username = username; </span></span></li>
<li><span> } </span></li>
<li><span> </span></li>
<li><span> <span>public</span><span> User() {} </span></span></li>
<li><span> </span></li>
<li><span> <span>@NotNull</span><span> </span></span></li>
<li><span> <span>public</span><span> String getName() </span></span></li>
<li><span> { </span></li>
<li><span> <span>return</span><span> name; </span></span></li>
<li><span> } </span></li>
<li><span> </span></li>
<li><span> <span>public</span><span> </span><span>void</span><span> setName(String name) </span></span></li>
<li><span> { </span></li>
<li><span> <span>this</span><span>.name = name; </span></span></li>
<li><span> } </span></li>
<li><span> </span></li>
<li><span> <span>@NotNull</span><span> </span><span>@Length</span><span>(min=</span><span>5</span><span>, max=</span><span>15</span><span>) </span></span></li>
<li><span> <span>public</span><span> String getPassword() </span></span></li>
<li><span> { </span></li>
<li><span> <span>return</span><span> password; </span></span></li>
<li><span> } </span></li>
<li><span> </span></li>
<li><span> <span>public</span><span> </span><span>void</span><span> setPassword(String password) </span></span></li>
<li><span> { </span></li>
<li><span> <span>this</span><span>.password = password; </span></span></li>
<li><span> } </span></li>
<li><span> </span></li>
<li><span> <span>@Id</span><span> </span><span>@NotNull</span><span> </span><span>@Length</span><span>(min=</span><span>5</span><span>, max=</span><span>15</span><span>) </span></span></li>
<li><span> <span>public</span><span> String getUsername() </span></span></li>
<li><span> { </span></li>
<li><span> <span>return</span><span> username; </span></span></li>
<li><span> } </span></li>
<li><span> </span></li>
<li><span> <span>public</span><span> </span><span>void</span><span> setUsername(String username) </span></span></li>
<li><span> { </span></li>
<li><span> <span>this</span><span>.username = username; </span></span></li>
<li><span> } </span></li>
<li><span> </span></li>
<li><span> <span>@Override</span><span> </span></span></li>
<li><span> <span>public</span><span> String toString() </span></span></li>
<li><span> { </span></li>
<li><span> <span>return</span><span> </span><span>&#8220;User(&#8220;</span><span> + username + </span><span>&#8220;)&#8221;</span><span>; </span></span></li>
<li><span> } </span></li>
<li><span>} </span></li>
</ol>
</div>
<pre style="display:none;">package org.jboss.seam.example.registration;

import static org.jboss.seam.ScopeType.SESSION;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

@Entity
@Name("user")
@Scope(SESSION)
@Table(name="users")
public class User implements Serializable
{
   private static final long serialVersionUID = 1881413500711441951L;

   private String username;
   private String password;
   private String name;

   public User(String name, String password, String username)
   {
      this.name = name;
      this.password = password;
      this.username = username;
   }

   public User() {}

   @NotNull
   public String getName()
   {
      return name;
   }

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

   @NotNull @Length(min=5, max=15)
   public String getPassword()
   {
      return password;
   }

   public void setPassword(String password)
   {
      this.password = password;
   }

   @Id @NotNull @Length(min=5, max=15)
   public String getUsername()
   {
      return username;
   }

   public void setUsername(String username)
   {
      this.username = username;
   }

   @Override
   public String toString()
   {
      return "User(" + username + ")";
   }
}</pre>
<p><span style="font-family:Tahoma;"><img src="http://www.mastertheboss.com/images/emo/victory.png" alt="jboss seam tutorial" align="right" />As we said, Jboss seam needs a component name specified by the <strong>@Name </strong>annotation. This name must be unique within the Seam application. So  JSF when meets the variable &#8220;user&#8221; delegates  Seam to resolve a context variable with a name &#8220;user&#8221;.</span></p>
<p><span style="font-family:Tahoma;"></p>
<p>When Seam instantiates the  component, it binds the new instance of a User to a context variable in the component&#8217;s default context. The default context is specified using the <strong>@Scope annotation</strong>. In our case the User bean is a session scoped component</p>
<p>Our Entity Bean has a façade which will be accessed by our clients. The façade is a standard Stateless Session Bean, but with special Jboss Seam Annotations.</span></p>
<p><img src="http://www.mastertheboss.com/images/stories/seam1.png" alt="jboss seam ejb" width="507" height="427" /></p>
<p><em>Picture 1: presentation tier invoke the RegisterAction EJB.</em></p>
<div>
<div>
<div><a href="http://www.mastertheboss.com/seam/63-jboss-seam-tutorial-1.html#">view plain</a><a href="http://www.mastertheboss.com/seam/63-jboss-seam-tutorial-1.html#">copy to clipboard</a><a href="http://www.mastertheboss.com/seam/63-jboss-seam-tutorial-1.html#">print</a><a href="http://www.mastertheboss.com/seam/63-jboss-seam-tutorial-1.html#">?</a></div>
</div>
<ol>
<li><span><span>package</span><span> org.jboss.seam.example.registration; </span></span></li>
<li><span> </span></li>
<li><span><span>import</span><span> java.util.List; </span></span></li>
<li><span> </span></li>
<li><span><span>import</span><span> javax.ejb.Stateless; </span></span></li>
<li><span><span>import</span><span> javax.persistence.EntityManager; </span></span></li>
<li><span><span>import</span><span> javax.persistence.PersistenceContext; </span></span></li>
<li><span> </span></li>
<li><span><span>import</span><span> org.jboss.seam.annotations.In; </span></span></li>
<li><span><span>import</span><span> org.jboss.seam.annotations.Logger; </span></span></li>
<li><span><span>import</span><span> org.jboss.seam.annotations.Name; </span></span></li>
<li><span><span>import</span><span> org.jboss.seam.faces.FacesMessages; </span></span></li>
<li><span><span>import</span><span> org.jboss.seam.log.Log; </span></span></li>
<li><span> </span></li>
<li><span><span>import</span><span> org.jboss.seam.annotations.Factory; </span></span></li>
<li><span><span>import</span><span> org.jboss.seam.annotations.datamodel.DataModel; </span></span></li>
<li><span> </span></li>
<li><span><span>@Stateless</span><span> </span></span></li>
<li><span><span>@Name</span><span>(</span><span>&#8220;register&#8221;</span><span>) </span></span></li>
<li><span><span>public</span><span> </span><span>class</span><span> RegisterAction </span><span>implements</span><span> Register </span></span></li>
<li><span>{ </span></li>
<li><span> </span></li>
<li><span> <span>@In</span><span> </span></span></li>
<li><span> <span>private</span><span> User user; </span></span></li>
<li><span> </span></li>
<li><span> <span>@PersistenceContext</span><span> </span></span></li>
<li><span> <span>private</span><span> EntityManager em; </span></span></li>
<li><span> </span></li>
<li><span> <span>@Logger</span><span> </span></span></li>
<li><span> <span>private</span><span> </span><span>static</span><span> Log log; </span></span></li>
<li><span> </span></li>
<li><span> <span>@DataModel</span><span> </span></span></li>
<li><span> <span>private</span><span> List items=</span><span>null</span><span>; </span></span></li>
<li><span> </span></li>
<li><span> </span></li>
<li><span> <span>public</span><span> String registerUser() </span></span></li>
<li><span> { </span></li>
<li><span> </span></li>
<li><span> em.persist(user); </span></li>
<li><span> log.info(<span>&#8220;Registered new user #{user.username}&#8221;</span><span>); </span></span></li>
<li><span> <span>return</span><span> </span><span>&#8220;/registered.jspx&#8221;</span><span>; </span></span></li>
<li><span> </span></li>
<li><span> } </span></li>
<li><span> </span></li>
<li><span> <span>@Factory</span><span>(</span><span>&#8220;items&#8221;</span><span>) </span></span></li>
<li><span> <span>public</span><span> </span><span>void</span><span> getItems() { </span></span></li>
<li><span> List list = em.createQuery(<span>&#8220;From User u order by u.name&#8221;</span><span>).getResultList(); </span></span></li>
<li><span> items = list; </span></li>
<li><span> } </span></li>
<li><span> </span></li>
<li><span>} </span></li>
</ol>
</div>
<pre style="display:none;">package org.jboss.seam.example.registration;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.log.Log;

import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.datamodel.DataModel;

@Stateless
@Name("register")
public class RegisterAction implements Register
{

   @In
   private User user;

   @PersistenceContext
   private EntityManager em;

   @Logger
   private static Log log;

   @DataModel
   private List items=null;

   public String registerUser()
   {

         em.persist(user);
         log.info("Registered new user #{user.username}");
         return "/registered.jspx";

   }

   @Factory("items")
    public void getItems() {
        List list = em.createQuery("From User u order by u.name").getResultList();
        items = list;
   }

}</pre>
<p><span style="font-size:12px;"><span style="font-family:Tahoma;">Let&#8217;s see in detail: well about the &#8220;name&#8221; annotation we have already discussed, </span></span></p>
<p><span style="font-size:12px;"><span style="font-family:Tahoma;">The <strong>@In annotation </strong>marks an attribute of the bean as injected by Seam. In this case, the attribute is </span></span><span style="font-family:Tahoma;">injected from a context variable named user (the instance variable name).<br />
The Seam <strong>@Logger </strong>annotation is used to inject the component&#8217;s Log instance.</p>
<p>Let&#8217;s move on the registerUser: this is the core method of the application which persist the data on the DB. Notice that it has no parameters because the Bean is injected with the @In annotation.<br />
</span><span style="font-family:Tahoma;"><br />
</span></p>
<p><span style="font-family:Tahoma;"><img src="http://www.mastertheboss.com/images/emo/amazing.png" alt="jboss seam tutorial" align="right" />Maybe you have noticed that this method contains a <em>redirection</em>: well you may asking what happened to JSF navigation rules ? well they still exist but Seam has a nice shortcut which is useful for small application : you can simply return the view as the outcome, eliminating the requirement for a navigation rule. For larger applications of course is better to keep a higher level of indirection and so using navigation rules.</span></p>
<p><span style="font-family:Tahoma;"></p>
<p>Last piece of the puzzle are <strong>@DataModel </strong>and the <strong>@Factory </strong>annotation</span></p>
<p><span style="font-family:Tahoma;">Data models are pretty handy components when it&#8217;s necessary to display database data onto a presentation tier. This allows you a fairly simple way to look up the data, determine the selected row, and use it for computations and display purposes.</p>
<p>As you&#8217;ll see the DataModel will be used to populate the JSF DataTable element with the Values provided in the @Factory method getItems()</span></p>
<p><span style="color:#006600;">&lt;h:dataTable var=&#8221;<span style="color:#0000ff;">u</span>&#8221; value=&#8221;<span style="color:#0000ff;">#{items}</span>&#8221; <span style="color:#ff6600;">rendered</span>=&#8221;<span style="color:#0000ff;">#{items.rowCount&gt;0}</span>&#8220;&gt;<br />
&lt;h:column&gt;</span></p>
<p><span style="color:#006600;"> &lt;f:facet name=&#8221;header&#8221;&gt;<br />
&lt;h:outputText <span style="color:#ff6600;">value</span>=&#8221;username&#8221;/&gt;<br />
&lt;/f:facet&gt;<br />
&lt;h:outputText <span style="color:#ff6600;">value</span>=&#8221;<span style="color:#0000ff;">#{u.username}</span>&#8220;/&gt;</span></p>
<p><span style="color:#006600;"> &lt;/h:column&gt;</span></p>
<p><span style="color:#006600;"> &lt;h:column&gt;</span></p>
<p><span style="color:#006600;"> &lt;f:facet name=&#8221;header&#8221;&gt;<br />
&lt;h:outputText <span style="color:#ff6600;">value</span>=&#8221;password&#8221;/&gt;<br />
&lt;/f:facet&gt;<br />
&lt;h:outputText <span style="color:#ff6600;">value</span>=&#8221;<span style="color:#0000ff;">#{u.password}</span>&#8220;/&gt;</span></p>
<p><span style="color:#006600;"> &lt;/h:column&gt;</p>
<p>&lt;/h:dataTable&gt;</span><br />
<span style="font-family:Tahoma;">So when JSF meets the variable &#8220;items&#8221; will delegate to the @Factory method getItems which will simply create a List of User objects.</span></p>
<p>@Factory(&#8220;items&#8221;)<br />
public void getItems() {<br />
List list = em.createQuery(&#8220;From User u order by u.name&#8221;).getResultList();<br />
items = list;<br />
}</p>
<p><span style="font-family:Tahoma;">Once instantiated the list will be stored in the variable</span></p>
<p>@DataModel<br />
private List&lt;User&gt; items=null;</p>
<p><span style="font-family:Tahoma;">when this is clear, retrieving the single fields is just a piece of cake</span></p>
<p>&lt;h:outputText value=&#8221;#{u.username}&#8221;/&gt;<br />
&lt;h:outputText value=&#8221;#{u.password}&#8221;/&gt;</p>
<p><img src="http://www.mastertheboss.com/images/stories/seam2.png" alt="jboss seam ejb" width="503" height="421" /></p>
<p><em>Picture 2: Data is queried using the RegisterAction&#8217;s Factory method.</em></p>
<h2>JBoss Seam Project picture:</h2>
<p><span style="font-family:Tahoma;">So this is how our Seam application looks like. </span><br />
<img src="http://www.mastertheboss.com/images/stories/seamfolder.jpg" alt="jboss seam tutorial" /><br />
<em>Picture 3: How a typical Seam project is made up.<br />
</em></p>
<p><span style="font-family:Tahoma;"><img src="http://www.mastertheboss.com/images/emo/secret-smile.png" alt="jboss seam tutorial" align="right" />Before packing, in the jboss-seam-registration.jar you need to add a seam property file: the <strong>seam.properties</strong> file is empty here but it is required for JBoss to know that this JAR file contains Seam EJB3 bean classes, and process the annotations accordingly.</span></p>
<div style="margin:0;"><span style="font-family:Tahoma;"></p>
<p>One thing you might wonder what is the file is how do you connect to your Datasource: well that’s managed by the persistence.xml file which simply points to the Default HSQL Datasource</span></div>
<div style="margin:0;"><span style="color:#006600;"> &lt;persistence-unit name=&#8221;userDatabase&#8221;&gt;</span></div>
<div style="margin:0;"><span style="color:#006600;"> &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;</span></div>
<div style="margin:0;"><span style="color:#006600;"> &lt;jta-data-source&gt;<span style="color:#000000;">java:/DefaultDS</span>&lt;/jta-data-source&gt;</span></div>
<div style="margin:0;"><span style="color:#006600;"> &lt;properties&gt;</span></div>
<div style="margin:0;"><span style="color:#006600;"> &lt;property name=&#8221;<span style="color:#0000ff;">hibernate.hbm2ddl.auto</span>&#8221; value=&#8221;<span style="color:#0000ff;">create-drop</span>&#8220;/&gt;</span></div>
<div style="margin:0;"><span style="color:#006600;"> &lt;/properties&gt;</span></div>
<div style="margin:0;"><span style="color:#006600;"> &lt;/persistence-unit&gt;</span></div>
<p><span style="font-family:Tahoma;">If you want to build this application, the easiest way is simply replace the files that you find under the registration example provided with the Seam distribution. Siimply build and deploy your project with ant and you&#8217;re done !</span></p>
<p><span style="font-family:Verdana;">Several Java EE APIs (EJB, JSF, etc.), as well as popular open source frameworks like Spring, make use of the concept of dependency injection. Injection involves the automatic, runtime insertion of a property value into a bean. This simple concept can greatly simplify development, especially in a Java EE environment. </span></p>
<p><span style="font-family:Verdana;"><span style="font-size:12px;">The Seam component model also supports a more general version of dependency injection, called bijection. Standard dependency injection involves a one-time initialization of a bean reference within a component, typically done by some kind of container or other runtime service.</span></span></p>
<p><span style="font-family:Verdana;"><span style="font-size:12px;">Seam introduces the notion of bijection as a generalization of injection.</p>
<p>In contrast to injection, bijection is:</span></span></p>
<ul>
<li><span style="font-family:Verdana;"><span style="font-size:12px;"><em>contextual </em>- bijection is used to assemble stateful components from various different contexts (a component from a &#8220;wider&#8221; context may even have a reference to a component from a &#8220;narrower&#8221; context) </span></span></li>
<li><span style="font-family:Verdana;"><span style="font-size:12px;"><em>bidirectional </em>- values are injected from context variables into attributes of the component being invoked, and also outjected from the component attributes back out to the context, allowing the component being invoked to manipulate the values of contextual variables simply by setting its own instance variables </span></span></li>
<li><span style="font-family:Verdana;"><span style="font-size:12px;"><em>dynamic </em>- since the value of contextual variables changes over time, and since Seam components are stateful, bijection takes place every time a component is invoked </span></span></li>
</ul>
<p><span style="font-family:Verdana;"><span style="font-size:12px;"> </span></span></p>
<p><span style="font-family:Verdana;"><span style="font-size:12px;">Before seeing Seam bijection, let&#8217;s see what is Simple Injection, from an Example </span></span></p>
<div>
<div>
<div><a href="http://www.mastertheboss.com/seam/65-jboss-seam-tutorial-part-2.html#">view plain</a><a href="http://www.mastertheboss.com/seam/65-jboss-seam-tutorial-part-2.html#">copy to clipboard</a><a href="http://www.mastertheboss.com/seam/65-jboss-seam-tutorial-part-2.html#">print</a><a href="http://www.mastertheboss.com/seam/65-jboss-seam-tutorial-part-2.html#">?</a></div>
</div>
<ol>
<li><span><span>@Name</span><span>(</span><span>&#8220;MyBean&#8221;</span><span>) </span></span></li>
<li><span><span>public</span><span> </span><span>class</span><span> MyBean { </span></span></li>
<li><span><span>@In</span><span> </span></span></li>
<li><span><span>private</span><span> OtherBean otherBean; </span></span></li>
<li><span> </span></li>
<li><span> <span>public</span><span> SomeBean getOtherBean() { </span></span></li>
<li><span> <span>return</span><span> otherBean; </span></span></li>
<li><span> } </span></li>
<li><span> <span>public</span><span> </span><span>void</span><span> setOtherBean(OtherBean b) </span></span></li>
<li><span> { </span></li>
<li><span> otherBean = b; </span></li>
<li><span> } </span></li>
<li><span>} </span></li>
</ol>
</div>
<pre style="display:none;">@Name("MyBean")
public class MyBean {
@In
private OtherBean otherBean; 

  public SomeBean getOtherBean() {
   return otherBean;
  }
  public void setOtherBean(OtherBean b)
 {
  otherBean = b;
 }
}</pre>
<p><span style="font-family:Verdana;">Here, we’re annotating the formBean property on the Seam component MyBean, telling Seam to inject the value of this property whenever MyBean is invoked. In this case, we’re using @In with no arguments to inject an otherBean instance in MyBean class.</p>
<p>By default, Seam will search all of its contexts for a component with the same name as the annotated property &#8220;otherBean.&#8221; : the first one it finds (in an ordered search of contexts, starting from the event context and ending with application context) is used as the value of the annotated property. If no component of the given name is found anywhere, the injection will not happen, and the property will remain uninitialized.</span></p>
<h1>JBoss Seam Bijection</h1>
<p><span style="font-family:Verdana;">As mentioned at the start of this section, Seam extends simple injection by introducing the concept of outjection, or the export of a component value from one component back into the scope where the component lives.</p>
<p>Let&#8217;s recall our previous Registration example and add some spice to it. The User Entity Bean will stay the same, we won&#8217;t change our model. Rather we add a new Stateless Bean, UserAction</span></p>
<div>
<div>
<div><a href="http://www.mastertheboss.com/seam/65-jboss-seam-tutorial-part-2.html#">view plain</a><a href="http://www.mastertheboss.com/seam/65-jboss-seam-tutorial-part-2.html#">copy to clipboard</a><a href="http://www.mastertheboss.com/seam/65-jboss-seam-tutorial-part-2.html#">print</a><a href="http://www.mastertheboss.com/seam/65-jboss-seam-tutorial-part-2.html#">?</a></div>
</div>
<ol>
<li><span><span>@Stateless</span><span> </span></span></li>
<li><span><span>@Name</span><span>(</span><span>&#8220;useraction&#8221;</span><span>) </span></span></li>
<li><span> </span></li>
<li><span><span>public</span><span> </span><span>class</span><span> UserAction </span><span>implements</span><span> UserItf { </span></span></li>
<li><span><span>@In</span><span> </span><span>@Out</span><span> </span><span>private</span><span> User user; </span></span></li>
<li><span><span>@Out</span><span> </span><span>private</span><span> List userList; </span></span></li>
<li><span> </span></li>
<li><span><span>@PersistenceContext</span><span> </span><span>private</span><span> EntityManager em; </span></span></li>
<li><span> </span></li>
<li><span> <span>public</span><span> String addAndDisplay() { </span></span></li>
<li><span> em.persist (user); </span></li>
<li><span> user = <span>new</span><span> User (); </span></span></li>
<li><span> userList = em.createQuery(<span>&#8220;From User u order by u.name&#8221;</span><span>).getResultList(); </span></span></li>
<li><span> <span>return</span><span> </span><span>null</span><span>; </span></span></li>
<li><span> } </span></li>
</ol>
</div>
<pre style="display:none;">@Stateless
@Name("useraction") 

public class UserAction implements UserItf {
@In @Out private User user;
@Out private List userList; 

@PersistenceContext private EntityManager em; 

 public String addAndDisplay() {
  em.persist (user);
  user = new User ();
  userList = em.createQuery("From User u order by u.name").getResultList();
  return null;
 }</pre>
<p><span style="font-family:Verdana;">The useraction component in Seam is the UserAction session bean, as specified by the @Name annotation on the class. The UserAction class has user and userList fields annotated with the @In and @Out annotations.<br />
</span><span style="font-family:Verdana;"><br />
The <strong>@In and @Out annotations </strong>are at the heart of the Seam programming model. So, let&#8217;s look at exactly what they do here.<br />
</span><span style="font-family:Verdana;"><br />
The <strong>@In annotation</strong> tells Seam to assign the user component, which is composed from the JSF form data, to the user field (dependency injection) before executing any method in the session bean. You can specify an arbitrary name for the injected component in @In. But if there is no named specified, as it is here, Seam will just inject the component with the same type and same name as the receiving field variable.<br />
</span><span style="font-family:Verdana;"><br />
The <strong>@Out annotations</strong> tell Seam to assign values of the userList and user fields to the managed components of the same names after any method execution. We call this action &#8220;dependency outjection&#8221; in Seam. This way, in the addAndDisplay method, we simply need to update the user and userList field values and they will be automatically available on the web page.</p>
<p></span><span style="font-family:Verdana;">So the addAndDisplay() method simply saves the fields to the database via the JPA EntityManager,then it refreshes the user and userList objects, which are outjected after the method exits. The addAndDisplay() returns null to indicate that the current JSF page will be re-displayed with the most up-to-date model data after the call.<br />
</span></p>
<p><span style="font-family:Verdana;"><img src="http://www.mastertheboss.com/images/emo/victory.png" alt="jboss seam tutorial" align="right" />In short, </span><strong><span style="font-family:Verdana;">bijection lets you alias a context variable to a component instance variable, by specifying that the value of the instance variable is injected, outjected, or both. </span><br />
</strong><span style="font-family:Verdana;"><br />
This is the hello.xhtml view</span></p>
<p><span style="color:#006600;">&lt;f:view&gt;<br />
&lt;h:form&gt;Please enter your info:&lt;br/&gt;</p>
<p></span><span>Username:</span><span style="color:#006600;"> &lt;h:inputText <span style="color:#ff9900;">value</span>=&#8221;<span style="color:#0000ff;">#{user.username}</span>&#8221; required=&#8221;true&#8221;/&gt;<br />
</span><span>Real Name:</span><span style="color:#006600;"> &lt;h:inputText <span style="color:#ff9900;">value</span>=&#8221;<span style="color:#0000ff;">#{user.name}</span>&#8221; required=&#8221;true&#8221;/&gt;<br />
</span><span>Password:</span><span style="color:#006600;"> &lt;h:inputSecret <span style="color:#ff9900;">value</span>=&#8221;<span style="color:#0000ff;">#{user.password}</span>&#8221; required=&#8221;true&#8221;/&gt;<br />
&lt;h:commandButton type=&#8221;submit&#8221; value=&#8221;Add User&#8221; action=&#8221;<span style="color:#0000ff;">#{useraction.addAndDisplay}</span>&#8220;/&gt;<br />
&lt;/h:form&gt;</p>
<p>&lt;h:dataTable <span style="color:#ff9900;">value</span>=&#8221;<span style="color:#0000ff;">#{userList}</span>&#8221; var=&#8221;u&#8221;&gt;<br />
&lt;h:column&gt;<br />
&lt;h:outputText <span style="color:#ff9900;">value</span>=&#8221;<span style="color:#0000ff;">#{u.username}</span>&#8220;/&gt;&amp;nbsp;<br />
&lt;h:outputText <span style="color:#ff9900;">value</span>=&#8221;<span style="color:#0000ff;">#{u.name}</span>&#8220;/&gt;&amp;nbsp;<br />
&lt;/h:column&gt;<br />
&lt;/h:dataTable&gt;<br />
&lt;/f:view&gt;</span></p>
<p><span style="font-family:Verdana;">As you can see, the datatable references the userList, which is populated in the addAndDisplayMethod by the following query </span></p>
<p><span style="font-family:Courier New;">userList = em.createQuery(&#8220;From User u order by u.name&#8221;).getResultList(); </span></p>
<p><em>Picture 1: Seam bijection depicted<br />
</em><img src="http://www.mastertheboss.com/images/stories/seam3.jpg" alt="jboss seam tutorial" width="475" height="392" /></p>
<h2>Getter / Setter Based Bijection</h2>
<p><span style="font-family:Verdana;">In the above example, we demonstrated Seam bijection against field variables. You can also biject components against getter and setter methods. For instance, take a look at the following code:</span></p>
<div>
<div>
<div><a href="http://www.mastertheboss.com/seam/65-jboss-seam-tutorial-part-2.html#">view plain</a><a href="http://www.mastertheboss.com/seam/65-jboss-seam-tutorial-part-2.html#">copy to clipboard</a><a href="http://www.mastertheboss.com/seam/65-jboss-seam-tutorial-part-2.html#">print</a><a href="http://www.mastertheboss.com/seam/65-jboss-seam-tutorial-part-2.html#">?</a></div>
</div>
<ol>
<li><span><span>private</span><span> User user; </span></span></li>
<li><span><span>private</span><span> List userList; </span></span></li>
<li><span> </span></li>
<li><span> <span>@In</span><span> </span><span>public</span><span> </span><span>void</span><span> setUser (User user) { </span></span></li>
<li><span> <span>this</span><span>.user = user; </span></span></li>
<li><span> } </span></li>
<li><span> <span>@Out</span><span> </span><span>public</span><span> User getUser () { </span></span></li>
<li><span> <span>return</span><span> user; </span></span></li>
<li><span> } </span></li>
<li><span> <span>@Out</span><span> </span><span>public</span><span> List getUserList () { </span></span></li>
<li><span> <span>return</span><span> userList; </span></span></li>
<li><span> } </span></li>
</ol>
</div>
<pre style="display:none;">private User user;
private List userList; 

 @In public void setUser (User user) {
   this.user = user;
 }
 @Out public User getUser () {
  return user;
 }
 @Out public List getUserList () {
  return userList;
 }</pre>
<p><span style="font-size:12px;"><span style="font-family:Verdana;">You may wonder why not complicating so much the lift with getter/setter bijection ?<br />
the real value of this change is that you can add custom logic to manipulate the bijection process.<br />
For instance, you can validate the injected object or retrieve the outjected object on the fly from the database.</span></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/techpassion.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/techpassion.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/techpassion.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/techpassion.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/techpassion.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/techpassion.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/techpassion.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/techpassion.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/techpassion.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/techpassion.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/techpassion.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/techpassion.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/techpassion.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/techpassion.wordpress.com/90/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techpassion.wordpress.com&amp;blog=5988916&amp;post=90&amp;subd=techpassion&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://techpassion.wordpress.com/2009/06/02/jboss-seam-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9eea02dca209112818f5a9ee1f48cb3e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Admin</media:title>
		</media:content>

		<media:content url="http://www.mastertheboss.com/images/emo/what.png" medium="image">
			<media:title type="html">jboss seam tutorial</media:title>
		</media:content>

		<media:content url="http://www.mastertheboss.com/images/emo/victory.png" medium="image">
			<media:title type="html">jboss seam tutorial</media:title>
		</media:content>

		<media:content url="http://www.mastertheboss.com/images/stories/seam1.png" medium="image">
			<media:title type="html">jboss seam ejb</media:title>
		</media:content>

		<media:content url="http://www.mastertheboss.com/images/emo/amazing.png" medium="image">
			<media:title type="html">jboss seam tutorial</media:title>
		</media:content>

		<media:content url="http://www.mastertheboss.com/images/stories/seam2.png" medium="image">
			<media:title type="html">jboss seam ejb</media:title>
		</media:content>

		<media:content url="http://www.mastertheboss.com/images/stories/seamfolder.jpg" medium="image">
			<media:title type="html">jboss seam tutorial</media:title>
		</media:content>

		<media:content url="http://www.mastertheboss.com/images/emo/secret-smile.png" medium="image">
			<media:title type="html">jboss seam tutorial</media:title>
		</media:content>

		<media:content url="http://www.mastertheboss.com/images/emo/victory.png" medium="image">
			<media:title type="html">jboss seam tutorial</media:title>
		</media:content>

		<media:content url="http://www.mastertheboss.com/images/stories/seam3.jpg" medium="image">
			<media:title type="html">jboss seam tutorial</media:title>
		</media:content>
	</item>
		<item>
		<title>JavaScript interview questions</title>
		<link>http://techpassion.wordpress.com/2009/06/02/javascript-interview-questions/</link>
		<comments>http://techpassion.wordpress.com/2009/06/02/javascript-interview-questions/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 23:10:54 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[Javascript, CSS, HTML/XHTML]]></category>
		<category><![CDATA[javascipt]]></category>

		<guid isPermaLink="false">http://techpassion.wordpress.com/?p=88</guid>
		<description><![CDATA[JavaScript interview questions and answers By admin &#124; May 28, 2006 What’s relationship between JavaScript and ECMAScript? &#8211; ECMAScript is yet another name for JavaScript (other names include LiveScript). The current JavaScript that you see supported in browsers is ECMAScript revision 3. What are JavaScript types? &#8211; Number, String, Boolean, Function, Object, Null, Undefined. How [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techpassion.wordpress.com&amp;blog=5988916&amp;post=88&amp;subd=techpassion&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1>JavaScript interview questions and answers</h1>
<div><span>By <a title="View all posts by admin" href="http://www.techinterviews.com/author/admin/">admin</a></span><span> | </span><span><abbr title="2006-05-28T01:46:13-0500">May 28, 2006</abbr></span></div>
<p><!-- .entry-meta --></p>
<ol>
<li><strong>What’s relationship between JavaScript and ECMAScript?</strong> &#8211; ECMAScript is yet another name for JavaScript (other names include LiveScript). The current JavaScript that you see supported in browsers is ECMAScript revision 3.</li>
<li><strong>What are JavaScript types?</strong> &#8211; Number, String, Boolean, Function, Object, Null, Undefined.</li>
<li><strong>How do you convert numbers between different bases in JavaScript?</strong> &#8211; Use the parseInt() function, that takes a string as the first parameter, and the base as a second parameter. So to convert hexadecimal 3F to decimal, use parseInt (&#8220;3F&#8221;, 16);</li>
<li><strong>What does isNaN function do?</strong> &#8211; Return true if the argument is not a number.</li>
<li><strong>What is negative infinity?</strong> &#8211; It’s a number in JavaScript, derived by dividing negative number by zero.</li>
<p><span> </span></p>
<li><strong>What boolean operators does JavaScript support?</strong> &#8211; &amp;&amp;, || and !</li>
<li><strong>What does &#8220;1&#8243;+2+4 evaluate to?</strong> &#8211; Since 1 is a string, everything is a string, so the result is 124.</li>
<li><strong>How about 2+5+&#8221;8&#8243;?</strong> &#8211; Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, it’s concatenation, so 78 is the result.</li>
<li><strong>What looping structures are there in JavaScript?</strong> &#8211; for, while, do-while loops, but no foreach.</li>
<li><strong>How do you create a new object in JavaScript?</strong> &#8211; var obj = new Object(); or var obj = {};</li>
<li><strong>How do you assign object properties?</strong> &#8211; obj["age"] = 17 or obj.age = 17.</li>
<li><strong>What’s a way to append a value to an array?</strong> &#8211; arr[arr.length] = value;</li>
<li><strong>What is this keyword?</strong> &#8211; It refers to the current object.</li>
</ol>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/techpassion.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/techpassion.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/techpassion.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/techpassion.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/techpassion.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/techpassion.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/techpassion.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/techpassion.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/techpassion.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/techpassion.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/techpassion.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/techpassion.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/techpassion.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/techpassion.wordpress.com/88/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techpassion.wordpress.com&amp;blog=5988916&amp;post=88&amp;subd=techpassion&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://techpassion.wordpress.com/2009/06/02/javascript-interview-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9eea02dca209112818f5a9ee1f48cb3e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Admin</media:title>
		</media:content>
	</item>
		<item>
		<title>CSS Best Practices</title>
		<link>http://techpassion.wordpress.com/2009/06/02/css-best-practices/</link>
		<comments>http://techpassion.wordpress.com/2009/06/02/css-best-practices/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 23:07:23 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[Javascript, CSS, HTML/XHTML]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://techpassion.wordpress.com/?p=85</guid>
		<description><![CDATA[General CSS Rules Build and test your CSS in Firefox (or Safari if you are working on a Mac). Specify units for non-zero values, but not for zero values. Don’t use quotation marks around paths/URLs when setting a background image or loading in an imported file Try to avoid applying padding/borders and a fixed width [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techpassion.wordpress.com&amp;blog=5988916&amp;post=85&amp;subd=techpassion&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3><a href="http://www.evotech.net/blog/2007/04/css-best-practices/#rules">General CSS Rules </a></h3>
<ul>
<li>Build and test your CSS in Firefox  (or Safari if you are working on a Mac).</li>
<li>Specify units for non-zero values, but not for zero values.</li>
<li>Don’t use quotation marks around paths/URLs when setting a background image or loading in an imported file</li>
<li>Try to avoid applying padding/borders and a fixed width to an element. Rather, apply padding to the parent element.</li>
<li>Minimize number of ID’s used</li>
<li>Minimize number of classes used</li>
<li>Don’t use anchors, instead use ID’s.</li>
<li>Sandbox your style declarations</li>
<li>Combine selectors.</li>
<li>Use good naming conventions</li>
<li>Control the browsers CSS: Start with a clean slate.</li>
<li>Declare relative font sizes instead of absolute.</li>
<li>Create classes for error handling named based on the error</li>
<li>Avoid !important.</li>
<li>Avoid in-line CSS</li>
<li>Code link pseudo-classes in this order: Link, Visited, Hover, Active.</li>
</ul>
<h3><a href="http://www.evotech.net/blog/2007/04/css-best-practices/#maintain">Stylesheet Maintenance</a></h3>
<ul>
<li>Minimize and clean up your css</li>
<li>Organize your CSS file</li>
<li>There are pros and cons to using Multiple stylesheets</li>
</ul>
<h3><a href="http://www.evotech.net/blog/2007/04/css-best-practices/#html">HTML Development</a></h3>
<ul>
<li>Separate Structure and Presentation</li>
<li>Use HTML structure</li>
<li>Encompass everything in an element.</li>
<li>Use HTML elements for their intented purpose:</li>
<li>Avoid excess code</li>
<li>Avoid meaningless markup</li>
<li>Case sensitivity</li>
</ul>
<h3>General CSS Rules</h3>
<h4>Build and test your CSS in Firefox  or Safari if you are working on a Mac.</h4>
<ul>
<li>Do not look at it or test your code in other browsers, especially IE, until the code is complete, approved and validated. This way you will start with clean, standards-compliant code that you can alter for non-standards compliant browsers, rather hacking from buggy code to support good browsers</li>
<li>If developing in Safari, develop with embedded styles in the header, but launch with imported styles to eliminate potential caching issues.</li>
<li><code>@import</code> or <code>&lt;link&gt;</code> the css. It is better to <code>&lt;link rel="stylesheet" type="text/css" ... &gt;</code> because using <code>@import</code> can delay the rendering of your page.</li>
<li>Use as few browser hacks as possible, and document them with comments. Try to use valid CSS filters instead of non-validating hacks</li>
</ul>
<h4>Specify units for non-zero values.</h4>
<ul>
<li>Zero is zero, so do don’t include a unit type. For all other cases, CSS requires you to specify units on all quantities such as fonts, margins and sizes. Example: margin: 0 4px 0 2em;</li>
</ul>
<h4>Don’t use quotation marks around paths/URLs when setting a background image or loading in an imported file</h4>
<ul>
<li>They      are not required or necessary and they will freeze IE5 on the Mac.</li>
</ul>
<h4>Try to avoid applying padding/borders and a fixed width to an element. Rather, apply padding to the parent element.</h4>
<ul>
<li>Because of IE 6 (and lower) box-model issues, if you apply padding to the parent element instead of the child element, IE will render the same as standards compliant browsers.</li>
</ul>
<h4>Minimize use of ID’s:</h4>
<ul>
<li>By encompassing sections in a named outer div, you can generally stylize all the contained components without the use of classes.</li>
<li>Use IDs sparingly: IDs have to be unique on a page, so using them for structural elements means that you can only ever have one content block on a page. #mainnavigation li li a should suffice for a drop down menu link and can be overwritten with #mainnavigation li li li a if there are submenus.</li>
<li>With minimal use of ID’s one can still target almost any element on the page, while allowing ASP.net autogenerated code (which is “ID happy”) to have the freedom to put ID’s all over the page.</li>
<li>Combine      your selectors and sandbox your declarations (see below)</li>
</ul>
<h4>Minimize use of classes</h4>
<ul>
<li>Only use classes on elements that have any chance of being repeated on a page and in different locations, if the element is going to exist in a predictable location cascade based on the parent div ID,</li>
</ul>
<h4>Don’t use anchors, instead use ID’s.</h4>
<ul>
<li>Less      code with multi-purpose code.       Instead of using <code>&lt;a name=”anchor”&gt;</code> give an id to the parent of where that anchor would fall. All ID’s need to be unique, but so do the named anchors, so you are actually saving code and avoiding the pitfall of the effects of a a:hover defined for actual links</li>
</ul>
<h4>Sandbox your style declarations</h4>
<ul>
<li>Limit      the “reach” of style declarations by pre-pending the class name,      such as #maincontent p{}.</li>
</ul>
<h4>Combine selectors.</h4>
<ul>
<li>Keeping your CSS light is important to minimize download times; as much as possible, group selectors and rely on inheritance.</li>
</ul>
<h4>Naming conventions:</h4>
<ul>
<li>Never use layout descriptives in class names. Rather, use functional names for your classes, avoid words that describe how they look or where they are located on the page. “mainnavigation” is better than “leftnavigation”. Use “.copyright” and “.pullquote” instead of “smallgrey” or “indentitalic”. Name classes/IDs based on function, not appearance. If you create a .smallblue class, and later get a request to change the text to large and red, the class stops making any form of sense. Instead use descriptive classes like</li>
<li>Always use intention revealing classnames: Its tempting to use short cryptic class names (.s, .lbl) but unless you keep a glossary up to date of your class names, you will forget what they do. You may also run into problems with older browsers that can occasionally confuse classnames that start the same (i.e. .err and .errors are sometimes confused)</li>
</ul>
<ul>
<li>Avoid using the same classname for different purposes. The cascade can be very powerful but sometimes there is a temptation to use the same generic classname in many places. If you don’t sandbox your Css well, you can run into troubles.</li>
<li>Always use the same classname for similar purposes: Becuase the cascade is so powerful, you should reuse a classname in different places when they represent the same concept.</li>
<li>Put your classname on the outer-most element. The child elements can be targeted with the parent elements classname or ID. Often you see things like:<code>&lt;div&gt;...&lt;/div&gt;<br />
&lt;div&gt;...&lt;/div&gt;<br />
&lt;div&gt;...&lt;/div&gt;</code>It’s far better to write:</p>
<p><code>&lt;div id="header"&gt;<br />
&lt;h3&gt;...&lt;/h3&gt;<br />
&lt;p&gt;...&lt;/p&gt;<br />
&lt;ul&gt;&lt;li&gt;...&lt;/li&gt;&lt;ul&gt;<br />
&lt;/div&gt;</code></li>
</ul>
<ul>
<li>Although class and div names can include lowercase, uppercase, numbers and additional characters in class and div names, it is best to use all lower case letters and to for multiple word classes, separate the words with an underscore or use camel case. HTML attributes “id” and “class” are case sensitive!</li>
<li>Never use javascript method or property names as ID values.  <a href="http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html">JavaScript <span>DOM</span> bindings</a> specifies that javascript can index by id. For example, using “length” as an ID value on an element will cause headaches when using myObjects.length.</li>
</ul>
<h4>Start with a clean slate.</h4>
<ul>
<li>Create      default page with no rendering;       include this code but change color and font-family if necessary<code>body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset, input, p, blockquote, th, td { font-family: Arial, Helvetica, sans-serif; color:#000000; font-size: x-small;}<br />
table{border-collapse: collapse; border-spacing:0;}<br />
fieldset, img{border:0;}<br />
address, caption, cite, code, dfn, em, strong, th, var{font-style: normal; font-weight:normal;}<br />
h1, h2, h3, h4, h5, h6 {font-size:100%;}<br />
q:before, q:after{content:'';}</code></li>
<li>If you select other fonts for display, you don’t need to declare default classes since the first declaration declares default classes for all necessary elements.</li>
</ul>
<h4>Declare relative font sizes instead of absolute.</h4>
<ul>
<li>Always declare font-sizes in percentages or ems for maximum usability, consistency, and accessibility. This will enable pages to grow organically when user chooses to make text larger or smaller. Ems are easier to control than pixels.</li>
</ul>
<h4>Create classes for error handling named based on the error:</h4>
<ul>
<li>Form error handling is a good place to use multiple classnames. As an example, if you have a form, fields are typically either required or optional and have an error or not. Use “error required”, “error optional, “error feedback” (for a total of 4 classes, instead of 6), etc. Don’t call the classes “rederror”, redbigerror, etc, because when coding new error messages it won’t be obvious to the programmers which class to use.</li>
</ul>
<h4>Avoid !important.</h4>
<h4>Avoid in-line CSS</h4>
<ul>
<li>Inline      styles negates the power of CSS and should only be used for testing      purposes, such as including <code>style=”border: 1px solid #ff0000;”</code> to identify      box model quirks</li>
</ul>
<h4>Code link pseudo-classes in this order: Link, Visited, Hover, Active.</h4>
<ul>
<li>In your CSS, code the links in order of <code>a:link, a:visited, a:hover</code> and <code>a:active</code>. Some people remember this best by the mneumonic “<strong>L</strong>o<strong>V</strong>e <strong>HA</strong>te”. In the hover definition, include <code>visited:hover</code> to ensure your hover effect works on visited links.</li>
</ul>
<h3>Stylesheet Maintenance</h3>
<h4>Minimize and clean up your css</h4>
<ul>
<li>Use as little CSS as possible, remove styles and parts of styles not being used or that were experimented with in the design process.</li>
</ul>
<h4>Organize your CSS file</h4>
<ul>
<li>Introduce your stylesheets with comments and explanation of how the particular sheet fits in with other sheets and with the site.</li>
<li>Use a predictable format. Organize similar rules together and use comments before each section to help you keep track of things for future redesigns/updates.</li>
<li>Group      your styles with short and precise labels via comments</li>
<li>Make sure to comment blocks of CSS appropriately, group like-selectors, and establish a consistent naming convention, white space formatting. Incase different developers are using different platforms to edit the CSS, it is best to use spaces instead of tabs for white spce. Also, it is helpful to have consistent property order, though this is one I don’t do.</li>
<li>Start with clearing all default values, as mentioned above: this will reduce redundancy. Follow this by global styles. Lastly include section specific styles. For example, declare default element values. Next create sections of code for each section of your document. Next come the content sections which I generally divide into #header, #navigation, #maincontent and #footer. Include all the layout for the various elements for each of these id’s that are site global within each section</li>
<li>After site-wide declarations grouped by section/ID, if there are different “page colors” or layout looks, include a section for each of the different looks. If a declaration is valid for all “looks”, include it in the declarations above. If a declaration is valid for a subset of looks only, first declare a section for the multiple subset looks. This should be followed by unique page sections.</li>
<li>Finally,      declare “weird” effects that only effect a paragraph type, a link based on      value, etc.</li>
</ul>
<h4>Multiple stylesheets</h4>
<ul>
<li>Multiple stylesheets are appropriate for large and complexly styled sites, however extra http calls should be minimized.</li>
<li>Make sure multiple style sheets are really worth while &#8211; a single long CSS file can at least be searched easily (”find all instances of h2″)</li>
<li>The base styles file contains CSS rules that can be applied on every page, more specific sheets based on section or page color schema.</li>
</ul>
<h3>HTML Development</h3>
<h4>Separate Structure and Presentation</h4>
<ul>
<li> The goal should be to only have one line of CSS on the entire page: the call to an external style sheet.<br />
The eventual goal should also be to have one line of JavaScript &#8211; the call to the external file, with no inline event handlers, but we haven’t covered that yet.</li>
<li>Use semantic HTML structure that have semantic meaning such as <code>&lt;strong&gt;</code> and <code>&lt;em&gt;</code><br />
instead of <code>&lt;b&gt;</code> and <code>&lt;large&gt;</code>. To give emphasis to a title, or stylizing a p tag, use semantic mark up such as  <code>&lt;h1&gt;</code> thru <code>&lt;h6&gt;</code></li>
</ul>
<h4>Encompass everything in an element.</h4>
<ul>
<li><code>&lt;div&gt;</code> and <code>&lt;span&gt;</code> have no intrinsic meaning.  Encompass all text in appropriate elements: <code>&lt;h1&gt;</code> … <code>&lt;h6&gt;</code>, <code>&lt;p&gt;</code>, <code>&lt;cite&gt;</code>, etc.</li>
</ul>
<h4>Use HTML elements for their intented purpose:</h4>
<ul>
<li> Use <code>&lt;blockquote&gt;</code> for blockquotes. <code>&lt;li&gt;</code> for list items, <code>&lt;cite&gt;</code> for citations.</li>
<li> Use list items for lists of links.  Remember, navigations are generally a list of links and it is appropriate to use lists.</li>
</ul>
<h4>Avoid excess code,</h4>
<ul>
<li> Instead of repeated <code>&lt;br /&gt;</code> and   use margin and padding</li>
</ul>
<h4>Avoid meaningless markup</h4>
<ul>
<li>Instead of <code>&lt;b&gt;</code> and <code>&lt;i&gt;</code>, use <code>&lt;strong&gt;</code> and <code>&lt;em&gt;</code></li>
</ul>
<h4>Case sensitivity</h4>
<ul>
<li> All HTML markup, JavaScript, and CSS should be lowercase. Event handlers should be written in all lower case: use onlick not onClick. Use <code>&lt;p&gt;</code>, not <code>&lt;P&gt;</code>. Attribute values should all be lower case as well, unless referring to a file name that includes other characters. File names and file extensions should also be lowercase (no rule on this, just easier to remember class names, file names, image names, etc. if you don’t have to worry about case.</li>
<li>If a header should be all-caps, code it in regular case as you would want to see it printed, and then transform the text to all uppercase with CSS text transformation.</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/techpassion.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/techpassion.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/techpassion.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/techpassion.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/techpassion.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/techpassion.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/techpassion.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/techpassion.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/techpassion.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/techpassion.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/techpassion.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/techpassion.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/techpassion.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/techpassion.wordpress.com/85/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techpassion.wordpress.com&amp;blog=5988916&amp;post=85&amp;subd=techpassion&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://techpassion.wordpress.com/2009/06/02/css-best-practices/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9eea02dca209112818f5a9ee1f48cb3e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Admin</media:title>
		</media:content>
	</item>
		<item>
		<title>XHTML, CSS &amp; JavaScript Web Developer Applicant Questions</title>
		<link>http://techpassion.wordpress.com/2009/06/02/xhtml-css-javascript-web-developer-applicant-questions/</link>
		<comments>http://techpassion.wordpress.com/2009/06/02/xhtml-css-javascript-web-developer-applicant-questions/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 23:05:13 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[Javascript, CSS, HTML/XHTML]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://techpassion.wordpress.com/?p=83</guid>
		<description><![CDATA[XHTML Web Standards Interview Question Question: What is a DTD? What DTD do you generally use? Why? Pros and cons. Answer See the bottom half of DTD: the Document Type Declaration Answer Rating: Completely wrong answer though pretends to know it I don’t know (I give points for honesty), trying unsuccessfully but honestly to give [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techpassion.wordpress.com&amp;blog=5988916&amp;post=83&amp;subd=techpassion&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div>
<h4>XHTML Web Standards Interview Question</h4>
<p>Question:</p>
<p>What is a DTD? What DTD do you generally use?  Why? Pros and cons.</p>
<p>Answer</p>
<p>See the bottom half of <a href="http://www.evotech.net/blog/2007/04/dtd-the-document-type-declaration/">DTD: the Document Type Declaration</a></p>
<p>Answer Rating:</p>
<ol>
<li>Completely wrong answer though pretends to know it</li>
<li>I don’t know (I give points for honesty), trying unsuccessfully but honestly to give the right answer</li>
<li>Knowledge of the definition, but doesn’t know why they are used.</li>
<li>Knowledge of which one to use and why</li>
<li>Explanation of Quirks mode versus Regular mode and analysis of which one is best for different media</li>
</ol>
</div>
<div>
<h4>Accessibility Interview Question</h4>
<p>Question</p>
<p>Tell me some considerations in selecting font size?</p>
<p>Answer</p>
<p>Font sizes should be declared using relative measurement values, such as ems, via a style sheet, without the use of the term !important. There are issues with browser font size enlarging which can be rectified via CSS.</p>
<p>Answer Rating</p>
<ol>
<li>uses &lt;font&gt; tag</li>
<li>Gives an answer using pixels using CSS</li>
<li>Explains that font size should be declared using relative font sizes</li>
<li>Explains that font size should be declared using ems or percentages</li>
<li>Gives the answer above</li>
</ol>
</div>
<div>
<h4>CSS Interview Question</h4>
<p>Question</p>
<p>a) What are the possible values for the display attribute that are supported by all browsers?<br />
b) What is the default value for the display attribute for the image element? (what is the difference between inline and block level elements)<br />
c)What does display: run-in do?<br />
d) Difference between “visibility:hidden” and “display:none”? What are the pros and cons of using display:none?</p>
<p>Answer</p>
<p>main values: none, block, inline, list-item, run-in<br />
all values: inline | block | list-item | run-in | compact | marker | table | inline-table | table-row-group | table-header-group | table-footer-group | table-row | table-column-group | table-column | table-cell | table-caption | none | inherit<br />
default value: inline, block or list-item, depending on the element. The <code>&lt;img&gt;</code> is an inline element.<br />
Run-in should make the run-in element be the first line of the next sibling block level element, if it is before a block level element that is not floated or absolutely positioned. If the next sibling is positioned or floated, then the run-in element will be a block level element instead of appearing in-line.<br />
<a href="http://www.quirksmode.org/css/display.html">PPK’s Quirksmode</a> explains it well. The <a href="http://www.w3schools.com/css/pr_class_display.asp">w3schools</a> lists table display values.<br />
When visibility is set to hidden, the element being hidden still occupies its same place in the layout of the page. If the display is set to none, the element does not occupy any space on the page — as if it didn’t exist..</p>
<p>Answer Rating</p>
<ol>
<li>Doesn’t know</li>
<li>Knows the answer to A</li>
<li>Knows the answer to A and D</li>
<li>Knows the answer to A, B and D</li>
<li>Knows the answer to C too!</li>
</ol>
</div>
<div>
<h4>CSS Interview Question</h4>
<p>Question</p>
<p>a) What are the five possible values for “position”?<br />
b) What is the default/initial value for “position”?<br />
c) How does the browser determine where to place positioned elements<br />
d) What are the pros and cons of using absolute positioning?<br />
e) if they are really advanced, ask about IE z-index issues with positioned elements.</p>
<p>Answer</p>
<p>a) Values for position: static, relative, absolute, fixed, inherit<br />
b) Static<br />
c) They are placed relative to the next parent element that has absolute or relative value declared<br />
d) Absolutely positioned elements are removed from the document flow. The positioned element does not flow around the content of other elements, nor does their content flow around the positioned element. An absolutely positioned element may overlap other elements, or be overlapped by them.<br />
e) IE treats a position like a z-index reset, so you have to declare position of static on the parent element containing the z-indexed elements to have them responsd to z-index correctly.</p>
<p>Answer Rating</p>
<ol>
<li>Doesn’t know</li>
<li>Knows 4 out of 5 answers in part A</li>
<li>Knows A &amp; B</li>
<li>Knows A, B &amp; C</li>
<li>Knows A-D</li>
<li>Knows E too</li>
</ol>
</div>
<div>
<h4>CSS Interview Question</h4>
<p>Question:</p>
<p>Write a snippet of CSS that will display a paragraph in blue in older browsers, red in newer browsers, green in IE6 and black in IE7</p>
<p>Possible Answer:</p>
<p>#content p{color:blue}<br />
html&gt;body #content p {color:red}<br />
* html #content p{color:green}<br />
html&gt;body #content p {*color:black;}</p>
<p>Answer Rating</p>
<ol>
<li>Doesn’t know</li>
<li>Knows how to declare one color, but no hacks</li>
<li>knows the html&gt;body hack and * html hack</li>
<li>Knows all the hacks, but doesn’t validate or uses conditional comments in the HTML</li>
<li> Gives you the right answer and explains why the CSS won’t validate, or, uses a valid hack, other than conditional IE comments, instead of the above answer.</li>
</ol>
</div>
<div>
<h4>Basic Javascript Interview Question</h4>
<p>Question:</p>
<p>What is the correct way to include JavaScript into your HTML?</p>
<p>Answer:</p>
<p>See <a title="Permanent link to including javascript in XHTML, including CDATA" rel="bookmark" href="http://www.evotech.net/blog/2007/05/including-javascript-in-xhtml/">Including Javascript in XHTML </a> for answers.</p>
<p>Answer Rating:</p>
<ol>
<li>&lt;a href=”javscript:function()”&gt; &#8211; and other incorrect answers</li>
<li> verbally explains the theory but doesn’t know how to do it</li>
<li> correct explanation using inline event handlers or inline code</li>
<li> discusses and knows how to implement javascript event listeners</li>
<li> Explainst how you include JS within an XHTML document and ensure it validates using CDATA, explains</li>
</ol>
</div>
<div>
<h4>Basic Javascript Array / XHTML Form Interview Question</h4>
<p>Question</p>
<p>Are the following all equal, and, if so, what would your code look like to make the following all equal the same thing:</p>
<pre>  alert(document.forms["myform"].elements["field"].value);
  alert(document.forms[1].elements[1].value);
  alert(document.myform.field.value);</pre>
<p>answer:</p>
<pre>&lt;form name="myform" method="post" action="something"&gt;
&lt;input name="anything" value="anything" type="something" /&gt;
&lt;input name="field" value="something" type="something" /&gt;
&lt;/form&gt;</pre>
<p>Answer includes knowing that the form is the second form on the page, and that the <code>field</code> input element is the second element within that form.</p>
<p>Answer Rating</p>
<ol>
<li>Doesn’t know how to code forms and doesn’t know that the first index of an array is 0.</li>
<li>Knows either how to code forms with valid XHTML or that array starts at 0, but not both.</li>
<li>Knows how to code forms but not correctly, but omits something like doesn’t know that the form needs to be the second one on the page, and the element is the second one in the form. Would know how to do it if they actually put thought into it.</li>
<li>Codes the form correctly, but uses ID instead of name</li>
<li>Codes everything correctly</li>
</ol>
</div>
<div>
<h4>JavaScript Interview Question</h4>
<p>Question:</p>
<p>How do you dynamically add a paragraph with stylized content to a page?</p>
<p>Possible Answer:</p>
<pre>newParagraph = document.createElement('p');
newParagraph.setAttribute('class', 'myClass');
newText = document.createTextNode('this is a new paragraph');
newParagraph.appendChild(newText);
myLocation = document.getElementById('parent_of_new_paragraph);
myLocation.appendChild(newParagraph);</pre>
<p>Answer Rating:</p>
<ol>
<li>Wrong Answer (i.e. “you can’t”), I don’t know.</li>
<li>Use JavaScript, with no knowledge or incomplete knowledge of how that is done. Suggesting innerHTML, but not really knowing. Or explanation of accessibilty issues surrounding this.</li>
<li>Able to explain how you create a node, add content to the node, add a class attributes to that element, and then add that node as a child of the parent element (the above example)</li>
<li>Explanation of how to do it (worth 3 points) and explanation as to issues that arise when doing it, such as screen readers not knowing that text has changed, IE6 and IE7 not applying styles included with added content, not duplicating IDs, etc.</li>
<li>Has no clue how to do it to start, but can figure it out with guidance: extra points for the quick learner!</li>
</ol>
</div>
<h3>Other questions ideas:</h3>
<p><strong>Q: </strong>How do you organize your CSS? How do you come up with id and class names (what naming conventions do you use)?<br />
<strong>A: </strong>While there are no right answers, there are <a href="http://www.evotech.net/blog/2007/04/css-best-practices/"> best practices</a>. Issues to look for are not having div mania, no inline CSS, no presentational markup, minimal use of classes, understanding the CSS cascade.</p>
<p><strong>Q: </strong>What do you think of hacks? When should you use them? If you use them, how do you maintain them? What can be done to avoid needing to use box-model hacks? (if they aren’t pros, you can ask them what is the issue with x-browsers and the box model)</p>
<p><strong>Q: </strong>What are the pros and cons of using tables for layout? Do you use tables? What are the pros and cons of tableless design? How do you generally layout your pages?<br />
<strong>A: </strong>check for them NOT using tables</p>
<p><strong>Q: </strong>Check to ensure that they separate structure and semantics first from presentation later? Do not ask about this during HTML, but do in webstandards.</p>
<p><strong>Q: </strong>What are some deprecated elements and attributes that you use, and in what instances do you use them?<br />
<strong>A:</strong> <a href="http://www.evotech.net/blog/2007/06/xhtml-html-strict-transitional-deprecated/">List of deprecated elements and attributes</a>.</p>
<p><strong>Q: </strong>What is involved in making a website accessible? What are arguments you use to convince others to invest in making their web site accessible.<br />
<strong>A: </strong>See <a href="http://www.evotech.net/blog/2007/04/making-the-web-accessible/">Making the web Accessible</a>. Making sites accessible also makes them more search engine friendly (saves money), makes your pages accessible to the 20% of the population that has some type of disability (so you can make more money) and it’s the law in many places.</p>
<p><strong>Q: </strong>Define what web standards mean to you? How do you implement web standards?</p>
<p><strong>Q: </strong>In CSS, how can you make a form elments background-color change when the user is entering text? will this work in all browsers?</p>
<p><strong>Q: </strong>How can you target an element in your HTML using the DOM?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/techpassion.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/techpassion.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/techpassion.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/techpassion.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/techpassion.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/techpassion.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/techpassion.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/techpassion.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/techpassion.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/techpassion.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/techpassion.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/techpassion.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/techpassion.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/techpassion.wordpress.com/83/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techpassion.wordpress.com&amp;blog=5988916&amp;post=83&amp;subd=techpassion&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://techpassion.wordpress.com/2009/06/02/xhtml-css-javascript-web-developer-applicant-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9eea02dca209112818f5a9ee1f48cb3e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Admin</media:title>
		</media:content>
	</item>
		<item>
		<title>Hibernate Interview Questions</title>
		<link>http://techpassion.wordpress.com/2009/05/30/hibernate-interview-questions/</link>
		<comments>http://techpassion.wordpress.com/2009/05/30/hibernate-interview-questions/#comments</comments>
		<pubDate>Sat, 30 May 2009 12:25:43 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[Hibernate Framework]]></category>
		<category><![CDATA[Hibernate]]></category>

		<guid isPermaLink="false">http://techpassion.wordpress.com/?p=76</guid>
		<description><![CDATA[1.What is ORM ? ORM stands for object/relational mapping. ORM is the automated persistence of objects in a Java application to the tables in a relational database. 2.What does ORM consists of ? An ORM solution consists of the followig four pieces: API for performing basic CRUD operations API to express ries refering to classes [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techpassion.wordpress.com&amp;blog=5988916&amp;post=76&amp;subd=techpassion&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 		TD P { margin-bottom: 0in } 		TH P { margin-bottom: 0in } 		A:link { so-language: zxx } --><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">1.What is ORM ?</span></span></p>
<p align="justify"><a name="KonaLink0"></a><a name="KonaLink1"></a><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">ORM stands for object/relational mapping. ORM is the automated persistence of objects in a </span></span><a href="http://www.developersbook.com/hibernate/interview-questions/hibernate-interview-questions-faqs.php#" target="undefined"><span style="color:#ff9900;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="font-weight:normal;">Java application</span></span></span></span></a><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> to the tables in a </span></span><a href="http://www.developersbook.com/hibernate/interview-questions/hibernate-interview-questions-faqs.php#" target="undefined"><span style="color:#ff9900;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="font-weight:normal;">relational database</span></span></span></span></a><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">.</span></span></p>
<p><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">2.What does ORM consists of ?</span></span></p>
<p align="justify"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">An ORM solution consists of the followig four pieces:</span></span></p>
<ul>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">API 	for performing basic CRUD operations </span></span></p>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">API 	to express ries refering to classes </span></span></p>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Facilities 	to specify metadata </span></span></p>
</li>
<li><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Optimization 	facilities : dirty checking,lazy associations fetching </span></span></li>
</ul>
<p><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">3.What are the ORM levels ?</span></span></p>
<p align="justify"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">The ORM levels are:</span></span></p>
<ul>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Pure 	relational (stored procedure.) </span></span></p>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Light 	objects mapping (JDBC) </span></span></p>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Medium 	object mapping </span></span></p>
</li>
<li><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Full object 	Mapping (composition,inheritance, polymorphism, persistence by 	reachability) </span></span></li>
</ul>
<p><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">4.What is Hibernate?</span></span></p>
<p align="justify"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Hibernate is a pure Java object-relational mapping (ORM) and persistence framework that allows you to map plain old Java objects to relational database tables using (XML) configuration files.Its purpose is to relieve the developer from a significant amount of relational data persistence-related programming tasks.</span></span></p>
<p><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">5.Why do you need ORM tools like hibernate?</span></span></p>
<p align="justify"><a name="KonaLink2"></a><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">The main advantage of ORM like hibernate is that it shields developers from messy </span></span><a href="http://www.developersbook.com/hibernate/interview-questions/hibernate-interview-questions-faqs.php#" target="undefined"><span style="color:#ff9900;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="font-weight:normal;">SQL</span></span></span></span></a><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">. Apart from this, ORM provides following benefits:</span></span></p>
<ul>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Improved 	productivity</strong> </span></span></p>
<ul>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">High-level 		object-oriented API </span></span></p>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Less 		Java code to write </span></span></p>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">No 		SQL to write </span></span></p>
</li>
</ul>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Improved 	performance</strong> </span></span></p>
<ul>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Sophisticated 		caching </span></span></p>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Lazy 		loading </span></span></p>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Eager 		loading </span></span></p>
</li>
</ul>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Improved 	maintainability</strong> </span></span></p>
<ul>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">A 		lot less code to write </span></span></p>
</li>
</ul>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Improved 	portability</strong> </span></span></p>
<ul>
<li><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">ORM 		framework generates database-specific SQL for you </span></span></li>
</ul>
</li>
</ul>
<p><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">6.What Does Hibernate Simplify?</span></span></p>
<p align="justify"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Hibernate simplifies:</span></span></p>
<ul>
<li>
<p style="margin-bottom:0;"><a name="KonaLink3"></a><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Saving 	and retrieving </span></span><a href="http://www.developersbook.com/hibernate/interview-questions/hibernate-interview-questions-faqs.php#" target="undefined"><span style="color:#ff9900;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="font-weight:normal;">your 	domain</span></span></span></span></a><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> objects </span></span></p>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Making 	database column and table name changes </span></span></p>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Centralizing 	pre save and post retrieve logic </span></span></p>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Complex 	joins for retrieving related items </span></span></p>
</li>
<li><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Schema 	creation from object model </span></span></li>
</ul>
<p><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">7.What is the need for Hibernate xml mapping file? </span></span></p>
<p align="justify"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Hibernate mapping file tells Hibernate which tables and columns to use to load and store objects. Typical mapping file look as follows:</span></span></p>
<p><img src="http://www.developersbook.com/hibernate/images/hbm-mapping.png" border="0" alt="Hibernate Mapping file" width="483" height="273" align="bottom" /></p>
<p><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">8.What are the most common methods of Hibernate configuration?</span></span></p>
<p align="justify"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">The most common methods of Hibernate configuration are:</span></span></p>
<ul>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Programmatic 	configuration </span></span></p>
</li>
<li><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">XML 	configuration (</span></span><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">hibernate.cfg.xml</span></span></code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">) </span></span></li>
</ul>
<p><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">9.What are the important tags of hibernate.cfg.xml?</span></span></p>
<p align="justify"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">An Action Class is an adapter between the contents of an incoming HTTP rest and the corresponding business logic that should be executed to process this rest.</span></span></p>
<p><img src="http://www.developersbook.com/hibernate/images/hbm-config.png" border="0" alt="hibernate.cfg.xml" width="616" height="372" align="bottom" /></p>
<p><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">10.What are the Core interfaces are of Hibernate framework?</span></span></p>
<table dir="ltr" border="0" cellspacing="0" cellpadding="2" width="9" align="right">
<col width="5"></col>
<tbody>
<tr>
<td width="5"></td>
</tr>
</tbody>
</table>
<p align="justify"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">The five core interfaces are used in just about every Hibernate application. Using these interfaces, you can store and retrieve persistent objects and control transactions.</span></span></p>
<ul>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Session 	interface </span></span></p>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">SessionFactory 	interface </span></span></p>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Configuration 	interface </span></span></p>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Transaction 	interface </span></span></p>
</li>
<li><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Query and 	Criteria interfaces </span></span></li>
</ul>
<p><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">11.What role does the Session interface play in Hibernate?</span></span></p>
<p align="justify"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">The Session interface is the primary interface used by Hibernate applications. It is a single-threaded, short-lived object representing a conversation between the application and the persistent store. It allows you to create query objects to retrieve persistent objects.</span></span></p>
<p><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Session session = sessionFactory.openSession();</span></span></code></p>
<p align="justify"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Session interface role</strong>:</span></span></p>
<ul>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Wraps 	a JDBC connection </span></span></p>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Factory 	for Transaction </span></span></p>
</li>
<li><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Holds a 	mandatory (first-level) cache of persistent objects, used when 	navigating the object graph or looking up objects by identifier </span></span></li>
</ul>
<p><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">12.What role does the SessionFactory interface play in Hibernate?</span></span></p>
<p align="justify"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">The application obtains Session instances from a SessionFactory. There is typically a single SessionFactory for the whole application—created during application initialization. The SessionFactory caches generate SQL statements and other mapping metadata that Hibernate uses at runtime. It also holds cached data that has been read in one unit of work and may be reused in a future unit of work</span></span></p>
<p><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">SessionFactory sessionFactory = configuration.buildSessionFactory();</span></span></code></p>
<table dir="ltr" border="0" cellspacing="0" cellpadding="0" width="7" align="right" bgcolor="#fafafa">
<col width="7"></col>
<tbody>
<tr>
<td width="7" height="2"></td>
</tr>
</tbody>
</table>
<p>13.What is the general flow of Hibernate communication with RDBMS?</p>
<p align="justify"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">The general flow of Hibernate communication with RDBMS is :</span></span></p>
<ul>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Load 	the Hibernate configuration file and create configuration object. It 	will automatically load all hbm mapping files </span></span></p>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Create 	session factory from configuration object </span></span></p>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Get 	one session from this session factory </span></span></p>
</li>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Create 	HQL Query </span></span></p>
</li>
<li><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Execute 	query to get list containing Java objects </span></span></li>
</ul>
<p><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">14.What is Hibernate Query Language (HQL)?</span></span></p>
<p align="justify"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Hibernate offers a query language that embodies a very powerful and flexible mechanism to query, store, update, and retrieve objects from a database. This language, the Hibernate query Language (HQL), is an object-oriented extension to SQL.</span></span></p>
<p align="justify">
<p><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">15.How do you map Java Objects with Database tables?</span></span></p>
<ul>
<li>
<p style="margin-bottom:0;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">First 	we need to write Java domain objects (beans with setter and getter). 	The variables should be same as database columns. </span></span></p>
</li>
<li><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Write 	hbm.xml, where we map java class to table and database columns to 	Java class variables. </span></span></li>
</ul>
<p align="justify"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Example</strong> :</span></span></p>
<pre><span style="color:#008000;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">&lt;hibernate-mapping&gt;</span></span></span>
  <span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="color:#008000;">&lt;class</span> <span style="color:#800040;">name</span>=<span style="color:#0000ff;">"com.test.User"</span>  <span style="color:#800040;">table</span>=<span style="color:#0000ff;">"user"</span><span style="color:#008000;">&gt;</span></span></span>
   <span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="color:#008000;">&lt;property</span>  <span style="color:#800040;">column</span>=<span style="color:#0000ff;">"USER_NAME"</span> <span style="color:#800040;">length</span>=<span style="color:#0000ff;">"255"</span></span></span>
      <span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="color:#800040;">name</span>=<span style="color:#0000ff;">"userName"</span> <span style="color:#800040;">not-null</span>=<span style="color:#800040;">"true"</span>  <span style="color:#800040;">type</span>=<span style="color:#0000ff;">"java.lang.String"</span><span style="color:#008000;">/&gt;</span></span></span>
   <span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="color:#008000;">&lt;property</span>  <span style="color:#800040;">column</span>=<span style="color:#0000ff;">"USER_PASSWORD"</span> <span style="color:#800040;">length</span>=<span style="color:#0000ff;">"255"</span></span></span>
     <span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="color:#800040;">name</span>=<span style="color:#0000ff;">"userPassword"</span> <span style="color:#800040;">not-null</span>=<span style="color:#0000ff;">"true"</span>  <span style="color:#800040;">type</span>=<span style="color:#0000ff;">"java.lang.String"</span><span style="color:#008000;">/&gt;</span></span></span>
 <span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="color:#008000;">&lt;/class&gt;</span></span></span>
<span style="color:#008000;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">&lt;/hibernate-mapping&gt;</span></span></span>

 <span style="font-family:Times New Roman,serif;"><span style="font-size:small;">16.What’s the difference between load() and get()? </span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">load() vs. get() :-</span></span></pre>
<table border="0" cellspacing="0" cellpadding="6" width="665">
<col width="348"></col>
<col width="293"></col>
<tbody>
<tr>
<th width="348"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">load()</span></span></th>
<th width="293"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">get()</span></span></th>
</tr>
<tr>
<td width="348"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Only use the </span></span><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">load()</span></span></code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> method if you are sure that the object exists.</span></span></td>
<td width="293"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">If you are not 			sure that the object exists, then use one of the </span></span><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">get()</span></span></code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> methods.</span></span></td>
</tr>
<tr>
<td width="348"><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">load()</span></span></code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> method will throw an exception if the unique id is not found in 			the database.</span></span></td>
<td width="293"><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">get()</span></span></code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> method will return null if the unique id is not found in the 			database.</span></span></td>
</tr>
<tr>
<td width="348"><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">load()</span></span></code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> just returns a proxy by default and database won’t be hit until 			the proxy is first invoked.</span></span></td>
<td width="293"><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">get()</span></span></code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> will hit the database immediately.</span></span></td>
</tr>
</tbody>
</table>
<pre> <span style="font-family:Times New Roman,serif;"><span style="font-size:small;">17.What is the difference between and merge and update ?</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Use </span></span><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">update()</span></span></code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> if you are sure that the session does not contain an already persistent instance with the same identifier, and </span></span><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">merge()</span></span></code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> if you want to merge your modifications at any time without consideration of the state of the session.</span></span>

  <span style="font-family:Times New Roman,serif;"><span style="font-size:small;">18.How do you define sequence generated primary key in hibernate?</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Using &lt;generator&gt; tag.</span></span>
 <span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Example</strong>:-</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="color:#008000;">&lt;id</span> <span style="color:#800040;">column</span>=<span style="color:#0000ff;">"USER_ID"</span> <span style="color:#800040;">name</span>=<span style="color:#0000ff;">"id"</span> <span style="color:#800040;">type</span>=<span style="color:#0000ff;">"java.lang.Long"</span><span style="color:#008000;">&gt; </span></span></span>
    <span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="color:#008000;">&lt;generator</span> <span style="color:#800040;">class</span>=<span style="color:#0000ff;">"sequence"</span><span style="color:#008000;">&gt; </span></span></span>
     <span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="color:#008000;">&lt;param</span> <span style="color:#800040;">name</span>=<span style="color:#0000ff;">"table"</span>&gt;SEQUENCE_NAME<span style="color:#008000;">&lt;/param&gt;</span></span></span>
  <span style="color:#008000;"> <span style="font-family:Times New Roman,serif;"><span style="font-size:small;">&lt;generator&gt;</span></span></span>
<span style="color:#008000;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">&lt;/id&gt;</span></span></span></pre>
<table dir="ltr" border="0" cellspacing="0" cellpadding="0" width="15" align="right" bgcolor="#fafafa">
<col width="15"></col>
<tbody>
<tr>
<td width="15" height="16"></td>
</tr>
</tbody>
</table>
<p><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">19.Define cascade and inverse option in one-many mapping?</span></span></p>
<pre style="margin-bottom:.2in;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">cascade - enable operations to cascade to child entities.</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">cascade="all|none|save-update|delete|all-delete-orphan"

inverse - mark this collection as the "inverse" end of a bidirectional association.

inverse="true|false"

Essentially "inverse" indicates which end of a relationship should be ignored, so when persisting a parent who has a collection of children, should you ask the parent for its list of children, or ask the children who the parents are?</span></span>
<a name="KonaLink01"></a><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">20.What do you mean by Named – </span></span><a href="http://www.developersbook.com/hibernate/interview-questions/hibernate-interview-questions-faqs-2.php#" target="undefined"><span style="color:#ff9900;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>SQL query</strong></span></span></span></a><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">?</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Named SQL queries are defined in the mapping xml document and called wherever required.</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Example:</strong></span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="color:#008000;">&lt;sql-query </span><span style="color:#800040;">name</span> =<span style="color:#0000ff;"> "empdetails"</span>&gt;</span></span>
   <span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="color:#008000;">&lt;return</span> <span style="color:#800040;">alias</span>=<span style="color:#0000ff;">"emp"</span> <span style="color:#800040;">class</span>=<span style="color:#0000ff;">"com.test.Employee"</span><span style="color:#008000;">/&gt;</span></span></span>
<span style="color:#ff00ff;">      <span style="font-family:Times New Roman,serif;"><span style="font-size:small;">SELECT emp.EMP_ID AS {emp.empid},</span></span></span>
<span style="color:#ff00ff;">                 <span style="font-family:Times New Roman,serif;"><span style="font-size:small;">emp.EMP_ADDRESS AS {emp.address},</span></span></span>
<span style="color:#ff00ff;">                 <span style="font-family:Times New Roman,serif;"><span style="font-size:small;">emp.EMP_NAME AS {emp.name}</span></span></span>
<span style="color:#ff00ff;">      <span style="font-family:Times New Roman,serif;"><span style="font-size:small;">FROM Employee EMP WHERE emp.NAME LIKE :name</span></span></span>
<span style="color:#008000;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">&lt;/sql-query&gt;</span></span></span>

<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Invoke Named Query :</span></span>

<span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="color:#800040;">List </span>people = <span style="color:#800040;">session</span>.getNamedQuery(<span style="color:#0000ff;">"empdetails"</span>)</span></span>
                     <span style="font-family:Times New Roman,serif;"><span style="font-size:small;">.setString(<span style="color:#0000ff;">"TomBrady"</span>, name)</span></span>
                     <span style="font-family:Times New Roman,serif;"><span style="font-size:small;">.setMaxResults(50)</span></span>
                     <span style="font-family:Times New Roman,serif;"><span style="font-size:small;">.list();</span></span>

<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">21.How do you invoke Stored Procedures?</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="color:#008000;">&lt;sql-query</span> <span style="color:#800040;">name</span>=<span style="color:#0000ff;">"selectAllEmployees_SP"</span> <span style="color:#800040;">callable</span>=<span style="color:#0000ff;">"true"</span><span style="color:#008000;">&gt;</span></span></span>
<span style="color:#008000;"> <span style="font-family:Times New Roman,serif;"><span style="font-size:small;">&lt;return</span> <span style="color:#800040;">alias</span>=<span style="color:#0000ff;">"emp"</span> <span style="color:#800040;">class</span>=<span style="color:#0000ff;">"employee"</span><span style="color:#008000;">&gt;</span></span></span>
   <span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="color:#008000;">&lt;return-property</span> <span style="color:#800040;">name</span>=<span style="color:#0000ff;">"empid"</span> <span style="color:#800040;">column</span>=<span style="color:#0000ff;">"EMP_ID"</span><span style="color:#008000;">/&gt;</span>       </span></span>
  <span style="color:#800040;"> </span><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="color:#008000;">&lt;return-property</span> <span style="color:#800040;">name</span>=<span style="color:#0000ff;">"name"</span> <span style="color:#800040;">column</span>=<span style="color:#0000ff;">"EMP_NAME"</span><span style="color:#008000;">/&gt; </span>      </span></span>
  <span style="color:#008000;"> <span style="font-family:Times New Roman,serif;"><span style="font-size:small;">&lt;return-property</span> <span style="color:#800040;">name</span>=<span style="color:#0000ff;">"address"</span> <span style="color:#800040;">column</span>=<span style="color:#0000ff;">"EMP_ADDRESS"</span><span style="color:#008000;">/&gt;</span></span></span>
    <span style="font-family:Times New Roman,serif;"><span style="font-size:small;">{ <span style="color:#000080;">? = call selectAllEmployees()</span> }</span></span>
<span style="color:#008000;"> <span style="font-family:Times New Roman,serif;"><span style="font-size:small;">&lt;/return&gt;</span></span></span>
<span style="color:#008000;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">&lt;/sql-query&gt;</span></span></span>

<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">22.Explain Criteria API</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Criteria is a simplified API for retrieving entities by composing Criterion objects. This is a very convenient approach for functionality like "search" screens where there is a variable number of conditions to be placed upon the result set.</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Example</strong> :</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="color:#800040;">List </span>employees = <span style="color:#800040;">session</span>.createCriteria(Employee.class)</span></span>
                         <span style="font-family:Times New Roman,serif;"><span style="font-size:small;">.add(Restrictions.like(<span style="color:#0000ff;">"name"</span>, <span style="color:#0000ff;">"a%"</span>) )</span></span>
                         <span style="font-family:Times New Roman,serif;"><span style="font-size:small;">.add(Restrictions.like(<span style="color:#0000ff;">"address"</span>, <span style="color:#0000a0;">"Boston"</span>))</span></span>
                         <span style="font-family:Times New Roman,serif;"><span style="font-size:small;">.addOrder(Order.asc(<span style="color:#0000ff;">"name"</span>) )</span></span>
                         <span style="font-family:Times New Roman,serif;"><span style="font-size:small;">.list();</span></span>

<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">23.Define HibernateTemplate?</span></span>
<code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">org.springframework.orm.hibernate.HibernateTemplate</span></span></code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> is a helper class which provides different methods for querying/retrieving data from the database. It also converts checked HibernateExceptions into unchecked DataAccessExceptions.</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">24.What are the benefits does HibernateTemplate provide?</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">The benefits of HibernateTemplate are :</span></span></pre>
<ul>
<li>
<pre><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">HibernateTemplate</span></span></code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">, a Spring Template class simplifies interactions with Hibernate Session.</span></span></pre>
</li>
<li>
<pre><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Common functions are simplified to single method calls.</span></span></pre>
</li>
<li>
<pre><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Sessions are automatically closed.</span></span></pre>
</li>
<li>
<pre style="margin-bottom:.2in;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Exceptions are automatically caught and converted to runtime exceptions.</span></span></pre>
</li>
</ul>
<pre style="margin-bottom:.2in;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">25.How do you switch between relational databases without code changes?</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Using Hibernate SQL Dialects , we can switch databases. Hibernate will generate appropriate hql queries based on the dialect defined.</span></span>
<a name="KonaLink11"></a><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">26.If you want to see the Hibernate generated </span></span><a href="http://www.developersbook.com/hibernate/interview-questions/hibernate-interview-questions-faqs-2.php#" target="undefined"><span style="color:#ff9900;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>SQL  </strong></span></span></span></a><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">statements on console, what should we do?</span></span>
<a name="KonaLink31"></a><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">In Hibernate </span></span><a href="http://www.developersbook.com/hibernate/interview-questions/hibernate-interview-questions-faqs-2.php#" target="undefined"><span style="color:#ff9900;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="font-weight:normal;">configuration file</span></span></span></span></a><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> set as follows:</span></span>
<code><span style="color:#008000;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">&lt;property</span></span></span></code><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> </span></span></code><code><span style="color:#800040;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">name</span></span></span></code><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">=</span></span></code><code><span style="color:#0000ff;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">"show_sql"</span></span></span></code><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">&gt;true</span></span></code><code><span style="color:#008000;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">&lt;/property&gt;</span></span></span></code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">

27.What are derived properties?</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">The properties that are not mapped to a column, but calculated at runtime by evaluation of an expression are called derived properties. The expression can be defined using the formula attribute of the element.</span></span></pre>
<table dir="ltr" border="0" cellspacing="0" cellpadding="2" width="9" align="right">
<col width="5"></col>
<tbody>
<tr>
<td width="5"></td>
</tr>
</tbody>
</table>
<pre style="margin-bottom:.2in;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">28.What is component mapping in Hibernate?</span></span></pre>
<ul>
<li>
<pre><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">A component is an object saved as a value, not as a reference</span></span></pre>
</li>
<li>
<pre><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">A component can be saved directly without needing to declare interfaces or identifier properties</span></span></pre>
</li>
<li>
<pre><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Required to define an empty constructor</span></span></pre>
</li>
<li>
<pre style="margin-bottom:.2in;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Shared references not supported</span></span></pre>
</li>
</ul>
<pre style="margin-bottom:.2in;text-align:justify;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Example</strong>:</span></span>

<img src="http://www.developersbook.com/hibernate/images/component-mapping.png" border="0" alt="Component Mapping" width="642" height="415" align="bottom" />

<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">29.What is the difference between sorted and ordered collection in hibernate?</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>sorted collection vs. order collection</strong> :-</span></span></pre>
<table border="0" cellspacing="0" cellpadding="6" width="665">
<col width="325"></col>
<col width="316"></col>
<tbody>
<tr>
<th width="325"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">sorted 			collection</span></span></th>
<th width="316"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">order 			collection</span></span></th>
</tr>
<tr>
<td width="325"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">A sorted 			collection is sorting a collection by utilizing the sorting 			features provided by the Java collections framework. The sorting 			occurs in the memory of JVM which running Hibernate, after the 			data being read from database using java comparator.</span></span></td>
<td width="316"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Order 			collection is sorting a collection by specifying the order-by 			clause for sorting this collection when retrieval.</span></span></td>
</tr>
<tr>
<td width="325"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">If your 			collection is not large, it will be more efficient way to sort it.</span></span></td>
<td width="316"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">If your 			collection is very large, it will be more efficient way to sort it 			.</span></span></td>
</tr>
</tbody>
</table>
<pre><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">31.What is the advantage of Hibernate over jdbc? </span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Hibernate Vs. JDBC :-</span></span></pre>
<table border="0" cellspacing="0" cellpadding="6" width="665">
<col width="323"></col>
<col width="318"></col>
<tbody>
<tr>
<th width="323"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">JDBC</span></span></th>
<th width="318"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Hibernate</span></span></th>
</tr>
<tr>
<td width="323"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">With JDBC, 			developer has to write code to map an object model&#8217;s data 			representation to a relational data model and its corresponding 			database schema.</span></span></td>
<td width="318"><a name="KonaLink02"></a><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Hibernate 			is flexible and powerful ORM solution to map Java classes to </span></span><a href="http://www.developersbook.com/hibernate/interview-questions/hibernate-interview-questions-faqs-3.php#" target="undefined"><span style="color:#ff9900;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="font-weight:normal;">database 			tables</span></span></span></span></a><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">. 			Hibernate itself takes care of this mapping using XML files so 			developer does not need to write code for this.</span></span></td>
</tr>
<tr>
<td width="323"><a name="KonaLink13"></a><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">With 			JDBC, the automatic mapping of </span></span><a href="http://www.developersbook.com/hibernate/interview-questions/hibernate-interview-questions-faqs-3.php#" target="undefined"><span style="color:#ff9900;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="font-weight:normal;">Java 			objects</span></span></span></span></a><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> with database tables and vice versa conversion is to be taken care 			of by the developer manually with lines of code.</span></span></td>
<td width="318"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Hibernate 			provides transparent persistence and developer does not need to 			write code explicitly to map database tables tuples to application 			objects during interaction with RDBMS.</span></span></td>
</tr>
<tr>
<td width="323"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">JDBC supports 			only native Structured Query Language (SQL). Developer has to find 			out the efficient way to access database, i.e. to select effective 			query from a number of queries to perform same task.</span></span></td>
<td width="318"><a name="KonaLink21"></a><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Hibernate 			provides a powerful query language Hibernate Query Language 			(independent from type of database) that is expressed in a 			familiar SQL like syntax and includes full support for polymorphic 			queries. Hibernate also supports native </span></span><a href="http://www.developersbook.com/hibernate/interview-questions/hibernate-interview-questions-faqs-3.php#" target="undefined"><span style="color:#ff9900;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><span style="font-weight:normal;">SQL</span></span></span></span></a><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> statements. It also selects an effective way to perform a database 			manipulation task for an application.</span></span></td>
</tr>
<tr>
<td width="323"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Application 			using JDBC to handle persistent data (database tables) having 			database specific code in large amount. The code written to map 			table data to application objects and vice versa is actually to 			map table fields to object properties. As table changed or 			database changed then it’s essential to change object structure 			as well as to change code written to map 			table-to-object/object-to-table.</span></span></td>
<td width="318"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Hibernate 			provides this mapping itself. The actual mapping between tables 			and application objects is done in XML files. If there is change 			in Database or in any table then the only need to change XML file 			properties.</span></span></td>
</tr>
<tr>
<td width="323"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">With JDBC, it 			is developer’s responsibility to handle JDBC result set and 			convert it to Java objects through code to use this persistent 			data in application. So with JDBC, mapping between Java objects 			and database tables is done manually.</span></span></td>
<td width="318"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Hibernate 			reduces lines of code by maintaining object-table mapping itself 			and returns result to application in form of Java objects. It 			relieves programmer from manual handling of persistent data, hence 			reducing the development time and maintenance cost.</span></span></td>
</tr>
<tr>
<td width="323"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">With JDBC, 			caching is maintained by hand-coding.</span></span></td>
<td width="318"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Hibernate, 			with Transparent Persistence, cache is set to application work 			space. Relational tuples are moved to this cache as a result of 			query. It improves performance if client application reads same 			data many times for same write. Automatic Transparent Persistence 			allows the developer to concentrate more on business logic rather 			than this application code.</span></span></td>
</tr>
<tr>
<td width="323"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">In JDBC there 			is no check that always every user has updated data. This check 			has to be added by the developer.</span></span></td>
<td width="318"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Hibernate 			enables developer to define version type field to application, due 			to this defined field Hibernate updates version field of database 			table every time relational tuple is updated in form of Java class 			object to that table. So if two users retrieve same tuple and then 			modify it and one user save this modified tuple to database, 			version is automatically updated for this tuple by Hibernate. When 			other user tries to save updated tuple to database then it does 			not allow saving it because this user does not have updated data.</span></span></td>
</tr>
</tbody>
</table>
<table dir="ltr" border="0" cellspacing="0" cellpadding="0" width="13" align="right" bgcolor="#fafafa">
<col width="13"></col>
<tbody>
<tr>
<td width="13" height="2"></td>
</tr>
</tbody>
</table>
<pre style="margin-bottom:.2in;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">32.What are the Collection types in Hibernate ?</span></span></pre>
<ul>
<li>
<pre><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Bag</span></span></pre>
</li>
<li>
<pre><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Set</span></span></pre>
</li>
<li>
<pre><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">List</span></span></pre>
</li>
<li>
<pre><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Array</span></span></pre>
</li>
<li>
<pre style="margin-bottom:.2in;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Map</span></span></pre>
</li>
</ul>
<pre style="margin-bottom:.2in;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">33.What are the ways to express joins in HQL?</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">HQL provides four ways of expressing (inner and outer) joins:-</span></span></pre>
<ul>
<li>
<pre><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">An <em>implicit</em> association join</span></span></pre>
</li>
<li>
<pre><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">An ordinary join in the FROM clause</span></span></pre>
</li>
<li>
<pre><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">A fetch join in the FROM clause.</span></span></pre>
</li>
<li>
<pre style="margin-bottom:.2in;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">A <em>theta-style</em> join in the WHERE clause.</span></span></pre>
</li>
</ul>
<pre style="margin-bottom:.2in;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">34.Define cascade and inverse option in one-many mapping?</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">cascade - enable operations to cascade to child entities.</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">cascade="all|none|save-update|delete|all-delete-orphan"

inverse - mark this collection as the "inverse" end of a bidirectional association.

inverse="true|false"

Essentially "inverse" indicates which end of a relationship should be ignored, so when persisting a parent who has a collection of children, should you ask the parent for its list of children, or ask the children who the parents are?</span></span>

<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">35.What is Hibernate proxy? </span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">The </span></span><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">proxy</span></span></code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> attribute enables lazy initialization of persistent instances of the class. Hibernate will initially return CGLIB proxies which implement the named interface. The actual persistent object will be loaded when a method of the proxy is invoked.</span></span></pre>
<table dir="ltr" border="0" cellspacing="0" cellpadding="0" width="17" align="right" bgcolor="#fafafa">
<col width="17"></col>
<tbody>
<tr>
<td width="17" height="2"></td>
</tr>
</tbody>
</table>
<pre style="margin-bottom:.2in;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">36.How can Hibernate be configured to access an instance variable directly and not through a setter method ?</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">By mapping the property with access="field" in Hibernate metadata. This forces hibernate to bypass the setter method and access the instance variable directly while initializing a newly loaded object.</span></span>

<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">37.How can a whole class be mapped as immutable?</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Mark the class as mutable="false" (Default is true),. This specifies that instances of the class are (not) mutable. Immutable classes, may not be updated or deleted by the application.</span></span>

<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">38.What is the use of dynamic-insert and dynamic-update attributes in a class mapping?</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Criteria is a simplified API for retrieving entities by composing Criterion objects. This is a very convenient approach for functionality like "search" screens where there is a variable number of conditions to be placed upon the result set.</span></span></pre>
<ul>
<li>
<pre><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">dynamic-update</span></span></code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> (defaults to </span></span><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">false</span></span></code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">): Specifies that </span></span><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">UPDATE</span></span></code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> SQL should be generated at runtime and contain only those columns whose values have changed</span></span></pre>
</li>
<li>
<pre style="margin-bottom:.2in;"><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">dynamic-insert</span></span></code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> (defaults to </span></span><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">false</span></span></code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">): Specifies that </span></span><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">INSERT</span></span></code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> SQL should be generated at runtime and contain only the columns whose values are not null.</span></span></pre>
</li>
</ul>
<pre style="margin-bottom:.2in;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">39.What do you mean by fetching strategy ?</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">A </span></span><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><em>fetching strategy</em></span></span><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> is the strategy Hibernate will use for retrieving associated objects if the application needs to navigate the association. Fetch strategies may be declared in the O/R mapping metadata, or over-ridden by a particular HQL or </span></span><code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Criteria</span></span></code><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"> query.</span></span>

<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">40.What is automatic dirty checking?</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Automatic dirty checking is a feature that saves us the effort of explicitly asking Hibernate to update the database when we modify the state of an object inside a transaction.</span></span>

<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">41.What is transactional write-behind?</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Hibernate uses a sophisticated algorithm to determine an efficient ordering that avoids database foreign key constraint violations but is still sufficiently predictable to the user. This feature is called transactional write-behind.</span></span>

<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">42.What are Callback interfaces?</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Callback interfaces allow the application to receive a notification when something interesting happens to an object—for example, when an object is loaded, saved, or deleted. Hibernate applications don't need to implement these callbacks, but they're useful for implementing certain kinds of generic functionality.</span></span>

<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">43.What are the types of Hibernate instance states ?</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Three types of instance states:</span></span></pre>
<ul>
<li>
<pre><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Transient -The instance is not associated with any persistence context</span></span></pre>
</li>
<li>
<pre><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Persistent -The instance is associated with a persistence context</span></span></pre>
</li>
<li>
<pre style="margin-bottom:.2in;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Detached -The instance was associated with a persistence context which has been closed – currently not associated</span></span></pre>
</li>
</ul>
<pre style="margin-bottom:.2in;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">44.What are the differences between EJB 3.0 &amp; Hibernate</span></span>

<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Hibernate Vs EJB 3.0 :-</span></span></pre>
<table border="0" cellspacing="0" cellpadding="6" width="665">
<col width="330"></col>
<col width="311"></col>
<tbody>
<tr>
<th width="330"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Hibernate</span></span></th>
<th width="311"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">EJB 3.0</span></span></th>
</tr>
<tr>
<td width="330"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Session</strong>–Cache 			or collection of loaded objects relating to a single unit of work</span></span></td>
<td width="311"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Persistence 			Context</strong>-Set of entities that can be managed by a given 			EntityManager is defined by a persistence unit</span></span></td>
</tr>
<tr>
<td width="330"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>XDoclet 			Annotations</strong> used to support Attribute Oriented Programming</span></span></td>
<td width="311"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Java 5.0 			Annotations</strong> used to support Attribute Oriented Programming</span></span></td>
</tr>
<tr>
<td width="330"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Defines HQL</strong> for expressing queries to the database</span></span></td>
<td width="311"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Defines EJB 			QL</strong> for expressing queries</span></span></td>
</tr>
<tr>
<td width="330"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Supports 			Entity Relationships</strong> through mapping files and annotations in 			JavaDoc</span></span></td>
<td width="311"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Support 			Entity Relationships</strong> through Java 5.0 annotations</span></span></td>
</tr>
<tr>
<td width="330"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Provides a 			Persistence Manager API</strong> exposed via the Session, Query, 			Criteria, and Transaction API</span></span></td>
<td width="311"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Provides 			and Entity Manager Interface</strong> for managing CRUD operations for 			an Entity</span></span></td>
</tr>
<tr>
<td width="330"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Provides 			callback support</strong> through lifecycle, interceptor, and 			validatable interfaces</span></span></td>
<td width="311"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Provides 			callback support</strong> through Entity Listener and Callback methods</span></span></td>
</tr>
<tr>
<td width="330"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Entity 			Relationships are unidirectional</strong>. Bidirectional relationships 			are implemented by two unidirectional relationships</span></span></td>
<td width="311"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Entity 			Relationships are bidirectional or unidirectional</strong></span></span></td>
</tr>
</tbody>
</table>
<pre style="margin-bottom:.2in;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">45.What are the types of inheritance models in Hibernate?</span></span>
<span style="font-family:Times New Roman,serif;"><span style="font-size:small;">There are three types of inheritance models in Hibernate:</span></span></pre>
<ul>
<li>
<pre><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Table per class hierarchy</span></span></pre>
</li>
<li>
<pre><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Table per subclass</span></span></pre>
</li>
<li>
<pre style="margin-bottom:.2in;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Table per concrete class</span></span></pre>
</li>
</ul>
<p style="margin-bottom:0;">
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/techpassion.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/techpassion.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/techpassion.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/techpassion.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/techpassion.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/techpassion.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/techpassion.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/techpassion.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/techpassion.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/techpassion.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/techpassion.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/techpassion.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/techpassion.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/techpassion.wordpress.com/76/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techpassion.wordpress.com&amp;blog=5988916&amp;post=76&amp;subd=techpassion&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://techpassion.wordpress.com/2009/05/30/hibernate-interview-questions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9eea02dca209112818f5a9ee1f48cb3e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Admin</media:title>
		</media:content>

		<media:content url="http://www.developersbook.com/hibernate/images/hbm-mapping.png" medium="image">
			<media:title type="html">Hibernate Mapping file</media:title>
		</media:content>

		<media:content url="http://www.developersbook.com/hibernate/images/hbm-config.png" medium="image">
			<media:title type="html">hibernate.cfg.xml</media:title>
		</media:content>

		<media:content url="http://www.developersbook.com/hibernate/images/component-mapping.png" medium="image">
			<media:title type="html">Component Mapping</media:title>
		</media:content>
	</item>
		<item>
		<title>JSF Interview Questions</title>
		<link>http://techpassion.wordpress.com/2009/05/29/jsf-interview-questions/</link>
		<comments>http://techpassion.wordpress.com/2009/05/29/jsf-interview-questions/#comments</comments>
		<pubDate>Fri, 29 May 2009 23:43:00 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[JSF]]></category>

		<guid isPermaLink="false">http://techpassion.wordpress.com/?p=71</guid>
		<description><![CDATA[1. What is JSF (or JavaServer Faces)? A server side user interface component framework for Java™ technology-based web applications.JavaServer Faces (JSF) is an industry standard and a framework for building component-based user interfaces for web applications. JSF contains an API for representing UI components and managing their state; handling events, server-side validation, and data conversion; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techpassion.wordpress.com&amp;blog=5988916&amp;post=71&amp;subd=techpassion&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify"><span>1.</span> What is JSF (or JavaServer Faces)?</p>
<p><span>A server side user interface component framework for Java™ technology-based web applications.JavaServer Faces (JSF) is an industry standard and a framework for building component-based user interfaces for web applications.<br />
JSF contains an API for representing UI components and managing their state; handling events, server-side validation, and data conversion; defining page navigation; supporting internationalization and accessibility; and providing extensibility for all these features. </span></p>
<p align="justify"><span>2. </span>What are the advantages of JSF?</p>
<p align="justify"><span> The major benefits of JavaServer Faces technology are:</span></p>
<ul>
<li>JavaServer Faces architecture makes it easy for the developers to use. In JavaServer Faces technology, user interfaces can be created easily with its built-in UI component library, which handles most of the complexities of user interface management.</li>
<li>Offers a clean separation between behavior and presentation.</li>
<li>Provides a rich architecture for managing component state, processing component data, validating user input, and handling events.</li>
<li>Robust event handling mechanism.</li>
<li>Events easily tied to server-side code.</li>
<li>Render kit support for different clients</li>
<li>Component-level control over statefulness</li>
<li>Highly &#8216;pluggable&#8217; &#8211; components, view handler, etc</li>
<li>JSF also supports internationalization and accessibility</li>
<li>Offers multiple, standardized vendor implementations</li>
</ul>
<p><span> </span></p>
<p align="justify"><span>3. </span>What are differences between struts and JSF?</p>
<p align="justify">In a nutshell, Faces has the following advantages over Struts:</p>
<ul>
<li>
<p align="justify">Eliminated the need for a Form Bean</p>
</li>
<li>
<p align="justify">Eliminated the need for a DTO Class</p>
</li>
<li>
<p align="justify">Allows the use of the same POJO on all Tiers because of the Backing Bean</p>
</li>
<div>The primary advantages of Struts as compared to JavaServer Faces technology are as follows:</div>
<li>
<p align="justify">Because Struts is a web <a id="KonaLink0" href="http://www.developersbook.com/jsf/interview-questions/jsf-interview-questions-faqs.php#" target="undefined"><span style="color:#ff9900!important;font-weight:400;font-size:13px;position:static;"><span style="border-bottom:1px solid #ff9900;color:#ff9900!important;font-family:&quot;font-weight:400;font-size:13px;position:static;background-color:transparent;">application </span><span style="border-bottom:1px solid #ff9900;color:#ff9900!important;font-family:&quot;font-weight:400;font-size:13px;position:static;background-color:transparent;">framework</span></span></a>, it has a more sophisticated controller architecture than does JavaServer Faces technology. It is more sophisticated partly because the application developer can access the controller by creating an Action object that can integrate with the controller, whereas JavaServer Faces technology does not allow access to the controller. In addition, the Struts controller can do things like access control on each Action based on user roles. This functionality is not provided by JavaServer Faces technology.</p>
</li>
</ul>
<table style="height:24px;" border="0" width="1" align="right">
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
<p><span> </span></p>
<ul>
<li>
<p align="justify">Struts includes a powerful layout management framework, called Tiles, which allows you to create templates that you can reuse across multiple pages, thus enabling you to establish an overall look-and-feel for an application.</p>
</li>
<li>
<p align="justify">The Struts validation framework includes a larger set of standard validators, which automatically generate both server-side and client-side validation code based on a set of rules in a configuration file. You can also create custom validators and easily include them in your application by adding definitions of them in your configuration file.</p>
</li>
<div>The greatest advantage that JavaServer Faces technology has over Struts is its flexible, extensible UI component model, which includes:</div>
<li>
<p align="justify">A standard component API for specifying the state and behavior of a wide range of components, including simple components, such as input fields, and more complex components, such as scrollable <a id="KonaLink1" href="http://www.developersbook.com/jsf/interview-questions/jsf-interview-questions-faqs.php#" target="undefined"><span style="color:#ff9900!important;font-weight:400;font-size:13px;position:static;"><span style="color:#ff9900!important;font-family:&quot;font-weight:400;font-size:13px;position:static;">data </span><span style="color:#ff9900!important;font-family:&quot;font-weight:400;font-size:13px;position:static;">tables</span></span></a>. Developers can also create their own components based on these APIs, and many third parties have already done so and have made their component libraries publicly available.</p>
</li>
<li>
<p align="justify">A separate rendering model that defines how to render the components in various ways. For example, a component used for selecting an item from a list can be rendered as a menu or a set of radio buttons.</p>
</li>
<li>
<p align="justify">An event and listener model that defines how to handle events generated by activating a component, such as what to do when a user clicks a button.</p>
</li>
<li>
<p align="justify">Conversion and validation models for converting and validating component data.</p>
</li>
</ul>
<p align="justify"><span>4. </span> What are the available implementations of JavaServer Faces?</p>
<p align="justify"><span>The main implementations of JavaServer Faces are:</span></p>
<ul>
<li>Reference Implementation (<strong>RI</strong>) by Sun Microsystems.</li>
<li>Apache <strong>MyFaces </strong>is an <a id="KonaLink2" href="http://www.developersbook.com/jsf/interview-questions/jsf-interview-questions-faqs.php#" target="undefined"><span style="color:#ff9900!important;font-weight:400;font-size:13px;position:static;"><span style="color:#ff9900!important;font-family:&quot;font-weight:400;font-size:13px;position:static;">open </span><span style="color:#ff9900!important;font-family:&quot;font-weight:400;font-size:13px;position:static;">source</span></span></a> JavaServer Faces (JSF) implementation or run-time.</li>
<li><strong>ADF Faces</strong> is Oracle’s implementation for the JSF standard.</li>
</ul>
<p align="justify"><span>6. </span>What typical JSF application consists of?</p>
<p align="justify"><span>A typical JSF application consists of the following parts:</span></p>
<ul>
<li>JavaBeans components for managing application state and behavior.</li>
<li>Event-driven development (via listeners as in traditional GUI development).</li>
<li>Pages that represent MVC-style views; pages reference view roots via the JSF component tree.</li>
</ul>
<p align="justify"><span>7. </span>What Is a JavaServer Faces Application?</p>
<p align="justify">JavaServer Faces applications are just like any other Java web application. They run in a servlet container, and they typically contain the following:</p>
<ul>
<li>JavaBeans components containing application-specific functionality and data.</li>
<li>Event listeners.</li>
<li>Pages, such as JSP pages.</li>
<li>Server-side helper classes, such as database access beans.</li>
<div>In addition to these items, a JavaServer Faces application also has:</div>
<li>A <a id="KonaLink3" href="http://www.developersbook.com/jsf/interview-questions/jsf-interview-questions-faqs.php#" target="undefined"><span style="color:#ff9900!important;font-weight:400;font-size:13px;position:static;"><span style="color:#ff9900!important;font-family:&quot;font-weight:400;font-size:13px;position:static;">custom </span><span style="color:#ff9900!important;font-family:&quot;font-weight:400;font-size:13px;position:static;">tag</span></span></a> library for rendering UI components on a page.</li>
<li>A custom tag library for representing event handlers, validators, and other actions.</li>
<li>UI components represented as stateful objects on the server.</li>
<li>Backing beans, which define properties and functions for UI components.</li>
<li>Validators, converters, event listeners, and event handlers.</li>
<li>An application configuration resource file for configuring application resources.</li>
</ul>
<p align="justify"><span>8. </span>What is Managed Bean?</p>
<table border="0" align="right">
<tbody>
<tr>
<td>
<table border="0">
<tbody>
<tr>
<th scope="row"></th>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p align="justify">JavaBean objects managed by a JSF implementation are called managed beans. A managed bean describes how a bean is created and managed. It has nothing to do with the bean&#8217;s functionalities.</p>
<p align="justify"><span>9. </span>What is Backing Bean?</p>
<p align="justify">Backing beans are JavaBeans components associated with UI components used in a page. Backing-bean management separates the definition of UI component objects from objects that perform application-specific processing and hold data.</p>
<p align="justify">The backing bean defines properties and handling-logics associated with the UI components used on the page. Each backing-bean property is bound to either a component instance or its value. A backing bean also defines a set of methods that perform functions for the component, such as validating the component&#8217;s data, handling events that the component fires and performing processing associated with navigation when the component activates.</p>
<p align="justify"><span>10. </span>What are the differences between a Backing Bean and Managed Bean?</p>
<p align="justify">Backing Beans are merely a convention, a subtype of JSF Managed Beans which have a very particular purpose. There is nothing special in a Backing Bean that makes it different from any other managed bean apart from its usage.</p>
<p align="justify">What makes a Backing Bean is the relationship it has with a JSF page; it acts as a place to put component references and Event code.</p>
<table border="1" cellspacing="2" cellpadding="2" align="justify">
<tbody>
<tr valign="top" bgcolor="#add2e2">
<th>Backing Beans</th>
<th>Managed Beans</th>
</tr>
<tr>
<td>A backing bean is any bean that is referenced by a form.</td>
<td>A managed bean is a backing bean that has been registered with JSF (in faces-config.xml) and it automatically created (and optionally initialized) by JSF when it is needed.</td>
</tr>
<tr>
<td></td>
<td>The advantage of managed beans is that the JSF framework will automatically create these beans, optionally initialize them with parameters you specify in faces-config.xml,</td>
</tr>
<tr>
<td>Backing Beans should be defined only  in the request scope</td>
<td>The managed beans that are created by JSF can be stored within the request, session, or application scopes</td>
</tr>
</tbody>
</table>
<p align="justify">Backing Beans should be defined in the request scope, exist in a one-to-one relationship with a particular page and hold all of the page specific event handling code.In a real-world scenario, several pages may need to share the same backing bean behind the scenes.A backing bean not only contains view data, but also behavior related to that data.</p>
<p align="justify"><span>11. </span>What is view object?</p>
<p align="justify">A view object is a model object used specifically in the presentation tier. It contains the data that must display in the view layer and the logic to validate user input, handle events, and interact with the business-logic tier. The backing bean is the view object in a JSF-based application. Backing bean and view object are interchangeable terms.</p>
<p align="justify"><span>12.</span> What is domain <a id="KonaLink0" href="http://www.developersbook.com/jsf/interview-questions/jsf-interview-questions-faqs-2.php#" target="undefined"><span style="color:#ff9900!important;font-weight:bold;font-size:13px;position:static;"><span style="color:#ff9900!important;font-family:&quot;font-weight:bold;font-size:13px;position:static;">object </span><span style="color:#ff9900!important;font-family:&quot;font-weight:bold;font-size:13px;position:static;">model</span></span></a>?</p>
<p align="justify">Domain object model is about the business object and should belong in the business-logic tier. It contains the business data and business logic associated with the specific business object.</p>
<p align="justify"><span>13. </span>What is the difference between the domain object model and a view object?</p>
<p align="justify">In a simple Web application, a domain object model can be used across all tiers, however, in a more complex Web application, a separate view object model needs to be used. Domain object model is about the business object and should belong in the business-logic tier. It contains the business data and business logic associated with the specific business object. A view object contains presentation-specific data and behavior. It contains data and logic specific to the presentation tier.</p>
<p><span> </span></p>
<p align="justify"><span>14. </span>What do you mean by Bean Scope?</p>
<p align="justify">Bean Scope typically holds beans and other objects that need to be available in the different components of a web application.</p>
<table style="height:24px;" border="0" width="5" align="right">
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
<p align="justify"><span>15. </span> What are the different kinds of Bean Scopes in JSF?</p>
<p><span>JSF supports three Bean Scopes. <em>viz.,</em></span></p>
<ul><span></p>
<li><strong>Request Scope: </strong> The request scope is short-lived. It starts when an HTTP request is submitted and ends when the response is sent back to the client.</li>
<p></span><span></p>
<li><strong>Session Scope:</strong> The session scope persists from the time that a session is established until session termination.</li>
<p></span><span></p>
<li><strong>Application Scope: </strong> The application scope persists for the entire duration of the web application. This scope is shared among all the requests and sessions.</li>
<p></span></ul>
<p align="justify"><span>16. </span>What is the difference between JSP-EL and JSF-EL?</p>
<table border="1" cellspacing="2" cellpadding="2" align="justify">
<tbody>
<tr valign="top">
<th>JSP-EL</th>
<th>JSF-EL</th>
</tr>
<tr>
<td>In JSP-EL the value expressions are delimited by ${…}.</td>
<td>In JSf-EL the value expressions are delimited by #{…}.</td>
</tr>
<tr>
<td>The ${…} delimiter denotes the immediate evaluation of the expressions, at the time that the application server processes the page.</td>
<td>The #{…} delimiter denotes deferred evaluation. With deferred evaluation ,the <a id="KonaLink1" href="http://www.developersbook.com/jsf/interview-questions/jsf-interview-questions-faqs-2.php#" target="undefined"><span style="color:#ff9900!important;font-weight:400;font-size:13px;position:static;"><span style="color:#ff9900!important;font-family:&quot;font-weight:400;font-size:13px;position:static;">application </span><span style="color:#ff9900!important;font-family:&quot;font-weight:400;font-size:13px;position:static;">server</span></span></a> retains the expression and evaluates it whenever a value is needed.</td>
</tr>
</tbody>
</table>
<p><span style="text-decoration:underline;"><em>note</em></span><em>:As of JSF 1.2 and JSP 2.1 ,the syntax of both expression languages has been unified.</em></p>
<p align="center"><a href="http://www.developersbook.com/jsf/unified-expression-language.php"></a></p>
<p align="justify"><span>17. </span>What are The main tags in JSF?</p>
<p align="justify">JSF application typically uses JSP pages to represent views. JSF provides useful special tags to enhance these views. Each tag gives rise to an associated component. JSF (Sun Implementation) provides 43 tags in two standard JSF <a id="KonaLink2" href="http://www.developersbook.com/jsf/interview-questions/jsf-interview-questions-faqs-2.php#" target="undefined"><span style="color:#ff9900!important;font-weight:400;font-size:13px;position:static;"><span style="color:#ff9900!important;font-family:&quot;font-weight:400;font-size:13px;position:static;">tag </span><span style="color:#ff9900!important;font-family:&quot;font-weight:400;font-size:13px;position:static;">libraries</span></span></a>:</p>
<ul>
<li>JSF Core Tags  Library.</li>
<li>JSF Html Tags Library.</li>
</ul>
<p align="justify"><span>18. </span>How do you declare the managed beans in the faces-config.xml file?</p>
<p align="justify">The bean instance is configured in the <em><code>faces-config.xml</code></em> file:</p>
<ul>
<pre>  &lt;managed-bean&gt;
	 &lt;managed-bean-name&gt;login&lt;/managed-bean-name&gt;
	 &lt;managed-bean-class&gt;com.developersBookJsf.loginBean&lt;/managed-bean-class&gt;
	 &lt;managed-bean-scope&gt;request&lt;/managed-bean-scope&gt;
  &lt;/managed-bean&gt;</pre>
</ul>
<p align="justify">This means: Construct an object of the class <em><code>com.developersBookJsf.loginBean</code></em>, give it the name <em><code>login</code></em>, and keep it alive for the duration of the <em><code>request</code></em>.</p>
<p align="justify"><span>19. </span>How to declare the Message Bundle in JSF?</p>
<p align="justify">We can declare the message bundle in two ways:<br />
(Let’s  assume <em><code>com.developersBookJsf.messages</code></em> is the properties file)</p>
<ul><strong>1.</strong> The simplest way is to include the following elements in <code><em>faces-config.xml file:</em></code></p>
<pre>    &lt;application&gt;
	&lt;resource-bundle&gt;
	&lt;base-name&gt;com.developersBookJsf.messages&lt;/base-name&gt;
	&lt;var&gt;message&lt;/var&gt;
	&lt;/resource-bundle&gt;
    &lt;/application&gt;</pre>
<p><strong>2.</strong> Alternatively, you can add the <code><em>f:loadBundle</em></code> element to each JSF page that needs access to the bundle:</p>
<pre>   &lt;f:loadBundle baseName = “com.developersBookJsf.messages” var=”message”/&gt;</pre>
</ul>
<table border="0" align="right">
<tbody>
<tr>
<td>
<div id="articleText">
<div></div>
</div>
</td>
</tr>
</tbody>
</table>
<p align="justify"><span>20. </span>How to declare the  page navigation (navigation rules) in faces-config.xml file ?</p>
<p align="justify">Navigation rules tells JSF implementation which page to send back to the <a id="KonaLink3" href="http://www.developersbook.com/jsf/interview-questions/jsf-interview-questions-faqs-2.php#" target="undefined"><span style="color:#ff9900!important;font-weight:400;font-size:13px;position:static;"><span style="color:#ff9900!important;font-family:&quot;font-weight:400;font-size:13px;position:static;">browser</span></span></a> after a form has been submitted. We can declare the page navigation as follows:</p>
<ul>
<pre>  &lt;naviagation-rule&gt;
    &lt;from-view-id&gt;/index.jsp&lt;/from-view-id&gt;
    &lt;navigation-case&gt;
	 &lt;from-outcome&gt;login&lt;/from-outcome&gt;
	 &lt;to-view-id&gt;/welcome.jsp&lt;/to-view-id&gt;
    &lt;/navigation-case&gt;
  &lt;/naviagation-rule&gt;</pre>
</ul>
<p align="justify">This declaration states that the <em><code>login </code></em>action navigates to <em><code>/welcome.jsp</code></em>, if it occurred inside <em><code>/index.jsp</code></em>.</p>
<p align="justify"><span>21. </span>What if no navigation rule matches a given action?</p>
<p align="justify">If no navigation rule matches a given action, then the current page is redisplayed.</p>
<p align="justify"><span>22.</span> What are the JSF life-cycle phases?</p>
<p align="justify"><span> The six phases of the JSF <a id="KonaLink0" href="http://www.developersbook.com/jsf/interview-questions/jsf-interview-questions-faqs-3.php#" target="undefined"><span style="color:#ff9900!important;font-weight:400;font-size:13px;position:static;"><span style="color:#ff9900!important;font-family:&quot;font-weight:400;font-size:13px;position:static;">application</span></span></a> lifecycle are as follows (note the event processing at each phase): </span></p>
<table border="0" width="25%" align="right">
<tbody>
<tr>
<td>
<table style="height:128px;" border="1" width="6" align="left">
<tbody>
<tr>
<th></th>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p align="justify"><span> </span></p>
<ul><strong>1.</strong> Restore view<br />
<strong>2.</strong> Apply request values; process events<br />
<strong>3.</strong> Process validations; process events<br />
<strong>4.</strong> Update model values; process events<br />
<strong>5.</strong> Invoke application; process events<br />
<strong>6.</strong> Render response</ul>
<p align="justify"><span>23. </span>Explain briefly the life-cycle phases of JSF?</p>
<ul><strong>1. <span style="text-decoration:underline;">Restore View</span> : </strong> A request comes through the FacesServlet controller. The controller examines the request and extracts the view ID, which is determined by the name of the <a id="KonaLink1" href="http://www.developersbook.com/jsf/interview-questions/jsf-interview-questions-faqs-3.php#" target="undefined"><span style="color:#ff9900!important;font-weight:400;font-size:13px;position:static;"><span style="color:#ff9900!important;font-family:&quot;font-weight:400;font-size:13px;position:static;">JSP</span></span></a> page.<br />
<strong>2. <span style="text-decoration:underline;">Apply request values</span>: </strong> The purpose of the apply request values phase is for each component to retrieve its current state. The components must first be retrieved or created from the FacesContext object, followed by their values.<br />
<strong>3. <span style="text-decoration:underline;">Process validations</span>: </strong> In  this phase, each component will have its values validated against the application&#8217;s validation rules.<br />
<strong>4. <span style="text-decoration:underline;">Update model values</span>: </strong> In this  phase JSF updates the actual values of the server-side model ,by updating the properties of your backing beans.<br />
<strong>5. <span style="text-decoration:underline;">Invoke application</span>: </strong> In this phase the JSF controller invokes the application to handle Form submissions.<br />
<strong>6. <span style="text-decoration:underline;">Render response</span>: </strong> In this phase JSF  displays the view with all of its components in their current state.</ul>
<div>
<p align="center"><a href="http://www.developersbook.com/jsf/jsf-tutorial/jsf-tutorial.php#2"><span style="text-decoration:underline;"><strong>More about JSF Lifecycle</strong></span></a></p>
<p><img style="border:1px solid #add2e2;" src="http://developersbook.com/jsf/images/JSF-Lifecycle.png" alt="JSF Lifecycle" width="693" height="543" /></div>
<table border="0" align="right">
<tbody>
<tr>
<td>
<table border="0">
<tbody>
<tr>
<th scope="row"></th>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p align="justify"><span>24. </span>What does it mean by render kit in JSF?</p>
<p align="justify">A render kit defines how component classes map to component tags that are appropriate for a particular client. The JavaServer Faces implementation includes a <a id="KonaLink2" href="http://www.developersbook.com/jsf/interview-questions/jsf-interview-questions-faqs-3.php#" target="undefined"><span style="color:#ff9900!important;font-weight:400;font-size:13px;position:static;"><span style="color:#ff9900!important;font-family:&quot;font-weight:400;font-size:13px;position:static;">standard </span><span style="color:#ff9900!important;font-family:&quot;font-weight:400;font-size:13px;position:static;">HTML</span></span></a> render kit for rendering to an HTML client.</p>
<p align="justify"><span>25. </span> Is it possible to have more than one Faces Configuration file?</p>
<p align="justify"><span>We can have any number of config files. Just need to register in <code><em><a id="KonaLink3" href="http://www.developersbook.com/jsf/interview-questions/jsf-interview-questions-faqs-3.php#" target="undefined"><span style="color:#ff9900!important;font-weight:400;font-size:11.7px;position:static;"><span style="border-bottom:1px solid #ff9900;color:#ff9900!important;font-family:Courier New,Courier;font-weight:400;font-size:11.7px;position:static;background-color:transparent;">web.xml</span></span><span style="position:relative;"> </span></a></em></code></span></p>
<div id="preLoadLayer3" style="position:absolute;z-index:4000;top:-32px;left:-18px;display:none;"><em><a id="KonaLink3" href="http://www.developersbook.com/jsf/interview-questions/jsf-interview-questions-faqs-3.php#" target="undefined"><img style="border:0 none;" src="http://kona.kontera.com/javascript/lib/imgs/grey_loader.gif" alt="" /></a></em></div>
<p><em> </em>.<br />
Assume that we want to use faces-config(1,2,and 3),to register more than one faces configuration file in JSF,just declare in the <code><em>web.xml file</em></code></p>
<ul>
<pre>	&lt;context-param&gt;
		&lt;param-name&gt;javax.faces.CONFIG_FILES&lt;/param-name&gt;
		&lt;param-value&gt;
			/WEB-INF/faces-config1.xml,
			/WEB-INF/faces-config2.xml,
			/WEB-INF/faces-config3.xml
		&lt;/param-value&gt;
	&lt;/context-param&gt;</pre>
</ul>
<p align="justify">
<p align="justify">
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/techpassion.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/techpassion.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/techpassion.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/techpassion.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/techpassion.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/techpassion.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/techpassion.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/techpassion.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/techpassion.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/techpassion.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/techpassion.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/techpassion.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/techpassion.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/techpassion.wordpress.com/71/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techpassion.wordpress.com&amp;blog=5988916&amp;post=71&amp;subd=techpassion&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://techpassion.wordpress.com/2009/05/29/jsf-interview-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9eea02dca209112818f5a9ee1f48cb3e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Admin</media:title>
		</media:content>

		<media:content url="http://developersbook.com/jsf/images/JSF-Lifecycle.png" medium="image">
			<media:title type="html">JSF Lifecycle</media:title>
		</media:content>

		<media:content url="http://kona.kontera.com/javascript/lib/imgs/grey_loader.gif" medium="image" />
	</item>
	</channel>
</rss>
