<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3839600004564876445</id><updated>2012-02-16T19:19:15.366-08:00</updated><category term='digital certificate'/><category term='Unix'/><category term='DTD'/><category term='Import Certificate'/><category term='Java Web development interview questions'/><category term='public key'/><category term='Hibernate Interview questions 3'/><category term='SCHEMA'/><category term='cryptography'/><category term='private key'/><category term='connection pooling'/><category term='datasource connection'/><category term='XML Questions 2'/><category term='JSP interview questions'/><category term='CA'/><category term='Hibernate'/><category term='ActionScript'/><category term='JavaScriptAJAXinterview'/><category term='Servlet Questions 2'/><category term='Move a Certificate'/><category term='JDBC Questions 2'/><category term='Ajax'/><category term='Apache mod_SSL'/><category term='Simple Java Questions'/><category term='Apache SSL'/><category term='encryption'/><category term='Difference between JDBC and hibernate'/><category term='DOM'/><category term='Third Normal Form'/><category term='Servlet Questions 3'/><category term='SSL'/><category term='What is connection pooling?'/><category term='jdbc connection'/><category term='Digital Certificate Enrollment'/><category term='JDBC Questions 1'/><category term='digital certificate installation'/><category term='What&apos;s the differences between object and object references?'/><category term='StringBuffer versus String'/><category term='ShellScriptingquestions'/><category term='Servlet Questions 1'/><category term='Secure Socket Layer'/><category term='Hibernate Interview questions 1'/><category term='Junit'/><category term='XML'/><category term='siteminder sso netegrity'/><category term='links'/><category term='Hibernate Vs. iBatis?'/><category term='Good Java Interview questions'/><category term='SAX'/><category term='CSR'/><category term='generate certificate'/><category term='Backup a Certificate'/><category term='Running multiple Tomcat instances on one server'/><category term='CSR Generation Instructions- Tomcat'/><category term='Different types of SQL Joins'/><category term='Database Connection Pooling with Tomcat'/><category term='What&apos;s the difference between &quot;PreparedStatement&quot; and &quot;Statement&quot;?'/><category term='Flex Data Access'/><category term='Difference between String StringBuffer and StringBuilder'/><category term='Hibernate Interview questions 2'/><category term='JavaInterviewQuestions'/><category term='Events in Flex'/><category term='Difference between equals and hashCode method'/><category term='Hibernate Interview questions'/><category term='https'/><category term='MXML'/><category term='Multithreading'/><category term='Singleton Design Pattern'/><category term='XML Questions 1'/><title type='text'>Java</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>68</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-5722680472662974003</id><published>2008-07-05T14:40:00.001-07:00</published><updated>2008-07-05T14:41:54.736-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate Vs. iBatis?'/><title type='text'>Hibernate Vs. iBatis?</title><content type='html'>Hibernate Vs. iBatis?&lt;br /&gt;Hibernate or iBatis or both ? Which is better?&lt;br /&gt;Which one to use and when?&lt;br /&gt;&lt;br /&gt;These are the few questions that continuously get asked in most of forums.&lt;br /&gt;What’s really difference between two and really more importantly when should I use one over the other. Its pretty interesting question because there are major differences between iBatis and Hibernate.&lt;br /&gt;&lt;br /&gt;Within in the java persistence there is no one size, fits all solution. So, in this case Hibernate which is a de facto standard is used in lot of places.&lt;br /&gt;&lt;br /&gt;Let us consider a scenario where Hibernate work great for initial model. Now Suddenly if you are using stored procedures, well we can do it in Hibernate but its little difficult; ok we map those, all of sudden we got some reporting type of queries, those don’t have keys have group bys; with some difficulty here we can use name queries and stuff like that, but now starts getting more complicated, we have complex joins, yes you can do in hibernate, but we can’t do with average developer. We have sql that just doesn’t work.&lt;br /&gt;&lt;br /&gt;So these are some of the complexities. One of the other things I find is, if am looking at an application that doesn’t work very well with an ORM, aside from these considerations of using stored procedures, already using SQL, complex joins. In other words, Hibernate works very well if your data model is well in sync with object model, because ORM solutions like Hibernate map object to tables. However, let’s suppose data model is not in sync with object model, in this case you have do lot of additional coding and complexities are entering into your application, start coming the beyond the benefits of ORM. So, again all of sudden you are noticing that the flow is gone; our application is becoming very very complex and developers can’t maintain the code.&lt;br /&gt;&lt;br /&gt;This is where the model starts breaking down. One size does not fit all. So this is where I like to use iBatis; as the alternative solution for these type of situations, iBatis maps results sets to objects, so no need to care about table structures. This works very well for stored procedures, works very well for reporting applications, etc,.&lt;br /&gt;&lt;br /&gt;Now the question is , does it work well for simple CRUD applications? Well, it works because what we have to write is sql. Then why not use Hibernate for that?&lt;br /&gt;&lt;br /&gt;You can start see Some of the decision criteria that comes into play. So one of the other follow on questions that typically get is , can I use both? That’s really interesting question! because the answer is sure.&lt;br /&gt;&lt;br /&gt;But,such a thing will never ever exists is java persistence world. However we can kind of use both to create this little hybrid. So think of this kind scenario, we have very large application where Hibernate is working very well for it, but we have a reporting piece that just is a real nag , its query only , so we can do is, we can use iBatis to pull up the queries for reporting piece and still use Hibernate for all the operational stuff and updates. This model actually works well, it doesn’t break the transactional model, and it doesn’t affect any of the primary &amp;amp; secondary caches with a Hibernate. It’s a good solution.&lt;br /&gt;&lt;br /&gt;   * Use iBatis if&lt;br /&gt;         o You want to create your own SQL's and are willing to maintain them&lt;br /&gt;         o your environment is driven by relational data model&lt;br /&gt;         o you have to work existing and complex schema's&lt;br /&gt;   * Use Hibernate if&lt;br /&gt;         o your environment is driven by object model and wants generates SQL automatically&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The message is,&lt;br /&gt;&lt;br /&gt;   * One size does not fit all the java persistence and the important to know there are other solutions besides the traditional ORMs, and that would be iBatis.&lt;br /&gt;   * Both the solutions work well, given their specific domain.&lt;br /&gt;   * Look for the opportunity where you can use both.&lt;br /&gt;&lt;br /&gt;What is iBatis ?&lt;br /&gt;&lt;br /&gt;    * A JDBC Framework&lt;br /&gt;          o Developers write SQL, iBATIS executes it using JDBC.&lt;br /&gt;          o No more try/catch/finally/try/catch.&lt;br /&gt;    * An SQL Mapper&lt;br /&gt;          o Automatically maps object properties to prepared statement parameters.&lt;br /&gt;          o Automatically maps result sets to objects.&lt;br /&gt;          o Support for getting rid of N+1 queries.&lt;br /&gt;    * A Transaction Manager&lt;br /&gt;          o iBATIS will provide transaction management for database operations if no other transaction manager is available.&lt;br /&gt;          o iBATIS will use external transaction management (Spring, EJB CMT, etc.) if available.&lt;br /&gt;    * Great integration with Spring, but can also be used without Spring (the Spring folks were early supporters of iBATIS).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;What isn’t iBATIS ?&lt;br /&gt;&lt;br /&gt;    * An ORM&lt;br /&gt;          o Does not generate SQL&lt;br /&gt;          o Does not have a proprietary query language&lt;br /&gt;          o Does not know about object identity&lt;br /&gt;          o Does not transparently persist objects&lt;br /&gt;          o Does not build an object cache&lt;br /&gt;&lt;br /&gt;Essentially, iBatis is a very lightweight persistence solution that gives you most of the semantics of an O/R Mapping toolkit, without all the drama. In other words ,iBATIS strives to ease the development of data-driven applications by abstracting the low-level details involved in database communication (loading a database driver, obtaining and managing connections, managing transaction semantics, etc.), as well as providing higher-level ORM capabilities (automated and configurable mapping of objects to SQL calls, data type conversion management, support for static queries as well as dynamic queries based upon an object's state, mapping of complex joins to complex object graphs, etc.). iBATIS simply maps JavaBeans to SQL statements using a very simple XML descriptor. Simplicity is the key advantage of iBATIS over other frameworks and object relational mapping tools.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-5722680472662974003?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/5722680472662974003/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=5722680472662974003' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/5722680472662974003'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/5722680472662974003'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/07/hibernate-vs-ibatis.html' title='Hibernate Vs. iBatis?'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-7792406110811413775</id><published>2008-07-05T14:35:00.000-07:00</published><updated>2008-07-05T14:38:06.812-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='XML Questions 2'/><title type='text'>XML Questions 2</title><content type='html'>16.What is the relevance of ElementFormDefault attribute in the Schema?&lt;br /&gt;&lt;br /&gt;ElementFormDefault indicates whether or not locally declared elements must be qualified by the target namespace in an instance document. ElementFormDefault attribute in the Schema has the following relevance:&lt;br /&gt;&lt;br /&gt;   * Qualified: Each and every element of the Schema must be qualified with the namespace in the instance document.&lt;br /&gt;   * Unqualified: means only globally declared elements must be qualified with there namespace and not the local elements.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;17.What is XML parser?&lt;br /&gt;&lt;br /&gt;An XML parser is a piece of software which can do following:&lt;br /&gt;&lt;br /&gt;   * Check for well-formedness&lt;br /&gt;   * Validate the document&lt;br /&gt;   * Allows us to read, create or modify existing XML documents&lt;br /&gt;&lt;br /&gt;Note: Parser is piece of software provided by vendors. An XML parser is built in Java runtime from JDK 1.4 onwards&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="que"&gt;&lt;span class="queIndex"&gt;18.&lt;/span&gt;&lt;strong&gt;What is DOM&lt;/strong&gt;?&lt;/span&gt; &lt;p class="content" align="justify"&gt;The Document Object Model (&lt;strong&gt;DOM&lt;/strong&gt;) is a platform and language-independent standard object model for representing XML and related formats. DOM is standard API which is not specific to any programming language. DOM represents an XML document as a tree model. The tree model makes the XML document hierarchal by nature. Each and every construct of the XML document is represented as a node in the tree.&lt;/p&gt;&lt;br /&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;19.&lt;/span&gt;&lt;strong&gt;What is SAX?&lt;/strong&gt;&lt;/span&gt; &lt;p class="content" align="justify"&gt;SAX-Simple API for XML processing. SAX provides a mechanism for reading data from an XML document. It is a popular alternative to the Document Object Model (DOM).SAX provides an event based processing approach unlike DOM which is tree based.&lt;/p&gt;&lt;br /&gt;  &lt;span class="que"&gt;  &lt;span class="queIndex"&gt;20.&lt;/span&gt;&lt;strong&gt;What are the interfaces of SAX?&lt;/strong&gt;&lt;/span&gt;     &lt;p class="content" align="justify"&gt;The interfaces of SAX are: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;DocumentHandler&lt;/strong&gt;- is used for getting event notification relating to a document.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;DTDHandler&lt;/strong&gt;- is implemented to get the notifications related to declarations in DTD like entities and notations&lt;/li&gt;&lt;li&gt;&lt;strong&gt;EntityResolver&lt;/strong&gt;- is used for reading external entities.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;ErrorHandler&lt;/strong&gt;- is used for handling error related notifications.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;   &lt;span class="que"&gt;&lt;span class="queIndex"&gt;21.&lt;/span&gt;&lt;strong&gt;What is the difference between SAX parser and  DOM parser?&lt;/strong&gt;&lt;/span&gt;   &lt;br /&gt;&lt;p class="content" align="justify"&gt;&lt;table class="mytable" border="1" cellpadding="5" cellspacing="5"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;th width="50%"&gt;&lt;strong&gt;SAX&lt;/strong&gt;&lt;/th&gt;      &lt;th width="50%"&gt;&lt;strong&gt;DOM&lt;/strong&gt;&lt;/th&gt;   &lt;/tr&gt;   &lt;tr class="odd"&gt;     &lt;td&gt;A SAX parser takes the occurrences of components of an input document as events (i.e., event based processing), and tells the client what it reads as it reads through the input document.&lt;/td&gt;     &lt;td&gt;A  DOM parser creates a tree structure in memory from an input document and then  waits for requests from client.&lt;/td&gt;   &lt;/tr&gt;   &lt;tr class="even"&gt;     &lt;td&gt;No  navigation possible (top to bottom only once)&lt;/td&gt;     &lt;td&gt;Whereas,  we can navigate the DOM tree in any direction, any no. of times.&lt;/td&gt;   &lt;/tr&gt;    &lt;tr class="odd"&gt;     &lt;td&gt;We  cannot modify the document content in SAX&lt;/td&gt;     &lt;td&gt;We  can modify the document content in DOM&lt;/td&gt;   &lt;/tr&gt;        &lt;tr class="even"&gt;     &lt;td&gt;A  SAX parser serves the client &lt;a id="KonaLink1" target="_top" class="kLink" style="text-decoration: underline ! important; position: static;" href="http://www.developersbook.com/xml/interview-questions/xml-interview-questions-faqs-2.php#"&gt;&lt;span style="color: rgb(242, 101, 34) ! important;font-family:&amp;quot;;font-size:13;"  &gt;&lt;span class="kLink" style="border-bottom: 1px solid rgb(242, 101, 34); color: rgb(242, 101, 34) ! important;font-family:&amp;quot;;font-size:13;color:#0000e0;"   &gt;application&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; always only with pieces of the  document at any given time.&lt;/td&gt;     &lt;td&gt;A DOM parser always serves the client application with the entire document no matter how much is actually needed by the client.&lt;/td&gt;   &lt;/tr&gt;     &lt;tr class="odd"&gt;       &lt;td&gt;A  SAX parser, however, is much more space efficient in case of a big input  document&lt;/td&gt;       &lt;td&gt;A  DOM parser is space inefficient when the document is huge.&lt;/td&gt;     &lt;/tr&gt;   &lt;tr class="even"&gt;     &lt;td&gt;&lt;p&gt;Use  SAX parser when       &lt;/p&gt;&lt;ul&gt;&lt;li&gt;Input document is too big for available memory.&lt;/li&gt;&lt;li&gt;When only a part of the document is to be read  and we create the data structures of our own.&lt;/li&gt;&lt;li&gt;If you use SAX, you are using much less memory and  performing much less dynamic memory allocation.&lt;/li&gt;&lt;/ul&gt;       &lt;/td&gt;     &lt;td&gt;&lt;p&gt;Use  DOM when       &lt;/p&gt;&lt;ul&gt;&lt;li&gt;Your application has to access various parts of the document and using your own structure is just as complicated as the DOM tree.&lt;/li&gt;&lt;li&gt;Your application has to change the tree very  frequently and data has to be stored for a significant amount of time. &lt;/li&gt;&lt;/ul&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;22.&lt;/span&gt;&lt;strong&gt;What is a CDATA section in XML?&lt;/strong&gt;&lt;/span&gt; &lt;p class="content" align="justify"&gt;CDATA Sections are used to escape blocks of text containing characters which would otherwise be recognized as markup. All tags and entity references are ignored by an XML processor that treats them just like any character data. CDATA blocks have been provided as a convenience measure when you want to include large blocks of special characters as character data, but you do not want to have to use entity references all the time.&lt;/p&gt;&lt;br /&gt;&lt;span class="que"&gt; &lt;span class="queIndex"&gt;23.&lt;/span&gt;&lt;strong&gt;What is XSL?&lt;/strong&gt;&lt;/span&gt;  &lt;p class="content" align="justify"&gt;e&lt;strong&gt;X&lt;/strong&gt;tensible &lt;strong&gt;S&lt;/strong&gt;tylesheet &lt;strong&gt;L&lt;/strong&gt;anguage(&lt;strong&gt;XSL&lt;/strong&gt;)   deals with most displaying the contents  of XML documents.XSL  consists of three parts: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;XSLT - a language for transforming XML documents&lt;/li&gt;&lt;li&gt;XPath - a language for navigating in XML documents&lt;/li&gt;&lt;li&gt;XSL-FO - a language for formatting XML documents&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;24.&lt;/span&gt;&lt;strong&gt;How is XSL different from Cascading Style Sheets? Why is a new Stylesheet language needed?&lt;/strong&gt;&lt;/span&gt; &lt;p class="content" align="justify"&gt; XSL is compatible with &lt;a id="KonaLink2" target="_top" class="kLink" style="text-decoration: underline ! important; position: static;" href="http://www.developersbook.com/xml/interview-questions/xml-interview-questions-faqs-2.php#"&gt;&lt;span style="color: rgb(242, 101, 34) ! important;font-family:&amp;quot;;font-size:13;"  &gt;&lt;span class="kLink" style="color: rgb(242, 101, 34) ! important;font-family:&amp;quot;;font-size:13;"  &gt;CSS&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; and is designed to handle the new capabilities of XML that CSS can't handle. XSL is derived from Document Style Semantics and Specification Language (DSSSL), a complex Stylesheet language with roots in the SGML community. The syntax of XSL is quite different from CSS, which could be used to display simple XML data but isn't general enough to handle all the possibilities generated by XML. XSL adds the capability to handle these possibilities. For instance, CSS cannot add new items or generated text (for instance, to assign a purchase order number) or add a footer (such as an order confirmation). XSL allows for these capabilities.&lt;/p&gt; &lt;p class="content" align="justify"&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;25.&lt;/span&gt;&lt;strong&gt;What is XSLT?&lt;/strong&gt;&lt;/span&gt; &lt;/p&gt;&lt;p class="content" align="justify"&gt;eXtensible Stylesheet Language Transformation (XSLT) deals with transformation of one XML document into XHTML documents or to other XML documents. XSLT uses XPath for traversing an XML document and arriving at a particular node.&lt;/p&gt; &lt;div align="center"&gt;&lt;img src="http://www.developersbook.com/xml/images/XSLT.gif" alt="XSLT " align="middle" border="0" height="388" width="541" /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="title" align="center"&gt;Figure 3: XSLT &lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="que"&gt; &lt;span class="queIndex"&gt;26.&lt;/span&gt;&lt;strong&gt;What is the role of XSL transformer?&lt;/strong&gt;&lt;/span&gt;  &lt;p class="content" align="justify"&gt;An XSL transformer will transform in the following way: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;The source tree is obtained by parsing in a normal XML style&lt;/li&gt;&lt;li&gt;The transformation is now applied to the source with the help of information available in        Stylesheet. &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span class="que"&gt;&lt;span class="queIndex"&gt;27.&lt;/span&gt;What is the structure of XSLT?&lt;/span&gt; &lt;div align="center"&gt;&lt;img src="http://www.developersbook.com/xml/images/XSLT-structure.gif" alt="XSLT Structure" align="middle" border="0" height="228" width="608" /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="title" align="center"&gt;Figure 4: XSLT Structure&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt;&lt;span class="que"&gt; &lt;span class="queIndex"&gt;28.&lt;/span&gt;&lt;strong&gt;What is XSL template?&lt;/strong&gt;&lt;/span&gt;  &lt;p class="content" align="justify"&gt;Template specifies transformation rules. A Stylesheet document can be made up of at least one template, which acts as an entry point. Every template uniquely identifies a particular node in the source tree.&lt;/p&gt;&lt;br /&gt;&lt;span class="que"&gt; &lt;span class="queIndex"&gt;29.&lt;/span&gt;&lt;strong&gt;What is XPath?&lt;/strong&gt;&lt;/span&gt;  &lt;p class="content" align="justify"&gt;XPath is an expression language used for addressing parts of an XML document.  XPath is used to navigate through elements and attributes in an XML document.&lt;/p&gt;&lt;br /&gt;&lt;span class="que"&gt; &lt;span class="queIndex"&gt;30.&lt;/span&gt;&lt;strong&gt;What is XSL-FO?&lt;/strong&gt;&lt;/span&gt;  &lt;p class="content" align="justify"&gt;XSL-FO   deals with formatting XML data. This can be used for generating output in a particular format like XML to PDF, XML to DOC, etc.&lt;/p&gt;&lt;span class="que"&gt; &lt;span class="queIndex"&gt;31.&lt;/span&gt;&lt;strong&gt;How XSL-FO Works (or) How would you produce PDF output using XSL’s?&lt;/strong&gt;&lt;/span&gt;  &lt;div align="center"&gt;&lt;img src="http://www.developersbook.com/xml/images/XSL-FO.gif" alt="XSLT FO" align="middle" border="0" /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="title" align="center"&gt;Figure 5: XSL-FO&lt;/div&gt; &lt;p class="content" align="justify"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class="content" align="justify"&gt;&lt;br /&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;p class="content" align="justify"&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-7792406110811413775?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/7792406110811413775/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=7792406110811413775' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/7792406110811413775'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/7792406110811413775'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/07/16.html' title='XML Questions 2'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-9113112282855748983</id><published>2008-07-05T14:30:00.000-07:00</published><updated>2008-07-05T14:35:22.069-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='XML Questions 1'/><title type='text'>XML Questions 1</title><content type='html'>&lt;div  style="text-align: left; font-style: italic; font-weight: bold;font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;1.What is XML?&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;   * Extensible Markup Language (XML) is the universal language for data on the Web&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;   * XML is a technology which allows us to create our own markup language.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;   * XML documents are universally accepted as a standard way of representing information in platform and language independent manner.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;   * XML is universal standard for information interchange.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;   * XML documents can be created in any language and can be used in any language.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;2.What is the difference between XML and HTML?&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;XML is no way clashes with HTML, since they are for two different purposes.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;HTML     XML&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;HTML is for displaying purpose.     whereas  XML is for data representation.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;HTML is used to mark up text so it can be displayed to users.     XML is used to mark up data so it can be processed by computers.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;HTML describes both structure (e.g. &lt;/span&gt;&lt;/div&gt;&lt;p  style="font-weight: bold; font-style: italic; text-align: left;font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;, &lt;/span&gt;&lt;/p&gt;&lt;h2  style="font-weight: bold; font-style: italic; text-align: left;font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;, &lt;em&gt;) and appearance (e.g.&lt;br /&gt;, &lt;span&gt;, )     XML describes only content, or “meaning”&lt;br /&gt;HTML uses a fixed, unchangeable set of tags     In XML, you make up your own tags&lt;br /&gt;&lt;br /&gt;3.What are the benefits of XML?&lt;br /&gt;&lt;br /&gt;There are many benefits of using XML on the Web :&lt;br /&gt;&lt;br /&gt; * Simplicity- Information coded in XML is easy to read and understand, plus it can be processed easily by computers.&lt;br /&gt;&lt;br /&gt; * Openness- XML is a W3C standard, endorsed by software industry market leaders.&lt;br /&gt;&lt;br /&gt; * Extensibility - There is no fixed set of tags. New tags can be created as they are needed.&lt;br /&gt;&lt;br /&gt; * Self-description- In traditional databases, data records require schemas set up by the database administrator. XML documents can be stored without such definitions, because they contain meta data in the form of tags and attributes.&lt;br /&gt;&lt;br /&gt; * Contains machine-readable context information- Tags, attributes and element structure provide context information that can be used to interpret the meaning of content, opening up new possibilities for highly efficient search engines, intelligent data mining, agents, etc.&lt;br /&gt;&lt;br /&gt; * Separates content  from presentation- XML tags describe meaning not presentation. The motto of HTML is: "I know how it looks", whereas the motto of XML is: "I know what it means, and you tell me how it should look." The look and feel of an XML document can be controlled by XSL style sheets, allowing the look of a document to be changed without touching the content of the document. Multiple views or presentations of the same content are easily rendered.&lt;br /&gt;&lt;br /&gt; * Supports multilingual documents and Unicode-This is important for the internationalization of applications.&lt;br /&gt;&lt;br /&gt; * Facilitates the comparison and aggregation of data - The tree structure of XML documents allows documents to be compared and aggregated efficiently element by element.&lt;br /&gt;&lt;br /&gt; * Can embed multiple data types - XML documents can contain any possible data type - from multimedia data (image, sound, video) to active components (Java applets, ActiveX).&lt;br /&gt;&lt;br /&gt; * Can embed existing data - Mapping existing data structures like file systems or relational databases to XML is simple. XML supports multiple data formats and can cover all existing data structures and .&lt;br /&gt;&lt;br /&gt; * Provides a 'one-server view' for distributed data - XML documents can consist of nested elements that are distributed over multiple remote servers. XML is currently the most sophisticated format for distributed data - the World Wide Web can be seen as one huge XML database.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;4.What is a well-formed XML document?&lt;br /&gt;&lt;br /&gt;If a document is syntactically correct it can be called as well-formed XML documents. A well-formed document conforms to XML's basic rules of syntax:&lt;br /&gt;&lt;br /&gt; * Every open tag must be closed.&lt;br /&gt; * The open tag must exactly match the closing tag: XML is case-sensitive.&lt;br /&gt; * All elements must be embedded within a single root element.&lt;br /&gt; * Child tags must be closed before parent tags.&lt;br /&gt; * A well-formed document has correct XML tag syntax, but the elements might be invalid for the specified document type.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;5.What is a valid XML document?&lt;br /&gt;&lt;br /&gt;If a document is structurally correct then it can be called as valid XML documents. A valid document conforms to the predefined rules of a specific type of document:&lt;br /&gt;&lt;br /&gt; * These rules can be written by the author of the XML document or by someone else.&lt;br /&gt; * The rules determine the type of data that each part of a document can contain.&lt;br /&gt;&lt;br /&gt;Note:Valid XML document is implicitly well-formed, but well-formed may not be valid&lt;br /&gt;&lt;br /&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;6.&lt;/span&gt;&lt;strong&gt;What is the structure of XML document&lt;/strong&gt; ?&lt;/span&gt; &lt;div align="center"&gt;&lt;img src="http://www.developersbook.com/xml/images/XML-Structure.gif" alt="XML Structure" align="middle" border="0" /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="title" align="center"&gt;Figure 1: XML Structure&lt;/div&gt;&lt;br /&gt;&lt;span class="que"&gt; &lt;span class="queIndex"&gt;7.&lt;/span&gt;&lt;strong&gt;What is a Processing Instruction in XML? &lt;/strong&gt;&lt;/span&gt;  &lt;p class="content" align="justify"&gt;A ProcessingIntruction is the information which we would like to give to application. Through a ProcessingInstruction an application would get idea about how to process the document. A ProcessingInstruction can appear anywhere and any no. of times in a document. &lt;/p&gt;&lt;br /&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;8.&lt;/span&gt;&lt;strong&gt;How does the XML structure is defined?&lt;/strong&gt;&lt;/span&gt;    &lt;p class="content" align="justify"&gt;XML document will have a structure which has to be defined before we can create the documents and work with them. The structural rules can be defined using many available technologies, but the following are popular way of doing so- &lt;/p&gt;&lt;ul&gt;&lt;li&gt;Document Type  Definition (DTD)&lt;/li&gt;&lt;li&gt;Schema&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;9.&lt;/span&gt;&lt;strong&gt;What is DTD?&lt;/strong&gt;&lt;/span&gt;    &lt;p class="content" align="justify"&gt;A &lt;strong&gt;Document Type Definition&lt;/strong&gt; (DTD) defines the legal building blocks of an XML document. It defines rules for a specific type of document, including: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;Names  of elements, and how and where they can be used&lt;/li&gt;&lt;li&gt;The  order of elements&lt;/li&gt;&lt;li&gt;Proper  nesting and containment of elements&lt;/li&gt;&lt;li&gt;Element  attributes&lt;/li&gt;&lt;/ul&gt; &lt;p class="content" align="justify"&gt;To apply a DTD to an XML document, you can:  &lt;/p&gt;&lt;ul&gt;&lt;li&gt;Include the DTD's element definitions within  the XML document itself.&lt;/li&gt;&lt;li&gt;Provide the DTD as a separate file, whose name you reference in the XML document. &lt;/li&gt;&lt;/ul&gt;  &lt;br /&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;10.&lt;/span&gt;&lt;strong&gt;What is XML Schema?&lt;/strong&gt;&lt;/span&gt;    &lt;p class="content" align="justify"&gt;An XML &lt;strong&gt;Schema&lt;/strong&gt; describes the structure of an XML instance document by defining what each element must or may contain.XML Schema is expressed in the form of a separate XML file. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;XML Schema provides much more control on element and attribute datatypes. &lt;/li&gt;&lt;li&gt;Some datatypes are predefined and new ones can be created.&lt;/li&gt;&lt;li&gt;  	&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p class="content" align="justify"&gt; &lt;/p&gt; &lt;div align="center"&gt;&lt;img src="http://www.developersbook.com/xml/images/schema.gif" alt="Xchema" align="middle" border="0" /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="title" align="center"&gt;Figure 2: XML Schema&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="que"&gt;      &lt;span class="queIndex"&gt;11.&lt;/span&gt;&lt;strong&gt;What are differences between DTDs and Schema?&lt;/strong&gt;&lt;/span&gt;        &lt;table class="mytable" border="1" cellpadding="5" cellspacing="5"&gt;&lt;tbody&gt;&lt;tr&gt;     &lt;th width="50%"&gt;&lt;strong&gt;Schema&lt;/strong&gt;&lt;/th&gt;      &lt;th width="50%"&gt;&lt;strong&gt;DTD&lt;/strong&gt;&lt;/th&gt;   &lt;/tr&gt;   &lt;tr class="odd"&gt;     &lt;td&gt;Schema  document is an XML document i.e., the structure of an XML document is specified  by another XML document. &lt;/td&gt;     &lt;td&gt;DTDs  follow SGML syntax.&lt;/td&gt;   &lt;/tr&gt;   &lt;tr class="even"&gt;     &lt;td&gt;Schema  supports variety of dataTypes similar to programming language.&lt;/td&gt;     &lt;td&gt;In  DTD everything is treated as text.&lt;/td&gt;   &lt;/tr&gt;    &lt;tr class="odd"&gt;     &lt;td&gt;In  Schema,  It is possible to inherit and  create relationship among elements.&lt;/td&gt;     &lt;td&gt;This  is not possible in DTD without invalidating existing documents.&lt;/td&gt;   &lt;/tr&gt;        &lt;tr class="even"&gt;     &lt;td&gt;In  Schema, It is possible to group elements and attributes so that they can be  treated as single logical unit.&lt;/td&gt;     &lt;td&gt;Grouping  of elements and attributes is not possible in DTD.&lt;/td&gt;   &lt;/tr&gt;     &lt;tr class="odd"&gt;       &lt;td&gt;In  Schemas, it is possible to specify an upper limit for the number of occurrences  of an element &lt;/td&gt;       &lt;td&gt;It  is not possible to specify an upper limit of an element in DTDs&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;12.What is a Complex Element?&lt;br /&gt;&lt;br /&gt;A complex element is an XML element that contains other elements and/or attributes.&lt;br /&gt;There are four kinds of complex elements:&lt;br /&gt;&lt;br /&gt; * empty elements&lt;br /&gt; * elements that contain only other elements&lt;br /&gt; * elements that contain only text&lt;br /&gt; * elements that contain both other elements and text&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;13.What is a Simple Element?&lt;br /&gt;&lt;br /&gt;A simple element is an XML element that can contain only text.&lt;br /&gt;&lt;br /&gt; * A simple element cannot have attributes&lt;br /&gt; * A simple element cannot contain other elements&lt;br /&gt; * A simple element cannot be empty&lt;br /&gt; * However, the text can be of many different types, and may have various restrictions applied to it&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;14.What are namespaces? Why are they important?&lt;br /&gt;&lt;br /&gt;A simple element is an XML element that can contain only text.&lt;br /&gt;&lt;br /&gt; * Namespaces are a simple and straightforward way to distinguish names used in XML documents, no matter where they come from.&lt;br /&gt; * XML namespaces are used for providing uniquely named elements and attributes in an XML instance&lt;br /&gt; * They allow developers to qualify uniquely the element names and relationships and make these names recognizable, to avoid name collisions on elements that have the same name but are defined in different vocabularies.&lt;br /&gt; * They allow tags from multiple namespaces to be mixed, which is essential if data is coming from multiple sources.&lt;br /&gt;&lt;br /&gt;&lt;title&gt; tag to mean the title of a book, contained only within the &lt;book&gt; element. A directory of people, however, might define &lt;title&gt; to indicate a person's position, for instance: &lt;title&gt;President&lt;/title&gt;Example: a bookstore may define the . Namespaces help define this distinction clearly.&lt;br /&gt;&lt;br /&gt;Note: a) Every namespace has a unique name which is a string. To maintain the uniqueness among namespaces a IRL is most preferred approach, since URLs are unique.&lt;br /&gt;&lt;br /&gt;      b) Except for no-namespace Schemas, every XML Schema uses at least two namespaces:&lt;br /&gt;             1.the target namespace.&lt;br /&gt;             2. The XMLSchema namespace (http://w3.org/2001/XMLSchema)      &lt;br /&gt;&lt;br /&gt;15.What are the ways to use namespaces?&lt;br /&gt;&lt;br /&gt;There are two ways to use namespaces:&lt;br /&gt;&lt;br /&gt; * Declare a default namespace&lt;br /&gt; * Associate a prefix with a namespace, then use the prefix in the XML to refer to the namespace&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-9113112282855748983?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/9113112282855748983/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=9113112282855748983' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/9113112282855748983'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/9113112282855748983'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/07/xml-questions-1.html' title='XML Questions 1'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-5653114211970036820</id><published>2008-07-05T14:27:00.000-07:00</published><updated>2008-07-05T14:29:15.225-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JDBC Questions 2'/><title type='text'>JDBC Questions 2</title><content type='html'>&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;16.&lt;/span&gt;&lt;strong&gt;Which type of JDBC driver is the fastest one&lt;/strong&gt;? &lt;/span&gt; &lt;p class="content" align="justify"&gt; JDBC Net pure Java driver(Type IV) is the fastest driver because it converts the JDBC calls into vendor specific protocol calls and it directly interacts with the database.&lt;/p&gt;&lt;br /&gt;&lt;span class="que"&gt; &lt;span class="queIndex"&gt;17.&lt;/span&gt;&lt;strong&gt;Does the JDBC-ODBC   Bridge support multiple  concurrent open statements per connection?&lt;/strong&gt;&lt;/span&gt;  &lt;p class="content" align="justify"&gt;No. You can open only one Statement object per  connection when you are using the JDBC-ODBC Bridge.&lt;/p&gt;&lt;br /&gt; &lt;span class="que"&gt; &lt;span class="queIndex"&gt;18.&lt;/span&gt;&lt;strong&gt;Which is the right type of driver to use and when? &lt;/strong&gt;&lt;/span&gt;  &lt;p class="content" align="justify"&gt; &lt;/p&gt;&lt;ul&gt;&lt;li&gt;Type I driver is handy for prototyping&lt;/li&gt;&lt;li&gt;Type III driver adds &lt;a id="KonaLink0" target="_top" class="kLink" style="text-decoration: underline ! important; position: static;" href="http://www.developersbook.com/jdbc/interview-questions/jdbc-interview-questions-faqs-2.php#"&gt;&lt;span style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;color:#f26522;" &gt;&lt;span class="kLink" style="border-bottom: 1px solid rgb(242, 101, 34); color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static; padding-bottom: 1px; background-color: transparent;"&gt;security&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;, caching, and connection control&lt;/li&gt;&lt;li&gt;Type III and Type IV drivers need no pre-installation&lt;/li&gt;&lt;/ul&gt;     &lt;span class="que"&gt; &lt;span class="queIndex"&gt;19.&lt;/span&gt;&lt;strong&gt;What are the standard isolation levels defined by JDBC?&lt;/strong&gt;&lt;/span&gt;  &lt;p class="content" align="justify"&gt;The  values are defined in the class java.sql.Connection and are:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;TRANSACTION_NONE&lt;/li&gt;&lt;li&gt;TRANSACTION_READ_COMMITTED&lt;/li&gt;&lt;li&gt;TRANSACTION_READ_UNCOMMITTED&lt;/li&gt;&lt;li&gt;TRANSACTION_REPEATABLE_READ&lt;/li&gt;&lt;li&gt;TRANSACTION_SERIALIZABLE&lt;/li&gt;&lt;/ul&gt; &lt;p class="content" align="justify"&gt;Any  given database may not support all of these levels.&lt;/p&gt; &lt;br /&gt; &lt;span class="que"&gt; &lt;span class="queIndex"&gt;20.&lt;/span&gt;&lt;strong&gt;What is resultset ?&lt;/strong&gt;&lt;/span&gt;  &lt;p class="content" align="justify"&gt;The ResultSet represents set of rows retrieved due to query execution.&lt;br /&gt;&lt;/p&gt;&lt;pre class="mid"&gt;  ResultSet rs = stmt.executeQuery(sqlQuery);&lt;/pre&gt; &lt;p&gt; 21.What are the types of resultsets?&lt;br /&gt;&lt;br /&gt;The values are defined in the class java.sql.Connection and are:&lt;br /&gt;&lt;br /&gt;    * TYPE_FORWARD_ONLY specifies that a resultset is not scrollable, that is, rows within it can be advanced only in the forward direction.&lt;br /&gt;    * TYPE_SCROLL_INSENSITIVE specifies that a resultset is scrollable in either direction but is insensitive to changes committed by other transactions or other statements in the same transaction.&lt;br /&gt;    * TYPE_SCROLL_SENSITIVE specifies that a resultset is scrollable in either direction and is affected by changes committed by other transactions or statements within the same transaction.&lt;br /&gt;&lt;br /&gt;Note: A TYPE_FORWARD_ONLY resultset is always insensitive.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;22.What’s the difference between TYPE_SCROLL_INSENSITIVE and TYPE_SCROLL_SENSITIVE?&lt;br /&gt;&lt;br /&gt;TYPE_SCROLL_INSENSITIVE     TYPE_SCROLL_SENSITIVE&lt;br /&gt;An insensitive  resultset is like the snapshot of the data in the database when query was executed.     A sensitive resultset does NOT represent a snapshot of data, rather it contains points to those rows which satisfy the query condition.&lt;br /&gt;After we get the resultset the changes made to data are not visible through the resultset, and hence they are known as insensitive.     After we obtain the resultset if the data is modified then such modifications are visible through resultset.&lt;br /&gt;Performance not effected with insensitive.     Since a trip is made for every ‘get’ operation, the performance drastically get affected.&lt;br /&gt;&lt;br /&gt;22.What is rowset?&lt;br /&gt;&lt;br /&gt;A RowSet is an object that encapsulates a set of rows from either Java Database Connectivity (JDBC) result sets or tabular data sources like a file or spreadsheet. RowSets support component-based development models like JavaBeans, with a standard set of properties and an event notification mechanism.&lt;br /&gt;&lt;br /&gt;24.What are the different types  of RowSet ?&lt;br /&gt;&lt;br /&gt;There are two types of RowSet are there. They are:&lt;br /&gt;&lt;br /&gt;    * Connected - A connected RowSet object connects to the database once and remains connected until the application terminates.&lt;br /&gt;    * Disconnected - A disconnected RowSet object connects to the database, executes a query to retrieve the data from the database and then closes the connection. A program may change the data in a disconnected RowSet while it is disconnected. Modified data can be updated in the database after a disconnected RowSet reestablishes the connection with the database.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;25.What is the need of BatchUpdates?&lt;br /&gt;&lt;br /&gt;The BatchUpdates feature allows us to group SQL statements together and send to database server in one single trip.&lt;br /&gt;&lt;br /&gt;26.What is a DataSource?&lt;br /&gt;&lt;br /&gt;A DataSource object is the representation of a data source in the Java programming language. In basic terms,&lt;br /&gt;&lt;br /&gt;    * A DataSource is a facility for storing data.&lt;br /&gt;    * DataSource can be referenced by JNDI.&lt;br /&gt;    * Data Source may point to RDBMS, file System , any DBMS etc..&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;27.What are the advantages of DataSource?&lt;br /&gt;&lt;br /&gt;The few advantages of data source are :&lt;br /&gt;&lt;br /&gt;    * An application does not need to hardcode driver information, as it does with the DriverManager.&lt;br /&gt;    * The DataDource implementations can easily change the properties of data sources. For example: There is no need to modify the application code when making changes to the database details.&lt;br /&gt;    * The DataSource facility allows developers to implement a DataSource class to take advantage of features like connection pooling and distributed transactions.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;28.What is connection pooling? what is the main advantage of using connection pooling?&lt;br /&gt;&lt;br /&gt;A connection pool is a mechanism to reuse connections created. Connection pooling can increase performance dramatically by reusing connections rather than creating a new physical connection each time a connection is requested..&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-5653114211970036820?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/5653114211970036820/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=5653114211970036820' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/5653114211970036820'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/5653114211970036820'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/07/jdbc-questions-2.html' title='JDBC Questions 2'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-6187062163550078187</id><published>2008-07-05T14:26:00.000-07:00</published><updated>2008-07-05T14:27:31.644-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JDBC Questions 1'/><title type='text'>JDBC Questions 1</title><content type='html'>&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;1.&lt;/span&gt;What is the JDBC?&lt;/span&gt; &lt;p class="content" align="justify"&gt;Java Database Connectivity (&lt;strong&gt;JDBC&lt;/strong&gt;) is a standard Java API to interact with relational databases form Java. &lt;strong&gt;JDBC&lt;/strong&gt; has set of classes and interfaces which can use from Java application and talk to database without learning RDBMS details and using Database Specific JDBC Drivers.&lt;/p&gt;&lt;br /&gt; &lt;span class="que"&gt;  &lt;span class="queIndex"&gt;2.&lt;/span&gt;What are the new features added to JDBC 4.0?&lt;/span&gt; &lt;p class="content" align="justify"&gt;The major features added in JDBC 4.0 include :&lt;/p&gt; &lt;ul&gt;&lt;li&gt;Auto-loading of JDBC driver class&lt;/li&gt;&lt;li&gt;Connection management enhancements&lt;/li&gt;&lt;li&gt;Support for &lt;code&gt;RowId&lt;/code&gt; &lt;a id="KonaLink0" target="_top" class="kLink" style="text-decoration: underline ! important; position: static;" href="http://www.developersbook.com/jdbc/interview-questions/jdbc-interview-questions-faqs.php#"&gt;&lt;span style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;color:#f26522;" &gt;&lt;span class="kLink" style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;"&gt;SQL&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; type&lt;/li&gt;&lt;li&gt;DataSet implementation of SQL using Annotations&lt;/li&gt;&lt;li&gt;SQL exception handling enhancements&lt;/li&gt;&lt;li&gt;SQL XML support&lt;/li&gt;&lt;/ul&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;3.&lt;/span&gt;Explain Basic Steps in writing a Java program  using JDBC?&lt;/span&gt; &lt;p class="content" align="justify"&gt;JDBC makes the interaction  with RDBMS simple and intuitive. When a Java application  needs to access database : &lt;/p&gt;&lt;ul&gt;&lt;li&gt;Load the RDBMS specific JDBC driver because this driver actually communicates with the database (Incase of JDBC 4.0 this is automatically loaded).&lt;/li&gt;&lt;li&gt;Open the connection to  database which is then used to send &lt;a id="KonaLink1" target="_top" class="kLink" style="text-decoration: underline ! important; position: static;" href="http://www.developersbook.com/jdbc/interview-questions/jdbc-interview-questions-faqs.php#"&gt;&lt;span style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;color:#f26522;" &gt;&lt;span class="kLink" style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;"&gt;SQL &lt;/span&gt;&lt;span class="kLink" style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;"&gt;statements&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; and get results back. &lt;/li&gt;&lt;li&gt;Create JDBC Statement  object. This object contains &lt;a id="KonaLink2" target="_top" class="kLink" style="text-decoration: underline ! important; position: static;" href="http://www.developersbook.com/jdbc/interview-questions/jdbc-interview-questions-faqs.php#"&gt;&lt;span style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;color:#f26522;" &gt;&lt;span class="kLink" style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;"&gt;SQL &lt;/span&gt;&lt;span class="kLink" style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;"&gt;query&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;Execute statement which  returns resultset(s). ResultSet contains the tuples of database table as a  result of SQL query. &lt;/li&gt;&lt;li&gt;Process the result set.&lt;/li&gt;&lt;li&gt;Close the connection.&lt;/li&gt;&lt;/ul&gt; &lt;br /&gt;&lt;span class="que"&gt;&lt;span class="queIndex"&gt;4.&lt;/span&gt;Exaplain the JDBC Architecture.&lt;/span&gt; &lt;p class="content" align="justify"&gt;The JDBC Architecture consists of two layers: &lt;/p&gt; &lt;ul&gt;&lt;li&gt;The JDBC API, which provides the &lt;strong&gt;application-to-JDBC Manager&lt;/strong&gt; connection.&lt;/li&gt;&lt;li&gt;The JDBC Driver API, which supports the &lt;strong&gt;JDBC Manager-to-Driver&lt;/strong&gt; Connection.&lt;/li&gt;&lt;/ul&gt; &lt;p class="content" align="justify"&gt;The JDBC API uses a driver manager and database-specific drivers to provide transparent connectivity to heterogeneous databases. The JDBC driver manager ensures that the correct driver is used to access each data source. The driver manager is capable of supporting multiple concurrent drivers connected to multiple heterogeneous databases. The location of the driver manager with respect to the JDBC drivers and the Java application is shown in Figure 1.&lt;/p&gt;  &lt;div align="center"&gt;&lt;img src="http://www.developersbook.com/jdbc/images/JDBC-Architecture.gif" alt="JDBC Architecture" align="middle" border="0" /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="title" align="center"&gt;Figure 1: JDBC Architecture&lt;/div&gt;&lt;br /&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;5.&lt;/span&gt;What are the main components of JDBC ?&lt;/span&gt;  &lt;p class="content" align="justify"&gt;The life cycle of a servlet consists of the following phases:&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;strong&gt;DriverManager&lt;/strong&gt;: Manages a list of database drivers. Matches connection requests from the java application with the proper database driver using communication subprotocol. The first driver that recognizes a certain subprotocol under JDBC will be used to establish a database Connection.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Driver&lt;/strong&gt;: The database communications link, handling all communication with the database. Normally, once the driver is loaded, the developer need not call it explicitly.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Connection &lt;/strong&gt;: Interface with all methods for contacting a database.The connection object represents communication context, i.e., all communication with database is through connection object only. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Statement&lt;/strong&gt; : Encapsulates  an SQL statement which is passed to the database to be parsed, compiled,  planned and executed.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;ResultSet&lt;/strong&gt;:    The ResultSet represents set of  rows retrieved due to query execution.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt; &lt;span class="que"&gt; &lt;span class="queIndex"&gt;6.&lt;/span&gt;&lt;strong&gt;How the JDBC application works? &lt;/strong&gt;&lt;/span&gt;  &lt;p class="content" align="justify"&gt;A JDBC application can be logically divided into two layers:  &lt;/p&gt;&lt;p class="content" align="justify"&gt; 1. &lt;strong&gt;Driver layer&lt;/strong&gt;  &lt;/p&gt;&lt;p class="content" align="justify"&gt;2. &lt;strong&gt;Application layer&lt;/strong&gt; &lt;/p&gt;&lt;ul&gt;&lt;li&gt;Driver layer consists of DriverManager class and the available JDBC drivers. &lt;/li&gt;&lt;li&gt;The application begins with requesting the DriverManager for the connection.&lt;/li&gt;&lt;li&gt;An appropriate driver is choosen and is used for establishing the connection. This connection is given to the application which falls under the application layer.&lt;/li&gt;&lt;li&gt;The application uses this connection to create Statement kind of objects, through which SQL commands are sent to backend and obtain the results. &lt;/li&gt;&lt;/ul&gt; &lt;div align="center"&gt;&lt;img src="http://www.developersbook.com/jdbc/images/JDBC-Application.gif" alt="JDBC Application" align="middle" border="0" /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="title" align="center"&gt;Figure 2: JDBC Application&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt; 7.How do I load a database driver with JDBC 4.0 / Java 6?&lt;br /&gt;&lt;br /&gt;Provided the JAR file containing the driver is properly configured, just place the JAR file in the classpath. Java developers NO longer need to explicitly load JDBC drivers using code like Class.forName() to register a JDBC driver.The DriverManager class takes care of this by automatically locating a suitable driver when the DriverManager.getConnection() method is called. This feature is backward-compatible, so no changes are needed to the existing JDBC code.&lt;br /&gt;&lt;br /&gt;8.What is JDBC Driver interface?&lt;br /&gt;&lt;br /&gt;The JDBC Driver interface provides vendor-specific implementations of the abstract classes provided by the JDBC API. Each vendor driver must provide implementations of the java.sql.Connection,Statement,PreparedStatement, CallableStatement, ResultSet and Driver.&lt;br /&gt;&lt;br /&gt;9.What does the connection object represents?&lt;br /&gt;&lt;br /&gt;The connection object represents communication context, i.e., all communication with database is through connection object only.&lt;br /&gt;&lt;br /&gt;10.What is Statement ?&lt;br /&gt;&lt;br /&gt;Statement acts like a vehicle through which SQL commands can be sent. Through the connection object we create statement kind of objects.&lt;br /&gt;Through the connection object we create statement kind of objects.&lt;br /&gt;&lt;br /&gt;               Statement stmt  = conn.createStatement();&lt;br /&gt;&lt;br /&gt;This method returns object which implements statement interface.&lt;br /&gt;&lt;br /&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;11.&lt;/span&gt;&lt;strong&gt;What is PreparedStatement?&lt;/strong&gt;&lt;/span&gt; &lt;p class="content" align="justify"&gt;A prepared statement is an SQL statement that is precompiled by the database. Through precompilation, prepared statements improve the performance of SQL commands that are executed multiple times (given that the database supports prepared statements). Once compiled, prepared statements can be customized prior to each execution by altering predefined SQL parameters.&lt;br /&gt;&lt;/p&gt;&lt;pre class="mid"&gt; PreparedStatement pstmt = conn.prepareStatement("UPDATE EMPLOYEES SET SALARY = ? WHERE ID = ?");&lt;br /&gt;  pstmt.setBigDecimal(1, 153833.00);&lt;br /&gt;  pstmt.setInt(2, 110592);&lt;/pre&gt; &lt;p class="content"&gt;&lt;em&gt;Here: &lt;strong&gt;&lt;code&gt;conn&lt;/code&gt;&lt;/strong&gt; is an instance of the Connection class and &lt;code&gt;"&lt;strong&gt;?&lt;/strong&gt;"&lt;/code&gt; represents parameters.These parameters must be specified before execution.&lt;/em&gt;&lt;/p&gt;    &lt;br /&gt;   &lt;br /&gt;     &lt;br /&gt;       &lt;span class="que"&gt;      &lt;span class="queIndex"&gt;12.&lt;/span&gt;&lt;strong&gt;What is the difference between a Statement and a  PreparedStatement?&lt;/strong&gt;&lt;/span&gt;     &lt;p class="content" align="justify"&gt;&lt;table class="mytable" border="1" cellpadding="5" cellspacing="5"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;th width="50%"&gt;&lt;strong&gt;Statement&lt;/strong&gt;&lt;/th&gt;      &lt;th width="50%"&gt;&lt;strong&gt;PreparedStatement&lt;/strong&gt;&lt;/th&gt;   &lt;/tr&gt;   &lt;tr class="odd"&gt;     &lt;td&gt;A standard Statement is used to create a Java representation of a  literal SQL statement and execute it on the database.&lt;/td&gt;     &lt;td&gt;A PreparedStatement is a precompiled  statement. This means that when the PreparedStatement is executed, the RDBMS can just run the PreparedStatement SQL statement without having to compile it first.&lt;/td&gt;   &lt;/tr&gt;   &lt;tr class="even"&gt;     &lt;td&gt;Statement has to verify its metadata against the database every time.&lt;/td&gt;     &lt;td&gt;While a prepared statement has to verify its metadata against the database only once. &lt;/td&gt;   &lt;/tr&gt;    &lt;tr class="odd"&gt;     &lt;td&gt;If  you want to execute the SQL statement once go for STATEMENT&lt;/td&gt;     &lt;td&gt;If you want to execute a single SQL statement multiple number of times, then go for PREPAREDSTATEMENT.  PreparedStatement objects can be reused with passing different values to the queries &lt;/td&gt;   &lt;/tr&gt;    &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;&lt;br /&gt; &lt;span class="que"&gt;  &lt;span class="queIndex"&gt;13.&lt;/span&gt;&lt;strong&gt;What are callable statements ?&lt;/strong&gt;&lt;/span&gt; &lt;p class="content" align="justify"&gt;Callable statements are used from JDBC  application to invoke stored procedures and  functions.&lt;/p&gt;&lt;br /&gt; &lt;span class="que"&gt;  &lt;span class="queIndex"&gt;14.&lt;/span&gt;How to call a stored procedure from JDBC ?&lt;/span&gt; &lt;p class="content" align="justify"&gt;PL/SQL stored procedures are called from within JDBC programs by means of the prepareCall() method of the Connection object created. A call to this method takes variable bind parameters as input parameters as well as output variables and creates an object instance of the CallableStatement class.&lt;/p&gt; &lt;p class="content" align="justify"&gt;The following line of code illustrates this:&lt;/p&gt; &lt;pre class="mid"&gt;   CallableStatement stproc_stmt = conn.prepareCall("{call procname(?,?,?)}");&lt;/pre&gt; &lt;p class="content" align="justify"&gt;Here conn is an instance of the Connection class.&lt;/p&gt;&lt;br /&gt;  &lt;span class="que"&gt;  &lt;span class="queIndex"&gt;15.&lt;/span&gt;&lt;strong&gt;What are  types of JDBC drivers?&lt;/strong&gt;&lt;/span&gt; &lt;p class="content" align="justify"&gt;There are four types of drivers defined by JDBC  as follows: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Type 1: JDBC/ODBC&lt;/strong&gt;—These require an ODBC (Open Database Connectivity) driver for the database to be installed. This type of driver works by translating the submitted queries into equivalent ODBC queries and forwards them via native API calls directly to the ODBC driver. It provides no host redirection capability.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Type2: Native API (partly-Java driver)&lt;/strong&gt;—This type of driver uses a vendor-specific driver or database API to interact with the database. An example of such an API is Oracle OCI (Oracle Call Interface). It also provides no host redirection.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;    &lt;strong&gt;Type 3: Open Protocol-Net&lt;/strong&gt;—This is not  vendor specific and works by forwarding database requests to a remote database  source using a net &lt;a id="KonaLink3" target="_top" class="kLink" style="text-decoration: underline ! important; position: static;" href="http://www.developersbook.com/jdbc/interview-questions/jdbc-interview-questions-faqs.php#"&gt;&lt;span style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;color:#f26522;" &gt;&lt;span class="kLink" style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;"&gt;server&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; component. How the net server component accesses the database is transparent to the client. The client driver communicates with the net server using a database-independent protocol and the net server translates this protocol into database calls. This type of driver can access any database.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;    &lt;strong&gt;Type 4: Proprietary Protocol-Net(pure Java  driver)&lt;/strong&gt;—This has a same configuration as a type 3 driver but uses a wire protocol specific to a particular vendor and hence can access only that vendor's database. Again this is all transparent to the client.&lt;/li&gt;&lt;/ul&gt; &lt;p class="content" align="justify"&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;em&gt;Type 4 JDBC driver is most preferred kind of  approach in JDBC.&lt;/em&gt;&lt;/p&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-6187062163550078187?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/6187062163550078187/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=6187062163550078187' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/6187062163550078187'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/6187062163550078187'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/07/jdbc-questions-1.html' title='JDBC Questions 1'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-3167363348367195098</id><published>2008-07-05T14:22:00.000-07:00</published><updated>2008-07-05T14:24:41.244-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Servlet Questions 3'/><title type='text'>Servlet Questions 3</title><content type='html'>&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;30.&lt;/span&gt;What is session?&lt;/span&gt; &lt;p class="content" align="justify"&gt;A session refers to all the requests that a single client might make to a &lt;a id="KonaLink0" target="_top" class="kLink" style="text-decoration: underline ! important; position: static;" href="http://www.developersbook.com/servlets/interview-questions/servlets-interview-questions-faqs-3.php#"&gt;&lt;span style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;color:#f26522;" &gt;&lt;span class="kLink" style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;"&gt;server&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; in the course of viewing any pages associated with a given application. Sessions are specific to both the individual user and the application. As a result, every user of an application has a separate session and has access to a separate set of session variables. &lt;/p&gt;&lt;div align="center"&gt;&lt;img src="http://www.developersbook.com/servlets/images/session.gif" alt="Session" border="0" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt; 31.What is Session Tracking?&lt;br /&gt;&lt;br /&gt;Session tracking is a mechanism that servlets use to maintain state about a series of requests from the same user (that is, requests originating from the same browser) across some period of time.&lt;br /&gt;&lt;br /&gt;32.What is the need of Session Tracking in web application?&lt;br /&gt;&lt;br /&gt;HTTP is a stateless protocol i.e., every request is treated as new request. For web applications to be more realistic they have to retain information across multiple requests. Such information which is part of the application is reffered as "state". To keep track of this state we need session tracking.&lt;br /&gt;&lt;br /&gt;Typical example: Putting things one at a time into a shopping cart, then checking out--each page request must somehow be associated with previous requests.&lt;br /&gt;&lt;br /&gt;33.What are the types of Session Tracking ?&lt;br /&gt;&lt;br /&gt;Sessions need to work with all web browsers and take into account the users security preferences. Therefore there are a variety of ways to send and receive the identifier:&lt;br /&gt;&lt;br /&gt;    * URL rewriting : URL rewriting is a method of session tracking in which some extra data (session ID) is appended at the end of each URL. This extra data identifies the session. The server can associate this session identifier with the data it has stored about that session. This method is used with browsers that do not support cookies or where the user has disabled the cookies.&lt;br /&gt;&lt;br /&gt;    * Hidden Form Fields : Similar to URL rewriting. The server embeds new hidden fields in every dynamically generated form page for the client. When the client submits the form to the server the hidden fields identify the client.&lt;br /&gt;&lt;br /&gt;    * Cookies : Cookie is a small amount of information sent by a servlet to a Web browser. Saved by the browser, and later sent back to the server in subsequent requests. A cookie has a name, a single value, and optional attributes. A cookie's value can uniquely identify a client.&lt;br /&gt;&lt;br /&gt;    * Secure Socket Layer (SSL) Sessions : Web browsers that support Secure Socket Layer communication can use SSL's support via HTTPS for generating a unique session key as part of the encrypted conversation.&lt;br /&gt;&lt;br /&gt;Learn more about Session Tracking     &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;34.How do I use cookies to store session state on the client?&lt;br /&gt;&lt;br /&gt;In a servlet, the HttpServletResponse and HttpServletRequest objects passed to method HttpServlet.service() can be used to create cookies on the client and use cookie information transmitted during client requests. JSPs can also use cookies, in scriptlet code or, preferably, from within custom tag code.&lt;br /&gt;&lt;br /&gt;    * To set a cookie on the client, use the addCookie() method in class HttpServletResponse. Multiple cookies may be set for the same request, and a single cookie name may have multiple values.&lt;br /&gt;    * To get all of the cookies associated with a single HTTP request, use the getCookies() method of class HttpServletRequest&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;35.What are some advantages of storing session state in cookies?&lt;br /&gt;&lt;br /&gt;    * Cookies are usually persistent, so for low-security sites, user data that needs to be stored long-term (such as a user ID, historical information, etc.) can be maintained easily with no server interaction.&lt;br /&gt;    * For small- and medium-sized session data, the entire session data (instead of just the session ID) can be kept in the cookie.&lt;br /&gt;&lt;br /&gt;&lt;span class="que"&gt;&lt;span class="queIndex"&gt;36.&lt;/span&gt;What are some disadvantages of storing session state in cookies?&lt;/span&gt; &lt;ul&gt;&lt;li&gt; Cookies are controlled by programming a low-level API, which is more  difficult to implement than some other approaches.&lt;/li&gt;&lt;li&gt; All data for a session are kept on the client. Corruption, expiration or purging of cookie files can all result in incomplete, inconsistent, or missing information.&lt;/li&gt;&lt;li&gt; Cookies may not be available for many reasons: the user may have disabled them, the browser version may not support them, the browser may be behind a firewall that filters cookies, and so on. Servlets and JSP pages that rely exclusively on cookies for client-side session state will not operate properly for all clients. Using cookies, and then switching to an alternate client-side session state strategy in cases where cookies aren't available, complicates development and maintenance.&lt;/li&gt;&lt;li&gt; Browser instances share cookies, so users cannot have multiple  simultaneous sessions.&lt;/li&gt;&lt;li&gt; Cookie-based solutions work only for HTTP clients. This is because cookies are a feature of the HTTP protocol. Notice that the while package &lt;code&gt;javax.servlet.http&lt;/code&gt; supports session management (via class &lt;code&gt; HttpSession&lt;/code&gt;),  package &lt;code&gt;javax.servlet&lt;/code&gt; has no such support. &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;37.&lt;/span&gt;What is URL rewriting?&lt;/span&gt; &lt;p class="content" align="justify"&gt;URL rewriting is a method of session tracking in which some extra data is appended at the end of each URL. This extra data identifies the session. The server can associate this session identifier with the data it has stored about that session. &lt;/p&gt;&lt;p class="content" align="justify"&gt;  Every URL on the page must be encoded using method &lt;code&gt; HttpServletResponse&lt;/code&gt;.encodeURL(). Each time a URL is output, the servlet passes the URL to encodeURL(), which encodes session ID in the URL if the browser isn't accepting cookies, or if the session tracking is turned off.&lt;br /&gt;  E.g., http://abc/path/index.jsp;jsessionid=123465hfhs&lt;br /&gt;&lt;/p&gt;&lt;ul&gt;&lt;strong&gt;Advantages&lt;/strong&gt;&lt;li&gt;URL rewriting works just about everywhere, especially when cookies are turned off.&lt;/li&gt;&lt;li&gt;Multiple simultaneous sessions are possible for a single user. Session information is local to each browser instance, since it's stored in URLs in each page being displayed. This scheme isn't foolproof, though, since users can start a new browser instance using a URL for an active session, and confuse the server by interacting with the same session through two instances.&lt;/li&gt;&lt;li&gt;Entirely static pages cannot be used with URL rewriting, since every link must be dynamically written with the session state. It is possible to combine static and dynamic content, using (for example) templating or server-side includes. This limitation is also a barrier to integrating legacy web pages with newer, servlet-based pages.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;ul&gt;&lt;strong&gt;DisAdvantages&lt;/strong&gt;&lt;li&gt;Every URL on a page which needs the session information must be rewritten each time a page is served. Not only is this expensive computationally, but it can greatly increase communication overhead.&lt;/li&gt;&lt;li&gt;URL rewriting limits the client's interaction with the server to HTTP GETs, which can result in awkward restrictions on the page.&lt;/li&gt;&lt;li&gt;URL rewriting does not work well with JSP technology.&lt;/li&gt;&lt;li&gt;If a client workstation crashes, all of the URLs (and therefore all of the data for that session) are lost.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;38.&lt;/span&gt;How can an existing session be invalidated?&lt;/span&gt; &lt;p class="content" align="justify"&gt;An existing session can be invalidated in the following two ways: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;Setting timeout in the deployment descriptor: This can be done by specifying timeout between the &lt;code&gt;&lt;session-timeout&gt;&lt;/code&gt;tags as follows:    &lt;/li&gt;&lt;pre class="mid"&gt;&lt;session-config&gt;&lt;br /&gt;       &lt;&lt;strong&gt;session-timeout&gt;10&lt;/session-timeout&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/session-config&gt;&lt;/pre&gt;&lt;p class="content" align="justify"&gt;This will set the time for session timeout to be ten minutes.&lt;/p&gt;&lt;br /&gt;&lt;li&gt;Setting timeout programmatically: This will set the timeout for a specific session. The syntax for setting the timeout programmatically is as follows:&lt;/li&gt;&lt;pre class="mid"&gt;public void setMaxInactiveInterval(int interval)&lt;/pre&gt;   The &lt;code&gt;setMaxInactiveInterval()&lt;/code&gt; method sets the maximum time in seconds before a session becomes invalid.&lt;br /&gt;&lt;u&gt;Note &lt;/u&gt;:Setting the inactive period a&lt;em&gt;s negative(-1), makes the container stop tracking session, i.e, session never expires. &lt;/em&gt;&lt;/ul&gt;&lt;br /&gt;    &lt;span class="que"&gt;&lt;span class="queIndex"&gt;39.&lt;/span&gt;How can the session in Servlet can be destroyed?&lt;/span&gt;  &lt;p class="content" align="justify"&gt;An existing session can be destroyed in the following two ways: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;Programatically : Using &lt;code&gt;session.invalidate()&lt;/code&gt; method, which makes the container abonden the session on which the method is called. &lt;/li&gt;&lt;li&gt;When the server itself is shutdown. &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;    &lt;span class="que"&gt;&lt;span class="queIndex"&gt;40.&lt;/span&gt;A client sends requests to two different web components. Both of the components access the session. Will they end up using the same session object or different session ?&lt;/span&gt;     &lt;p class="content" align="justify"&gt;Creates only one session i.e., they end up with using same session . &lt;/p&gt;     &lt;p class="content" align="justify"&gt;Sessions is specific to the client but not the web components. And there is a 1-1 mapping between client and a session. &lt;/p&gt;&lt;br /&gt;    &lt;span class="que"&gt;&lt;span class="queIndex"&gt;41.&lt;/span&gt;What is servlet lazy loading?&lt;/span&gt;     &lt;ul&gt;&lt;li&gt;A container doesnot initialize the servlets ass soon as it starts up, it initializes a servlet when it receives a request for that servlet first time. This is called lazy loading.&lt;/li&gt;&lt;li&gt;The servlet specification defines the &lt;load-on-startup&gt; element, which can be specified in the deployment descriptor to make the servlet container load and initialize the servlet as soon as it starts up. &lt;/li&gt;&lt;li&gt;The process of loading a servlet before any  request comes in is called preloading or preinitializing a servlet.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;       &lt;span class="que"&gt;&lt;span class="queIndex"&gt;42.&lt;/span&gt;What is Servlet Chaining?&lt;/span&gt;     &lt;p class="content" align="justify"&gt;Servlet Chaining is a method where the output of one servlet is piped into a second servlet. The output of the second servlet could be piped into a third servlet, and so on. The last servlet in the chain returns the output to the Web browser.&lt;/p&gt;&lt;br /&gt;       &lt;span class="que"&gt;&lt;span class="queIndex"&gt;43.&lt;/span&gt;How are filters?&lt;/span&gt;     &lt;p class="content" align="justify"&gt;Filters are Java components that are used to intercept an incoming request to a Web resource and a response sent back from the resource. It is used to abstract any useful information contained in the request or response. Some of the important functions performed by filters are as follows: &lt;/p&gt;     &lt;ul&gt;&lt;li&gt;Security checks&lt;/li&gt;&lt;li&gt;Modifying the request or response&lt;/li&gt;&lt;li&gt;Data compression&lt;/li&gt;&lt;li&gt;Logging and auditing&lt;/li&gt;&lt;li&gt;Response compression&lt;/li&gt;&lt;/ul&gt;     &lt;p class="content" align="justify"&gt;Filters are configured in the deployment descriptor of a Web application. Hence, a user is not required to recompile anything to change the input or output of the Web application.&lt;/p&gt;&lt;br /&gt;   &lt;span class="que"&gt;&lt;span class="queIndex"&gt;44.&lt;/span&gt;What are the functions of an intercepting filter?&lt;/span&gt;     &lt;p class="content" align="justify"&gt;The functions of an intercepting filter are as follows:&lt;/p&gt;     &lt;ul&gt;&lt;li&gt;It intercepts the request from a client before it reaches the servlet and modifies the request if  required.&lt;/li&gt;&lt;li&gt;It intercepts the response from the servlet back  to the client and modifies the request if required.&lt;/li&gt;&lt;li&gt;There can be many filters forming a chain, in which case the output of one filter becomes an input to the next filter. Hence, various modifications can be performed on a single request and response.&lt;/li&gt;&lt;/ul&gt;&lt;div align="center"&gt;&lt;img src="http://www.developersbook.com/servlets/images/intercepting-filter.gif" alt="Intercepting Filter.gif" border="0" /&gt; &lt;/div&gt;&lt;br /&gt;   &lt;br /&gt;    &lt;span class="que"&gt;&lt;span class="queIndex"&gt;45.&lt;/span&gt;What are the functions of the Servlet container?&lt;/span&gt;     &lt;p class="content" align="justify"&gt;The functions of the Servlet container are as follows:&lt;/p&gt;     &lt;ul&gt;&lt;li&gt;&lt;strong&gt;Lifecycle management&lt;/strong&gt; : It manages the life and death of a servlet, such as class loading, instantiation, initialization, service, and making servlet instances eligible for garbage collection. &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Communication support&lt;/strong&gt; : It       handles the communication between the servlet and the &lt;a id="KonaLink3" target="_top" class="kLink" style="text-decoration: underline ! important; position: static;" href="http://www.developersbook.com/servlets/interview-questions/servlets-interview-questions-faqs-3.php#"&gt;&lt;span style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;color:#f26522;" &gt;&lt;span class="kLink" style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;"&gt;Web &lt;/span&gt;&lt;span class="kLink" style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;"&gt;server&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;. &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Multithreading support&lt;/strong&gt; : It automatically creates a new thread for every servlet request received. When the Servlet service() method completes, the thread dies. &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Declarative security&lt;/strong&gt; : It       manages the security inside the XML deployment descriptor file. &lt;/li&gt;&lt;li&gt;&lt;strong&gt;JSP support&lt;/strong&gt; : The container       is responsible for converting JSPs to servlets and for maintaining them. &lt;/li&gt;&lt;/ul&gt;                                                                                 &lt;br /&gt;&lt;/div&gt;                                                                                                                                                                                      &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-3167363348367195098?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/3167363348367195098/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=3167363348367195098' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/3167363348367195098'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/3167363348367195098'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/07/servlet-questions-3.html' title='Servlet Questions 3'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-6730337529409141548</id><published>2008-07-05T14:19:00.000-07:00</published><updated>2008-07-05T14:21:35.820-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Servlet Questions 2'/><title type='text'>Servlet Questions 2</title><content type='html'>16.When to use doGet() and when doPost()?&lt;br /&gt;&lt;br /&gt;Always prefer to use GET (As because GET is faster than POST), except mentioned in the following reason:&lt;br /&gt;&lt;br /&gt;    * If data is sensitive&lt;br /&gt;    * Date is greater than 1024 characters&lt;br /&gt;    * If your application don't need bookmarks.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;17.How do I support both GET and POST from the same Servlet?&lt;br /&gt;&lt;br /&gt;The easy way is, just support POST, then have your doGet method call your doPost method:&lt;br /&gt;&lt;br /&gt; public void doGet(HttpServletRequest request, HttpServletResponse response)&lt;br /&gt;                        throws ServletException, IOException&lt;br /&gt;{&lt;br /&gt;    doPost(request, response);  &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;18.Should I override the service() method?&lt;br /&gt;&lt;br /&gt;We never override the service method, since the HTTP Servlets have already taken care of it . The default service function invokes the doXXX() method corresponding to the method of the HTTP request.For example, if the HTTP request method is GET, doGet() method is called by default. A servlet should override the doXXX() method for the HTTP methods that servlet supports. Because HTTP service method check the request method and calls the appropriate handler method, it is not necessary to override the service method itself. Only override the appropriate doXXX() method.&lt;br /&gt;&lt;br /&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;19.&lt;/span&gt;How the typical servlet code look like ?&lt;/span&gt; &lt;div align="center"&gt;&lt;img src="http://www.developersbook.com/servlets/images/servlet.gif" alt="Servlet Code" height="454" width="636" /&gt;&lt;/div&gt;  &lt;br /&gt; &lt;span class="que"&gt;&lt;span class="queIndex"&gt;20.&lt;/span&gt;What is a servlet context object?&lt;/span&gt; &lt;p class="content" align="justify"&gt;A servlet context object contains the information about the Web application of which the servlet is a part. It also provides access to the resources common to all the servlets in the application. Each Web application in a container has a single servlet context associated with it.&lt;/p&gt;&lt;br /&gt; &lt;span class="que"&gt;&lt;span class="queIndex"&gt;21.&lt;/span&gt;What are the differences between the ServletConfig interface and the ServletContext interface?&lt;/span&gt; &lt;p class="content" align="justify"&gt; &lt;table class="mytable" border="1" cellpadding="5" cellspacing="5"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;th width="50%"&gt;ServletConfig&lt;/th&gt;      &lt;th width="50%"&gt;ServletContext&lt;/th&gt;   &lt;/tr&gt;   &lt;tr class="odd"&gt;     &lt;td&gt;The ServletConfig interface is implemented by the servlet container in order to pass configuration information to a servlet. The &lt;a id="KonaLink1" target="_top" class="kLink" style="text-decoration: underline ! important; position: static;" href="http://www.developersbook.com/servlets/interview-questions/servlets-interview-questions-faqs-2.php#"&gt;&lt;span style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;color:#f26522;" &gt;&lt;span class="kLink" style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;"&gt;server&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; passes an object that implements the ServletConfig interface to the  servlet's init() method. &lt;/td&gt;     &lt;td&gt;A ServletContext defines a set of methods that a  servlet uses to communicate with its servlet container.&lt;/td&gt;   &lt;/tr&gt;   &lt;tr class="even"&gt;     &lt;td&gt;There is one ServletConfig parameter per  servlet. &lt;/td&gt;     &lt;td&gt;There is one ServletContext for the entire  webapp and all the servlets in a webapp share it.&lt;/td&gt;   &lt;/tr&gt;    &lt;tr class="odd"&gt;     &lt;td&gt;The param-value pairs for ServletConfig object are specified in the &lt;init-param&gt; within the &lt;servlet&gt; tags in the web.xml file&lt;/td&gt;     &lt;td&gt;The param-value pairs for ServletContext object  are specified in the &lt;context-param&gt; tags in the web.xml file.&lt;/td&gt;   &lt;/tr&gt;    &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="que"&gt;&lt;span class="queIndex"&gt;22.&lt;/span&gt;What's the difference between forward() and sendRedirect() methods?&lt;/span&gt;&lt;br /&gt;&lt;p class="content" align="justify"&gt; &lt;table class="mytable" border="1" cellpadding="5" cellspacing="5"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;th width="50%"&gt;forward()&lt;/th&gt;      &lt;th width="50%"&gt;sendRedirect()&lt;/th&gt;   &lt;/tr&gt;   &lt;tr class="odd"&gt;     &lt;td&gt;A forward is performed internally by the servlet.&lt;/td&gt;     &lt;td&gt;A redirect is a two step process, where the web application instructs the browser to fetch a second URL, which differs from the original.&lt;/td&gt;   &lt;/tr&gt;   &lt;tr class="even"&gt;     &lt;td&gt;The  browser is  completely unaware that it has taken place, so its original URL remains intact.&lt;/td&gt;     &lt;td&gt;The browser, in this case, is doing the work and knows  that it's making a new request.&lt;/td&gt;   &lt;/tr&gt;    &lt;tr class="odd"&gt;     &lt;td&gt;Any browser reload of the resulting page will simple  repeat the original request, with the original URL&lt;/td&gt;     &lt;td&gt;A browser reloads of the second URL ,will not repeat  the original request, but will rather fetch the second URL.&lt;/td&gt;   &lt;/tr&gt;    &lt;tr class="even"&gt;      &lt;td&gt;Both resources must be part of the same context (Some containers make provisions for cross-context communication but this tends not to be very portable)&lt;/td&gt;      &lt;td&gt;This method can be used to redirect users to resources  that are not part of the current context, or even in the same domain.&lt;/td&gt;    &lt;/tr&gt;    &lt;tr class="odd"&gt;      &lt;td&gt;Since both resources are part of same context, the original  request context is retained&lt;/td&gt;      &lt;td&gt;Because this involves a new request, the previous request scope objects, with all of its parameters and attributes are no longer available after a redirect.&lt;br /&gt;      (Variables  will need to be passed by via the session object).&lt;/td&gt;    &lt;/tr&gt;    &lt;tr class="even"&gt;      &lt;td&gt;Forward is marginally faster than redirect.&lt;/td&gt;      &lt;td&gt;redirect is marginally slower than a forward, since it  requires two browser requests, not one.&lt;/td&gt;    &lt;/tr&gt;    &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="que"&gt;&lt;span class="queIndex"&gt;23.&lt;/span&gt;What is the difference between the include() and forward() methods?&lt;/span&gt;    &lt;table class="mytable" border="1" cellpadding="5" cellspacing="5"&gt;&lt;tbody&gt;&lt;tr&gt;     &lt;th width="50%"&gt;include()&lt;/th&gt;      &lt;th width="50%"&gt;forward()&lt;/th&gt;   &lt;/tr&gt;   &lt;tr class="odd"&gt;     &lt;td&gt;The &lt;code&gt;RequestDispatcher include()&lt;/code&gt; method inserts the the contents of the specified resource directly in the flow of the servlet response, as if it were part of the calling servlet.&lt;/td&gt;     &lt;td&gt;The &lt;code&gt;RequestDispatcher forward()&lt;/code&gt; method is used to show a different resource in place  of the servlet that was originally called. &lt;/td&gt;   &lt;/tr&gt;   &lt;tr class="even"&gt;     &lt;td&gt;If you include a servlet or &lt;a id="KonaLink2" target="_top" class="kLink" style="text-decoration: underline ! important; position: static;" href="http://www.developersbook.com/servlets/interview-questions/servlets-interview-questions-faqs-2.php#"&gt;&lt;span style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;color:#f26522;" &gt;&lt;span class="kLink" style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;"&gt;JSP&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; document, the included resource must not attempt to change the response status code or HTTP headers, any such request will be ignored. &lt;/td&gt;     &lt;td&gt;The forwarded resource may be another servlet, JSP or static HTML document, but the response is issued under the same URL that was originally requested. In other words, it is not the same as a redirection.&lt;/td&gt;   &lt;/tr&gt;    &lt;tr class="odd"&gt;     &lt;td&gt;The &lt;code&gt;include()&lt;/code&gt; method is often used to include common  "boilerplate" text or template markup that may be included by many  servlets. &lt;/td&gt;     &lt;td&gt;The &lt;code&gt;forward()&lt;/code&gt; method is often used where a servlet is taking a controller role; processing some input and deciding the outcome by returning a particular response page.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;24.What's the use of the servlet wrapper classes??&lt;br /&gt;&lt;br /&gt;The HttpServletRequestWrapper and HttpServletResponseWrapper classes are designed to make it easy for developers to create custom implementations of the servlet request and response types. The classes are constructed with the standard HttpServletRequest and HttpServletResponse instances respectively and their default behaviour is to pass all method calls directly to the underlying objects.&lt;br /&gt;&lt;span class="que"&gt;&lt;span class="queIndex"&gt;25.&lt;/span&gt;What is the directory structure of a WAR file?&lt;/span&gt; &lt;div align="center"&gt;&lt;img src="http://www.developersbook.com/servlets/images/war.gif" alt="WAR directory structure" /&gt;&lt;/div&gt;   &lt;span class="que"&gt;&lt;span class="queIndex"&gt;26.&lt;/span&gt;What is a deployment descriptor?&lt;/span&gt; &lt;p class="content" align="justify"&gt;A deployment descriptor is an XML document with an .xml extension. It defines a component's deployment settings. It declares transaction attributes and &lt;a id="KonaLink3" target="_top" class="kLink" style="text-decoration: underline ! important; position: static;" href="http://www.developersbook.com/servlets/interview-questions/servlets-interview-questions-faqs-2.php#"&gt;&lt;span style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;color:#f26522;" &gt;&lt;span class="kLink" style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;"&gt;security&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; authorization for an enterprise bean. The information provided by a deployment descriptor is declarative and therefore it can be modified without changing the source code of a bean.&lt;br /&gt;The JavaEE server reads the deployment descriptor at run time and acts upon the component accordingly. &lt;/p&gt;&lt;br /&gt; &lt;span class="que"&gt;&lt;span class="queIndex"&gt;27.&lt;/span&gt;What is the difference between the getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface and javax.servlet.ServletContext interface?&lt;/span&gt;    &lt;table class="mytable" border="1" cellpadding="5" cellspacing="5"&gt;&lt;tbody&gt;&lt;tr&gt;     &lt;th width="50%"&gt;ServletRequest.getRequestDispatcher(String path)&lt;/th&gt;      &lt;th width="50%"&gt;ServletContext.getRequestDispatcher(String path)&lt;/th&gt;   &lt;/tr&gt;   &lt;tr class="even"&gt;     &lt;td&gt;&lt;p&gt;The &lt;code&gt;getRequestDispatcher(String path)&lt;/code&gt; method of  &lt;code&gt;javax.servlet.ServletRequest&lt;/code&gt; interface accepts parameter the path to the resource to be included or forwarded to, which can be relative to the request of the calling servlet. If the path begins with a “/” it is interpreted as relative to the current context root.&lt;/p&gt;&lt;/td&gt;     &lt;td&gt;The &lt;code&gt;getRequestDispatcher(String path)&lt;/code&gt; method of &lt;code&gt;javax.servlet.ServletContext&lt;/code&gt; interface cannot accept relative paths. All path must start with a “/” and are   interpreted as relative to current context root.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt; 28.What is preinitialization of a servlet?&lt;br /&gt;&lt;br /&gt;A container does not initialize the servlets as soon as it starts up, it initializes a servlet when it receives a request for that servlet first time. This is called lazy loading. The servlet specification defines the element, which can be specified in the deployment descriptor to make the servlet container load and initialize the servlet as soon as it starts up. The process of loading a servlet before any request comes in is called preloading or preinitializing a servlet.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;29.What is the &lt;load-on-startup&gt; element?&lt;br /&gt;&lt;br /&gt;The &lt;load-on-startup&gt; element of a deployment descriptor is used to load a servlet file when the server starts instead of waiting for the first request. It is also used to specify the order in which the files are to be loaded. The &lt;load-on-startup&gt; element is written in the deployment descriptor as follows:&lt;br /&gt;&lt;br /&gt;&lt;servlet&gt;&lt;br /&gt;   &lt;servlet-name&gt;ServletName&lt;/servlet-name&gt;&lt;br /&gt;   &lt;servlet-class&gt;ClassName&lt;/servlet-class&gt;&lt;br /&gt;   &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;&lt;br /&gt;&lt;/servlet&gt;&lt;br /&gt;&lt;br /&gt;Note: The container loads the servlets in the order specified in the &lt;load-on-startup&gt; element.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-6730337529409141548?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/6730337529409141548/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=6730337529409141548' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/6730337529409141548'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/6730337529409141548'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/07/servlet-questions-2.html' title='Servlet Questions 2'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-1489259904636419979</id><published>2008-07-05T14:16:00.000-07:00</published><updated>2008-07-05T14:19:18.099-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Servlet Questions 1'/><title type='text'>Servlet Questions 1</title><content type='html'>1.What is the Servlet?&lt;br /&gt;&lt;br /&gt;A servlet is a Java programming language class that is used to extend the capabilities of servers that host applications accessed by means of a request- response programming model.&lt;br /&gt;&lt;br /&gt;2.What are the new features added to Servlet 2.5?&lt;br /&gt;&lt;br /&gt;Following are the changes introduced in Servlet 2.5:&lt;br /&gt;&lt;br /&gt;    * A new dependency on J2SE 5.0&lt;br /&gt;    * Support for annotations&lt;br /&gt;    * Loading the class&lt;br /&gt;    * Several web.xml conveniences&lt;br /&gt;    * A handful of removed restrictions&lt;br /&gt;    * Some edge case clarifications&lt;br /&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;3.&lt;/span&gt;What are the uses of Servlet?&lt;/span&gt; &lt;p class="content" align="justify"&gt;Typical uses for HTTP Servlets include:&lt;/p&gt; &lt;ul&gt;&lt;li&gt;Processing and/or storing data submitted by an HTML form.&lt;/li&gt;&lt;li&gt;Providing dynamic content, e.g. returning the results of a database query to the client.&lt;/li&gt;&lt;li&gt;A Servlet can handle multiple request concurrently and be used to develop high performance system &lt;/li&gt;&lt;li&gt;Managing state information on top of the stateless HTTP, e.g. for an online shopping cart system which manages shopping carts for many concurrent customers and maps every request to the right customer.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt; &lt;span class="que"&gt;&lt;span class="queIndex"&gt;4.&lt;/span&gt;What are the advantages of Servlet over CGI?&lt;/span&gt; &lt;p class="content" align="justify"&gt;Servlets have several advantages over CGI:&lt;/p&gt; &lt;ul&gt;&lt;li&gt;A Servlet does not run in a separate process. This removes the overhead of creating a new process for each request.&lt;/li&gt;&lt;li&gt;A Servlet stays in memory between requests. A CGI program (and probably also an extensive runtime system or interpreter) needs to be loaded and started for each CGI request.&lt;/li&gt;&lt;li&gt;There is only a single instance which answers all requests concurrently. This saves memory and allows a Servlet to easily manage persistent data.&lt;/li&gt;&lt;li&gt;Several web.xml conveniences&lt;/li&gt;&lt;li&gt;A handful of removed restrictions &lt;/li&gt;&lt;li&gt;Some edge case clarifications&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;5.&lt;/span&gt;What are the phases of the servlet life cycle?&lt;/span&gt;  &lt;p class="content" align="justify"&gt;The life cycle of a servlet consists of the following phases:&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;strong&gt;Servlet class loading&lt;/strong&gt; : For each servlet defined in the deployment descriptor of the Web &lt;a id="KonaLink1" target="_top" class="kLink" style="text-decoration: underline ! important; position: static;" href="http://www.developersbook.com/servlets/interview-questions/servlets-interview-questions-faqs.php#"&gt;&lt;span style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;color:#f26522;" &gt;&lt;span class="kLink" style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;"&gt;application&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;, the servlet container locates and loads a class of the type of the servlet. This can happen when the servlet engine itself is started, or later when a client request is actually delegated to the servlet.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Servlet instantiation&lt;/strong&gt; : After loading, it instantiates one or more object instances of the servlet class to service the client requests.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Initialization (call the init method)&lt;/strong&gt; : After instantiation, the container initializes a servlet before it is ready to handle client requests. The container initializes the servlet by invoking its init() method, passing an object implementing the ServletConfig interface. In the init() method, the servlet can read configuration parameters from the deployment descriptor or perform any other one-time activities, so the init() method is invoked once and only once by the servlet container. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Request handling (call the service method)&lt;/strong&gt; : After the servlet is initialized, the container may keep it ready for handling client requests. When client requests arrive, they are delegated to the servlet through the service() method, passing the request and response objects as parameters. In the case of HTTP requests, the request and response objects are implementations of HttpServletRequest and HttpServletResponse respectively. In the HttpServlet class, the service() method invokes a different handler method for each type of HTTP request, doGet() method for GET requests, doPost() method for POST requests, and so on.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Removal from service (call the destroy method)&lt;/strong&gt; : A servlet container may decide to remove a servlet from service for various reasons, such as to conserve memory resources. To do this, the servlet container calls the destroy() method on the servlet. Once the destroy() method has been called, the servlet may not service any more client requests. Now the servlet instance is eligible for garbage collection&lt;/li&gt;&lt;p class="content" align="justify"&gt;The life cycle of a servlet is controlled by the container in which the servlet has been deployed.&lt;/p&gt;&lt;div align="center"&gt;&lt;img src="http://www.developersbook.com/servlets/images/servlet-lifecycle.gif" alt="Servlet Lifecycle" align="middle" border="0" /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;6.&lt;/span&gt;Why do we need a constructor in a servlet if we use the init method?&lt;/span&gt; &lt;p class="content" align="justify"&gt;Even though there is an init method in a servlet which gets called to initialize it, a constructor is still required to instantiate the servlet. Even though you as the &lt;a id="KonaLink2" target="_top" class="kLink" style="text-decoration: underline ! important; position: static;" href="http://www.developersbook.com/servlets/interview-questions/servlets-interview-questions-faqs.php#"&gt;&lt;span style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;color:#f26522;" &gt;&lt;span class="kLink" style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;"&gt;developer&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; would never need to explicitly call the servlet's constructor, it is still being used by the container (the container still uses the constructor to create an instance of the servlet). Just like a normal POJO (plain old java object) that might have an init method, it is no use calling the init method if you haven't constructed an object to call it on yet.&lt;/p&gt; &lt;br /&gt;  &lt;span class="que"&gt;  &lt;span class="queIndex"&gt;7.&lt;/span&gt;How the servlet is loaded?&lt;/span&gt; &lt;p class="content" align="justify"&gt; A servlet can be loaded when:&lt;/p&gt; &lt;ul&gt;&lt;li&gt;First request is made.&lt;/li&gt;&lt;li&gt;Server starts up (auto-load).&lt;/li&gt;&lt;li&gt;There is only a single instance which answers all requests concurrently. This saves memory and allows a Servlet to easily manage persistent data.&lt;/li&gt;&lt;li&gt;Administrator manually loads.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;8.&lt;/span&gt;How a Servlet is unloaded?&lt;/span&gt; &lt;p class="content" align="justify"&gt; A servlet is unloaded when:&lt;/p&gt; &lt;ul&gt;&lt;li&gt;Server shuts down.&lt;/li&gt;&lt;li&gt;Administrator manually unloads.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt; &lt;span class="que"&gt;  &lt;span class="queIndex"&gt;9.&lt;/span&gt;What is Servlet interface?&lt;/span&gt; &lt;p class="content" align="justify"&gt;The central abstraction in the Servlet API is the Servlet interface. All servlets implement this interface, either directly or , more commonly by extending a class that implements it.&lt;/p&gt;&lt;div align="center"&gt;&lt;img src="http://www.developersbook.com/servlets/images/hire.gif" alt="Servlet" /&gt;&lt;/div&gt;&lt;br /&gt;&lt;p class="content" align="justify"&gt;&lt;em&gt;Note: Most Servlets, however, extend one of the standard implementations of that interface, namely&lt;/em&gt; &lt;code&gt;javax.servlet.GenericServlet&lt;/code&gt; and &lt;code&gt;javax.servlet.http.HttpServlet&lt;/code&gt;.&lt;/p&gt; 10.What is the GenericServlet class?&lt;br /&gt;&lt;br /&gt;GenericServlet is an abstract class that implements the Servlet interface and the ServletConfig interface. In addition to the methods declared in these two interfaces, this class also provides simple versions of the lifecycle methods init and destroy, and implements the log method declared in the ServletContext interface.&lt;br /&gt;Note: This class is known as generic servlet, since it is not specific to any protocol.&lt;br /&gt;&lt;br /&gt;11.What's the difference between GenericServlet and HttpServlet?&lt;br /&gt;&lt;br /&gt;GenericServlet     HttpServlet&lt;br /&gt;The GenericServlet is an abstract class that is extended by HttpServlet to provide HTTP protocol-specific methods.     An abstract class that simplifies writing HTTP servlets. It extends the GenericServlet base class and provides an framework for handling the HTTP protocol.&lt;br /&gt;The GenericServlet does not include protocol-specific methods for handling request parameters, cookies, sessions and setting response headers.     The HttpServlet subclass passes generic service method requests to the relevant doGet() or doPost() method.&lt;br /&gt;GenericServlet is not specific to any protocol.     HttpServlet only supports HTTP and HTTPS protocol.&lt;br /&gt;&lt;br /&gt;12.Why is HttpServlet declared abstract?&lt;br /&gt;&lt;br /&gt;The HttpServlet class is declared abstract because the default implementations of the main service methods do nothing and must be overridden. This is a convenience implementation of the Servlet interface, which means that developers do not need to implement all service methods. If your servlet is required to handle doGet() requests for example, there is no need to write a doPost() method too.&lt;br /&gt;&lt;br /&gt;13.Can servlet have a constructor ?&lt;br /&gt;&lt;br /&gt;One can definitely have constructor in servlet.Even you can use the constrctor in servlet for initialization purpose,but this type of approch is not so common. You can perform common operations with the constructor as you normally do.The only thing is that you cannot call that constructor explicitly by the new keyword as we normally do.In the case of servlet, servlet container is responsible for instantiating the servlet, so the constructor is also called by servlet container only.&lt;br /&gt;&lt;br /&gt;14.What are the types of protocols supported by HttpServlet ?&lt;br /&gt;&lt;br /&gt;It extends the GenericServlet base class and provides a framework for handling the HTTP protocol. So, HttpServlet only supports HTTP and HTTPS protocol.&lt;br /&gt;&lt;br /&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;15.&lt;/span&gt;What is the difference between doGet() and doPost()? &lt;/span&gt;       &lt;table class="mytable" border="1" cellpadding="5" cellspacing="5" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;     &lt;th scope="row" width="2%"&gt;&lt;div align="right"&gt;#&lt;/div&gt;&lt;/th&gt;     &lt;th width="48%"&gt;doGet()&lt;/th&gt;     &lt;th width="50%"&gt;doPost()&lt;/th&gt;   &lt;/tr&gt;   &lt;tr class="odd"&gt;     &lt;td scope="row"&gt;&lt;div align="right"&gt;1&lt;/div&gt;&lt;/td&gt;     &lt;td&gt;In doGet() the parameters are appended to the URL and  sent along with header information.&lt;/td&gt;     &lt;td&gt;In doPost(), on the other hand will (typically) send the  information through a socket back to the &lt;a id="KonaLink3" target="_top" class="kLink" style="text-decoration: underline ! important; position: static;" href="http://www.developersbook.com/servlets/interview-questions/servlets-interview-questions-faqs.php#"&gt;&lt;span style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;color:#f26522;" &gt;&lt;span class="kLink" style="border-bottom: 1px solid rgb(242, 101, 34); color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static; padding-bottom: 1px; background-color: transparent;"&gt;webserver&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; and it won't show up in the  URL bar.&lt;/td&gt;   &lt;/tr&gt;   &lt;tr class="odd"&gt;     &lt;td&gt;&lt;div align="right"&gt;2&lt;/div&gt;&lt;/td&gt;     &lt;td&gt;The amount of information you can send back  using a GET is restricted as URLs can only be 1024 characters.&lt;/td&gt;     &lt;td&gt;You can send much more information to the server this way - and it's not restricted to textual data either. It is possible to send files and even binary data such as serialized Java objects!&lt;/td&gt;   &lt;/tr&gt;   &lt;tr class="odd"&gt;     &lt;td scope="row"&gt;&lt;div align="right"&gt;3&lt;/div&gt;&lt;/td&gt;     &lt;td&gt;doGet() is a request for information; it does not (or should not) change anything on the  server. (doGet() should be idempotent)&lt;/td&gt;     &lt;td&gt;doPost() provides information (such as placing an  order for merchandise) that the server is expected to remember &lt;/td&gt;   &lt;/tr&gt;   &lt;tr class="even"&gt;     &lt;td scope="row"&gt;&lt;div align="right"&gt;4&lt;/div&gt;&lt;/td&gt;     &lt;td&gt;Parameters are not encrypted&lt;/td&gt;     &lt;td&gt;Parameters are encrypted &lt;/td&gt;   &lt;/tr&gt;   &lt;tr class="odd"&gt;     &lt;td scope="row"&gt;&lt;div align="right"&gt;5&lt;/div&gt;&lt;/td&gt;     &lt;td&gt;doGet() is faster if we set the response content length  since the same connection is used. Thus increasing the performance&lt;/td&gt;     &lt;td&gt;doPost() is generally used to update or post some information to the server.doPost is slower compared to doGet since doPost does not write the content length&lt;/td&gt;   &lt;/tr&gt;   &lt;tr class="even"&gt;     &lt;td scope="row"&gt;&lt;div align="right"&gt;6&lt;/div&gt;&lt;/td&gt;     &lt;td&gt;doGet() should be idempotent. i.e. doget should be able  to be repeated safely many times&lt;/td&gt;     &lt;td&gt;This method does not need to be idempotent. Operations requested through POST can have side effects for which the user can be held accountable.&lt;/td&gt;   &lt;/tr&gt;   &lt;tr class="odd"&gt;     &lt;td scope="row"&gt;&lt;div align="right"&gt;7&lt;/div&gt;&lt;/td&gt;     &lt;td&gt;doGet() should be safe without any side effects for  which user is held responsible&lt;/td&gt;     &lt;td&gt;This method does not need to be either safe&lt;/td&gt;   &lt;/tr&gt;   &lt;tr class="even"&gt;     &lt;td scope="row"&gt;&lt;div align="right"&gt;8&lt;/div&gt;&lt;/td&gt;     &lt;td&gt;It allows bookmarks.&lt;/td&gt;     &lt;td&gt;It disallows bookmarks.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-1489259904636419979?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/1489259904636419979/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=1489259904636419979' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/1489259904636419979'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/1489259904636419979'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/07/servlet-questions-1.html' title='Servlet Questions 1'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-8709632451111192337</id><published>2008-07-05T14:14:00.000-07:00</published><updated>2008-07-05T14:15:42.403-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate Interview questions 3'/><title type='text'>Hibernate Interview questions 3</title><content type='html'>&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;31.&lt;/span&gt;What is the advantage of Hibernate over jdbc? &lt;/span&gt; Hibernate Vs. JDBC :-&lt;br /&gt;  &lt;table class="mytable" style="border: 1px solid rgb(173, 210, 226);" cellpadding="6" cellspacing="0"&gt;&lt;tbody&gt;&lt;tr&gt;     &lt;th class="m_tit1" scope="col"&gt;JDBC &lt;/th&gt;     &lt;th class="m_tit1" scope="col"&gt;Hibernate &lt;/th&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="tb" width="50%"&gt;With JDBC, &lt;a id="KonaLink0" target="_top" class="kLink" style="text-decoration: underline ! important; position: static;" href="http://www.developersbook.com/hibernate/interview-questions/hibernate-interview-questions-faqs-3.php#"&gt;&lt;span style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;color:#f26522;" &gt;&lt;span class="kLink" style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;"&gt;developer&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; has to write code to map an object model's data representation to a relational data model and its corresponding database schema.  &lt;/td&gt;     &lt;td class="tb"&gt;Hibernate is flexible and powerful ORM solution to map Java classes to database tables. Hibernate itself takes care of this mapping using XML files so developer does not need to write code for this. &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="tb"&gt;With JDBC, the automatic mapping of Java objects with database tables and vice versa conversion is to be taken care of by the developer manually with lines of code.  &lt;/td&gt;     &lt;td class="tb"&gt;Hibernate provides transparent persistence and developer does not need to write code explicitly to map database tables tuples to &lt;a id="KonaLink1" target="_top" class="kLink" style="text-decoration: underline ! important; position: static;" href="http://www.developersbook.com/hibernate/interview-questions/hibernate-interview-questions-faqs-3.php#"&gt;&lt;span style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;color:#f26522;" &gt;&lt;span class="kLink" style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;"&gt;application&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; objects during interaction with RDBMS.  &lt;/td&gt;   &lt;/tr&gt;    &lt;tr&gt;     &lt;td class="tb"&gt;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.  &lt;/td&gt;     &lt;td class="tb"&gt;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 &lt;a id="KonaLink2" target="_top" class="kLink" style="text-decoration: underline ! important; position: static;" href="http://www.developersbook.com/hibernate/interview-questions/hibernate-interview-questions-faqs-3.php#"&gt;&lt;span style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;color:#f26522;" &gt;&lt;span class="kLink" style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;"&gt;SQL &lt;/span&gt;&lt;span class="kLink" style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;"&gt;statements&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;. It also selects an effective way to perform a database manipulation task for an application.  &lt;/td&gt;   &lt;/tr&gt;      &lt;tr&gt;     &lt;td class="tb"&gt; 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. &lt;/td&gt;     &lt;td class="tb"&gt;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.  &lt;/td&gt;   &lt;/tr&gt;      &lt;tr&gt;     &lt;td class="tb"&gt; 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.  &lt;/td&gt;     &lt;td class="tb"&gt;Hibernate reduces lines of code by maintaining object-table mapping itself and returns result to application in form of Java objects. It relieves &lt;a id="KonaLink3" target="_top" class="kLink" style="text-decoration: underline ! important; position: static;" href="http://www.developersbook.com/hibernate/interview-questions/hibernate-interview-questions-faqs-3.php#"&gt;&lt;span style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;color:#f26522;" &gt;&lt;span class="kLink" style="color: rgb(242, 101, 34) ! important; font-family: &amp;quot;Trebuchet MS&amp;quot;,Verdana,Arial,Helvetica,sans-serif; font-weight: 400; font-size: 13px; position: static;"&gt;programmer&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; from manual handling of persistent data, hence reducing the development time and maintenance cost.  &lt;/td&gt;   &lt;/tr&gt;      &lt;tr&gt;     &lt;td class="tb"&gt;With JDBC, caching is maintained by hand-coding.   &lt;/td&gt;     &lt;td class="tb"&gt;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.  &lt;/td&gt;   &lt;/tr&gt;       &lt;tr&gt;     &lt;td class="tb"&gt;In JDBC there is no check that always every user has updated data. This check has to be added by the developer.   &lt;/td&gt;     &lt;td class="tb"&gt;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.  &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt; 32.What are the Collection types in Hibernate ?&lt;br /&gt;&lt;br /&gt;    * Bag&lt;br /&gt;    * Set&lt;br /&gt;    * List&lt;br /&gt;    * Array&lt;br /&gt;    * Map&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;33.What are the ways to express joins in HQL?&lt;br /&gt;&lt;br /&gt;HQL provides four ways of expressing (inner and outer) joins:-&lt;br /&gt;&lt;br /&gt;    * An implicit association join&lt;br /&gt;    * An ordinary join in the FROM clause&lt;br /&gt;    * A fetch join in the FROM clause.&lt;br /&gt;    * A theta-style join in the WHERE clause.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;34.Define cascade and inverse option in one-many mapping?&lt;br /&gt;&lt;br /&gt;cascade - enable operations to cascade to child entities.&lt;br /&gt;cascade="all|none|save-update|delete|all-delete-orphan"&lt;br /&gt;&lt;br /&gt;inverse - mark this collection as the "inverse" end of a bidirectional association.&lt;br /&gt;inverse="true|false"&lt;br /&gt;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?&lt;br /&gt;&lt;br /&gt;35.What is Hibernate proxy?&lt;br /&gt;&lt;br /&gt;The proxy 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.&lt;br /&gt;&lt;br /&gt;36.How can Hibernate be configured to access an instance variable directly and not through a setter method ?&lt;br /&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;37.How can a whole class be mapped as immutable?&lt;br /&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;38.What is the use of dynamic-insert and dynamic-update attributes in a class mapping?&lt;br /&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;    * dynamic-update (defaults to false): Specifies that UPDATE SQL should be generated at runtime and contain only those columns whose values have changed&lt;br /&gt;    * dynamic-insert (defaults to false): Specifies that INSERT SQL should be generated at runtime and contain only the columns whose values are not null.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;39.What do you mean by fetching strategy ?&lt;br /&gt;&lt;br /&gt;A fetching strategy 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 Criteria query.&lt;br /&gt;&lt;br /&gt;40.What is automatic dirty checking?&lt;br /&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;41.What is transactional write-behind?&lt;br /&gt;&lt;br /&gt;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.&lt;br /&gt;People who read this also read:&lt;br /&gt;JSP Interview Questions&lt;br /&gt;Tibco Questions&lt;br /&gt;webMethods Certification&lt;br /&gt;Hibernate Interview Questions&lt;br /&gt;XML Questions&lt;br /&gt;&lt;br /&gt;42.What are Callback interfaces?&lt;br /&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;43.What are the types of Hibernate instance states ?&lt;br /&gt;&lt;br /&gt;Three types of instance states:&lt;br /&gt;&lt;br /&gt;    * Transient -The instance is not associated with any persistence context&lt;br /&gt;    * Persistent -The instance is associated with a persistence context&lt;br /&gt;    * Detached -The instance was associated with a persistence context which has been closed – currently not associated&lt;br /&gt;&lt;br /&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;44.&lt;/span&gt;What are the differences between EJB 3.0 &amp;amp; Hibernate&lt;/span&gt;  &lt;p class="content" align="justify"&gt;Hibernate Vs EJB 3.0 :-&lt;br /&gt;&lt;table class="mytable" style="border: 1px solid rgb(173, 210, 226);" cellpadding="6" cellspacing="0"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;th class="m_tit1" scope="col"&gt;Hibernate &lt;/th&gt;     &lt;th class="m_tit1" scope="col"&gt;EJB 3.0 &lt;/th&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="tb"&gt;&lt;b&gt;Session&lt;/b&gt;–Cache or collection of loaded objects relating to a single unit of work &lt;/td&gt;     &lt;td class="tb"&gt;&lt;b&gt;Persistence Context&lt;/b&gt;-Set of entities that can be managed by a given EntityManager is defined by a persistence unit &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="tb"&gt;&lt;b&gt;XDoclet Annotations&lt;/b&gt; used to support Attribute Oriented Programming &lt;/td&gt;     &lt;td class="tb"&gt;&lt;b&gt;Java 5.0 Annotations&lt;/b&gt; used to support Attribute Oriented Programming &lt;/td&gt;   &lt;/tr&gt;     &lt;tr&gt;     &lt;td class="tb"&gt;&lt;b&gt;Defines HQL&lt;/b&gt; for expressing queries to the database &lt;/td&gt;     &lt;td class="tb"&gt;&lt;b&gt;Defines EJB QL&lt;/b&gt; for expressing queries &lt;/td&gt;   &lt;/tr&gt;     &lt;tr&gt;     &lt;td class="tb"&gt;&lt;b&gt;Supports Entity Relationships&lt;/b&gt; through mapping files and annotations in JavaDoc &lt;/td&gt;     &lt;td class="tb"&gt;&lt;b&gt;Support Entity Relationships&lt;/b&gt; through Java 5.0 annotations &lt;/td&gt;   &lt;/tr&gt;     &lt;tr&gt;     &lt;td class="tb"&gt;&lt;b&gt;Provides a Persistence Manager API&lt;/b&gt; exposed via the Session, Query, Criteria, and Transaction API &lt;/td&gt;     &lt;td class="tb"&gt;&lt;b&gt;Provides and Entity Manager Interface&lt;/b&gt; for managing CRUD operations for an Entity &lt;/td&gt;   &lt;/tr&gt;     &lt;tr&gt;     &lt;td class="tb"&gt;&lt;b&gt;Provides callback support&lt;/b&gt; through lifecycle, interceptor, and validatable interfaces &lt;/td&gt;     &lt;td class="tb"&gt;&lt;b&gt;Provides callback support&lt;/b&gt; through Entity Listener and Callback methods &lt;/td&gt;   &lt;/tr&gt;     &lt;tr&gt;     &lt;td class="tb"&gt;&lt;b&gt;Entity Relationships are unidirectional&lt;/b&gt;. Bidirectional relationships are implemented by two unidirectional relationships &lt;/td&gt;     &lt;td class="tb"&gt;&lt;b&gt;Entity Relationships are bidirectional or unidirectional&lt;/b&gt; &lt;/td&gt;   &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt; &lt;br /&gt;   &lt;span class="que"&gt;  &lt;span class="queIndex"&gt;45.&lt;/span&gt;What are the types of inheritance models  in Hibernate?&lt;/span&gt; &lt;p class="content" align="justify"&gt;There are three types of inheritance models in Hibernate:&lt;/p&gt;  &lt;ul&gt;&lt;li&gt;Table per class hierarchy  &lt;/li&gt;&lt;li&gt;Table per subclass  &lt;/li&gt;&lt;li&gt;Table per concrete class&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-8709632451111192337?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/8709632451111192337/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=8709632451111192337' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/8709632451111192337'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/8709632451111192337'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/07/hibernate-interview-questions-3.html' title='Hibernate Interview questions 3'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-4165217277654758434</id><published>2008-07-05T14:04:00.000-07:00</published><updated>2008-07-05T14:13:51.443-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate Interview questions 2'/><title type='text'>Hibernate Interview questions 2</title><content type='html'>&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;16.&lt;/span&gt;What’s the difference between load() and get()? &lt;/span&gt; &lt;p class="content" align="justify"&gt;load() vs. get() :-&lt;br /&gt;&lt;table class="content" style="border: 1px solid rgb(173, 210, 226);" cellpadding="6" cellspacing="0"&gt;   &lt;tbody&gt;&lt;tr&gt;     &lt;th class="m_tit1" scope="col"&gt;load() &lt;/th&gt;     &lt;th class="m_tit1" scope="col"&gt;get() &lt;/th&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="tb"&gt;Only use the &lt;code&gt;load()&lt;/code&gt; method if you are sure that the object exists. &lt;/td&gt;     &lt;td class="tb"&gt;If you are not sure that the object exists, then use one of the &lt;code&gt;get()&lt;/code&gt; methods. &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="tb"&gt;&lt;code&gt;load()&lt;/code&gt; method will throw an exception if the unique id is not found in the database. &lt;/td&gt;     &lt;td class="tb"&gt;&lt;code&gt;get()&lt;/code&gt; method will return null if the unique id is not found in the database. &lt;/td&gt;   &lt;/tr&gt;     &lt;tr&gt;     &lt;td class="tb"&gt;&lt;code&gt;load()&lt;/code&gt; just returns a proxy by default and database won’t be hit until the proxy is first invoked.  &lt;/td&gt;     &lt;td class="tb"&gt;&lt;code&gt;get()&lt;/code&gt; will hit the database immediately. &lt;/td&gt;   &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt; &lt;br /&gt; &lt;span class="que"&gt;  &lt;span class="queIndex"&gt;17.&lt;/span&gt;What is the difference between and merge and update ?&lt;/span&gt; &lt;p class="content" align="justify"&gt;Use &lt;code&gt;update()&lt;/code&gt; if you are sure that the session does not contain an already persistent instance with the same identifier, and &lt;code&gt;merge()&lt;/code&gt; if you want to merge your modifications at any time without consideration of the state of the session.&lt;/p&gt; 19.Define cascade and inverse option in one-many mapping?&lt;br /&gt;&lt;br /&gt;cascade - enable operations to cascade to child entities.&lt;br /&gt;cascade="all|none|save-update|delete|all-delete-orphan"&lt;br /&gt;&lt;br /&gt;inverse - mark this collection as the "inverse" end of a bidirectional association.&lt;br /&gt;inverse="true|false"&lt;br /&gt;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?&lt;br /&gt;&lt;br /&gt;20.What does it mean to be inverse?&lt;br /&gt;&lt;br /&gt;It informs hibernate to ignore that end of the relationship. If the one–to–many was marked as inverse, hibernate would create a child–&gt;parent relationship (child.getParent). If the one–to–many was marked as non–inverse then a child–&gt;parent relationship would be created.&lt;br /&gt;&lt;br /&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;23.&lt;/span&gt;Explain Criteria API&lt;/span&gt; &lt;p class="content" align="justify"&gt;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.&lt;br /&gt;&lt;b&gt;Example&lt;/b&gt; :&lt;/p&gt;  &lt;pre&gt;&lt;span style="color:#800040;"&gt;List &lt;/span&gt;employees = &lt;span style="color:#800040;"&gt;session&lt;/span&gt;.createCriteria(Employee.class)&lt;br /&gt;           .add(Restrictions.like(&lt;span style="color:#0000ff;"&gt;"name"&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;"a%"&lt;/span&gt;) )&lt;br /&gt;           .add(Restrictions.like(&lt;span style="color:#0000ff;"&gt;"address"&lt;/span&gt;, &lt;span style="color:#0000a0;"&gt;"Boston"&lt;/span&gt;))&lt;br /&gt;    .addOrder(Order.asc(&lt;span style="color:#0000ff;"&gt;"name"&lt;/span&gt;) )&lt;br /&gt;    .list();&lt;/pre&gt;&lt;br /&gt;   &lt;span class="que"&gt;  &lt;span class="queIndex"&gt;24.&lt;/span&gt;Define HibernateTemplate?&lt;/span&gt; &lt;p class="content" align="justify"&gt;&lt;code&gt;org.springframework.orm.hibernate.HibernateTemplate&lt;/code&gt; is a helper class which provides different methods for querying/retrieving data from the database. It also converts checked HibernateExceptions into unchecked DataAccessExceptions.&lt;/p&gt;&lt;br /&gt; &lt;span class="que"&gt;  &lt;span class="queIndex"&gt;25.&lt;/span&gt;What are the benefits does HibernateTemplate provide?&lt;/span&gt; &lt;p class="content" align="justify"&gt;The benefits of HibernateTemplate are :  &lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;code&gt;HibernateTemplate&lt;/code&gt;, a Spring Template class simplifies interactions with Hibernate Session.  &lt;/li&gt;&lt;li&gt;Common functions are simplified to single method calls.  &lt;/li&gt;&lt;li&gt;Sessions are automatically closed.  &lt;/li&gt;&lt;li&gt;Exceptions are automatically caught and converted to runtime exceptions.&lt;/li&gt;&lt;/ul&gt; 26.How do you switch between relational databases without code changes?&lt;br /&gt;&lt;br /&gt;Using Hibernate SQL Dialects , we can switch databases. Hibernate will generate appropriate hql queries based on the dialect defined.&lt;br /&gt;&lt;br /&gt;27.If you want to see the Hibernate generated SQL statements on console, what should we do?&lt;br /&gt;&lt;br /&gt;In Hibernate configuration file set as follows:&lt;br /&gt;&lt;property name="show_sql"&gt;true&lt;/property&gt;&lt;br /&gt;&lt;br /&gt;28.What are derived properties?&lt;br /&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;&lt;span class="que"&gt;  &lt;span class="queIndex"&gt;29.&lt;/span&gt;What is component mapping in Hibernate?&lt;/span&gt;   &lt;ul&gt;&lt;li&gt;A component is an object saved as a value, not as a reference &lt;/li&gt;&lt;li&gt; A component can be saved directly without needing to declare interfaces or identifier properties &lt;/li&gt;&lt;li&gt; Required to define an empty constructor &lt;/li&gt;&lt;li&gt; Shared references not supported &lt;/li&gt;&lt;/ul&gt;   &lt;p class="content" align="justify"&gt;&lt;b&gt;Example&lt;/b&gt;:&lt;/p&gt; &lt;img src="http://www.developersbook.com/hibernate/images/component-mapping.png" alt="Component Mapping" border="0" height="415" width="642" /&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class="que"&gt;  &lt;span class="queIndex"&gt;30.&lt;/span&gt;What is the difference between sorted and ordered collection in hibernate?&lt;/span&gt; &lt;b&gt;sorted collection vs. order collection&lt;/b&gt; :-&lt;br /&gt;  &lt;table class="content" style="border: 1px solid rgb(173, 210, 226);" cellpadding="6" cellspacing="0"&gt;&lt;tbody&gt;&lt;tr&gt;     &lt;th class="m_tit1" scope="col"&gt;sorted collection &lt;/th&gt;     &lt;th class="m_tit1" scope="col"&gt;order collection &lt;/th&gt;   &lt;/tr&gt;   &lt;tr&gt;        &lt;td class="tb" width="50%"&gt;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. &lt;/td&gt;      &lt;td class="tb"&gt;Order collection is sorting a collection by specifying the order-by clause for sorting this collection when retrieval. &lt;/td&gt;   &lt;/tr&gt;   &lt;tr&gt;     &lt;td class="tb"&gt;If your collection is not large, it will be more efficient way to sort it. &lt;/td&gt;     &lt;td class="tb"&gt;If your collection is very large, it will be more efficient way to sort it . &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;p class="content" align="justify"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class="content" align="justify"&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-4165217277654758434?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/4165217277654758434/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=4165217277654758434' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/4165217277654758434'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/4165217277654758434'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/07/hibernate-interview-questions-2.html' title='Hibernate Interview questions 2'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-1723908122526792738</id><published>2008-07-05T14:01:00.000-07:00</published><updated>2008-07-05T14:04:52.926-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate Interview questions 1'/><title type='text'>Hibernate Interview questions 1</title><content type='html'>1.What is ORM ?&lt;br /&gt;&lt;br /&gt;ORM stands for object/relational mapping. ORM is the automated persistence of objects in a Java application to the tables in a relational database.&lt;br /&gt;&lt;br /&gt;2.What does ORM consists of ?&lt;br /&gt;&lt;br /&gt;An ORM solution consists of the followig four pieces:&lt;br /&gt;&lt;br /&gt;    * API for performing basic CRUD operations&lt;br /&gt;    * API to express ries refering to classes&lt;br /&gt;    * Facilities to specify metadata&lt;br /&gt;    * Optimization facilities : dirty checking,lazy associations fetching&lt;br /&gt;&lt;br /&gt;3.What are the ORM levels ?&lt;br /&gt;&lt;br /&gt;The ORM levels are:&lt;br /&gt;&lt;br /&gt;    * Pure relational (stored procedure.)&lt;br /&gt;    * Light objects mapping (JDBC)&lt;br /&gt;    * Medium object mapping&lt;br /&gt;    * Full object Mapping (composition,inheritance, polymorphism, persistence by reachability)&lt;br /&gt;&lt;br /&gt;4.What is Hibernate?&lt;br /&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;5.Why do you need ORM tools like hibernate?&lt;br /&gt;&lt;br /&gt;The main advantage of ORM like hibernate is that it shields developers from messy SQL. Apart from this, ORM provides following benefits:&lt;br /&gt;&lt;br /&gt;    * Improved productivity&lt;br /&gt;          o High-level object-oriented API&lt;br /&gt;          o Less Java code to write&lt;br /&gt;          o No SQL to write&lt;br /&gt;    * Improved performance&lt;br /&gt;          o Sophisticated caching&lt;br /&gt;          o Lazy loading&lt;br /&gt;          o Eager loading&lt;br /&gt;    * Improved maintainability&lt;br /&gt;          o A lot less code to write&lt;br /&gt;    * Improved portability&lt;br /&gt;          o ORM framework generates database-specific SQL for you&lt;br /&gt;&lt;br /&gt;6.What Does Hibernate Simplify?&lt;br /&gt;&lt;br /&gt;Hibernate simplifies:&lt;br /&gt;&lt;br /&gt;    * Saving and retrieving your domain objects&lt;br /&gt;    * Making database column and table name changes&lt;br /&gt;    * Centralizing pre save and post retrieve logic&lt;br /&gt;    * Complex joins for retrieving related items&lt;br /&gt;    * Schema creation from object model&lt;br /&gt;&lt;span class="que"&gt;  &lt;span class="Index"&gt;7.&lt;/span&gt;What is the need for Hibernate xml mapping file? &lt;/span&gt; &lt;p class="content" align="justify"&gt;Hibernate mapping file tells Hibernate which tables and columns to use to load and store objects. Typical mapping file look as follows:&lt;/p&gt; &lt;img src="http://www.developersbook.com/hibernate/images/hbm-mapping.png" alt="Hibernate Mapping file" border="0" height="273" width="483" /&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class="que"&gt;  &lt;span class="Index"&gt;8.&lt;/span&gt;What are the most common methods of Hibernate configuration?&lt;/span&gt; &lt;p class="content" align="justify"&gt;The most common methods of Hibernate configuration are:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Programmatic configuration  &lt;/li&gt;&lt;li&gt;XML configuration (&lt;code&gt;hibernate.cfg.xml&lt;/code&gt;) &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt; &lt;span class="que"&gt;  &lt;span class="Index"&gt;9.&lt;/span&gt;What are the important tags of hibernate.cfg.xml?&lt;/span&gt; &lt;p class="content" align="justify"&gt;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.&lt;/p&gt; &lt;img src="http://www.developersbook.com/hibernate/images/hbm-config.png" alt="hibernate.cfg.xml" border="0" height="372" width="616" /&gt;&lt;br /&gt;&lt;br /&gt;10.What are the Core interfaces are of Hibernate framework?&lt;br /&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;    * Session interface&lt;br /&gt;    * SessionFactory interface&lt;br /&gt;    * Configuration interface&lt;br /&gt;    * Transaction interface&lt;br /&gt;    * Query and Criteria interfaces&lt;br /&gt; 11.What role does the Session interface play in Hibernate?&lt;br /&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;Session session = sessionFactory.openSession();&lt;br /&gt;&lt;br /&gt;Session interface role:&lt;br /&gt;&lt;br /&gt;    * Wraps a JDBC connection&lt;br /&gt;    * Factory for Transaction&lt;br /&gt;    * Holds a mandatory (first-level) cache of persistent objects, used when navigating the object graph or looking up objects by identifier&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;12.What role does the SessionFactory interface play in Hibernate?&lt;br /&gt;&lt;br /&gt;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&lt;br /&gt;&lt;br /&gt;SessionFactory sessionFactory = configuration.buildSessionFactory();&lt;br /&gt;&lt;br /&gt;13.What is the general flow of Hibernate communication with RDBMS?&lt;br /&gt;&lt;br /&gt;The general flow of Hibernate communication with RDBMS is :&lt;br /&gt;&lt;br /&gt;    * Load the Hibernate configuration file and create configuration object. It will automatically load all hbm mapping files&lt;br /&gt;    * Create session factory from configuration object&lt;br /&gt;    * Get one session from this session factory&lt;br /&gt;    * Create HQL Query&lt;br /&gt;    * Execute query to get list containing Java objects&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;14.What is Hibernate Query Language (HQL)?&lt;br /&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;15.How do you map Java Objects with Database tables?&lt;br /&gt;&lt;br /&gt;    * First we need to write Java domain objects (beans with setter and getter). The variables should be same as database columns.&lt;br /&gt;    * Write hbm.xml, where we map java class to table and database columns to Java class variables.&lt;br /&gt;&lt;br /&gt;Example :&lt;br /&gt;&lt;br /&gt;&lt;hibernate-mapping&gt;&lt;br /&gt;  &lt;class name="com.test.User" table="user"&gt;&lt;br /&gt;   &lt;property  column="USER_NAME" length="255"&lt;br /&gt;      name="userName" not-null="true"  type="java.lang.String"/&gt;&lt;br /&gt;   &lt;property  column="USER_PASSWORD" length="255"&lt;br /&gt;     name="userPassword" not-null="true"  type="java.lang.String"/&gt;&lt;br /&gt; &lt;/class&gt;&lt;br /&gt;&lt;/hibernate-mapping&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-1723908122526792738?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/1723908122526792738/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=1723908122526792738' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/1723908122526792738'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/1723908122526792738'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/07/hibernate-interview-questions-1.html' title='Hibernate Interview questions 1'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-6871993695349912515</id><published>2008-07-04T12:48:00.001-07:00</published><updated>2008-07-04T12:48:39.543-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Difference between JDBC and hibernate'/><title type='text'>Difference between JDBC and hibernate</title><content type='html'>&lt;span&gt;&lt;span&gt;&lt;span style="color:#005e5e;"&gt;&lt;span style="font-size:100%;color:blue;"&gt;1)    Hibernate is data base independent, your code will work for all ORACLE,MySQL ,SQLServer etc.&lt;br /&gt;&lt;br /&gt;In case of JDBC query must be data base specific.&lt;br /&gt;&lt;br /&gt;2)    As Hibernate is set of Objects , you don?t need to learn SQL language.&lt;br /&gt;&lt;br /&gt;You can treat TABLE as a Object . Only Java knowledge is need.&lt;br /&gt;&lt;br /&gt;In case of JDBC you need to learn SQL.&lt;br /&gt;&lt;br /&gt;3) Don?t need Query tuning in case of Hibernate. If you use Criteria Quires in Hibernate then hibernate automatically tuned your query and return best result with performance.&lt;br /&gt;&lt;br /&gt;In case of JDBC you need to tune your queries.&lt;br /&gt;&lt;br /&gt;4) You will get benefit of Cache. Hibernate support two level of cache. First level and 2nd level. So you can store your data into Cache for better performance.&lt;br /&gt;&lt;br /&gt;In case of JDBC you need to implement your java cache .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;5)    Hibernate supports Query cache and It will provide the statistics about your query and database status.&lt;br /&gt;&lt;br /&gt;JDBC Not provides any statistics.&lt;br /&gt;&lt;br /&gt;6)    Development fast in case of Hibernate because you don?t need to write queries &lt;br /&gt;&lt;br /&gt;7)    No need to create any connection pool in case of Hibernate. You can use c3p0. &lt;br /&gt;&lt;br /&gt;In case of JDBC you need to write your own connection pool&lt;br /&gt;&lt;br /&gt;8)    In the xml file you can see all the relations between tables in case of Hibernate. Easy readability.&lt;br /&gt;&lt;br /&gt;9)    You can load your objects on start up using lazy=false in case of Hibernate.&lt;br /&gt;&lt;br /&gt;JDBC Don?t have such support.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;10 ) Hibernate Supports automatic versioning of rows but JDBC Not. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-6871993695349912515?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/6871993695349912515/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=6871993695349912515' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/6871993695349912515'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/6871993695349912515'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/07/difference-between-jdbc-and-hibernate.html' title='Difference between JDBC and hibernate'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-7951432901058347126</id><published>2008-07-04T12:35:00.000-07:00</published><updated>2008-07-04T12:38:18.007-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Third Normal Form'/><title type='text'>Third Normal Form</title><content type='html'>&lt;img src="file:///C:/DOCUME%7E1/SMSINS%7E1/LOCALS%7E1/Temp/moz-screenshot-35.jpg" alt="" /&gt;&lt;img src="file:///C:/DOCUME%7E1/SMSINS%7E1/LOCALS%7E1/Temp/moz-screenshot-36.jpg" alt="" /&gt;&lt;div&gt; &lt;div style="width: 450px; float: left;"&gt;  &lt;a name="intro"&gt;&lt;h2&gt;Introduction&lt;/h2&gt;&lt;/a&gt;  &lt;p class="bodytext"&gt;  This is meant to be a &lt;i&gt;very&lt;/i&gt; brief tutorial aimed at beginners who want to get  a conceptual grasp on the database normalization process.  I find it very difficult to visualize these concepts using words alone, so  I shall rely as much as possible upon pictures and diagrams.  &lt;/p&gt;&lt;p class="bodytext"&gt;  To demonstrate the main  principles involved, we will take the  classic example of an &lt;b&gt;Invoice&lt;/b&gt; and level it to the Third Normal Form.  We will also construct an &lt;b&gt;Entity Relationship Diagram&lt;/b&gt; (ERD) of the database  as we go.   &lt;/p&gt;&lt;p class="bodytext"&gt;  &lt;b&gt;To begin:&lt;/b&gt; First, memorize the 3 normal forms so that you can recite them in your sleep.  The meaning will become clear as we go. Just memorize them for now:  &lt;/p&gt;&lt;ol&gt;&lt;li&gt;No repeating elements or groups of elements   &lt;/li&gt;&lt;li&gt;No partial dependencies on a concatenated key   &lt;/li&gt;&lt;li&gt;No dependencies on non-key attributes    &lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;The Problem: Keeping Track of a Stack of Invoices &lt;/div&gt; &lt;div style="float: left; position: relative; top: -5px;"&gt; &lt;/div&gt;  &lt;/div&gt;    &lt;div style="width: 300px; float: left;"&gt;&lt;a name="invoice_order"&gt;&lt;/a&gt;   &lt;p class="bodytext"&gt;   Consider a typical invoice (&lt;b&gt;Figure A&lt;/b&gt;). It has been simplified to meet the   purposes of this discussion.   &lt;img src="http://www.phlonx.com/images/nf3/arrow1r.gif" /&gt;&lt;/p&gt;   &lt;p class="bodytext"&gt;   This document, or something like it, is the basis of the order fulfillment process of almost any business.   Every piece of information you see here is important.   How can we capture this information in a database? &lt;/p&gt;&lt;/div&gt; &lt;div style="width: 500px; float: right;"&gt;   &lt;span class="figure"&gt;Figure A: Invoice&lt;/span&gt;&lt;br /&gt;  &lt;img src="http://www.phlonx.com/images/nf3/nf3_fig_a.jpg" alt="Figure A: Invoice" height="480" width="600" /&gt; &lt;/div&gt;    &lt;div style="width: 600px;"&gt;       &lt;p class="bodytext"&gt;       Those of us who have an ordered mind but aren't quite aware of relational databases       might try to capture the Invoice data in a spreadsheet, such as Microsoft Excel.        &lt;/p&gt;&lt;p class="bodytext"&gt;       &lt;span class="figure"&gt;Figure A-1: orders spreadsheet&lt;/span&gt;&lt;br /&gt;      &lt;img src="http://www.phlonx.com/images/nf3/nf3_fig_a-1.jpg" alt="Figure A-1: orders spreadsheet" border="1" height="150" width="1090" /&gt;       &lt;/p&gt;&lt;p class="bodytext"&gt;    This isn't a bad approach, since it records every purchase made by every customer.     But what if you started to ask complicated questions, such as:    &lt;/p&gt;&lt;ul&gt;&lt;li&gt;How many 3" Red Freens did &lt;i&gt;Freens R Us&lt;/i&gt; order in  2002?     &lt;/li&gt;&lt;li&gt;What are total sales of 56" Blue Freens in the state of Texas?     &lt;/li&gt;&lt;li&gt;What items were sold on July 14, 2003?    &lt;/li&gt;&lt;/ul&gt;    As the spreadsheet grows it becomes increasingly difficult to ask the spreadsheet these questions.    In an attempt to put the data into a state where we can reasonably expect to answer such questions,        we begin the &lt;b&gt;normalization&lt;/b&gt; process. &lt;/div&gt;    &lt;div style="border-top: 1px solid black; width: 600px;"&gt;  &lt;a name="nf1"&gt;  &lt;/a&gt;&lt;p class="bodytext"&gt; &lt;a name="nf1"&gt; &lt;/a&gt;&lt;/p&gt;&lt;h2&gt;&lt;a name="nf1"&gt;First Normal Form: No Repeating Elements or Groups of Elements&lt;/a&gt;&lt;/h2&gt;   &lt;p class="bodytext"&gt;     Take a look at rows 2, 3 and 4 on the spreadsheet in Figure A-1. These represent all     the data we have for a single invoice (Invoice #125).   &lt;/p&gt;&lt;p class="bodytext"&gt;     In database lingo, this group of rows is referred to as a single &lt;b&gt;database row&lt;/b&gt;. Never mind the fact that      one database row is made up here of three spreadsheet rows: It's an unfortunate ambiguity of language.      Academic database theoreticians have a special word that helps a bit with the ambiguity: they refer to     the "thing" encapsulated by rows 2, 3 and 4 as a &lt;b&gt;tuple&lt;/b&gt; (pronounced &lt;i&gt;tu'ple&lt;/i&gt; or &lt;i&gt;too'ple&lt;/i&gt;).      We're not going to use that word here     (and if you're lucky, you'll never hear it again for the rest of your life). Here,     we will refer to this entity as a &lt;b&gt;&lt;i&gt;row&lt;/i&gt;&lt;/b&gt;.   &lt;/p&gt;&lt;p class="bodytext"&gt;   So, First Normal Form (NF1) wants us to get rid of &lt;b&gt;repeating elements&lt;/b&gt;. What are those?   &lt;/p&gt;&lt;p class="bodytext"&gt;     Again we turn our attention to the first invoice (#125) in Figure A-1. Cells H2, H3, and H4 contain a list of     Item ID numbers. This is a &lt;i&gt;column&lt;/i&gt; within our first database row. Similarly, I2-I4 constitute     a single &lt;i&gt;column&lt;/i&gt;; same with J2-J4, K2-K4, L2-L4, and M2-M4. Database columns are sometimes referred     to as &lt;b&gt;attributes&lt;/b&gt; (rows/columns are the same as tuples/attributes).   &lt;/p&gt;&lt;p class="bodytext"&gt;     You will notice that each of these columns contains a &lt;i&gt;list&lt;/i&gt; of values. It is precisely these     lists that NF1 objects to: NF1 abhors lists or arrays within a single database column.      NF1 craves &lt;b&gt;atomicity&lt;/b&gt;: the indivisibility of an attribute into similar parts.   &lt;/p&gt;&lt;p class="bodytext"&gt;     Therefore it is clear that we have to do something about the repeating &lt;b&gt;item information&lt;/b&gt;   data within the row for Invoice #125. On Figure A-1, that is the following cells:      &lt;/p&gt;&lt;ul class="bodytext"&gt;&lt;li&gt;H2 through M2       &lt;/li&gt;&lt;li&gt;H3 through M3       &lt;/li&gt;&lt;li&gt;H4 through M4     &lt;/li&gt;&lt;/ul&gt;   &lt;p class="bodytext"&gt;     Similar (though not necessarily &lt;i&gt;identical&lt;/i&gt;) data repeats within Invoice #125's row.      We can satisfy NF1's need for atomicity quite simply: by separating each item in these lists     into its own row.   &lt;/p&gt;&lt;p class="bodytext"&gt;     &lt;span class="figure"&gt;Figure A-2: flattened orders spreadsheet&lt;/span&gt;&lt;br /&gt;    &lt;img src="http://www.phlonx.com/images/nf3/nf3_fig_a-2.jpg" alt="Figure A-2: flattened orders spreadsheet" border="1" height="150" width="1090" /&gt;   &lt;/p&gt;&lt;p class="bodytext"&gt;     I can hear everyone objecting: We were trying to &lt;i&gt;reduce&lt;/i&gt; the amount of duplication, and here we have     introduced &lt;i&gt;more&lt;/i&gt;! Just look at all that duplicated customer data!   &lt;/p&gt;&lt;p class="bodytext"&gt;     Don't worry. The kind of duplication that we introduce at this stage will be addressed when we get to the      &lt;b&gt;Third Normal Form&lt;/b&gt;. Please be patient; this is a necessary step in the process.   &lt;/p&gt;&lt;p class="bodytext"&gt;     We have actually only told half the story of NF1. Strictly speaking, NF1 addresses two issues:     &lt;/p&gt;&lt;ol class="bodytext"&gt;&lt;li&gt;A row of data cannot contain repeating groups of similar data (&lt;b&gt;atomicity&lt;/b&gt;); and       &lt;/li&gt;&lt;li&gt;Each row of data must have a unique identifier (or &lt;b&gt;Primary Key&lt;/b&gt;).     &lt;/li&gt;&lt;/ol&gt;    &lt;p class="bodytext"&gt;     We have already dealt with atomicity. But to make the point about Primary Keys,      we shall bid farewell to the spreadsheet     and move our data into     a relational database management system (RDBMS). Here we shall use Microsoft Access     to create the &lt;b&gt;orders&lt;/b&gt; table,     as in &lt;b&gt;Figure B&lt;/b&gt;: &lt;/p&gt;&lt;/div&gt;  &lt;div style="width: 600px;"&gt;       &lt;span class="figure"&gt;Figure B: orders table&lt;/span&gt;&lt;br /&gt;      &lt;img src="http://www.phlonx.com/images/nf3/nf3_fig_b.jpg" alt="Figure B: orders table" height="167" width="1090" /&gt; &lt;/div&gt;    &lt;div style="width: 1000px;"&gt;  &lt;div style="padding: 3px; width: 300px; float: left;"&gt;   &lt;p class="bodytext"&gt;     This looks pretty much the same as the spreadsheet, but the difference is that within an RDBMS we can      identify a &lt;b&gt;primary key&lt;/b&gt;. A primary key is a column (or group of columns) that uniquely identifies &lt;i&gt;each row&lt;/i&gt;.   &lt;/p&gt;&lt;p class="bodytext"&gt;     As you can see from Figure B, there is no single column that uniquely identifies each row. However, if we      put a number of columns together, we can satisfy this requirement. &lt;/p&gt;&lt;/div&gt;  &lt;div style="padding: 3px; width: 300px; float: left;"&gt;   &lt;p class="bodytext"&gt;    The two columns that together    uniquely identify each row are &lt;b&gt;order_id&lt;/b&gt; and &lt;b&gt;item_id&lt;/b&gt;: no two rows have     the same combination of order_id and item_id. Therefore, together they qualify to be used as     the table's primary key.    Even though they are in two different table columns, they are treated as    a single entity. We call them &lt;b&gt;concatenated&lt;/b&gt;. &lt;/p&gt;&lt;/div&gt;  &lt;div style="padding: 3px; width: 300px; float: left;"&gt;    &lt;blockquote class="italic bodytext"&gt;      A value that uniquely identifies a row is called a &lt;b&gt;primary key&lt;/b&gt;.&lt;br /&gt;     When this value is made      up of two or more columns, it is referred to as a &lt;b&gt;concatenated primary key&lt;/b&gt;.    &lt;/blockquote&gt;  &lt;/div&gt;  &lt;/div&gt;  &lt;div class="spacer"&gt;&lt;hr /&gt;&lt;/div&gt;   &lt;div style="width: 300px; float: left;"&gt;       &lt;p class="bodytext"&gt;       The underlying structure of the &lt;b&gt;orders&lt;/b&gt; table can be represented as       &lt;b&gt;Figure C&lt;/b&gt;:        &lt;img src="http://www.phlonx.com/images/nf3/arrow1r.gif" /&gt;&lt;/p&gt;           &lt;p class="bodytext"&gt;     We identify the columns that make up the primary key with the &lt;b&gt;PK&lt;/b&gt; notation.       Figure C is the beginning of our &lt;b&gt;Entity Relationship Diagram&lt;/b&gt; (or ERD).   &lt;/p&gt;&lt;p class="bodytext"&gt;   Our database schema now satisfies the two requirements of First Normal Form:   &lt;b&gt;atomicity&lt;/b&gt; and &lt;b&gt;uniqueness&lt;/b&gt;. Thus it fulfills the most basic criterion of   a &lt;i&gt;relational&lt;/i&gt; database.   &lt;/p&gt;&lt;p class="bodytext"&gt;What's next?   &lt;/p&gt;&lt;/div&gt; &lt;div style="padding: 3px; float: left; position: relative; width: 300px;"&gt;       &lt;span class="figure"&gt;Figure C: orders table structure&lt;/span&gt;&lt;br /&gt;      &lt;img src="http://www.phlonx.com/images/nf3/nf3_fig_c.gif" alt="Figure C: Orders table structure" height="289" width="210" /&gt; &lt;/div&gt;    &lt;div style="border-top: 1px solid black; width: 600px; margin-top: 12px;"&gt;     &lt;a name="nf2"&gt;     &lt;/a&gt;&lt;h2&gt;&lt;a name="nf2"&gt;Second Normal Form: No Partial Dependencies on a Concatenated Key&lt;/a&gt;&lt;/h2&gt;     &lt;p class="bodytext"&gt;     Next we test each table for &lt;b&gt;partial dependencies on a concatenated key&lt;/b&gt;.     This means that for a table that has a concatenated primary key,     each column in the table that is not part of the primary key     &lt;i&gt;must&lt;/i&gt; depend upon the &lt;i&gt;entire&lt;/i&gt; concatenated key for its existence.     If any column only depends upon one part of the concatenated key, then     we say that the entire table has failed Second Normal Form and we must     create another table to rectify the failure.    &lt;/p&gt;&lt;p class="bodytext"&gt;     Still not clear? To try and understand this, let's take apart the     &lt;b&gt;orders&lt;/b&gt; table column by column. For each column we will     ask the question,     &lt;/p&gt;&lt;blockquote class="bodytext italic"&gt;Can this column exist &lt;b&gt;without&lt;/b&gt; one or the other part     of the concatenated primary key?&lt;/blockquote&gt;    &lt;p class="bodytext"&gt;     If the answer is "yes" — even once — then the table fails Second Normal Form.  &lt;/p&gt;&lt;/div&gt;    &lt;div style="width: 450px; float: left;"&gt;    &lt;p class="bodytext"&gt;     Refer to &lt;b&gt;Figure C&lt;/b&gt; again to remind us of the &lt;b&gt;orders&lt;/b&gt; table structure.     &lt;img src="http://www.phlonx.com/images/nf3/arrow1r.gif" /&gt;&lt;/p&gt;    &lt;p class="bodytext"&gt;     First, recall the meaning of the two columns in the primary key:    &lt;/p&gt;&lt;ul class="bodytext"&gt;&lt;li&gt;&lt;b&gt;order_id&lt;/b&gt; identifies the &lt;i&gt;invoice&lt;/i&gt; that this item comes from.     &lt;/li&gt;&lt;li&gt;&lt;b&gt;item_id&lt;/b&gt; is the inventory item's unique identifier. You can think of it       as a part number, inventory control number, SKU, or UPC code.    &lt;/li&gt;&lt;/ul&gt;    &lt;p class="bodytext"&gt;     We don't analyze these columns (since they are part of the primary key). Now consider the remaining columns...     &lt;/p&gt;&lt;p class="bodytext"&gt;     &lt;b&gt;order_date&lt;/b&gt; is the date on which the order was made. Obviously     it relies on &lt;b&gt;order_id&lt;/b&gt;; an order date has to have an order, otherwise it is only a date.      But can an order date exist without an &lt;b&gt;item_id&lt;/b&gt;?    &lt;/p&gt;&lt;p class="bodytext"&gt;     The short answer is yes: order_date relies on order_id, not item_id. Some of you might object, thinking     that this means you could have a dated order with no items (an empty invoice, in effect).      But this is not what we are saying at all: All we are trying to establish here is whether a     &lt;i&gt;particular&lt;/i&gt; order on a &lt;i&gt;particular&lt;/i&gt; date relies on a &lt;i&gt;particular&lt;/i&gt; item. Clearly,      it does not.      The problem of how to prevent empty orders falls under a discussion of "business rules" and could be     resolved using check constraints or application logic; it is not an issue for Normalization to solve.    &lt;/p&gt;&lt;p class="bodytext"&gt;     Therefore: order_date &lt;i&gt;fails&lt;/i&gt; Second Normal Form.         &lt;img src="http://www.phlonx.com/images/nf3/cross.gif" height="15" width="15" /&gt;    &lt;/p&gt;&lt;p class="bodytext"&gt;     So voilá,     our table has already failed Second Normal Form. But let's continue with testing the other     columns. We have to find all the columns that fail the test, and then we do something special with them.         &lt;/p&gt;&lt;p class="bodytext"&gt;     &lt;b&gt;customer_id&lt;/b&gt; is the ID number of the customer who placed the order. Does it rely on      &lt;b&gt;order_id&lt;/b&gt;? No: a customer can exist without placing any orders. Does it rely on     &lt;b&gt;item_id&lt;/b&gt;? No: for the same reason. This is interesting: customer_id (along with the     rest of the customer_* columns) does not rely on &lt;i&gt;either&lt;/i&gt; member of the primary key.      What do we do with these columns?    &lt;/p&gt;&lt;p class="bodytext"&gt;     We don't have to worry about them until we get to Third Normal Form. We mark them as "unknown" for now.     &lt;img src="http://www.phlonx.com/images/nf3/question.gif" height="15" width="15" /&gt;     &lt;/p&gt;&lt;p class="bodytext"&gt;     &lt;b&gt;item_description&lt;/b&gt; is the next column that is not itself part of the primary key.     This is the plain-language description of the inventory item. Obviously     it relies on &lt;b&gt;item_id&lt;/b&gt;. But can it exist without an &lt;b&gt;order_id&lt;/b&gt;?     &lt;/p&gt;&lt;p class="bodytext"&gt;     &lt;i&gt;Yes!&lt;/i&gt; An inventory item (together with its "description") could sit on a warehouse shelf forever,      and never be purchased... It can exist independent of an order. item_description fails the test.     &lt;img src="http://www.phlonx.com/images/nf3/cross.gif" height="15" width="15" /&gt;     &lt;/p&gt;&lt;p class="bodytext"&gt;     &lt;b&gt;item_qty&lt;/b&gt; refers to the number of items purchased on a particular invoice. Can this     quantity exist without an item_id? Impossible: we cannot talk about the "amount of nothing" (at     least not in database design). Can the quantity exist without an order_id? No: a quantity     that is purchased with an invoice is meaningless without an invoice. So this column does not     violate Second Normal Form: item_qty depends on &lt;b&gt;both&lt;/b&gt; parts of      our concatenated primary key.     &lt;img src="http://www.phlonx.com/images/nf3/check.gif" height="15" width="15" /&gt;    &lt;/p&gt;&lt;p class="bodytext"&gt;     &lt;b&gt;item_price&lt;/b&gt; is similar to &lt;b&gt;item_description&lt;/b&gt;. It depends on the &lt;b&gt;item_id&lt;/b&gt;     but not on the &lt;b&gt;order_id&lt;/b&gt;, so it &lt;i&gt;does&lt;/i&gt; violate Second Normal Form.     &lt;img src="http://www.phlonx.com/images/nf3/cross.gif" height="15" width="15" /&gt;    &lt;/p&gt;&lt;p class="bodytext"&gt;     &lt;b&gt;item_total_price&lt;/b&gt; is a tricky one. On the one hand, it seems to depend on both     &lt;b&gt;order_id&lt;/b&gt; and &lt;b&gt;item_id&lt;/b&gt;, in which case it passes Second Normal Form.      On the other hand, it is a &lt;i&gt;derived value&lt;/i&gt;: it is merely the product of      item_qty and item_price. What to do with this field?    &lt;/p&gt;&lt;p class="bodytext"&gt;     In fact, this field does not belong in our database at all. It can easily be reconstructed outside     of the database proper; to include it would be redundant (and could quite possibly introduce     corruption). Therefore we will discard it and speak of it no more. &lt;/p&gt;&lt;/div&gt;  &lt;div style="float: left; position: relative; left: 20px;"&gt;     &lt;span class="figure"&gt;Figure C:&lt;/span&gt;&lt;br /&gt;    &lt;img src="http://www.phlonx.com/images/nf3/nf3_fig_c.gif" alt="Figure C" height="289" width="210" /&gt; &lt;/div&gt;    &lt;div style="width: 450px; float: left;"&gt;    &lt;p class="bodytext"&gt;     &lt;b&gt;order_total_price&lt;/b&gt;, the sum of all the item_total_price fields for a particular order,     is another derived value. We discard this field too.    &lt;/p&gt;&lt;p class="bodytext"&gt;      Here is the markup from our NF2 analysis of the &lt;b&gt;orders&lt;/b&gt; table:     &lt;img src="http://www.phlonx.com/images/nf3/arrow1r.gif" /&gt;&lt;/p&gt;  &lt;/div&gt;  &lt;div style="float: left; position: relative; left: 20px;"&gt;     &lt;span class="figure"&gt;Figure C (revised):&lt;/span&gt;&lt;br /&gt;    &lt;img src="http://www.phlonx.com/images/nf3/nf3_fig_cr.jpg" alt="Figure C (revised)" height="327" width="223" /&gt; &lt;/div&gt;    &lt;div style="width: 600px; float: left;"&gt;    &lt;p class="bodytext"&gt;       What do we do with a table that fails Second Normal Form, as this one has?       First we take out the second half of the concatenated primary key (&lt;b&gt;item_id&lt;/b&gt;) and put it in its       own table.     &lt;/p&gt;&lt;p class="bodytext"&gt;       All the columns that depend on item_id - whether in whole or in part - follow it into the new table.       We call this new table &lt;b&gt;order_items&lt;/b&gt; (see &lt;b&gt;Figure D&lt;/b&gt;).    &lt;/p&gt;&lt;p class="bodytext"&gt;       The other fields - those that rely on just the first half of the primary key (order_id) and those we aren't       sure about - stay where they are. &lt;/p&gt;&lt;/div&gt;    &lt;div style="width: 700px; margin-top: 12px;"&gt;       &lt;span class="figure"&gt;Figure D: orders and order_items tables&lt;/span&gt;&lt;br /&gt;      &lt;img src="http://www.phlonx.com/images/nf3/nf3_fig_d.jpg" alt="Figure D: orders and order_items tables" height="356" width="646" /&gt; &lt;/div&gt;     &lt;div style="width: 450px; float: left; margin-top: 12px;"&gt;       &lt;p class="bodytext"&gt;       There are several things to notice:       &lt;/p&gt;&lt;ol class="bodytext"&gt;&lt;li&gt;We have brought a copy of the &lt;b&gt;order_id&lt;/b&gt; column over into the &lt;b&gt;order_items&lt;/b&gt; table.           This allows each order_item to "remember" which order it is a part of.         &lt;/li&gt;&lt;li&gt;The &lt;b&gt;orders&lt;/b&gt; table has fewer rows than it did before.         &lt;/li&gt;&lt;li&gt;The &lt;b&gt;orders&lt;/b&gt; table no longer has a concatenated primary key. The primary key now           consists of a single column, &lt;b&gt;order_id&lt;/b&gt;.         &lt;/li&gt;&lt;li&gt;The &lt;b&gt;order_items&lt;/b&gt; table &lt;i&gt;does&lt;/i&gt; have a concatenated primary key.       &lt;/li&gt;&lt;/ol&gt;  &lt;/div&gt;   &lt;div style="width: 250px; float: left; margin-top: 12px;"&gt;       &lt;p class="bodytext"&gt;       Here is the table structure (&lt;b&gt;Figure E&lt;/b&gt;):       &lt;img src="http://www.phlonx.com/images/nf3/arrow1r.gif" /&gt;&lt;/p&gt;       &lt;p class="bodytext"&gt;        If you are new to Entity Relationship Diagrams,        pay close attention to the line that connects these two tables. This line        means, in English,        &lt;/p&gt;&lt;ul class="bodytext italic"&gt;&lt;li&gt;each order can be associated with any number of order-items, but &lt;b&gt;at least&lt;/b&gt; one;         &lt;/li&gt;&lt;li&gt;each order-item is associated with one order, and &lt;b&gt;only&lt;/b&gt; one.        &lt;/li&gt;&lt;/ul&gt;   &lt;p class="bodytext"&gt;     There are other ways of depicting these table-to-table relationships; here I am using one of many standard conventions.      &lt;/p&gt;&lt;/div&gt;  &lt;div style="float: left; position: relative; left: 10px; top: 20px;"&gt;       &lt;span class="figure"&gt;Figure E: orders and order_items table structure&lt;/span&gt;&lt;br /&gt;      &lt;img src="http://www.phlonx.com/images/nf3/nf3_fig_e.gif" alt="Figure E: orders and order_items table structure" height="221" width="609" /&gt; &lt;/div&gt;    &lt;h2&gt;Second Normal Form: Phase II&lt;/h2&gt; &lt;div style="width: 450px; float: left;"&gt;    &lt;p class="bodytext"&gt;     But wait, there's more!    &lt;/p&gt;&lt;p class="bodytext"&gt;     Remember, NF2 &lt;i&gt;only&lt;/i&gt; applies to tables with a concatenated primary key. Now that &lt;b&gt;orders&lt;/b&gt;     has a single-column primary key, it has passed Second Normal Form. Congratulations!    &lt;/p&gt;&lt;p class="bodytext"&gt;     &lt;b&gt;order_items&lt;/b&gt;, however, still has a concatenated primary key. We have to pass it through     the NF2 analysis again, and see if it measures up. We ask the same question we did before:          &lt;/p&gt;&lt;blockquote class="bodytext italic"&gt;Can this column exist &lt;b&gt;without&lt;/b&gt; one or the other part     of the concatenated primary key?&lt;/blockquote&gt;      &lt;/div&gt;       &lt;div style="width: 450px; float: left;"&gt;   &lt;p class="bodytext"&gt;   First, refer to &lt;b&gt;Figure F&lt;/b&gt;, to remind us of the &lt;b&gt;order_items&lt;/b&gt; table structure.   &lt;img src="http://www.phlonx.com/images/nf3/arrow1r.gif" /&gt;&lt;/p&gt;   &lt;p class="bodytext"&gt;   Now consider the columns that are not part of the primary key...    &lt;/p&gt;&lt;p class="bodytext"&gt;   &lt;b&gt;item_description&lt;/b&gt; relies on &lt;b&gt;item_id&lt;/b&gt;, but not &lt;b&gt;order_id&lt;/b&gt;.       So (surprise), this column once again fails NF2.       &lt;img src="http://www.phlonx.com/images/nf3/cross.gif" height="15" width="15" /&gt;   &lt;/p&gt;&lt;p class="bodytext"&gt;   &lt;b&gt;item_qty&lt;/b&gt; relies on both members of the primary key. It &lt;i&gt;does not&lt;/i&gt; violate NF2.     &lt;img src="http://www.phlonx.com/images/nf3/check.gif" height="15" width="15" /&gt;   &lt;/p&gt;&lt;p class="bodytext"&gt;   &lt;b&gt;item_price&lt;/b&gt; relies on the &lt;b&gt;item_id&lt;/b&gt;   but not on the &lt;b&gt;order_id&lt;/b&gt;, so it &lt;i&gt;does&lt;/i&gt; violate Second Normal Form.     &lt;img src="http://www.phlonx.com/images/nf3/cross.gif" height="15" width="15" /&gt;   &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;/div&gt;  &lt;div style="float: left; position: relative; left: 20px;"&gt;   &lt;span class="figure"&gt;Figure F:&lt;/span&gt;&lt;br /&gt;  &lt;img src="http://www.phlonx.com/images/nf3/nf3_fig_f.gif" alt="Figure F" height="176" width="222" /&gt; &lt;/div&gt;    &lt;div style="width: 450px; float: left;"&gt;    &lt;p class="bodytext"&gt;     We should be getting good at this now...    &lt;img src="http://www.phlonx.com/images/nf3/arrow1r.gif" /&gt;&lt;/p&gt; &lt;/div&gt;  &lt;div style="float: left; position: relative; left: 20px;"&gt;     &lt;span class="figure"&gt;Figure F (revised):&lt;/span&gt;&lt;br /&gt;    &lt;img src="http://www.phlonx.com/images/nf3/nf3_fig_fr.gif" alt="Figure F (revised)" height="176" width="222" /&gt; &lt;/div&gt;     &lt;div style="width: 300px; float: left;"&gt;   ...Take the fields that fail NF2, and create a new table.   We call this new table &lt;b&gt;items&lt;/b&gt;:   &lt;img src="http://www.phlonx.com/images/nf3/arrow1r.gif" /&gt;   &lt;p class="bodytext"&gt;     But wait, something's wrong. When we did our first pass through the NF2 test, we took out &lt;i&gt;all&lt;/i&gt;     the fields that relied on item_id and put them into the new table. This time, we are only     taking the fields that failed the test: in other words, &lt;b&gt;item_qty&lt;/b&gt; stays where it is.     Why? What's different this time?   &lt;/p&gt;&lt;p class="bodytext"&gt;     The difference is that in the first pass, we removed the &lt;b&gt;item_id&lt;/b&gt; key from the &lt;b&gt;orders&lt;/b&gt; table     altogether, because of the one-to-many relationship between orders and order-items.      Therefore the &lt;b&gt;item_qty&lt;/b&gt; field &lt;i&gt;had&lt;/i&gt; to follow &lt;b&gt;item_id&lt;/b&gt; into the new table.   &lt;/p&gt;&lt;p class="bodytext"&gt;     In the second pass, &lt;b&gt;item_id&lt;/b&gt; was not removed from the &lt;b&gt;order_items&lt;/b&gt; table because     of the &lt;i&gt;many-to-one&lt;/i&gt; relationship between order-items and items.      Therefore, since item_qty does not violate NF2 this time,     it is permitted to stay in the table with the two primary key parts that it relies on. &lt;/p&gt;&lt;/div&gt;  &lt;div style="float: left;"&gt;       &lt;span class="figure"&gt;Figure G: order_items and items table&lt;/span&gt;&lt;br /&gt;      &lt;img src="http://www.phlonx.com/images/nf3/nf3_fig_g.jpg" alt="Figure G: order_items and items table" height="189" width="597" /&gt; &lt;/div&gt;    &lt;div style="clear: both; margin-bottom: 6px;"&gt;  &lt;div style="width: 225px; float: left;"&gt;  &lt;p class="bodytext"&gt;  This should be clearer with a new ERD. Here is how the &lt;b&gt;items&lt;/b&gt; table fits into the overall database schema:  &lt;img src="http://www.phlonx.com/images/nf3/arrow1r.gif" /&gt;&lt;/p&gt;  &lt;p class="bodytext"&gt;   The line that connects the &lt;b&gt;items&lt;/b&gt; and &lt;b&gt;order_items&lt;/b&gt; tables   means the following:   &lt;/p&gt;&lt;ul class="bodytext italic"&gt;&lt;li&gt;Each item can be associated with &lt;i&gt;any number&lt;/i&gt; of lines on any number    of invoices, including zero;   &lt;/li&gt;&lt;li&gt;each order-item is associated with one item, and &lt;b&gt;only&lt;/b&gt; one.   &lt;/li&gt;&lt;/ul&gt; &lt;/div&gt;  &lt;div style="float: left; position: relative; top: 25px;"&gt;  &lt;span class="figure"&gt;Figure H:&lt;/span&gt;&lt;br /&gt; &lt;img src="http://www.phlonx.com/images/nf3/nf3_fig_h.gif" alt="Figure H" height="166" width="662" /&gt; &lt;/div&gt;     &lt;div style="width: 500px;"&gt;   &lt;p class="bodytext"&gt;     These two lines are examples of &lt;i&gt;one-to-many&lt;/i&gt; relationships. This three-table structure,      considered in its entirety, is how we express a &lt;i&gt;many-to-many&lt;/i&gt; relationship:     &lt;/p&gt;&lt;blockquote class="bodytext italic"&gt;       Each order can have many items; each item can belong to many orders.     &lt;/blockquote&gt;        &lt;p class="bodytext"&gt;     Notice that this time, we did not bring a copy of the order_id column into the new table.      This is because individual items do not need to have knowledge of the orders they are part of.     The order_items table takes care of remembering this relationship via the order_id and item_id      columns. Taken together these columns comprise the primary key of order_items, but taken     separately they are &lt;i&gt;foreign keys&lt;/i&gt; or pointers to rows in other tables. More about      foreign keys when we get to Third Normal Form.  &lt;/p&gt;&lt;p class="bodytext"&gt;  Notice, too, that our new table does not have a concatenated primary key, so it passes NF2.    At this point, we have succeeded in attaining Second Normal Form!  &lt;/p&gt;&lt;/div&gt;  &lt;/div&gt;    &lt;div style="border-top: 1px solid black; width: 600px; margin-top: 12px;"&gt;   &lt;a name="nf3"&gt;   &lt;h2&gt;Third Normal Form: No Dependencies on Non-Key Attributes&lt;/h2&gt;&lt;/a&gt;    &lt;p class="bodytext"&gt;  At last, we return to the problem of the repeating Customer information. As our database now stands,  if a customer places more than one order then we have to input all of that customer's  contact information again. This is because there are columns in the &lt;b&gt;orders&lt;/b&gt;  table that rely on "non-key attributes".  &lt;/p&gt;&lt;p class="bodytext"&gt;  To better understand this concept, consider   the &lt;b&gt;order_date&lt;/b&gt; column. Can it exist independent of the &lt;b&gt;order_id&lt;/b&gt; column? &lt;i&gt;No&lt;/i&gt;:  an "order date" is meaningless without an order. &lt;b&gt;order_date&lt;/b&gt;    is said to &lt;i&gt;depend on a key attribute&lt;/i&gt; (order_id is the "key attribute" because it is the primary key     of the table).    &lt;/p&gt;&lt;p class="bodytext"&gt;     What about &lt;b&gt;customer_name&lt;/b&gt; — can it exist on its own, outside of the     &lt;b&gt;orders&lt;/b&gt; table?     &lt;/p&gt;&lt;p class="bodytext"&gt;     &lt;i&gt;Yes&lt;/i&gt;. It is meaningful to talk about a customer name without     referring to an order or invoice. The same goes for &lt;b&gt;customer_address&lt;/b&gt;,     &lt;b&gt;customer_city&lt;/b&gt;, and &lt;b&gt;customer_state&lt;/b&gt;. These four columns actually     rely on &lt;b&gt;customer_id&lt;/b&gt;, which is not a key in this table (it is a &lt;i&gt;non-key attribute&lt;/i&gt;).  &lt;/p&gt;&lt;/div&gt;    &lt;div style="width: 200px; float: left;"&gt;      &lt;p class="bodytext"&gt;     These fields belong in their own table, with &lt;b&gt;customer_id&lt;/b&gt;   as the primary key (see &lt;b&gt;Figure I&lt;/b&gt;).   &lt;img src="http://www.phlonx.com/images/nf3/arrow1r.gif" /&gt;&lt;/p&gt;   &lt;p class="bodytext"&gt;   However, you will notice in Figure I that we have severed the relationship between the &lt;b&gt;orders&lt;/b&gt;   table and the Customer data that used to inhabit it.    &lt;/p&gt;&lt;p class="bodytext"&gt;     This won't do at all. &lt;/p&gt;&lt;/div&gt;  &lt;div style="float: left; margin-left: 6px;"&gt;  &lt;span class="figure"&gt;Figure I:&lt;/span&gt;&lt;br /&gt;      &lt;img src="http://www.phlonx.com/images/nf3/nf3_fig_i.gif" alt="Figure I" border="1" height="310" width="662" /&gt; &lt;/div&gt;    &lt;div style="width: 200px; float: left;"&gt;   &lt;p class="bodytext"&gt;   We have to restore the relationship by creating an entity called a &lt;b&gt;foreign key&lt;/b&gt;   (indicated in our diagram by &lt;b&gt;(FK)&lt;/b&gt;) in the orders table.   A foreign key is essentially a column that points to the primary key in another table.   &lt;b&gt;Figure J&lt;/b&gt; describes this relationship, and  shows our completed ERD:   &lt;img src="http://www.phlonx.com/images/nf3/arrow1r.gif" /&gt;&lt;/p&gt;   &lt;p class="bodytext"&gt;   The relationship that has been established between the &lt;b&gt;orders&lt;/b&gt; and   &lt;b&gt;customers&lt;/b&gt; table may be expressed in this way:    &lt;/p&gt;&lt;ul class="bodytext italic"&gt;&lt;li&gt;each order is made by one, and &lt;b&gt;only&lt;/b&gt; one customer;    &lt;/li&gt;&lt;li&gt;each customer can make any number of orders, including zero.    &lt;/li&gt;&lt;/ul&gt; &lt;/div&gt;  &lt;div style="float: left; margin-left: 6px;"&gt;  &lt;span class="figure"&gt;Figure J:&lt;/span&gt;&lt;br /&gt;      &lt;img src="http://www.phlonx.com/images/nf3/nf3_fig_j.gif" alt="Figure J" border="1" height="310" width="662" /&gt; &lt;/div&gt;    &lt;div style="width: 600px;"&gt;  &lt;p class="bodytext"&gt;  And finally, here is what the data in each of the four tables looks like. Notice  that NF3 removed &lt;b&gt;columns&lt;/b&gt; from a table, rather than &lt;b&gt;rows&lt;/b&gt;. &lt;/p&gt;&lt;/div&gt;  &lt;div&gt;  &lt;span class="figure"&gt;Figure K:&lt;/span&gt;&lt;br /&gt; &lt;img src="http://www.phlonx.com/images/nf3/nf3_fig_k.jpg" alt="Figure K" border="1" height="359" width="842" /&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-7951432901058347126?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/7951432901058347126/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=7951432901058347126' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/7951432901058347126'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/7951432901058347126'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/07/third-normal-form.html' title='Third Normal Form'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-3821010120300692947</id><published>2008-06-28T17:29:00.000-07:00</published><updated>2008-06-28T17:33:56.059-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Junit'/><title type='text'>Junit 5</title><content type='html'>&lt;p&gt; &lt;b&gt;Do You Have To Write a Test for Everything?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; No, just test everything that could reasonably break. &lt;/p&gt;  &lt;p&gt; Be practical and maximize your testing investment. Remember that investments in testing are equal investments in design. If defects aren't being reported and your design responds well to change, then you're probably testing enough. If you're spending a lot of time fixing defects and your design is difficult to grow, you should write more tests. &lt;/p&gt;  &lt;p&gt;If something is difficult to test, it's usually an opportunity for a design improvement. Look to improve the design so that it's easier to test, and by doing so a better design will usually emerge.&lt;br /&gt;&lt;/p&gt;&lt;p&gt; &lt;b&gt;How Often Should You Run Your JUnit Tests?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; Run all your unit tests as often as possible, ideally every time the code is changed. Make sure all your unit tests always run at 100%. Frequent testing gives you confidence that your changes didn't break anything and generally lowers the stress of programming in the dark. &lt;/p&gt;  &lt;p&gt; For larger systems, you may just run specific test suites that are relevant to the code you're working on. &lt;/p&gt;  &lt;p&gt; Run all your acceptance, integration, stress, and unit tests at least once per day (or night). &lt;/p&gt;  &lt;p&gt; If you're using Eclipse, be sure to check out David Saff's continuous testing plug-in.&lt;br /&gt;&lt;/p&gt;&lt;p&gt; &lt;b&gt;What Do You Do When a Defect Is Reported?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; Test-driven development generally lowers the defect density of software. But we're all fallible, so sometimes a defect will slip through. When this happens, write a failing test that exposes the defect. When the test passes, you know the defect is fixed! &lt;/p&gt;  &lt;p&gt;Don't forget to use this as a learning opportunity. Perhaps the defect could have been prevented by being more aggressive about testing everything that could reasonably break. &lt;/p&gt;  &lt;p&gt; Or perhaps there are other places in the application that have the similar code that might break too.&lt;br /&gt;&lt;/p&gt;&lt;p&gt; &lt;b&gt;How simple is 'too simple to break'?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; The general philosophy is this: if it can't break on its own, it's too simple to break. &lt;/p&gt;  &lt;p&gt; First example is the getX() method. Suppose the getX() method only answers the value of an instance variable. In that case, getX() cannot break unless either the compiler or the interpreter is also broken. For that reason, don't test getX(); there is no benefit. The same is true of the setX() method, although if your setX() method does any parameter validation or has any side effects, you likely need to test it. &lt;/p&gt;  &lt;p&gt;Next example: suppose you have written a method that does nothing but forward parameters into a method called on another object. That method is too simple to break.&lt;br /&gt;&lt;/p&gt;  &lt;pre&gt;    public void myMethod(final int a, final String b) {&lt;br /&gt;       myCollaborator.anotherMethod(a, b);&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt; myMethod cannot possibly break because it does nothing: it forwards its input to another object and that's all. &lt;/p&gt;  &lt;p&gt; The only precondition for this method is "myCollaborator != null", but that is generally the responsibility of the constructor, and not of myMethod. If you are concerned, add a test to verify that myCollaborator is always set to something non-null by every constructor. &lt;/p&gt;  &lt;p&gt;The only way myMethod could break would be if myCollaborator.anotherMethod() were broken. In that case, test myCollaborator, and not the current class. &lt;/p&gt;  &lt;p&gt;It is true that adding tests for even these simple methods guards against the possibility that someone refactors and makes the methods "not-so-simple" anymore. In that case, though, the refactorer needs to be aware that the method is now complex enough to break, and should write tests for it -- and preferably before the refactoring. &lt;/p&gt;  &lt;p&gt;Another example: suppose you have a JSP and, like a good programmer, you have removed all business logic from it. All it does is provide a layout for a number of JavaBeans and never does anything that could change the value of any object. That JSP is too simple to break, and since JSPs are notoriously annoying to test, you should strive to make all your JSPs too simple to break. &lt;/p&gt;  &lt;p&gt; Here's the way testing goes: &lt;/p&gt;  &lt;pre&gt;    becomeTimidAndTestEverything&lt;br /&gt;   while writingTheSameThingOverAndOverAgain&lt;br /&gt;       becomeMoreAggressive&lt;br /&gt;       writeFewerTests&lt;br /&gt;       writeTestsForMoreInterestingCases&lt;br /&gt;       if getBurnedByStupidDefect&lt;br /&gt;           feelStupid&lt;br /&gt;           becomeTimidAndTestEverything&lt;br /&gt;       end&lt;br /&gt;   end&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt; The loop, as you can see, never terminates.&lt;/p&gt;&lt;br /&gt;&lt;p&gt; &lt;b&gt;How To Verify the JUnit Plugin in Eclipse?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; If you download and install the standard package of Eclipse 3.1.2, it comes with the JUnit plugin: org.junit_3.8.1. To verify this, you should find this directory under inside the plugins directory with these items: &lt;/p&gt;  Directory of C:\eclipse\plugins\org.junit_3.8.1  12/30/2007  03:24 PM              . 12/30/2007  03:24 PM              .. 01/18/2006  04:28 PM             2,520 about.html 01/18/2006  04:28 PM           121,070 junit.jar 01/18/2006  04:28 PM              META-INF 01/18/2006  04:28 PM               592 plugin.properties 01/18/2006  04:28 PM                84 plugin.xml                4 File(s)        124,266 bytes&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt; &lt;b&gt;How To Create Test Class in Eclipse?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; There are five ways to create a JUnit test case class in Eclipse with JUnit plugin: org.junit_3.8.1. First, select the directory (usually unittests/) that you wish to create the test case class in. &lt;/p&gt;  &lt;p&gt; 1. Select File &gt; New &gt; JUnit Test Case. &lt;/p&gt;  &lt;p&gt; 2. Select the arrow of the button in the upper left of the toolbar. Select JUnit Test Case. &lt;/p&gt;  &lt;p&gt; 3. Right click on a package in the Package Explorer view in the Java Perspective, and select JUnitTestCase. &lt;/p&gt;  &lt;p&gt; 4. Click on the arrow of the icon in the toolbar. Select JUnit Test Case. &lt;/p&gt;  &lt;p&gt; 5. You can create a normal Java class as shown in the Eclipse tutorial,  but include junit.framework.TestCase as the super class of the test class you are creating.&lt;br /&gt;&lt;/p&gt;&lt;p&gt; &lt;b&gt;How to Run a JUnit Test Case in Eclipse?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; There are three ways to run JUnit Test Cases or Test Suites in Eclipse with JUnit plugin: org.junit_3.8.1. &lt;/p&gt;  &lt;p&gt; 1. You can right click on the test case class or test suite class and select Run As &gt; JUnit Test. &lt;/p&gt;  &lt;p&gt; 2. You can select a test case or suite and click the arrow on the icon or select Run from the toolbar, and select Run As &gt; JUnit Test. &lt;/p&gt;  &lt;p&gt;3. You can select a test case or suite and click the arrow on the icon or select Run from the toolbar, and select Run... From here you will create a new JUnit test configuration, and name it. You can choose to run a single test case, or run all test cases in a project or folder.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt; &lt;b&gt;Can You Describe Steps of Creating Test Case Classes in Eclipse?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; There are detailed steps to create a test case class in Eclipse with JUnit plugin: org.junit_3.8.1. &lt;/p&gt;  &lt;p&gt; 1. Use the Browse button to search for a different super class. The default super class is junit.framework.TestCase. &lt;/p&gt;  &lt;p&gt; 2. Check which method stubs you would like to create. You can create a main method, setUp(), tearDown(), or a constructor(), but all of these are optional. A constructor is only run when the test case class is first instantiated, but the setUp() and tearDown() methods are run before and after, respectively, each test case is run. &lt;/p&gt;  &lt;p&gt;3. You can browse the application that you are creating for a class that you wish to test, or this could be left blank if you will generate the class while creating while creating the test. &lt;/p&gt;  &lt;p&gt;- If you selected a "Class Under Test" you can click the Next button, otherwise click Finish. You will be able to select which methods in the class under test that you want to write test cases for. The method signatures will be created for you. Click Finish. The new test case class will be open in the editor. &lt;/p&gt;  &lt;p&gt;- This test class demonstrates the basic functionality of the setUp() and tearDown() methods, and gives example test cases. The testForException() method demonstrates how to test that an exception is properly thrown. &lt;/p&gt;  &lt;p&gt;Note: All source methods in the class under test must be public or protected, not private, in order to be tested by JUnit. If the method in the class under test is private, the test class must be in the same package.&lt;br /&gt;&lt;/p&gt;&lt;p&gt; &lt;b&gt;How to creating a Test Suite using JUnit in Eclipse?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; There are four ways to create a JUnit test suite class in Eclipse with JUnit plugin: org.junit_3.8.1. First, select the directory (usually unittests/) that you wish to create the test suite class in. &lt;/p&gt;  &lt;p&gt; 1. Select File &gt; New &gt; Other... &gt; Java &gt; JUnit &gt; JUnit Test Suite.&lt;br /&gt;&lt;/p&gt;  &lt;p&gt; 2. Select the arrow of the button in the upper left of the toolbar. Select Other... &gt; Java &gt; JUnit &gt; JUnit Test Suite,&lt;br /&gt;&lt;/p&gt;  &lt;p&gt; 3. Right click on a package in the Package Explorer view in the Java Perspective, and select Other... &gt; Java &gt; JUnit &gt; JUnit Test Suite, or&lt;br /&gt;&lt;/p&gt;  &lt;p&gt; 4. You can create a normal Java class as shown in the Eclipse tutorial, but include junit.framework.TestSuite as the super class of the test class you are creating. &lt;/p&gt;&lt;p&gt; &lt;b&gt;How Do You Use Ant to Create HTML Test Reports?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; 1. Ensure that Ant's optional.jar file is either        in your CLASSPATH or exists in your $ANT_HOME/lib directory. &lt;/p&gt;  &lt;p&gt; 2. Add an ANT property for the directory containing the HTML reports: &lt;/p&gt; &lt;pre&gt;      &lt;perty name="test.reports" value="./reports"&gt;&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt; 3. Define the Ant task for running JUnit and generating reports: &lt;/p&gt; &lt;pre&gt;&lt;target name="test-html"&gt;&lt;br /&gt; &lt;junit fork="yes" printsummary="no" haltonfailure="no"&gt;&lt;br /&gt;   &lt;batchtest fork="yes" todir="${test.reports}"&gt;&lt;br /&gt;     &lt;fileset dir="${classes}"&gt;&lt;br /&gt;       &lt;include name="**/*Test.class"&gt;&lt;br /&gt;     &lt;/fileset&gt;&lt;br /&gt;   &lt;/batchtest&gt;&lt;br /&gt;   &lt;formatter type="xml"&gt;&lt;br /&gt;   &lt;classpath refid="test.classpath"&gt;&lt;br /&gt; &lt;/junit&gt;&lt;br /&gt;&lt;br /&gt; &lt;junitreport todir="${test.reports}"&gt;&lt;br /&gt;   &lt;fileset dir="${test.reports}"&gt;&lt;br /&gt;     &lt;include name="TEST-*.xml"&gt;&lt;br /&gt;   &lt;/fileset&gt;&lt;br /&gt;   &lt;report todir="${test.reports}"&gt;&lt;br /&gt; &lt;/junitreport&gt;&lt;br /&gt;&lt;/target&gt;&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt; 4. Run the test: &lt;/p&gt; &lt;pre&gt;      ant test-html&lt;br /&gt;&lt;/pre&gt;&lt;p&gt; &lt;b&gt;How Do You Test Classes That Must Be Run in a J2EE Container?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; To test classes that must be run in a J2EE container (e.g. servlets, EJBs),  you should refactor J2EE components to delegate functionality to other objects that don't have  to be run in a J2EE container will improve the design and testability of the software. &lt;/p&gt;  &lt;p&gt; Cactus is an open source JUnit extension that can be used to test J2EE components in their natural environment.&lt;br /&gt;&lt;/p&gt;&lt;p&gt; &lt;b&gt;How Do You Test Classes That Must Be Run in a J2EE Container?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; To test classes that must be run in a J2EE container (e.g. servlets, EJBs),  you should refactor J2EE components to delegate functionality to other objects that don't have  to be run in a J2EE container will improve the design and testability of the software. &lt;/p&gt;  &lt;p&gt; Cactus is an open source JUnit extension that can be used to test J2EE components in their natural environment.&lt;br /&gt;&lt;/p&gt;&lt;p&gt; &lt;b&gt;Can You Explain the Exception: "No runnable methods"?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; You will get this exception, if you use the JUnit 4.4 core runner to execute  a class that has no "@Test" method.  You can try this sample class: &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;pre&gt;public class Hello {&lt;br /&gt; public static void main(String[] arg) {&lt;br /&gt;   System.out.print("Hello world!");&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt; Run this class with the JUnit 4.4 core runner: &lt;/p&gt; &lt;pre&gt;java -cp .;junit-4.4.jar org.junit.runner.JUnitCore Hello&lt;br /&gt;&lt;br /&gt;JUnit version 4.4&lt;br /&gt;.E&lt;br /&gt;Time: 0&lt;br /&gt;There was 1 failure:&lt;br /&gt;1) initializationError0(Hello)&lt;br /&gt;java.lang.Exception: No runnable methods&lt;br /&gt;at org.junit.internal.runners.MethodValidator.validateInstanceM&lt;br /&gt;at org.junit.internal.runners.MethodValidator.validateMethodsFo&lt;br /&gt;at org.junit.internal.runners.JUnit4ClassRunner.validate(JUnit4&lt;br /&gt;at org.junit.internal.runners.JUnit4ClassRunner.&lt;init&gt;(JUnit4Cl&lt;br /&gt;at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Nativ&lt;br /&gt;...&lt;br /&gt;at org.junit.runner.JUnitCore.run(JUnitCore.java:100)&lt;br /&gt;at org.junit.runner.JUnitCore.runMain(JUnitCore.java:81)&lt;br /&gt;at org.junit.runner.JUnitCore.main(JUnitCore.java:44)&lt;br /&gt;&lt;br /&gt;FAILURES!!!&lt;br /&gt;Tests run: 1,  Failures: 1&lt;br /&gt;&lt;/init&gt;&lt;/pre&gt;&lt;p&gt;  &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-3821010120300692947?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/3821010120300692947/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=3821010120300692947' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/3821010120300692947'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/3821010120300692947'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/06/junit-5.html' title='Junit 5'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-7640872286003575397</id><published>2008-06-28T17:24:00.000-07:00</published><updated>2008-06-28T17:29:10.681-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Junit'/><title type='text'>Junit 4</title><content type='html'>&lt;p&gt; &lt;b&gt;When Do You Need to Write an @After Method?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; You need to consider the following points when anwering this question: &lt;/p&gt; &lt;ul&gt;&lt;li&gt;If there is no "@Before" method, you don't need to write an "@After" method. There is nothing to be released. &lt;/li&gt;&lt;li&gt;If the "@Before" method only creates Java internal objects, you don't need to write an "@After" method. Java internal objects will be released automatically by the Java garbage collector. &lt;/li&gt;&lt;li&gt;If the "@Before" method creates any external resources like files or database objects, you need to write an "@After" method to release those external resources. &lt;/li&gt;&lt;/ul&gt;  &lt;p&gt; Here is a good example of using "@After" methods from the JUnit FAQ: &lt;/p&gt; &lt;pre&gt;package junitfaq;&lt;br /&gt;&lt;br /&gt;import org.junit.*;&lt;br /&gt;import static org.junit.Assert.*;&lt;br /&gt;import java.io.*;&lt;br /&gt;&lt;br /&gt;public class OutputTest {&lt;br /&gt;&lt;br /&gt;   private File output;&lt;br /&gt;&lt;br /&gt;   @Before&lt;br /&gt;   public void createOutputFile() {&lt;br /&gt;       output = new File(...);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   @After&lt;br /&gt;   public void deleteOutputFile() {&lt;br /&gt;       output.delete();&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   @Test&lt;br /&gt;   public void testSomethingWithFile() {&lt;br /&gt;       ...&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   @Test&lt;br /&gt;   public void anotherTestWithFile() {&lt;br /&gt;       ...&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt; &lt;b&gt;How Do You Test an Unexpected Exception with JUnit?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; If you want to test a method that could raise an unexpected exception,  you should design a test that: &lt;/p&gt; &lt;ul&gt;&lt;li&gt;Put the test code inside a "try" block". &lt;/li&gt;&lt;li&gt;Catch any unexpected exception object. &lt;/li&gt;&lt;li&gt;Fail the test witl Assert.fail(). &lt;/li&gt;&lt;/ul&gt;  &lt;p&gt;JUnit runner will fail this test if the test code raised any unexpected exception.   &lt;/p&gt;  &lt;p&gt; Here is a good test class that test any unexpected exception raised by the get() method of the ArrayList class: &lt;/p&gt; import org.junit.*; import java.util.*;  // by FYICenter.com public class UnexpectedExceptionTest1 {    @Test public void testGet() {     ArrayList emptyList = new ArrayList&lt;object&gt;();      // catch any unexpected exception     try {        Object o = emptyList.get(1);     } catch (Exception e) {        Assert.fail("Unexpected exception");     }    } } &lt;/object&gt;  &lt;p&gt; If you run this test, it will fail: &lt;/p&gt; java -cp .;junit-4.4.jar org.junit.runner.JUnitCore     UnexpectedExceptionTest1  JUnit version 4.4 .E Time: 0.015 There was 1 failure: 1) testGet(UnexpectedExceptionTest1) java.lang.AssertionError: Unexpected exception  at org.junit.Assert.fail(Assert.java:74)  at UnexpectedExceptionTest1.testGet(UnexpectedExceptionTest1.ja  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe  at java.lang.reflect.Method.invoke(Method.java:597)  at org.junit.internal.runners.TestMethod.invoke(TestMethod.java  at org.junit.internal.runners.MethodRoadie.runTestMethod(Method  at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.j  at org.junit.internal.runners.MethodRoadie.runBeforesThenTestTh  at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie  at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.jav  at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMetho  at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUni  at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4Cla  at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassR  at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoa  at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4Class  at org.junit.internal.runners.CompositeRunner.runChildren(Compo  at org.junit.internal.runners.CompositeRunner.run(CompositeRunn  at org.junit.runner.JUnitCore.run(JUnitCore.java:130)  at org.junit.runner.JUnitCore.run(JUnitCore.java:109)  at org.junit.runner.JUnitCore.run(JUnitCore.java:100)  at org.junit.runner.JUnitCore.runMain(JUnitCore.java:81)  at org.junit.runner.JUnitCore.main(JUnitCore.java:44)  FAILURES!!! Tests run: 1,  Failures: 1 &lt;p&gt; &lt;b&gt;What Happens If a Test Method Throws an Exception?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; If you write a test method that throws an exception by itself or by the method being tested,  the JUnit runner will declare that this test fails.  &lt;/p&gt;  &lt;p&gt; The example test below is designed to let the test fail by throwing  the uncaught IndexOutOfBoundsException exception: &lt;/p&gt; import org.junit.*; import java.util.*;  // by FYICenter.com public class UnexpectedExceptionTest2 {     // throw any unexpected exception   @Test public void testGet() throws Exception {     ArrayList emptyList = new ArrayList&lt;object&gt;();     Exception anyException = null;      // don't catch any exception     Object o = emptyList.get(1);   } } &lt;/object&gt;  &lt;p&gt; If you run this test, it will fail: &lt;/p&gt; java -cp .;junit-4.4.jar org.junit.runner.JUnitCore     UnexpectedExceptionTest2  JUnit version 4.4 .E Time: 0.015 There was 1 failure: 1) testGet(UnexpectedExceptionTest2) java.lang.IndexOutOfBoundsException: Index: 1, Size: 0  at java.util.ArrayList.RangeCheck(ArrayList.java:547)  at java.util.ArrayList.get(ArrayList.java:322)  at UnexpectedExceptionTest2.testGet(UnexpectedExceptionTest2.ja  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe  at java.lang.reflect.Method.invoke(Method.java:597)  at org.junit.internal.runners.TestMethod.invoke(TestMethod.java  at org.junit.internal.runners.MethodRoadie.runTestMethod(Method  at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.j  at org.junit.internal.runners.MethodRoadie.runBeforesThenTestTh  at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie  at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.jav  at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMetho  at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUni  at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4Cla  at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassR  at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoa  at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4Class  at org.junit.internal.runners.CompositeRunner.runChildren(Compo  at org.junit.internal.runners.CompositeRunner.run(CompositeRunn  at org.junit.runner.JUnitCore.run(JUnitCore.java:130)  at org.junit.runner.JUnitCore.run(JUnitCore.java:109)  at org.junit.runner.JUnitCore.run(JUnitCore.java:100)  at org.junit.runner.JUnitCore.runMain(JUnitCore.java:81)  at org.junit.runner.JUnitCore.main(JUnitCore.java:44)  FAILURES!!! Tests run: 1,  Failures: 1&lt;br /&gt;&lt;br /&gt;&lt;p&gt; &lt;b&gt;How Do You Test a Method That Doesn't Return Anything?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; You need to follow the logic below to answer this question: &lt;/p&gt; &lt;ul&gt;&lt;li&gt;If a method is not returning anything through the "return" statement (void method),  it may return data through its arguments. In this case, you can test the data returned in any argument. &lt;/li&gt;&lt;li&gt;Else if a method is not returning any data through its arguments,  it may change values of its instance variables. In this case, you can test changes of any instance variables. &lt;/li&gt;&lt;li&gt;Else if a method is not changing any instance variable,  it may change values of its class variables. In this case, you can test changes of any class variables. &lt;/li&gt;&lt;li&gt;Else if a method is not changing any class variable,  it may change external resources. In this case, you can test changes of any external resources. &lt;/li&gt;&lt;li&gt;Else if a method is not changing any external resources,  it may just doing nothing but holding the thread in a waiting status.  In this case, you can test this waiting condition. &lt;/li&gt;&lt;li&gt;Else if a method is not holding the thread in waiting status,  then this method is really doing nothing.  In this case, there is no need to test this method. :-) &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt; &lt;b&gt;When Objects Are Garbage Collected After a Test Is Executed?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; My guess would be that all objects used in a test will be ready for Java garbage collector  to release them immediately after the test has been executed. But it seems that I was wrong. The JUnit FAQ provided the following answer.  &lt;/p&gt;  &lt;p&gt;&lt;i&gt; By design, the tree of Test instances is built in one pass, then the tests are executed in a second pass. The test runner holds strong references to all Test instances for the duration of the test execution. This means that for a very long test run with many Test instances, none of the tests may be garbage collected until the end of the entire test run.&lt;/i&gt; &lt;/p&gt;  &lt;p&gt;&lt;i&gt; Therefore, if you allocate external or limited resources in a test, you are responsible for freeing those resources. Explicitly setting an object to null in the tearDown() method, for example, allows it to be garbage collected before the end of the entire test run.&lt;/i&gt; &lt;/p&gt;  &lt;p&gt; If this is true, the JUnit runner should be improved to stop building all test instances before executing any tests.  Instead, the JUnit runner should just take one test at a time, build an instance of this test, execute the test, and  release the test when the execution is done.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt; &lt;b&gt;What Is Java "assert" Statement?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; "assert" statements are part of the Java assertion feature introduced in Java 1.4. Java assertion feature allows developer to put "assert" statements in Java source code  to help unit testing and debugging. &lt;/p&gt;  &lt;p&gt; An "assert" statement has the following format: &lt;/p&gt; &lt;pre&gt;   assert boolean_expression : string_expression;&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt; When this statement is executed:  &lt;/p&gt; &lt;ul&gt;&lt;li&gt;If boolean_expression evaluates to true, the statement will pass normally.  &lt;/li&gt;&lt;li&gt;If boolean_expression evaluates to false, the statement will fail with an "AssertionError" exception.  &lt;/li&gt;&lt;/ul&gt;  &lt;p&gt; Here is a good example of an "assert" statement used to check an invariant: &lt;/p&gt; &lt;pre&gt;// Day-of-week calculator&lt;br /&gt;// by FYICenter.com&lt;br /&gt;&lt;br /&gt;public class DayOfWeek {&lt;br /&gt; private int days = 0;&lt;br /&gt;&lt;br /&gt; // main method for testing purpose&lt;br /&gt; public static void main(String[] arg) {&lt;br /&gt;   int d = Integer.parseInt(arg[0]);&lt;br /&gt;   DayOfWeek o = new DayOfWeek(d);&lt;br /&gt;   System.out.print("Day of the week: "+o.getDayOfWeek());&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; // constrcutor&lt;br /&gt; public DayOfWeek(int d) {&lt;br /&gt;   days = d;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; // calculate day of the week&lt;br /&gt; public String getDayOfWeek() {&lt;br /&gt;   if (days % 7 == 0) {&lt;br /&gt;      return "Sunday";&lt;br /&gt;   } else if (days % 7 == 1) {&lt;br /&gt;      return "Monday";&lt;br /&gt;   } else if (days % 7 == 2) {&lt;br /&gt;      return "Tuesday";&lt;br /&gt;   } else if (days % 7 == 3) {&lt;br /&gt;      return "Wednesday";&lt;br /&gt;   } else if (days % 7 == 4) {&lt;br /&gt;      return "Thursday";&lt;br /&gt;   } else if (days % 7 == 5) {&lt;br /&gt;      return "Friday";&lt;br /&gt;   } else {&lt;br /&gt;      assert days % 7 == 6 : days;&lt;br /&gt;      return "Saturday";&lt;br /&gt;   }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;   &lt;p&gt; &lt;b&gt;How To Compile and Run Java Programs with "assert" Statements?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; If you are using "assert" statements in your Java program for unit testing and debugging,  you need to compile and execute the program with extra command options to use them: &lt;/p&gt; &lt;ul&gt;&lt;li&gt;Compilation - "javac -source 1.4 MyClass.java". This tells the compiler to accept source code containing assertions. &lt;/li&gt;&lt;li&gt;Executionn - "java -ea MyClass". This tells the JVM to not skill "assert" statements. "-ea" is the same as  "-enableassertions". &lt;/li&gt;&lt;/ul&gt;  &lt;p&gt; Here is an example of compiling and executing the sample program, DayOfWeek.java, presented in the previous question: &lt;/p&gt; &lt;pre&gt;javac -source 1.4 DayOfWeek.java&lt;br /&gt;&lt;br /&gt;java -ea DayOfWeek 1&lt;br /&gt;Day of the week: Monday&lt;br /&gt;&lt;br /&gt;java -ea DayOfWeek 6&lt;br /&gt;Day of the week: Saturday&lt;br /&gt;&lt;br /&gt;java -ea DayOfWeek 14&lt;br /&gt;Day of the week: Sunday&lt;br /&gt;&lt;br /&gt;java -ea DayOfWeek -2&lt;br /&gt;Exception in thread "main" java.lang.AssertionError: -2&lt;br /&gt;       at DayOfWeek.getDayOfWeek(DayOfWeek.java:34)&lt;br /&gt;       at DayOfWeek.main(DayOfWeek.java:11)&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt; As expected, the code does not handle negative numbers correctly. &lt;/p&gt;&lt;p&gt; &lt;b&gt;How To Test Programs Thats Use Java "assert" Statements?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; Since JUnit 3.8, the JUnit runner if fully compatible with the assertion feature. If a Java "assert" statement failed in a JUnit test, the JUnit runner will  report that this test fails. &lt;/p&gt;  &lt;p&gt; When you design your tests, you should ignore the fact the target class is using "assert" statements. Ingore those "assert" statement and write tests to cover all cases where the target class could break. &lt;/p&gt;  &lt;p&gt; Here is a good example of JUnit tests testing the sample program, DayOfWeek.java,  presented in the previous question.  test3() is designed to test the same area where the Java "assert" statement is located. &lt;/p&gt; &lt;pre&gt;import org.junit.*;&lt;br /&gt;// by FYICenter.com&lt;br /&gt;&lt;br /&gt;public class DayOfWeekTest {&lt;br /&gt;&lt;br /&gt; @Test public void test1() {&lt;br /&gt;   DayOfWeek d = new DayOfWeek(6);&lt;br /&gt;   Assert.assertTrue("Expecting Saturday",&lt;br /&gt;     d.getDayOfWeek().equals("Saturday"));&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; @Test public void test2() {&lt;br /&gt;   DayOfWeek d = new DayOfWeek(14);&lt;br /&gt;   Assert.assertTrue("Expecting Sunday",&lt;br /&gt;     d.getDayOfWeek().equals("Sunday"));&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; @Test public void test3() {&lt;br /&gt;   DayOfWeek d = new DayOfWeek(-2);&lt;br /&gt;   Assert.assertTrue("Expecting Friday",&lt;br /&gt;     d.getDayOfWeek().equals("Friday"));&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt; &lt;b&gt;Should You Run JUnit Tests with Java Assertion Disabled?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; If your test class is well designed and covering all cases where the target class could break,  you should run your test with Java assertion disabled by using the JVM "-da" option. &lt;/p&gt;  &lt;p&gt; If you are using the test class, DayOfWeekTest.java, presented in the previous question, here is the error report when executed with the "-da" option, disabling Java assertion: &lt;/p&gt; &lt;pre&gt;java -da -cp .;\local\junit4.4\junit-4.4.jar&lt;br /&gt;  org.junit.runner.JUnitCore DayOfWeekTest&lt;br /&gt;&lt;br /&gt;JUnit version 4.4&lt;br /&gt;...E&lt;br /&gt;Time: 0.015&lt;br /&gt;There was 1 failure:&lt;br /&gt;1) test3(DayOfWeekTest)&lt;br /&gt;java.lang.AssertionError: Expecting Friday&lt;br /&gt;at org.junit.Assert.fail(Assert.java:74)&lt;br /&gt;at org.junit.Assert.assertTrue(Assert.java:37)&lt;br /&gt;at DayOfWeekTest.test3(DayOfWeekTest.java:20)&lt;br /&gt;at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)&lt;br /&gt;...&lt;br /&gt;FAILURES!!!&lt;br /&gt;Tests run: 3,  Failures: 1&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt; test3() failed with the JUnit assertTrue() call, and caught the code problem with negative values.&lt;/p&gt;&lt;br /&gt;&lt;p&gt; &lt;b&gt;What Happens If You Run JUnit Tests with Java Assertion Enabled?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; As of JUnit 3.8, The JUnit runner will work nicely with Java assertion feature.  If Java assertion is enabled and a Java "assert" statement fails,  the JUnit runner will report this in same way as the calling test fails. &lt;/p&gt;  &lt;p&gt; If you are using the test class, DayOfWeekTest.java, presented in the previous question, Here is the error report when executed with the "-ea" option, enabling Java assertion: &lt;/p&gt; &lt;pre&gt;java -ea -cp&lt;br /&gt;.;\local\junit4.4\junit-4.4.jar&lt;br /&gt;org.junit.runner.JUnitCore DayOfWeekTest&lt;br /&gt;JUnit version 4.4&lt;br /&gt;...E&lt;br /&gt;Time: 0&lt;br /&gt;There was 1 failure:&lt;br /&gt;1) test3(DayOfWeekTest)&lt;br /&gt;java.lang.AssertionError: -2&lt;br /&gt;at DayOfWeek.getDayOfWeek(DayOfWeek.java:34)&lt;br /&gt;at DayOfWeekTest.test3(DayOfWeekTest.java:20)&lt;br /&gt;at sun.reflect.NativeMethodAccessorImpl.invoke0&lt;br /&gt;(Native Method)&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;FAILURES!!!&lt;br /&gt;Tests run: 3,  Failures: 1&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt; test3() failed with the Java "assert" statement inside the getDayOfWeek() method,  not the JUnit assertTrue() call. In other work, the code problem is caught by the Java  "assert" statement, not by the JUnit test. &lt;/p&gt;&lt;p&gt; &lt;b&gt;Why Does JUnit Only Report the First Failed Assertion in a Single Test?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; Reporting multiple failures in a single test is generally a sign that the test does too much, compared to what a unit test ought to do. Usually this means either that the test is really a functional/acceptance/customer test or, if it is a unit test, then it is too big a unit test. &lt;/p&gt;  &lt;p&gt;JUnit is designed to work best with a number of small tests. It executes each test within a separate instance of the test class. It reports failure on each test. Shared setup code is most natural when sharing between tests. This is a design decision that permeates JUnit, and when you decide to report multiple failures per test, you begin to fight against JUnit. This is not recommended. &lt;/p&gt;  &lt;p&gt;Long tests are a design smell and indicate the likelihood of a design problem. Kent Beck is fond of saying in this case that "there is an opportunity to learn something about your design." We would like to see a pattern language develop around these problems, but it has not yet been written down. &lt;/p&gt;  &lt;p&gt; Finally, note that a single test with multiple assertions is isomorphic to a test case with multiple tests: &lt;/p&gt;  &lt;p&gt; One test method, three assertions: &lt;/p&gt; &lt;pre&gt;    public class MyTestCase {&lt;br /&gt;       @Test&lt;br /&gt;       public void testSomething() {&lt;br /&gt;           // Set up for the test, manipulating local variables&lt;br /&gt;           assertTrue(condition1);&lt;br /&gt;           assertTrue(condition2);&lt;br /&gt;           assertTrue(condition3);&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt; Three test methods, one assertion each: &lt;/p&gt; &lt;pre&gt;    public class MyTestCase {&lt;br /&gt;       // Local variables become instance variables&lt;br /&gt;&lt;br /&gt;       @Before&lt;br /&gt;       public void setUp() {&lt;br /&gt;           // Set up for the test, manipulating instance variables&lt;br /&gt;       }&lt;br /&gt;      &lt;br /&gt;       @Test&lt;br /&gt;       public void testCondition1() {&lt;br /&gt;           assertTrue(condition1);&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       @Test&lt;br /&gt;       public void testCondition2() {&lt;br /&gt;           assertTrue(condition2);&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       @Test&lt;br /&gt;       public void testCondition3() {&lt;br /&gt;           assertTrue(condition3);&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt;The resulting tests use JUnit's natural execution and reporting mechanism and, failure in one test does not affect the execution of the other tests. You generally want exactly one test to fail for any given bug, if you can manage it. &lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-7640872286003575397?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/7640872286003575397/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=7640872286003575397' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/7640872286003575397'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/7640872286003575397'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/06/junit-4.html' title='Junit 4'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-2590179566848514498</id><published>2008-06-28T17:16:00.000-07:00</published><updated>2008-06-28T17:24:10.607-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Junit'/><title type='text'>Junit 3</title><content type='html'>&lt;p&gt; &lt;b&gt;Do You Need to Write a Test Class for Every Class That Need to Be Tested?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt;This is a simple question. But the answer shows your organization skills. &lt;/p&gt;  &lt;p&gt;The technical answer is no. There is no need to write one test class for each every class that need to be tested. One test class can contain many tests for many test target classes. &lt;/p&gt;  &lt;p&gt;But the practical answer is yes. You should design one test class per test target class for low level basic tests.  This makes your test classes much easier to manage and maintain. &lt;/p&gt;  &lt;p&gt;You should write separate test classes for high level tests that requires multiple target classes working together.&lt;/p&gt;&lt;br /&gt;&lt;p&gt; &lt;b&gt;What Is JUnit TestCase?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt;JUnit TestCase is the base class, junit.framework.TestCase, used in JUnit 3.8 that allows you to create a test case. TestCase class is no longer supported in JUnit 4.4. &lt;/p&gt;  &lt;p&gt; A test case defines the fixture to run multiple tests. To define a test case &lt;/p&gt; &lt;ul&gt;&lt;li&gt;Implement a subclass of TestCase&lt;/li&gt;&lt;li&gt;Define instance variables that store the state of the fixture&lt;/li&gt;&lt;li&gt;Initialize the fixture state by overriding setUp&lt;/li&gt;&lt;li&gt;Clean-up after a test by overriding tearDown&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt; Each test runs in its own fixture so there can be no side effects among test runs. Here is an example:  &lt;/p&gt; &lt;pre&gt;import junit.framework.*;&lt;br /&gt;// by FYICenter.com&lt;br /&gt;public class MathTest extends TestCase {&lt;br /&gt;   protected double fValue1;&lt;br /&gt;   protected double fValue2;&lt;br /&gt;&lt;br /&gt;   protected void setUp() {&lt;br /&gt;       fValue1= 2.0;&lt;br /&gt;       fValue2= 3.0;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public void testAdd() {&lt;br /&gt;       double result= fValue1 + fValue2;&lt;br /&gt;       assertTrue(result == 5.0);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt; &lt;b&gt;What Is JUnit TestSuite?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt;JUnit TestSuite is a container class, junit.framework.TestSuite, used in JUnit 3.8 that allows you to group multiple test cases into a collection and run them together. TestSuite class is no longer supported in JUnit 4.4. &lt;/p&gt;  &lt;p&gt; Each test runs in its own fixture so there can be no side effects among test runs. Here is an example:  &lt;/p&gt; import junit.framework.*; // by FYICenter.com public class RunTestSuite {     public static void main(String[] a) {         TestSuite suite = new TestSuite(MathTest.class);  TestResult result = new TestResult();         suite.run(result);         System.out.println("Was it successful? "             +result.wasSuccessful());         System.out.println("How many tests were there? "             +result.runCount());     } }&lt;br /&gt;&lt;br /&gt;&lt;p&gt; &lt;b&gt;How To Write a Single Class to Define Multiple Tests and Run Them?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt;Here is the answer for JUnit 3.8: &lt;/p&gt; &lt;pre&gt;   1. Define a subclass of junit.framework.TestCase.&lt;br /&gt;  2. Override the setUp() and tearDown() methods.&lt;br /&gt;  3. Define multiple "public void testXXX()" methods.&lt;br /&gt;     One for each test.&lt;br /&gt;     A test method name must be started with "test".&lt;br /&gt;         Call the methods of tested object.&lt;br /&gt;         Check the expected results with an assertXXX() method.&lt;br /&gt;  4. Define a "public static void main()" method to run tests.&lt;br /&gt;     Call "junit.textui.TestRunner.run()" to run all tests.&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt;Here is a nice example: &lt;/p&gt; &lt;pre&gt;import junit.framework.*;&lt;br /&gt;import junit.textui.*;&lt;br /&gt;// by FYICenter.com&lt;br /&gt;public class MathTestAndRun extends TestCase {&lt;br /&gt;   protected double fValue1;&lt;br /&gt;   protected double fValue2;&lt;br /&gt;&lt;br /&gt;   public static void main(String[] a){&lt;br /&gt;       junit.textui.TestRunner.run(MathTestAndRun.class);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   protected void setUp() {&lt;br /&gt;       fValue1= 2.0;&lt;br /&gt;       fValue2= 3.0;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public void testAdd() {&lt;br /&gt;       double result= fValue1 + fValue2;&lt;br /&gt;       assertTrue(result == 5.0);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public void testMultiply() {&lt;br /&gt;       double result= fValue1 * fValue2;&lt;br /&gt;       assertTrue(result == 6.0);&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;}&lt;br /&gt;&lt;p&gt; &lt;b&gt;How to Run Your JUnit 4.4 Tests with a JUnit 3.8 Runner?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; I am not sure why you have to do this. But if you want to, you can use the junit.framework.JUnit4TestAdapter class included in JUnit 4.4 JAR file. Here is sample code: &lt;/p&gt;  &lt;pre&gt;import junit.framework.Test;&lt;br /&gt;import junit.textui.TestRunner;&lt;br /&gt;import junit.framework.JUnit4TestAdapter;&lt;br /&gt;// by FYICenter.com&lt;br /&gt;&lt;br /&gt;public class JUnit3Adapter {&lt;br /&gt; public static void main (String[] args) {&lt;br /&gt;   Test adaptedTest = new JUnit4TestAdapter(HelloTest.class);&lt;br /&gt;   TestRunner.run(adaptedTest);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt; Classes junit.framework.Test, junit.textui.TestRunner and junit.framework.JUnit4TestAdapter  are included in the JUnit 4.4 JAR file. You don't need to include the JUnit 3.8 JAR file in your CLASSPATH.  &lt;/p&gt;&lt;p&gt; &lt;b&gt;How Do You Test a "private" Method?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; When a method is declared as "private", it can only be accessed within the same class. So there is no way to test a "private" method of a target class from any test class.  &lt;/p&gt;  &lt;p&gt; To resolve this problem, you have to perform unit testing manually.  Or you have to change your method from "private" to "protected".&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt; &lt;b&gt;Can You Write a JUnit Test Case Class in 10 Minutes?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt;Here is a good JUnit test case class example that you should be able to write within 10 minutes. This example is provided by Varun Chopra and valid for JUnit 3.8. &lt;/p&gt;  &lt;p&gt; Assuming that Java class DirLister.java has following three methods and one variable: &lt;/p&gt; &lt;ul&gt;&lt;li&gt;String dirPath - Member variable that represents directory in use&lt;/li&gt;&lt;li&gt;createLogFile(String fileName) - Member method that creates a file in dirPath&lt;/li&gt;&lt;li&gt;exists(String fileName) - Member method that checks the existence of a file within dirPath&lt;/li&gt;&lt;li&gt;getChildList() - Member method that gets the list of files and directories within dirPath&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt; We want to test above three methods with Junit.  For that, we will create another Java class that will have the test code for these three methods. See the class below: &lt;/p&gt; &lt;pre&gt;/*&lt;br /&gt;* DirListerTest.java&lt;br /&gt;* JUnit based test&lt;br /&gt;*&lt;br /&gt;* Created on May 26, 2005, 11:33 AM&lt;br /&gt;*/&lt;br /&gt;package javaegs.junit;&lt;br /&gt;&lt;br /&gt;import java.io.File;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import junit.framework.*;&lt;br /&gt;/**&lt;br /&gt;* @author varunc&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public class DirListerTest extends TestCase {&lt;br /&gt;&lt;br /&gt;DirLister dl;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;* Test of createLogFile method, of class&lt;br /&gt;javaegs.junit.DirLister.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public void testCreateLogFile() {&lt;br /&gt; dl = new DirLister("D:/temp/junittestdir");&lt;br /&gt; dl.createLogFile("logFile.log");&lt;br /&gt; assertTrue("File does not exist",dl.exists("logFile.log"));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;* Test of exists method, of class&lt;br /&gt;javaegs.junit.DirLister.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public void testExists() {&lt;br /&gt; dl = new DirLister("D:/temp/junittestdir");&lt;br /&gt; assertTrue("File does not exist",dl.exists("logFile.log"));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;* Test of getChildList method, of class&lt;br /&gt;javaegs.junit.DirLister.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public void testGetChildList() {&lt;br /&gt; dl = new DirLister("D:/temp/junittestdir");&lt;br /&gt; String[] files = null;&lt;br /&gt; try {&lt;br /&gt;  files = dl.getChildList();&lt;br /&gt; } catch(Exception ex) {&lt;br /&gt;  fail("Exception occured"+ex);&lt;br /&gt;  ex.printStackTrace();&lt;br /&gt;  }&lt;br /&gt; assertNotNull("Children can't be null",files);&lt;br /&gt; assertTrue("No. of files can't be 0",files.length&gt;0);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;* @param args the command line arguments&lt;br /&gt;*/&lt;br /&gt;public static void main(String[] args) {&lt;br /&gt;junit.textui.TestRunner.run(DirListerTest.class);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt; &lt;b&gt;Can You Explain a Sample JUnit Test Case Class?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; Assuming that you have been give the sample JUnit test case class listed in the previous question, you should be able to provide the following notes: &lt;/p&gt;  &lt;p&gt;DirListerTest class imports classes in junit.framework package. junit.framework package contains all common classes required to create junit test cases. &lt;/p&gt;  &lt;p&gt;DirListerTest class extends junit.framework.TestCase class. TestCase class further extends junit.framework.Assert class which contains various assertXXX() methods required to created test cases. Therefore to use Junit framework, test class must extend TestCase class. &lt;/p&gt;  &lt;p&gt;Corresponding to each method to be tested there is a method in the test class namely: testCreateLogFile(), testExists(), and testGetChildList(). You can name them anything but the starting word must be test.&lt;br /&gt;&lt;/p&gt;  &lt;p&gt;One important point I would like to mention here is that I created three different methods to demonstrate three different and common scenarios while programming. &lt;/p&gt; &lt;ul&gt;&lt;li&gt;exists() method of DirLister returns a value. Our test case will demonstrate how to test such methods, which return a value. &lt;/li&gt;&lt;li&gt;createLogFile() returns nothing. It even catches the exception and ignores it (in one sense). Therefore, we won?t get the exception even if that method fails. Our test case will demonstrate how to go about such methods. &lt;/li&gt;&lt;li&gt;getChildList() returns a value as well as may throw exception. We will see how to handle this using Junit framework. &lt;/li&gt;&lt;/ul&gt;  &lt;p&gt; Let's now look inside the second test case method testExists(): &lt;/p&gt; &lt;pre&gt;public void testExists() {&lt;br /&gt;dl = new DirLister("D:/temp/junittestdir");&lt;br /&gt;assertTrue("File does not exist",dl.exists("logFile.log"));&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt;First statement in it instantiates the DirLister object and points it to D:/temp/junittestdir directory. Next statement is what we need to focus on: &lt;/p&gt; &lt;pre&gt;  assertTrue("File does not exist",dl.exists("logFile.log"));&lt;br /&gt;&lt;/pre&gt; &lt;p&gt;assertTrue() is a standard method provided by Junit framework (there are many other assert methods also). It takes two arguments: a string message and a boolean condition. &lt;/p&gt;  &lt;p&gt;If boolean condition is true, test passes and string message is ignored. Otherwise test fails and string message is displayed. In this case, if dl.exists("logFile.log") passes, test passes, otherwise test fails. &lt;/p&gt;  &lt;p&gt;There is another variant of assertTrue() method provided by Junit that takes only one argument - the condition to check. This is true for all assertXXX methods provided by Junit. &lt;/p&gt;  &lt;p&gt;Now you may say, that was a boolean result. What if a non-boolean value is returned? Okay, so Junit provides alternatives. We can use assertEquals() as below: &lt;/p&gt; &lt;pre&gt;  assertEquals("not equal",dl.exists("logFile.log"), true);&lt;br /&gt;&lt;/pre&gt; &lt;p&gt;Here first argument is the message that is displayed in case test fails. Second argument is the actual value. Normally we will call the method to be tested here and whatever value that method will return, will become the actual value. Third argument is the value we expect. So here, we expect it to be ?true?, hence we put true there. &lt;/p&gt;  &lt;p&gt; There are various overloaded forms of assertEquals() method  that can handle every result (from byte to String to Object). &lt;/p&gt;  &lt;p&gt;Let's now look inside the first test case method testCreateLogFile(). If a method returns nothing and throws no exception, either it is not doing anything or is creating a side effect. createLogFile() is one such method. To test such methods, we will have to test the side effect they created. That's what testCreateLogFile() does. &lt;/p&gt; &lt;pre&gt;public void testCreateLogFile() {&lt;br /&gt;dl = new DirLister("D:/temp/junittestdir");&lt;br /&gt;dl.createLogFile("logFile.log");&lt;br /&gt;assertTrue("File does not exist",dl.exists("logFile.log"));&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt; &lt;p&gt; We expect that dl.createLogFile("logFile.log") should create logFile.log in directory in use. Therefore, in next statement we check the  existence of such a file. &lt;/p&gt; &lt;pre&gt; assertTrue("File does not exist",dl.exists("logFile.log"));&lt;br /&gt;&lt;/pre&gt; &lt;p&gt; If file will be there, test case will pass, otherwise it will fail. &lt;/p&gt;  &lt;p&gt; Let's now look inside the other test case method testGetChildList(). getChildList() method may throw an exception. Therefore, we will have to call it in try block. &lt;/p&gt; &lt;pre&gt; public void testGetChildList() {&lt;br /&gt; dl = new DirLister("D:/temp/junittestdir");&lt;br /&gt; String[] files = null;&lt;br /&gt; try {&lt;br /&gt;  files = dl.getChildList();&lt;br /&gt; } catch(Exception ex) {&lt;br /&gt;  fail("Exception occured"+ex);&lt;br /&gt;  ex.printStackTrace();&lt;br /&gt;  }&lt;br /&gt; assertNotNull("Children can't be null",files);&lt;br /&gt; assertTrue("No. of files can't be 0",files.length&gt;0);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt;If we don't expect getChildList() to throw exception for the directory value we provide, we can put in catch block a call to fail() method (as we have done). &lt;/p&gt;  &lt;p&gt;fail() is again a standard method provided by Junit framework (belongs to junit.framework.Assert class). It fails a test case, which means it will show in the output that test case was failed and show the message we provided as argument to it. It has a without-argument variant also. &lt;/p&gt;  &lt;p&gt;One more thing fail() will do is to exit the method. So assert statements following catch block will not be executed if fail() is called. That's logical since you should handle one bug at a time in unit testing. &lt;/p&gt;  &lt;p&gt; Okay, so what if getChildList() succeeds. If we know that directory we have provided has at least one file in it, then:&lt;br /&gt;&lt;/p&gt; &lt;pre&gt;    assertNotNull("Children can't be null",files);&lt;br /&gt;&lt;/pre&gt; &lt;p&gt; will be useful. It will check that "files" variable is not null.  If this test fails, it will display the message provided by us. &lt;/p&gt; &lt;pre&gt;    assertTrue("No. of files can't be 0",files.length&gt;0);&lt;br /&gt;&lt;/pre&gt; &lt;p&gt; will further make it certain that number of files is greater than 0. &lt;/p&gt;  &lt;p&gt; If we know the number of files within the directory we can do something like this: &lt;/p&gt; &lt;pre&gt;  assertEquals(?Not equal?, files.length, n);&lt;br /&gt;&lt;/pre&gt; &lt;p&gt; where n is the number of files.&lt;/p&gt;&lt;br /&gt;&lt;p&gt; &lt;b&gt;Do You Need to Write a main() Method in a JUnit Test Case Class?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; The right answer to this question is "No".  But many developers do write a main() method in a JUnit test case class to call a JUnit test runner to run all tests defined in this class.  This is not recommended, because you can always call a JUnit runner  to run a test case class as a system command.  &lt;/p&gt;  &lt;p&gt; If you want to know how to call a JUnit runner in a main() method,  you can this code included in the sample test case class listed in the previous question. This code is provided by Varun Chopra and valid for JUnit 3.8. &lt;/p&gt; &lt;pre&gt;public static void main(String[] args) {&lt;br /&gt; junit.textui.TestRunner.run(DirListerTest.class);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt; junit.textui.TestRunner.run() method takes test class name as argument.  Using reflection, this method finds all class methods whose name starts with test.  So it will find following 3 methods: &lt;/p&gt; &lt;pre&gt;  testCreateLogFile()&lt;br /&gt; testExists()&lt;br /&gt; testGetChildList()&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt; It will execute each of the 3 methods in unpredictable sequence  (hence test case methods should be independent of each other) and give the result in console.  Result will be something like this: &lt;/p&gt; &lt;pre&gt;Time: 0.016&lt;br /&gt;OK (3 tests)&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt; In case you want to see the output in a GUI,  you just need to replace statement in main method with following: &lt;/p&gt; &lt;pre&gt;    junit.swingui.TestRunner.run(DirListerTest.class);&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt; This will open up a nice swing based UI, which will show a green progress bar to show the status. &lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt; &lt;b&gt;Can You Explain the Life Cycle of a JUnit 4.4 Test Class?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; A JUnit 4.4 test class contains a @Before method, an @After method and multiple @test methods.  When calling a test runner to run this test class, the runner will execute those methods in a specific order giving the test class an execution life cycle like this: &lt;/p&gt; &lt;pre&gt;@Before&lt;br /&gt;@Test XXX1&lt;br /&gt;@After&lt;br /&gt;&lt;br /&gt;@Before&lt;br /&gt;@Test XXX2&lt;br /&gt;@After&lt;br /&gt;&lt;br /&gt;@Before&lt;br /&gt;@Test XXX3&lt;br /&gt;@After&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt; &lt;b&gt;What Is a JUnit Test Fixture?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; A test fixture is a fixed state of a set of objects used as a baseline for running tests. The purpose of a test fixture is to ensure that there is a well known and fixed environment  in which tests are run so that results are repeatable. Examples of fixtures: &lt;/p&gt; &lt;ul&gt;&lt;li&gt;Loading a database with a specific, known set of data&lt;/li&gt;&lt;li&gt;Copying a specific known set of files&lt;/li&gt;&lt;li&gt;Preparation of input data and setup/creation of fake or mock objects&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt; In other word, creating a test fixture is to create a set of objects initialized to certain states. &lt;/p&gt;  &lt;p&gt;If a group of tests requires diferent test fixtures, you can write code inside the test method to create its own test fixture. &lt;/p&gt;  &lt;p&gt;If a group of tests shares the same fixtures, you should write a separate setup code to create the common test fixture.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt; &lt;b&gt;How Do You Test an Expected Exception with JUnit?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; If you want to test a method that will throw an exception under a specific condition,  you can:  &lt;/p&gt; &lt;ul&gt;&lt;li&gt;Put the test code inside a "try" block". &lt;/li&gt;&lt;li&gt;Catch the expected exception object. &lt;/li&gt;&lt;li&gt;Assert the exception object with Assert.assertNotNull(). &lt;/li&gt;&lt;/ul&gt;  &lt;p&gt;JUnit runner will fail this test if the test code did not raise the expected exception.   &lt;/p&gt;  &lt;p&gt; Here is a good test class that test the expected IndexOutOfBoundsException exception raised by the get() method of the ArrayList class: &lt;/p&gt; &lt;pre&gt;import org.junit.*;&lt;br /&gt;import java.util.*;&lt;br /&gt;&lt;br /&gt;// by FYICenter.com&lt;br /&gt;public class ExpectedExceptionTest1 {&lt;br /&gt; @Test public void outOfBounds() {&lt;br /&gt;   ArrayList emptyList = new ArrayList&lt;object&gt;();     Exception eOutOfBounds = null;          // catch the expected exception     try {        Object o = emptyList.get(1);     } catch (IndexOutOfBoundsException e) {        eOutOfBounds = e;     }          // asset the exception object     Assert.assertNotNull("No expected exception", eOutOfBounds);   } }  &lt;/object&gt;&lt;/pre&gt;  &lt;p&gt; But there a better way to test the expected exception provided by the JUnit @Test annotation. See the next question.  &lt;/p&gt;&lt;pre&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;  &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-2590179566848514498?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/2590179566848514498/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=2590179566848514498' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/2590179566848514498'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/2590179566848514498'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/06/junit-3.html' title='Junit 3'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-6117233494097029534</id><published>2008-06-28T17:11:00.000-07:00</published><updated>2008-06-28T17:16:18.147-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Junit'/><title type='text'>Junit 2</title><content type='html'>&lt;p&gt; &lt;b&gt;What Happens If a JUnit Test Method Is Declared as "private"?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; If a JUnit test method is declared as "private", the compilation will pass ok. But the execution will fail. This is decause JUnit requires that all test methods must be declared as "public". For example:  &lt;/p&gt; &lt;pre&gt;type HelloTestPrivate.java&lt;br /&gt;&lt;br /&gt;import org.junit.Test;&lt;br /&gt;import static org.junit.Assert.*;&lt;br /&gt;// by FYICenter.com&lt;br /&gt;public class HelloTestPrivate {&lt;br /&gt;   @Test private void testHello() {&lt;br /&gt;       String message = "Hello World!";&lt;br /&gt;       assertEquals(12, message.length());&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;javac -cp junit-4.4.jar HelloTestPrivate.java&lt;br /&gt;&lt;br /&gt;java -cp .;junit-4.4.jar org.junit.runner.JUnitCore&lt;br /&gt;  HelloTestPrivate&lt;br /&gt;JUnit version 4.4&lt;br /&gt;.E&lt;br /&gt;Time: 0&lt;br /&gt;There was 1 failure:&lt;br /&gt;1) initializationError0(HelloTestPrivate)&lt;br /&gt;java.lang.Exception: Method testHello should be public&lt;br /&gt;at org.junit.internal.runners.MethodValidator.validateTestMethod&lt;br /&gt;at org.junit.internal.runners.MethodValidator.validateInstanceMe&lt;br /&gt;at org.junit.internal.runners.MethodValidator.validateMethodsFor&lt;br /&gt;at org.junit.internal.runners.JUnit4ClassRunner.validate(JUnit4C&lt;br /&gt;at org.junit.internal.runners.JUnit4ClassRunner.&lt;init&gt;(JUn&lt;br /&gt;at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native&lt;br /&gt;at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeC&lt;br /&gt;at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Del&lt;br /&gt;at java.lang.reflect.Constructor.newInstance(Constructor.java:51&lt;br /&gt;at org.junit.internal.requests.ClassRequest.buildRunner(ClassReq&lt;br /&gt;at org.junit.internal.requests.ClassRequest.getRunner(ClassReque&lt;br /&gt;at org.junit.internal.requests.ClassesRequest.getRunner(ClassesR&lt;br /&gt;at org.junit.runner.JUnitCore.run(JUnitCore.java:109)&lt;br /&gt;at org.junit.runner.JUnitCore.run(JUnitCore.java:100)&lt;br /&gt;at org.junit.runner.JUnitCore.runMain(JUnitCore.java:81)&lt;br /&gt;at org.junit.runner.JUnitCore.main(JUnitCore.java:44)&lt;br /&gt;&lt;br /&gt;FAILURES!!!&lt;br /&gt;Tests run: 1,  Failures: 1&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt; &lt;b&gt;What Happens If a JUnit Test Method Is Declared to Return "String"?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; If a JUnit test method is declared to return "String", the compilation will pass ok. But the execution will fail. This is decause JUnit requires that all test methods must be declared to return "void". For example:  &lt;/p&gt; type HelloTestNonVoid.java  import org.junit.Test; import static org.junit.Assert.*; // by FYICenter.com public class HelloTestNonVoid {     @Test public String testHello() {         String message = "Hello World!";         assertEquals(12, message.length());         return message;     } }  javac -cp junit-4.4.jar HelloTestNonVoid.java  java -cp .;junit-4.4.jar org.junit.runner.JUnitCore     HelloTestNonVoid  JUnit version 4.4 .E Time: 0 There was 1 failure: 1) initializationError0(HelloTestNonVoid) java.lang.Exception: Method testHello should be void         at org.junit.internal.runners.MethodValidator.validateTe         at org.junit.internal.runners.MethodValidator.validateIn         at org.junit.internal.runners.MethodValidator.validateMe         at org.junit.internal.runners.JUnit4ClassRunner.validate         at org.junit.internal.runners.JUnit4ClassRunner.&lt;init&gt;(J         at sun.reflect.NativeConstructorAccessorImpl.newInstance         at sun.reflect.NativeConstructorAccessorImpl.newInstance         at sun.reflect.DelegatingConstructorAccessorImpl.newInst         at java.lang.reflect.Constructor.newInstance(Constructor         at org.junit.internal.requests.ClassRequest.buildRunner(         at org.junit.internal.requests.ClassRequest.getRunner(Cl         at org.junit.internal.requests.ClassesRequest.getRunner(         at org.junit.runner.JUnitCore.run(JUnitCore.java:109)         at org.junit.runner.JUnitCore.run(JUnitCore.java:100)         at org.junit.runner.JUnitCore.runMain(JUnitCore.java:81)         at org.junit.runner.JUnitCore.main(JUnitCore.java:44)  FAILURES!!! Tests run: 1,  Failures: 1 &lt;pre&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt; &lt;b&gt;Why Does Poeple Import org.junit.Assert Statically?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; Poeple use the static import statement on org.junit.Assert to save coding time on calling its assetion methods. With a normal import statement, assertion method names must qualified with the class name like this:  &lt;/p&gt; import org.junit.Assert;  ...         Assert.assertEquals(12, message.length());   &lt;p&gt; With a static import statement, assertion method names can be used directly like this:  &lt;/p&gt; import static org.junit.Assert.*; ...         assertEquals(12, message.length()); &lt;p&gt; &lt;b&gt;How To Group Multiple Test Classes into a Suite in JUnit 4.4?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; JUnit 4.4 stops using the "public static Test suite()" method to build a test suite class.  It is now provides the org.junit.runners.Suite class and two annotations to help you to build test suite.  &lt;/p&gt;  &lt;p&gt; org.junit.runners.Suite - JUnit 4.4 runner class that runs a group of test classes. &lt;/p&gt;  &lt;p&gt; org.junit.runner.RunWith - JUnit 4.4 class annotation that specify runner class to run the annotated class. &lt;/p&gt;  &lt;p&gt; org.junit.runner.Suite.SuiteClasses - JUnit 4.4 class annotation that specify an array of test classes for  the Suite.class to run. &lt;/p&gt;  &lt;p&gt; The annotated class should be an empty class.   &lt;/p&gt;  &lt;p&gt; To run "@Suite.SuiteClasses" class, you can use the core runner: org.junit.runner.JUnitCore. &lt;/p&gt;  &lt;p&gt; Here is a good example of "@Suite.SuiteClasses" class: &lt;/p&gt; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; // by FYICenter.com  // specify a runner class: Suite.class @RunWith(Suite.class)  // specify an array of test classes @Suite.SuiteClasses({   HelloTest.class,    ExpectedExceptionTest1.class,   ExpectedExceptionTest2.class,   UnexpectedExceptionTest1.class,   UnexpectedExceptionTest2.class} )  // the actual class is empty public class AllTests { } &lt;pre&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt; &lt;b&gt;How To Run a "@Suite.SuiteClasses" Class in JUnit 4.4?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; If you define create "@Suite.SuiteClasses" class as described in the previous question,  you run it with the core runner: org.junit.runner.JUnitCore: &lt;/p&gt; java -cp .;junit-4.4.jar org.junit.runner.JUnitCore AllTests  JUnit version 4.4 ....E.E Time: 0.016 There were 2 failures:  1) testGet(UnexpectedExceptionTest1) java.lang.AssertionError: Unexpected exception  at org.junit.Assert.fail(Assert.java:74)  at UnexpectedExceptionTest1.testGet(UnexpectedExceptionTest1.java:13)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  ...  at org.junit.runner.JUnitCore.run(JUnitCore.java:100)  at org.junit.runner.JUnitCore.runMain(JUnitCore.java:81)  at org.junit.runner.JUnitCore.main(JUnitCore.java:44)  2) testGet(UnexpectedExceptionTest2) java.lang.IndexOutOfBoundsException: Index: 1, Size: 0  at java.util.ArrayList.RangeCheck(ArrayList.java:547)  at java.util.ArrayList.get(ArrayList.java:322)  at UnexpectedExceptionTest2.testGet(UnexpectedExceptionTest2.java:13)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  ...  at org.junit.runner.JUnitCore.run(JUnitCore.java:100)  at org.junit.runner.JUnitCore.runMain(JUnitCore.java:81)  at org.junit.runner.JUnitCore.main(JUnitCore.java:44)  FAILURES!!! Tests run: 5,  Failures: 2 &lt;p&gt; &lt;b&gt;What Is the "@SuiteClasses" Annotation?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; "@SuiteClasses" is a class annotation defined in JUnit 4.4 in org.junit.runners.Suite.SuiteClasses.  It allows you to define a suite class as described in the previous question. &lt;/p&gt;  &lt;p&gt; By the way, the API document of JUnit 4.4 has a major typo for the org.junit.runners.Suite class (Suite.html). &lt;/p&gt;  &lt;p&gt;&lt;i&gt; Using Suite as a runner allows you to manually build a suite containing tests from many classes. It is the JUnit 4 equivalent of the JUnit 3.8.x static Test suite() method. To use it, annotate a class with @RunWith(Suite.class) and @SuiteClasses(TestClass1.class, ...). When you run this class, it will run all the tests in all the suite classes. &lt;/i&gt; &lt;/p&gt;  &lt;p&gt; "@SuiteClasses(TestClass1.class, ...)" should be changed to "@Suite.SuiteClasses({TestClass1.class, ...})". &lt;/p&gt;  &lt;p&gt; Someone provided wrong information on build test suite in JUnit 4.4. Do not follow this: &lt;/p&gt;  &lt;p&gt;&lt;i&gt; JUnit provides tools to define the suite to be run and to display its results. To run tests and see the results on the console, run:&lt;/i&gt; &lt;/p&gt; org.junit.runner.TextListener.run(TestClass1.class, ...);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt; &lt;b&gt;Why Not Just Write a main() Method for Unit Testing?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt;It is possible to write a main() method in each class that need to be tested for unit testing. In the main() method, you could create test object of the class itself, and write some tests  to test its methods. &lt;/p&gt;  &lt;p&gt;However, this is not a recommended approach because of the following points: &lt;/p&gt; &lt;ul&gt;&lt;li&gt;Your classes will be cluttered with test code in main method. All those test codes will be packaged into the final product.&lt;/li&gt;&lt;li&gt;If you have a lots of classes to test, you need to run the main() method of every class.  This requires some extra coding effort.  &lt;/li&gt;&lt;li&gt;If you want the test results to be displayed in a GUI, you will have to write code for that GUI. &lt;/li&gt;&lt;li&gt;If you want to log the results of tests in HTML format or text format, you will have to write additional code. &lt;/li&gt;&lt;li&gt;If one method call fails, next method calls won?t be executed. You will have to work-around this.&lt;br /&gt; &lt;/li&gt;&lt;li&gt;If you start working on a project created by some other team in your organization, you may see an entirely different approach for testing. That will increase your learning time and things won?t be standard. &lt;/li&gt;&lt;/ul&gt;  &lt;p&gt;Above are some of the problems, which will be taken care of automatically if you use Junit. Junit provides a standard framework for writing your tests. It separates test code from project code, hence keeps everything clean.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt; &lt;b&gt;Why Not Just Use System.out.println() for Unit Testing?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; Inserting debug statements into code is a low-tech method for debugging it. It usually requires that output be scanned manually every time the program is run to ensure that the code is doing what's expected. &lt;/p&gt;  &lt;p&gt;It generally takes less time in the long run to codify expectations in the form of an automated JUnit test that retains its value over time. If it's difficult to write a test to assert expectations, the tests may be telling you that shorter and more cohesive methods would improve your design. &lt;/p&gt;&lt;p&gt; &lt;b&gt;Under What Conditions Should You Test set() and get() Methods?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; This is a good question for a job interview. It shows your experience with test design and data types. &lt;/p&gt;  &lt;p&gt;Tests should be designed to target areas that might break.  set() and get() methods on simple data types are unlikely to break. So no need to test them.  &lt;/p&gt;  &lt;p&gt;set() and get() methods on complex data types are likely to break. So you should test them.   &lt;/p&gt;&lt;p&gt; &lt;b&gt;Under What Conditions Should You Not Test Get() and Set() Methods?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt;The JUnit FAQ provides a good answer to this question: &lt;/p&gt;  &lt;p&gt; Most of the time, get/set methods just can't break, and if they can't break, then why test them? While it is usually better to test more, there is a definite curve of diminishing returns on test effort versus "code coverage". Remember the maxim: "Test until fear turns to boredom." &lt;/p&gt;  &lt;p&gt; Assume that the getX() method only does "return x;" and that the setX() method only does "this.x = x;". If you write this test: &lt;/p&gt; &lt;pre&gt;    @Test&lt;br /&gt;   public void testGetSetX() {&lt;br /&gt;       setX(23);&lt;br /&gt;       assertEquals(23, getX());&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;       &lt;p&gt; then you are testing the equivalent of the following: &lt;/p&gt; &lt;pre&gt;    @Test&lt;br /&gt;   public void testGetSetX() {&lt;br /&gt;       x = 23;&lt;br /&gt;       assertEquals(23, x);&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;       &lt;p&gt; or, if you prefer, &lt;/p&gt; &lt;pre&gt;    @Test&lt;br /&gt;   public void testGetSetX() {&lt;br /&gt;       assertEquals(23, 23);&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt;At this point, you are testing the Java compiler, or possibly the interpreter, and not your component or application. There is generally no need for you to do Java's testing for them. &lt;/p&gt;  &lt;p&gt;If you are concerned about whether a property has already been set at the point you wish to call getX(), then you want to test the constructor, and not the getX() method. This kind of test is especially useful if you have multiple constructors: &lt;/p&gt;  &lt;pre&gt;    @Test&lt;br /&gt;&lt;br /&gt;   public void testCreate() {&lt;br /&gt;       assertEquals(23, new MyClass(23).getX());&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-6117233494097029534?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/6117233494097029534/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=6117233494097029534' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/6117233494097029534'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/6117233494097029534'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/06/junit-2.html' title='Junit 2'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-4572601738071639680</id><published>2008-06-28T16:49:00.000-07:00</published><updated>2008-06-28T17:56:57.265-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Junit'/><title type='text'>Junit 1</title><content type='html'>&lt;p&gt; &lt;b&gt;What Is JUnit?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; What is JUnit? You need to remember the following points when answering this question: &lt;/p&gt; &lt;ul&gt;&lt;li&gt;It is a software testing framework to for unit testing.&lt;/li&gt;&lt;li&gt;It is written in Java and designed to test Java applications.&lt;/li&gt;&lt;li&gt;It is an Open Source Software maintained by the JUnit.org community.&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt; Answer from the JUnit FAQ: &lt;/p&gt;     &lt;p&gt;       JUnit is a simple, open source framework to write and run       repeatable tests. It is an instance of the xUnit architecture       for unit testing frameworks.  JUnit features include:     &lt;/p&gt;     &lt;ul&gt;&lt;li&gt;Assertions for testing expected results&lt;/li&gt;&lt;li&gt;Test fixtures for sharing common test data&lt;/li&gt;&lt;li&gt;Test runners for running tests&lt;/li&gt;&lt;/ul&gt;     &lt;p&gt;       JUnit was originally written by Erich Gamma and Kent Beck.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt; &lt;b&gt;Why Do You Use JUnit to Test Your Code?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt;This is a commonly asked question in a job interview. Your answer should have these points: &lt;/p&gt; &lt;ul&gt;&lt;li&gt;I believe that writing more tests will make me more productive, not less productive.&lt;/li&gt;&lt;li&gt;I believe that tests should be done as soon as possible at the code unit level. &lt;/li&gt;&lt;li&gt;I believe that using JUnit makes unit testing easier and faster.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt; &lt;b&gt;How To Wirte a Simple JUnit Test Class?&lt;/b&gt; &lt;/p&gt; &lt;p&gt;  &lt;/p&gt;&lt;p&gt;This is a common test in a job interview. You should be able to write this simple test class with one test method: &lt;/p&gt; &lt;pre&gt;import org.junit.*;&lt;br /&gt;// by FYICenter.com&lt;br /&gt;public class HelloTest {&lt;br /&gt; @Test public void testHello() {&lt;br /&gt;     String message = "Hello World!";&lt;br /&gt;     Assert.assertEquals(12, message.length());&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt; &lt;b&gt;How To Compile a JUnit Test Class?&lt;/b&gt; &lt;/p&gt; &lt;p&gt;  &lt;/p&gt;&lt;p&gt;Compiling a JUnit test class is like compiling any other Java classes. The only thing you need  watch out is that the JUnit JAR file must be included in the classpath.  For example, to compile the test class HelloTest.java described previously, you should do this: &lt;/p&gt; &lt;pre&gt;javac -cp junit-4.4.jar HelloTest.java&lt;br /&gt;&lt;br /&gt;dir HelloTest.*&lt;br /&gt;453 HelloTest.class&lt;br /&gt;183 HelloTest.java&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt; &lt;b&gt;How To Run a JUnit Test Class?&lt;/b&gt; &lt;/p&gt; &lt;p&gt;  &lt;/p&gt;&lt;p&gt;A JUnit test class usually contains a number of test methods. You can run all test methods in a JUnit test class with the JUnitCore runner class.  For example, to run the test class HelloTest.java described previously, you should do this: &lt;/p&gt; java -cp .; junit-4.4.jar org.junit.runner.JUnitCore HelloTest  JUnit version 4.4 . Time: 0.015  OK (1 test)&lt;br /&gt;&lt;br /&gt;&lt;p&gt; &lt;b&gt;What CLASSPATH Settings Are Needed to Run JUnit?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; It doesn't matter if you run your JUnit tests from a command line, from an IDE, or from "ant", you must define your CLASSPATH settings correctly. Here is what recommended by the JUnit FAQ with some minor changes: &lt;/p&gt;  &lt;p&gt; To run your JUnit tests, you'll need the following elemements in your CLASSPATH: &lt;/p&gt; &lt;ul&gt;&lt;li&gt;The JUnit JAR file.&lt;/li&gt;&lt;li&gt;Location of your JUnit test classes.&lt;/li&gt;&lt;li&gt;Location of classes to be tested.&lt;/li&gt;&lt;li&gt;JAR files of class libraries that are required by classes to be tested.&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt; If attempting to run your tests results in a NoClassDefFoundError, then something is missing from your CLASSPATH. &lt;/p&gt;  &lt;p&gt; If you are running your JUnit tests from a command line on a Windows system: &lt;/p&gt; &lt;pre&gt;set CLASSPATH=c:\A\junit-4.4.jar;c:\B\test_classes;&lt;br /&gt;c:\B\target_classes;c:\D\3rd_party.jar&lt;br /&gt;&lt;/pre&gt;  &lt;p&gt; If you are running your JUnit tests from a command line on a Unix (bash) system: &lt;/p&gt; &lt;pre&gt;export CLASSPATH=/A/junit-4.4.jar:/B/test_classes:&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt; &lt;b&gt;How Do I Run JUnit Tests from Command Window?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; To run JUnit tests from a command window, you need to check the following list: &lt;/p&gt;  &lt;p&gt; 1. Make sure that JDK is installed and the "java" command program is accessible through the PATH setting. Type "java -version" at the command prompt, you should see the JVM reports you back the version string. &lt;/p&gt;  &lt;p&gt; 2. Make sure that the CLASSPATH is defined as shown in the previous question.  &lt;/p&gt;  &lt;p&gt; 3. Invoke the JUnit runner by entering the following command:  &lt;/p&gt; java org.junit.runner.JUnitCore &lt;test&gt;&lt;br /&gt;&lt;/test&gt;&lt;p&gt; &lt;b&gt;How To Write a JUnit Test Method?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; This interview question is to check if you know the basic rules about writing a JUnit test method: &lt;/p&gt; &lt;ul&gt;&lt;li&gt;You need to mark the method as a JUnit test method with the JUnit annotation: @org.junit.Test.&lt;/li&gt;&lt;li&gt;A JUnit test method must be a "public" method. This allows the runner class to access this method.&lt;/li&gt;&lt;li&gt;A JUnit test method must be a "void" method. The runner class does not check any return values.&lt;/li&gt;&lt;li&gt;A JUnit test should perform one JUnit assertion - calling an org.junit.Assert.assertXXX() method.&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt; Here is a simple JUnit test method: &lt;/p&gt; &lt;pre&gt;import org.junit.*;&lt;br /&gt;// by FYICenter.com&lt;br /&gt;...&lt;br /&gt; @Test public void testHello() {&lt;br /&gt;     String message = "Hello World!";&lt;br /&gt;     Assert.assertEquals(12, message.length());&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt; &lt;b&gt;Can You Provide a List of Assertion Methods Supported by JUnit 4.4?&lt;/b&gt; &lt;/p&gt;  &lt;p&gt; You should be able to answer this question by looking up the org.junit.Assert class API document. Here is a list of assertino methods supported by JUnit 4.4: &lt;/p&gt; &lt;ul&gt;&lt;li&gt;assertEquals(expected, actual)&lt;/li&gt;&lt;li&gt;assertEquals(message, expected, actual)&lt;/li&gt;&lt;li&gt;assertEquals(expected, actual, delta)&lt;/li&gt;&lt;li&gt;assertEquals(message, expected, actual, delta)&lt;/li&gt;&lt;li&gt;assertFalse(condition)&lt;/li&gt;&lt;li&gt;assertFalse(message, condition)&lt;/li&gt;&lt;li&gt;assertNotNull(object)&lt;/li&gt;&lt;li&gt;assertNotNull(message, object)&lt;/li&gt;&lt;li&gt;assertNotSame(expected, actual)&lt;/li&gt;&lt;li&gt;assertNotSame(message, expected, actual)&lt;/li&gt;&lt;li&gt;assertNull(object)&lt;/li&gt;&lt;li&gt;assertNull(message, object)&lt;/li&gt;&lt;li&gt;assertSame(expected, actual)&lt;/li&gt;&lt;li&gt;assertSame(message, expected, actual)&lt;/li&gt;&lt;li&gt;assertTrue(condition)&lt;/li&gt;&lt;li&gt;assertTrue(message, condition)&lt;/li&gt;&lt;li&gt;fail()&lt;/li&gt;&lt;li&gt;fail(message)&lt;/li&gt;&lt;li&gt;failNotEquals(message, expected, actual)&lt;/li&gt;&lt;li&gt;failNotSame(message, expected, actual)&lt;/li&gt;&lt;li&gt;failSame(message)&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Java Doc&lt;/span&gt;&lt;br /&gt;&lt;h2&gt; &lt;span style=""&gt; org.junit&lt;/span&gt;&lt;br /&gt;Class Assert&lt;/h2&gt; java.lang.Object   &lt;img src="http://junit.sourceforge.net/javadoc_40/resources/inherit.gif" alt="extended by " /&gt;&lt;b&gt;org.junit.Assert&lt;/b&gt;  &lt;hr /&gt; &lt;dl&gt;&lt;dt&gt;&lt;pre&gt;public class &lt;b&gt;Assert&lt;/b&gt;&lt;dt&gt;extends java.lang.Object&lt;/dt&gt;&lt;/pre&gt;&lt;/dt&gt;&lt;/dl&gt;   &lt;p&gt; A set of assertion methods useful for writing tests. Only failed assertions are recorded.  These methods can be used directly: &lt;code&gt;Assert.assertEquals(...)&lt;/code&gt;, however, they  read better if they are referenced through static import:&lt;br /&gt;&lt;code&gt;    import static org.junit.Assert.*;&lt;br /&gt;  ...&lt;br /&gt;    assertEquals(...);&lt;br /&gt;  &lt;/code&gt; &lt;/p&gt;&lt;p&gt;  &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;See Also:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;AssertionError&lt;/code&gt;&lt;/dd&gt;&lt;/dl&gt;&lt;table summary="" border="1" cellpadding="3" cellspacing="0" width="100%"&gt;&lt;tbody&gt;&lt;tr class="TableSubHeadingColor" bgcolor="#eeeeff"&gt;&lt;th align="left"&gt;&lt;br /&gt;&lt;/th&gt; &lt;/tr&gt; &lt;tr class="TableRowColor" bgcolor="white"&gt; &lt;td&gt;&lt;br /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;   &lt;p&gt;  &lt;!-- ========= CONSTRUCTOR DETAIL ======== --&gt;  &lt;a name="constructor_detail"&gt;&lt;!-- --&gt;&lt;/a&gt; &lt;/p&gt;&lt;table summary="" border="1" cellpadding="3" cellspacing="0" width="100%"&gt; &lt;tbody&gt;&lt;tr class="TableHeadingColor" bg="" style="color: rgb(204, 204, 255);"&gt; &lt;th colspan="1" align="left"&gt;&lt;span style="font-size:85%;"&gt; &lt;b&gt;Constructor Detail&lt;/b&gt;&lt;/span&gt;&lt;/th&gt; &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;a name="Assert()"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; Assert&lt;/h3&gt; protected &lt;b&gt;Assert&lt;/b&gt;() &lt;dl&gt;&lt;dd&gt;Protect constructor since it is a static only class &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;/dl&gt;  &lt;!-- ============ METHOD DETAIL ========== --&gt;  &lt;a name="method_detail"&gt;&lt;!-- --&gt;&lt;/a&gt; &lt;table summary="" border="1" cellpadding="3" cellspacing="0" width="100%"&gt; &lt;tbody&gt;&lt;tr class="TableHeadingColor" bg="" style="color: rgb(204, 204, 255);"&gt; &lt;th colspan="1" align="left"&gt;&lt;span style="font-size:85%;"&gt; &lt;b&gt;Method Detail&lt;/b&gt;&lt;/span&gt;&lt;/th&gt; &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;a name="assertTrue(java.lang.String, boolean)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; assertTrue&lt;/h3&gt; public static void &lt;b&gt;assertTrue&lt;/b&gt;(java.lang.String message,                               boolean condition) &lt;dl&gt;&lt;dd&gt;Asserts that a condition is true. If it isn't it throws an  &lt;code&gt;AssertionError&lt;/code&gt; with the given message. &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;message&lt;/code&gt; - the identifying message or &lt;code&gt;null&lt;/code&gt; for the &lt;code&gt;AssertionError&lt;/code&gt;&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;condition&lt;/code&gt; - condition to be checked&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="assertTrue(boolean)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; assertTrue&lt;/h3&gt; public static void &lt;b&gt;assertTrue&lt;/b&gt;(boolean condition) &lt;dl&gt;&lt;dd&gt;Asserts that a condition is true. If it isn't it throws an  &lt;code&gt;AssertionError&lt;/code&gt; without a message. &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;condition&lt;/code&gt; - condition to be checked&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="assertFalse(java.lang.String, boolean)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; assertFalse&lt;/h3&gt; public static void &lt;b&gt;assertFalse&lt;/b&gt;(java.lang.String message,                                boolean condition) &lt;dl&gt;&lt;dd&gt;Asserts that a condition is false. If it isn't it throws an  &lt;code&gt;AssertionError&lt;/code&gt; with the given message. &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;message&lt;/code&gt; - the identifying message or &lt;code&gt;null&lt;/code&gt; for the &lt;code&gt;AssertionError&lt;/code&gt;&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;condition&lt;/code&gt; - condition to be checked&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="assertFalse(boolean)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; assertFalse&lt;/h3&gt; public static void &lt;b&gt;assertFalse&lt;/b&gt;(boolean condition) &lt;dl&gt;&lt;dd&gt;Asserts that a condition is false. If it isn't it throws an  &lt;code&gt;AssertionError&lt;/code&gt; without a message. &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;condition&lt;/code&gt; - condition to be checked&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="fail(java.lang.String)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; fail&lt;/h3&gt; public static void &lt;b&gt;fail&lt;/b&gt;(java.lang.String message) &lt;dl&gt;&lt;dd&gt;Fails a test with the given message. &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;message&lt;/code&gt; - the identifying message or &lt;code&gt;null&lt;/code&gt; for the &lt;code&gt;AssertionError&lt;/code&gt;&lt;/dd&gt;&lt;dt&gt;&lt;b&gt;See Also:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;AssertionError&lt;/code&gt;&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="fail()"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; fail&lt;/h3&gt; public static void &lt;b&gt;fail&lt;/b&gt;() &lt;dl&gt;&lt;dd&gt;Fails a test with no message. &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;br /&gt;&lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="assertEquals(java.lang.String, java.lang.Object, java.lang.Object)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; assertEquals&lt;/h3&gt; public static void &lt;b&gt;assertEquals&lt;/b&gt;(java.lang.String message,                                 java.lang.Object expected,                                 java.lang.Object actual) &lt;dl&gt;&lt;dd&gt;Asserts that two objects are equal. If they are not, an  &lt;code&gt;AssertionError&lt;/code&gt; is thrown with the given message. &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;message&lt;/code&gt; - the identifying message or &lt;code&gt;null&lt;/code&gt; for the &lt;code&gt;AssertionError&lt;/code&gt;&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;expected&lt;/code&gt; - expected value&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;actual&lt;/code&gt; - actual value&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="assertEquals(java.lang.Object, java.lang.Object)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; assertEquals&lt;/h3&gt; public static void &lt;b&gt;assertEquals&lt;/b&gt;(java.lang.Object expected,                                 java.lang.Object actual) &lt;dl&gt;&lt;dd&gt;Asserts that two objects are equal. If they are not, an  &lt;code&gt;AssertionError&lt;/code&gt; without a message is thrown. &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;expected&lt;/code&gt; - expected value&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;actual&lt;/code&gt; - the value to check against &lt;code&gt;expected&lt;/code&gt;&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="assertEquals(java.lang.String, java.lang.Object[], java.lang.Object[])"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; assertEquals&lt;/h3&gt; public static void &lt;b&gt;assertEquals&lt;/b&gt;(java.lang.String message,                                 java.lang.Object[] expecteds,                                 java.lang.Object[] actuals) &lt;dl&gt;&lt;dd&gt;Asserts that two object arrays are equal. If they are not, an  &lt;code&gt;AssertionError&lt;/code&gt; is thrown with the given message. &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;message&lt;/code&gt; - the identifying message or &lt;code&gt;null&lt;/code&gt; for the &lt;code&gt;AssertionError&lt;/code&gt;&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;expecteds&lt;/code&gt; - Object array or array of arrays (multi-dimensional array) with expected values&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;actuals&lt;/code&gt; - Object array or array of arrays (multi-dimensional array) with actual values&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="assertEquals(java.lang.Object[], java.lang.Object[])"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; assertEquals&lt;/h3&gt; public static void &lt;b&gt;assertEquals&lt;/b&gt;(java.lang.Object[] expecteds,                                 java.lang.Object[] actuals) &lt;dl&gt;&lt;dd&gt;Asserts that two object arrays are equal. If they are not, an  &lt;code&gt;AssertionError&lt;/code&gt; is thrown. &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;expecteds&lt;/code&gt; - Object array or array of arrays (multi-dimensional array) with expected values&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;actuals&lt;/code&gt; - Object array or array of arrays (multi-dimensional array) with actual values&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="assertEquals(java.lang.String, double, double, double)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; assertEquals&lt;/h3&gt; public static void &lt;b&gt;assertEquals&lt;/b&gt;(java.lang.String message,                                 double expected,                                 double actual,                                 double delta) &lt;dl&gt;&lt;dd&gt;Asserts that two doubles are equal to within a positive delta. If they  are not, an &lt;code&gt;AssertionError&lt;/code&gt; is thrown with the given message. If the  expected value is infinity then the delta value is ignored. NaNs are  considered equal:  &lt;code&gt;assertEquals(Double.NaN, Double.NaN, *)&lt;/code&gt; passes &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;message&lt;/code&gt; - the identifying message or &lt;code&gt;null&lt;/code&gt; for the &lt;code&gt;AssertionError&lt;/code&gt;&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;expected&lt;/code&gt; - expected value&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;actual&lt;/code&gt; - the value to check against &lt;code&gt;expected&lt;/code&gt;&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;delta&lt;/code&gt; - the maximum delta between &lt;code&gt;expected&lt;/code&gt; and &lt;code&gt;actual&lt;/code&gt; for which   both numbers are still considered equal.&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="assertEquals(double, double, double)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; assertEquals&lt;/h3&gt; public static void &lt;b&gt;assertEquals&lt;/b&gt;(double expected,                                 double actual,                                 double delta) &lt;dl&gt;&lt;dd&gt;Asserts that two doubles are equal to within a positive delta. If they  are not, an &lt;code&gt;AssertionError&lt;/code&gt; is thrown. If the  expected value is infinity then the delta value is ignored.NaNs are  considered equal:  &lt;code&gt;assertEquals(Double.NaN, Double.NaN, *)&lt;/code&gt; passes &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;expected&lt;/code&gt; - expected value&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;actual&lt;/code&gt; - the value to check against &lt;code&gt;expected&lt;/code&gt;&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;delta&lt;/code&gt; - the maximum delta between &lt;code&gt;expected&lt;/code&gt; and &lt;code&gt;actual&lt;/code&gt; for which   both numbers are still considered equal.&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="assertEquals(java.lang.String, float, float, float)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; assertEquals&lt;/h3&gt; public static void &lt;b&gt;assertEquals&lt;/b&gt;(java.lang.String message,                                 float expected,                                 float actual,                                 float delta) &lt;dl&gt;&lt;dd&gt;Asserts that two floats are equal to within a positive delta. If they  are not, an &lt;code&gt;AssertionError&lt;/code&gt; is thrown with the given message. If the  expected value is infinity then the delta value is ignored.NaNs are  considered equal:  &lt;code&gt;assertEquals(Float.NaN, Float.NaN, *)&lt;/code&gt; passes &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;message&lt;/code&gt; - the identifying message or &lt;code&gt;null&lt;/code&gt; for the &lt;code&gt;AssertionError&lt;/code&gt;&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;expected&lt;/code&gt; - the expected float value&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;actual&lt;/code&gt; - the float value to check against &lt;code&gt;expected&lt;/code&gt;&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;delta&lt;/code&gt; - the maximum delta between &lt;code&gt;expected&lt;/code&gt; and &lt;code&gt;actual&lt;/code&gt; for which   both numbers are still considered equal.&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="assertEquals(float, float, float)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; assertEquals&lt;/h3&gt; public static void &lt;b&gt;assertEquals&lt;/b&gt;(float expected,                                 float actual,                                 float delta) &lt;dl&gt;&lt;dd&gt;Asserts that two floats are equal to within a positive delta. If they  are not, an &lt;code&gt;AssertionError&lt;/code&gt; is thrown. If the  expected value is infinity then the delta value is ignored. &lt;code&gt;NaNs&lt;/code&gt; are  considered equal:  &lt;code&gt;assertEquals(Float.NaN, Float.NaN, *)&lt;/code&gt; passes &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;expected&lt;/code&gt; - the expected value&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;actual&lt;/code&gt; - the value to check against &lt;code&gt;expected&lt;/code&gt;&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;delta&lt;/code&gt; - the maximum delta between &lt;code&gt;expected&lt;/code&gt; and &lt;code&gt;actual&lt;/code&gt; for which   both numbers are still considered equal.&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="assertNotNull(java.lang.String, java.lang.Object)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; assertNotNull&lt;/h3&gt; public static void &lt;b&gt;assertNotNull&lt;/b&gt;(java.lang.String message,                                  java.lang.Object object) &lt;dl&gt;&lt;dd&gt;Asserts that an object isn't null. If it is an &lt;code&gt;AssertionError&lt;/code&gt; is  thrown with the given message. &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;message&lt;/code&gt; - the identifying message or &lt;code&gt;null&lt;/code&gt; for the &lt;code&gt;AssertionError&lt;/code&gt;&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;object&lt;/code&gt; - Object to check or &lt;code&gt;null&lt;/code&gt;&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="assertNotNull(java.lang.Object)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; assertNotNull&lt;/h3&gt; public static void &lt;b&gt;assertNotNull&lt;/b&gt;(java.lang.Object object) &lt;dl&gt;&lt;dd&gt;Asserts that an object isn't null. If it is an &lt;code&gt;AssertionError&lt;/code&gt; is  thrown. &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;object&lt;/code&gt; - Object to check or &lt;code&gt;null&lt;/code&gt;&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="assertNull(java.lang.String, java.lang.Object)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; assertNull&lt;/h3&gt; public static void &lt;b&gt;assertNull&lt;/b&gt;(java.lang.String message,                               java.lang.Object object) &lt;dl&gt;&lt;dd&gt;Asserts that an object is null. If it is not, an &lt;code&gt;AssertionError&lt;/code&gt; is  thrown with the given message. &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;message&lt;/code&gt; - the identifying message or &lt;code&gt;null&lt;/code&gt; for the &lt;code&gt;AssertionError&lt;/code&gt;&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;object&lt;/code&gt; - Object to check or &lt;code&gt;null&lt;/code&gt;&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="assertNull(java.lang.Object)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; assertNull&lt;/h3&gt; public static void &lt;b&gt;assertNull&lt;/b&gt;(java.lang.Object object) &lt;dl&gt;&lt;dd&gt;Asserts that an object is null. If it isn't an &lt;code&gt;AssertionError&lt;/code&gt; is  thrown. &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;object&lt;/code&gt; - Object to check or &lt;code&gt;null&lt;/code&gt;&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="assertSame(java.lang.String, java.lang.Object, java.lang.Object)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; assertSame&lt;/h3&gt; public static void &lt;b&gt;assertSame&lt;/b&gt;(java.lang.String message,                               java.lang.Object expected,                               java.lang.Object actual) &lt;dl&gt;&lt;dd&gt;Asserts that two objects refer to the same object. If they are not, an  &lt;code&gt;AssertionError&lt;/code&gt; is thrown with the given message. &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;message&lt;/code&gt; - the identifying message or &lt;code&gt;null&lt;/code&gt; for the &lt;code&gt;AssertionError&lt;/code&gt;&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;expected&lt;/code&gt; - the expected object&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;actual&lt;/code&gt; - the object to compare to &lt;code&gt;expected&lt;/code&gt;&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="assertSame(java.lang.Object, java.lang.Object)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; assertSame&lt;/h3&gt; public static void &lt;b&gt;assertSame&lt;/b&gt;(java.lang.Object expected,                               java.lang.Object actual) &lt;dl&gt;&lt;dd&gt;Asserts that two objects refer to the same object. If they are not the  same, an &lt;code&gt;AssertionError&lt;/code&gt; without a message is thrown. &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;expected&lt;/code&gt; - the expected object&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;actual&lt;/code&gt; - the object to compare to &lt;code&gt;expected&lt;/code&gt;&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="assertNotSame(java.lang.String, java.lang.Object, java.lang.Object)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; assertNotSame&lt;/h3&gt; public static void &lt;b&gt;assertNotSame&lt;/b&gt;(java.lang.String message,                                  java.lang.Object unexpected,                                  java.lang.Object actual) &lt;dl&gt;&lt;dd&gt;Asserts that two objects do not refer to the same object. If they do  refer to the same object, an &lt;code&gt;AssertionError&lt;/code&gt; is thrown with the given  message. &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;message&lt;/code&gt; - the identifying message or &lt;code&gt;null&lt;/code&gt; for the &lt;code&gt;AssertionError&lt;/code&gt;&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;unexpected&lt;/code&gt; - the object you don't expect&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;actual&lt;/code&gt; - the object to compare to &lt;code&gt;unexpected&lt;/code&gt;&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt; &lt;hr /&gt;  &lt;a name="assertNotSame(java.lang.Object, java.lang.Object)"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;h3&gt; assertNotSame&lt;/h3&gt; public static void &lt;b&gt;assertNotSame&lt;/b&gt;(java.lang.Object unexpected,                                  java.lang.Object actual) &lt;dl&gt;&lt;dd&gt;Asserts that two objects do not refer to the same object. If they do  refer to the same object, an &lt;code&gt;AssertionError&lt;/code&gt; without a message is thrown. &lt;p&gt; &lt;/p&gt;&lt;/dd&gt;&lt;dd&gt;&lt;dl&gt;&lt;dt&gt;&lt;b&gt;Parameters:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&lt;code&gt;unexpected&lt;/code&gt; - the object you don't expect&lt;/dd&gt;&lt;dd&gt;&lt;code&gt;actual&lt;/code&gt; - the object to compare to &lt;code&gt;unexpected&lt;/code&gt;&lt;/dd&gt;&lt;/dl&gt; &lt;/dd&gt;&lt;/dl&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-4572601738071639680?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/4572601738071639680/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=4572601738071639680' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/4572601738071639680'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/4572601738071639680'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/06/junit-1.html' title='Junit 1'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-8433934242200072515</id><published>2008-06-25T13:24:00.001-07:00</published><updated>2008-06-25T13:24:34.754-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Singleton Design Pattern'/><title type='text'>Singleton Design Pattern</title><content type='html'>&lt;h1&gt;Simply Singleton&lt;/h1&gt;                      &lt;h3&gt;Navigate the deceptively simple Singleton pattern&lt;/h3&gt;                      &lt;p class="byline"&gt;By David Geary, JavaWorld.com, 04/25/03&lt;/p&gt;                                            &lt;!-- CONTENT GOES HERE--&gt;                                               &lt;p class="first"&gt;Sometimes it's appropriate to have exactly one instance of a class: window managers, print spoolers, and filesystems are prototypical examples. Typically, those types of objects—known as singletons—are accessed by disparate objects throughout a software system, and therefore require a global point of access. Of course, just when you're certain you will never need more than one instance, it's a good bet you'll change your mind. &lt;/p&gt;                      &lt;p&gt;The Singleton design pattern addresses all of the previous paragraph's concerns. With the Singleton design pattern you can:&lt;/p&gt;                      &lt;ul&gt;&lt;li&gt;Ensure that only one instance of a class is created&lt;/li&gt;&lt;li&gt;Provide a global point of access to the object&lt;/li&gt;&lt;li&gt;Allow multiple instances in the future without affecting a singleton class's clients&lt;/li&gt;&lt;/ul&gt;                      &lt;p&gt;Although the Singleton design pattern—as evidenced below by the figure below—is one of the simplest design patterns, it presents a number of pitfalls for the unwary Java developer. This article discusses the Singleton design pattern and addresses those pitfalls. &lt;/p&gt;                      &lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You can download this article's source code from &lt;a href="http://www.javaworld.com/javaworld/jw-04-2003/jw-0425-designpatterns.html#resources"&gt;Resources&lt;/a&gt;.                      &lt;/p&gt;                      &lt;h3&gt;The Singleton pattern&lt;/h3&gt;                      &lt;p&gt;In &lt;a href="http://www.javaworld.com/javaworld/jw-04-2003/jw-0425-designpatterns.html#resources"&gt;&lt;em&gt;Design Patterns&lt;/em&gt;&lt;/a&gt;, the authors describe the Singleton pattern like this:                      &lt;/p&gt;                      &lt;blockquote&gt;Ensure a class has only one instance, and provide a global point of access to it.&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;                      &lt;p&gt;The figure below illustrates the Singleton design pattern class diagram.&lt;/p&gt;                      &lt;center&gt;                         &lt;p&gt;&lt;img src="http://www.javaworld.com/javaworld/jw-04-2003/images/jw-0425-designpatterns1.jpg" height="108" width="434" /&gt;&lt;/p&gt;                         &lt;p&gt;&lt;strong&gt;Singleton class diagram&lt;/strong&gt;&lt;/p&gt;                      &lt;/center&gt;                      &lt;p&gt;As you can see from the figure above, there's not a whole lot to the Singleton design pattern. Singletons maintain a static                         reference to the sole singleton instance and return a reference to that instance from a static &lt;code&gt;instance()&lt;/code&gt; method.                      &lt;/p&gt;                      &lt;p&gt;Example 1 shows a classic Singleton design pattern implementation:&lt;/p&gt;                      &lt;h4&gt;Example 1. The classic singleton&lt;/h4&gt;                      &lt;div id="codewrap"&gt;                         &lt;div id="codewrap27"&gt;&lt;pre&gt;public class ClassicSingleton {&lt;br /&gt;  private static ClassicSingleton instance = null;&lt;br /&gt;  protected ClassicSingleton() {&lt;br /&gt;     // Exists only to defeat instantiation.&lt;br /&gt;  }&lt;br /&gt;  public static ClassicSingleton getInstance() {&lt;br /&gt;     if(instance == null) {&lt;br /&gt;        instance = new ClassicSingleton();&lt;br /&gt;     }&lt;br /&gt;     return instance;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;                      &lt;/div&gt;&lt;br /&gt;&lt;br /&gt;                      &lt;p&gt;The singleton implemented in Example 1 is easy to understand. The &lt;code&gt;ClassicSingleton&lt;/code&gt; class maintains a static reference to the lone singleton instance and returns that reference from the static &lt;code&gt;getInstance()&lt;/code&gt; method.                      &lt;/p&gt;                      &lt;p&gt;There are several interesting points concerning the &lt;code&gt;ClassicSingleton&lt;/code&gt; class. First, &lt;code&gt;ClassicSingleton&lt;/code&gt; employs a technique known as &lt;em&gt;lazy instantiation&lt;/em&gt; to create the singleton; as a result, the singleton instance is not created until the &lt;code&gt;getInstance()&lt;/code&gt; method is called for the first time. This technique ensures that singleton instances are created only when needed.                      &lt;/p&gt;                      &lt;p&gt;Second, notice that &lt;code&gt;ClassicSingleton&lt;/code&gt; implements a protected constructor so clients cannot instantiate &lt;code&gt;ClassicSingleton&lt;/code&gt; instances; however, you may be surprised to discover that the following code is perfectly legal:                      &lt;/p&gt;                      &lt;div id="codewrap"&gt;                         &lt;div id="codewrap41"&gt;&lt;pre&gt;public class SingletonInstantiator {&lt;br /&gt; public SingletonInstantiator() {&lt;br /&gt;  ClassicSingleton instance = ClassicSingleton.getInstance();&lt;br /&gt;&lt;strong&gt;ClassicSingleton anotherInstance =&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;new ClassicSingleton();&lt;/strong&gt;&lt;br /&gt;      ...&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;                      &lt;/div&gt;&lt;br /&gt;&lt;br /&gt;                      &lt;p&gt;How can the class in the preceding code fragment—which does not extend &lt;code&gt;ClassicSingleton&lt;/code&gt;—create a &lt;code&gt;ClassicSingleton&lt;/code&gt; instance if the &lt;code&gt;ClassicSingleton&lt;/code&gt; constructor is protected? The answer is that protected constructors can be called by subclasses and &lt;em&gt;by other classes in the same package&lt;/em&gt;. Because &lt;code&gt;ClassicSingleton&lt;/code&gt; and &lt;code&gt;SingletonInstantiator&lt;/code&gt; are in the same package (the default package), &lt;code&gt;SingletonInstantiator()&lt;/code&gt; methods can create &lt;code&gt;ClassicSingleton&lt;/code&gt; instances. This dilemma has two solutions: You can make the &lt;code&gt;ClassicSingleton&lt;/code&gt; constructor private so that only &lt;code&gt;ClassicSingleton()&lt;/code&gt; methods call it; however, that means &lt;code&gt;ClassicSingleton&lt;/code&gt; cannot be subclassed. Sometimes, that is a desirable solution; if so, it's a good idea to declare your singleton class &lt;code&gt;final&lt;/code&gt;, which makes that intention explicit and allows the compiler to apply performance optimizations. The other solution is to put your singleton class in an explicit package, so classes in other packages (including the default package) cannot instantiate singleton instances. &lt;/p&gt;                      &lt;p&gt;A third interesting point about &lt;code&gt;ClassicSingleton&lt;/code&gt;: it's possible to have multiple singleton instances if classes loaded by different classloaders access a singleton. That scenario is not so far-fetched; for example, some servlet containers use distinct classloaders for each servlet, so if two servlets access a singleton, they will each have their own instance. &lt;/p&gt;                      &lt;p&gt;Fourth, if &lt;code&gt;ClassicSingleton&lt;/code&gt; implements the &lt;code&gt;java.io.Serializable&lt;/code&gt; interface, the class's instances can be serialized and deserialized. However, if you serialize a singleton object and subsequently deserialize that object more than once, you will have multiple singleton instances. &lt;/p&gt;                      &lt;p&gt;Finally, and perhaps most important, Example 1's &lt;code&gt;ClassicSingleton&lt;/code&gt; class is not thread-safe. If two threads—we'll call them Thread 1 and Thread 2—call &lt;code&gt;ClassicSingleton.getInstance()&lt;/code&gt; at the same time, two &lt;code&gt;ClassicSingleton&lt;/code&gt; instances can be created if Thread 1 is preempted just after it enters the &lt;code&gt;if&lt;/code&gt; block and control is subsequently given to Thread 2.                      &lt;/p&gt;                      &lt;p&gt;As you can see from the preceding discussion, although the Singleton pattern is one of the simplest design patterns, implementing it in Java is anything but simple. The rest of this article addresses Java-specific considerations for the Singleton pattern, but first let's take a short detour to see how you can test your singleton classes. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-8433934242200072515?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/8433934242200072515/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=8433934242200072515' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/8433934242200072515'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/8433934242200072515'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/06/singleton-design-pattern.html' title='Singleton Design Pattern'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-1427207482781108457</id><published>2008-06-25T08:24:00.000-07:00</published><updated>2008-06-25T08:30:24.592-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='links'/><title type='text'>links</title><content type='html'>Deploying &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;WebLogic&lt;/span&gt; Server Applications&lt;br /&gt;http://e-docs.bea.com/wls/docs81/deployment/scenarios.html#1014366&lt;br /&gt;&lt;br /&gt;&lt;h1 style="font-weight: normal;" class="booktitle"&gt;&lt;span style="font-size:85%;"&gt;Understanding Domain  Configuration&lt;/span&gt;&lt;/h1&gt;&lt;h1 style="font-weight: normal;" class="booktitle"&gt;&lt;span style="font-size:85%;"&gt;http://edocs.bea.com/wls/docs92/domain_config/understand_domains.html&lt;/span&gt;&lt;br /&gt;&lt;/h1&gt;&lt;span style="font-size:85%;"&gt;Using &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;WebLogic&lt;/span&gt; Server  Clusters&lt;br /&gt;http://edocs.bea.com/wls/docs92/cluster/overview.html&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);font-size:85%;color:#ffffff;"  &gt;&lt;b&gt;Troubleshooting Deployment Issues&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;https://support.bea.com/application_content/product_portlets/support_patterns/wls/TroubleshootingDeploymentIssuesPattern.html#Types_of_deployable_applications_and&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Deploying WebLogic Server Applications&lt;br /&gt;&lt;br /&gt;http://e-docs.bea.com/wls/docs81/deployment/tools.html#999152&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;SQL Interview Questions with Answers&lt;br /&gt;&lt;/h3&gt;http://www.geekinterview.com/articles/sql-interview-questions-with-answers.html&lt;br /&gt;&lt;br /&gt;Deploying WebLogic Server Applications&lt;br /&gt;&lt;br /&gt;http://e-docs.bea.com/wls/docs81/deployment/tools.html&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-1427207482781108457?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/1427207482781108457/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=1427207482781108457' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/1427207482781108457'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/1427207482781108457'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/06/links.html' title='links'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-8976603181549846783</id><published>2008-06-24T06:04:00.000-07:00</published><updated>2008-06-24T06:07:32.841-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Running multiple Tomcat instances on one server'/><title type='text'>Running multiple Tomcat instances on one server</title><content type='html'>&lt;p&gt;Here's a brief step by step guide to running more than one instance of Tomcat on a single machine.&lt;/p&gt;  &lt;h4&gt;Step 1: Install the Tomcat files&lt;/h4&gt; &lt;p&gt;Download Tomcat &lt;a href="http://tomcat.apache.org/download-41.cgi"&gt;4.1&lt;/a&gt; or &lt;a href="http://tomcat.apache.org/download-55.cgi"&gt;5.5&lt;/a&gt;, and unzip it into an appropriate directory. I usually put it in /usr/local, so it ends up in a directory called &lt;em&gt;/usr/local/apache-tomcat-5.5.17&lt;/em&gt; (5.5.17 being the current version as of this writing), and make a symlink named /usr/local/tomcat to that directory. When later versions come out, I can unzip them and relink, leaving the older version in case things don't work out (which rarely if ever happens, but I'm paranoid).&lt;/p&gt; &lt;h4&gt;Step 2: Make directories for each instance&lt;/h4&gt; &lt;p&gt;For each instance of Tomcat you're going to run, you'll need a directory that will be &lt;em&gt;CATALINA_HOME&lt;/em&gt;. For example, you might make them &lt;em&gt;/var/tomcat/serverA&lt;/em&gt; and &lt;em&gt;/var/tomcat/serverB&lt;/em&gt;. &lt;/p&gt; &lt;p&gt;In each of these directories you need the following subdirectories: conf, logs, temp, webapps, and work.&lt;/p&gt; &lt;p&gt;Put a server.xml and web.xml file in the conf directory. You can get these from the conf directory of the directory where you put the tomcat installation files, although of course you should tighten up your server.xml a bit.&lt;/p&gt; &lt;p&gt;The webapps directory is where you'll put the web applications you want to run on the particular instance of Tomcat. &lt;/p&gt; &lt;p&gt;I like to have the Tomcat manager webapp installed on each instance, so I can play with the webapps, and see how many active sessions there are. See my instructions for &lt;a href="http://azeditech.com/tomcat/configurating-tomcat-manager.html"&gt;configuring the Tomcat manager webapp&lt;/a&gt;.&lt;/p&gt; &lt;h4&gt;Step 3: Configure the ports and/or addresses for each instance&lt;/h4&gt; &lt;p&gt;Tomcat listens to at least two network ports, one for the shutdown command, and one or more for accepting requests. Two instances of Tomcat can't listen to the same port number on the same IP address, so you will need to edit your server.xml files to change the ports they listen to.&lt;/p&gt; &lt;p&gt;The first port to look at is the shutdown port. This is used by the command line shutdown script (actually, but the Java code it runs) to tell the Tomcat instance to shut itself down. This port is defined at the top of the server.xml file for the instance.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt; &lt;pre&gt;&lt;server port="8001" shutdown="_SHUTDOWN_COMMAND_" debug="0"&gt;&lt;/server&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-8976603181549846783?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/8976603181549846783/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=8976603181549846783' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/8976603181549846783'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/8976603181549846783'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/06/running-multiple-tomcat-instances-on.html' title='Running multiple Tomcat instances on one server'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-6799924273304067656</id><published>2008-06-23T10:09:00.000-07:00</published><updated>2008-06-23T10:11:29.285-07:00</updated><title type='text'>Weblogic Interview questions -5</title><content type='html'>&lt;span style="font-weight: bold;"&gt;How do I provide user credentials for starting a server?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;When you create a domain, the Configuration Wizard prompts you to provide the username and password for an initial administrative user. If you create the domain in development mode, the wizard saves the username and encrypted password in a boot identity file. A WebLogic Server instance can refer to a boot identity file during its startup process. If a server instance does not find such a file, it prompts you to enter credentials.&lt;br /&gt;&lt;br /&gt;If you create a domain in production mode, or if you want to change user credentials in an existing boot identity file, you can create a new boot identity file.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Can I start a Managed Server if the Administration Server is unavailable?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;By default, if a Managed Server is unable to connect to the specified Administration Server during startup, it can retrieve its configuration by reading a configuration file and other files directly. You cannot change the server's configuration until the Administration Server is available. A Managed Server that starts in this way is running in Managed Server Independence mode.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What is the function of T3 in WebLogic Server?&lt;/span&gt;&lt;br /&gt;T3 provides a framework for WebLogic Server messages that support for enhancements. These enhancements include abbreviations and features, such as object replacement, that work in the context of WebLogic Server clusters and HTTP and other product tunneling. T3 predates Java Object Serialization and RMI, while closely tracking and leveraging these specifications. T3 is a superset of Java Object. Serialization or RMI; anything you can do in Java Object Serialization and RMI can be done over T3. T3 is mandated between WebLogic Servers and between programmatic clients and a WebLogic Server cluster. HTTP and IIOP are optional protocols that can be used to communicate between other processes and WebLogic Server. It depends on what you want to do. For example, when you want to communicate between a browser and WebLogic Server-use HTTP, or an ORB and WebLogic Server-IIOP.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;How do you set the classpath?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;WebLogic Server installs the following script that you can use to set the classpath that a server requires:&lt;br /&gt;WL_HOME\server\bin\setWLSEnv.cmd (on Windows)&lt;br /&gt;WL_HOME/server/bin/setWLSEnv.sh (on UNIX)&lt;br /&gt;&lt;br /&gt;where WL_HOME is the directory in which you installed WebLogic Server.&lt;br /&gt;  &lt;br /&gt;&lt;span style="font-weight: bold;"&gt;How do stubs work in a WebLogic Server cluster?&lt;/span&gt;&lt;br /&gt;Clients that connect to a WebLogic Server cluster and look up a clustered object obtain a replica-aware stub for the object. This stub contains the list of available server instances that host implementations of the object. The stub also contains the load balancing logic for distributing the load among its host servers.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What happens when a failure occurs and the stub cannot connect to a WebLogic Server instance?&lt;/span&gt;&lt;br /&gt;When the failure occurs, the stub removes the failed server instance from its list. If there are no servers left in its list, the stubb uses DNS again to find a running server and obtain a current list of running instances. Also, the stub periodically refreshes its list of available server instances in the cluster; this allows the stub to take advantage of new servers as they are added to the cluster.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;How does a server know when another server is unavailable?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;WebLogic Server uses two mechanisms to determine if a given server instance is unavailable.&lt;br /&gt;&lt;br /&gt;Each WebLogic Server instance in a cluster uses multicast to broadcast regular "heartbeat" messages that advertise its availability. By monitoring heartbeat messages, server instances in a cluster determine when a server instance has failed. The other server instances will drop a server instance from the cluster, if they do not receive three consecutive heartbeats from that server instance&lt;br /&gt;&lt;br /&gt;WebLogic Server also monitors socket errors to determine the availability of a server instance. For example, if server instance A has an open socket to server instance B, and the socket unexpectedly closes, server A assumes that server B is offline.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;How are notifications made when a server is added to a cluster?&lt;/span&gt;&lt;br /&gt;The WebLogic Server cluster broadcasts the availability of a new server instance each time a new instance joins the cluster. Cluster-aware stubs also periodically update their list of available server instances.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;How do clients handle DNS requests to failed servers?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If a server fails and DNS continues to send requests to the unavailable machine, this can waste bandwidth. For a Java client application, this problem occurs only during startup. WebLogic Server caches the DNS entries and removes the unavailable ones, to prevent the client from accessing a failed server twice.&lt;br /&gt;&lt;br /&gt;Failed servers can be more of a problem for browser-based clients, because they always use DNS. To avoid unnecessary DNS requests with browser-based clients, use a third-party load-balancer such as Resonate, BigIP, Alteon, and LocalDirector. These products mask multiple DNS addresses as a single address. They also provide more sophisticated load-balancing options than round-robin, and they keep track of failed servers to avoid routing unnecessary requests.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;How many WebLogic Servers can I have on a multi-cpu machine?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;There are many possible configurations and each has its own advantages and disadvantages. BEA WebLogic Server has no built-in limit for the number of server instances that can reside in a cluster. Large, multi-processor servers such as Sun Microsystems, Inc. Sun Enterprise 10000, therefore, can host very large clusters or multiple clusters.&lt;br /&gt;&lt;br /&gt;In most cases, WebLogic Server clusters scale best when deployed with one WebLogic Server instance for every two CPUs. However, as with all capacity planning, you should test the actual deployment with your target web applications to determine the optimal number and distribution of server instances.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;How can I set deployment order for applications?&lt;/span&gt;&lt;br /&gt;WebLogic Server allows you to select the load order for applications. WebLogic Server deploys server-level resources (first JDBC and then JMS) before deploying applications. Applications are deployed in this order: connectors, then EJBs, then Web Applications. If the application is an EAR, the individual components are loaded in the order in which they are declared in the application.xml deployment descriptor.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Can I refresh static components of a deployed application without having to redeploy the entire application?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Yes. You can use weblogic.Deployer to specify a component and target a server, using the following syntax:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;java weblogic.Deployer -adminurl http://admin:7001 -name appname -targets server1,server2 -deploy jsps/*.jsp&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;When should I use the -nostage option?&lt;/span&gt;&lt;br /&gt;Set the staging mode to -nostage (using weblogic.Deployer or the Administration Console) if you don't want to copy deployment files but want to deploy an application from its present location. All target servers must be able to access the same set of deployment files.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;When should I use the external_stage option?&lt;/span&gt;&lt;br /&gt;Set -external_stage using weblogic.Deployer if you want to stage the application yourself, and prefer to copy it to its target by your own means.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Can I set the deployment order for application modules? For standalone modules?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The Load Order attribute controls the deployment order of standalone modules and applications relative to other modules and applications of the same type. For example, standalone EJBs with smaller Load Order values are deployed before those with higher values.&lt;br /&gt;&lt;br /&gt;Modules that are deployed as part of an Enterprise Application (EAR file or directory) are deployed in the order in which they are specified in the application.xml deployment descriptor.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What is the difference between the WL_HOME/config/examples/applications folder and the WL_HOME/config/examples/stage folder?&lt;/span&gt;&lt;br /&gt;The applications folder is intended for applications that are not yet ready for a production environment. WebLogic Server dynamically deploys the contents of the applications folder. The stage folder (or a folder that you create for the same purpose) is for storing copies of deployment files that are ready for deployment in a production environment (deployments that use the stage or external_stage deployment modes).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;How do I turn the auto-deployment feature off?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The auto-deployment feature checks the applications folder every three seconds to determine whether there are any new applications or any changes to existing applications and then dynamically deploys these changes.&lt;br /&gt;&lt;br /&gt;The auto-deployment feature is enabled for servers that run in development mode. To disable auto-deployment feature, use one of the following methods to place servers in production mode:&lt;br /&gt;&lt;br /&gt;    * In the Administration Console, click the name of the domain in the left pane, then select the Production Mode checkbox in the right pane.&lt;br /&gt;    * At the command line, include the following argument when starting the domain's Administration Server:&lt;br /&gt;&lt;br /&gt;          -Dweblogic.ProductionModeEnabled=true&lt;br /&gt;&lt;br /&gt;Production mode is set for all WebLogic Server instances in a given domain.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Must EJBs be homogeneously deployed across a cluster? Why?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Yes. In WebLogic Server 6.0 and later, EJBs must be homogeneously deployed across a cluster for the following reasons:&lt;br /&gt;&lt;br /&gt;    * To keep clustering EJBs simple&lt;br /&gt;    * To improve performance by avoiding cross-server calls. If EJBs are not deployed on all servers, cross-server calls are more likely.&lt;br /&gt;    * To ensure that every EJB is available locall.y&lt;br /&gt;    * To ensure that all classes are loaded in an undeployable way. Every server must have access to each EJB's classes so that it can be bound into the local JNDI tree. If only a subset of the servers deploys the bean, the other servers will have to load the bean's classes in their respective system classpaths which makes it impossible to undeploy the beans.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-6799924273304067656?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/6799924273304067656/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=6799924273304067656' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/6799924273304067656'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/6799924273304067656'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/06/weblogic-interview-questions-5.html' title='Weblogic Interview questions -5'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-8516114003501745646</id><published>2008-06-23T09:53:00.000-07:00</published><updated>2008-06-23T10:01:50.796-07:00</updated><title type='text'>Weblogic Interview questions -4</title><content type='html'>&lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;Why do I get an exception when trying to find a connection factory?&lt;/span&gt;&lt;/b&gt;&lt;span class="answers"&gt;&lt;br /&gt;The exception is usually something like java.io.InvalidClassException or java.lang.NoClassDefFoundError.&lt;br /&gt;Make sure weblogic.jar is in the CLASSPATH of the client. Also make sure you have the correct Java run-time jar files included (i.e., you might need rt.jar).&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;What can I do when I get java.lang.OutOfMemoryError because producers are faster than consumers?&lt;/span&gt;&lt;/b&gt;&lt;span class="answers"&gt;&lt;br /&gt;Quotas can be used to help this situation. Your sender will then receive ResourceAllocationExceptions and the server will stay up. WLS 6.X does not support paging of messages out of memory.&lt;br /&gt;As of WLS 6.1 SP02 or later, you can use the Message Paging feature, which can free up valuable virtual memory during peak message load periods by swapping out messages from virtual memory to persistent storage when message loads reach a specified threshold.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;Which of the following is NOT true about deploying EJBs in the WebLogic Server?&lt;/span&gt;&lt;br /&gt;a. The weblogic/config/examples/applications directory acts as an automatic deployment directory for EJB 2.0 .jar files and EJB .jar deployment directories&lt;br /&gt;b. The automatic redeployment feature of the WebLogic Server can only redeploy an EJB's implementation classes, you cannot redeploy an EJB's public interfaces&lt;br /&gt;c. Before deploying a packaged jar file containing uncompiled EJB classes and interfaces, we have to use weblogic.ejbc on the packaged .jar file to generate WebLogic Server container classes.&lt;/b&gt;&lt;br /&gt;&lt;span class="answers"&gt;&lt;br /&gt;Choice C is correct because it is NOT true. A and B are true about deploying EJBs in the WebLogic server. The weblogic/config/examples/applications directory acts as an automatic deployment directory for EJB 2.0 .jar files and EJB .jar deployment directories. When you start WebLogic Server, it automatically deploys any valid EJB 2.0 .jar files or .jar directories that reside in the applications directory. WebLogic Server also checks the contents of applications every ten seconds to determine whether an EJB deployment has changed. If a deployment has changed, it is automatically redeployed using the dynamic deployment feature.&lt;br /&gt;If you change the contents of a compiled EJB .jar file in applications, WebLogic Server automatically attempts to redeploy the .jar using the dynamic deployment feature. Since the automatic redeployment feature uses dynamic deployment, WebLogic Server can only redeploy an EJB's implementation classes. You cannot redeploy an EJB's public interfaces. You create compiled EJB 2.0 .jar files by Compiling your EJB classes and interfaces, packaging the EJB classes and interfaces into a valid .jar file and then Using weblogic.ejbc on the .jar file to generate WebLogic Server container classes. An uncompiled EJB .jar file has the same structure as a compiled file, but you do not have to compile individual class files and interfaces and you do not have to use weblogic.ejbc on the packaged .jar file to generate WebLogic Server container classes. So C is not true.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;How do I increase WebLogic Server memory?&lt;/span&gt;&lt;/b&gt;&lt;span class="answers"&gt;&lt;br /&gt;Increase the allocation of Java heap memory for WebLogic Server. (Set the minimum and the maximum to the same size.) Start WebLogic Server with the -ms32m option to increase the allocation, as in this example:&lt;br /&gt;$ java ... -ms32m -mx32m ...&lt;br /&gt;This allocates 32 megabytes of Java heap memory to WebLogic Server, which improves performance and allows WebLogic Server to handle more simultaneous connections. You can increase this value if necessary.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;What is error "ORA-6502?"&lt;/span&gt;&lt;/b&gt;&lt;span class="answers"&gt;&lt;br /&gt;The default length of a string bound to an OUTPUT parameter of a CallableStatement is 128 characters. If the value you assign to the bound parameter exceeds that length, you will get this error.&lt;br /&gt;You can adjust the length of the value of the bound parameter by passing an explicit length with the scale argument to the CallableStatement.registerOutputParameter() method.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;How can I control on which WebLogic Server(s) my application will run?&lt;span class="answers"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span class="answers"&gt;A system administrator can specify on which WebLogic Server(s) applications will run by specifying targets when configuring connection factories. Each connection factory can be deployed on multiple WebLogic servers.&lt;br /&gt;Note: If you use the default connection factory, you have no control over the WebLogic server on which the connection factory may be deployed. If you would like to target a particular WebLogic server, create a new connection factory and specify the appropriate JMS server target(s).&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;Which of the statements below is true for a web application using session management?&lt;/span&gt;&lt;br /&gt;a.) The session object is invalidated, when the session times out.&lt;br /&gt;b.) The session object is invalidated, when sessionInvalidate() method of HttpSession is invoked.&lt;br /&gt;a. Both of the above statements are true.&lt;br /&gt;b. Only statement a.) is true.&lt;br /&gt;c. Only statement b.) is true.&lt;br /&gt;d. None of the above statements is true.&lt;/b&gt;&lt;br /&gt;&lt;span class="answers"&gt;&lt;br /&gt;B is the correct choice. The session object will become invalid in either of the following scenarios:&lt;br /&gt;a.) When the session times out.&lt;br /&gt;b.) When invalidate() method of the HttpSession interface is invoked.&lt;br /&gt;Please note that invalidate() and not sessionInvalidate() is the method of HttpSession interface. Thus choice B is correct.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;How do I identify the document type of an XML document?&lt;/span&gt;&lt;/b&gt;&lt;span class="answers"&gt;&lt;br /&gt;If the XML document has a Public ID, then that is its document type. For example, if an XML document contains the following DOCTYPE declaration:&lt;br /&gt;&lt;!DOCTYPE mydoc PUBLIC "My public ID String"&lt;br /&gt;"http://foo.com/url/to/my/dtd"&gt;&lt;br /&gt;&lt;br /&gt;then its document type is My public ID String.&lt;br /&gt;&lt;br /&gt;If the DOCTYPE declaration does not contain a Public ID, but specifies a System ID, then the document type is the System ID. For example, in the following DOCTYPE declaration:&lt;br /&gt;&lt;!DOCTYPE mydoc SYSTEM "http://foo.com/url/to/my/dtd"&gt;&lt;br /&gt;the document type is http://foo.com/url/to/my/dtd.&lt;br /&gt;Note: The System ID is of the DTD, not of the XML document itself. It can, however, still be used as a way to identify the XML document.&lt;br /&gt;If the XML document does not specify a DOCTYPE declaration, then the document type can be either the root element name or the namespace URI, if it has one.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;How can I run multiple instances of the same servlet class in the same WebLogic Server instance?&lt;/span&gt;&lt;/b&gt;&lt;span class="answers"&gt;&lt;br /&gt;If you want to run multiple instances, your servlet will have to implement the SingleThreadModel interface. An instance of a class that implements the SingleThreadModel interface is guaranteed not to be invoked by multiple threads simultaneously. Multiple instances of a SingleThreadModel interface are used to service simultaneous requests, each running in a single thread.&lt;br /&gt;When designing your servlet, consider how you use shared resources outside of the servlet class such as file and database access. Because there are multiple instances of servlets that are identical, and may use exactly the same resources, there are still synchronization and sharing issues that must be resolved, even if you do implement the SingleThreadModel interface.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;How do I restrict access to servlets and JSPs?&lt;/span&gt;&lt;span class="answers"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;span class="answers"&gt;The Java Servlet API Specification v2.2 allows you to declaratively restrict access to specific Servlets and JSPs using the Web Application Deployment descriptor. Section 13.3.2 of the specification has an example deployment descriptor that uses declarative security. For more information, see Programming WebLogic HTTP Servlets.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;How do I protect WebLogic Server from security attacks from bogus clients using the WL-Proxy-Client-Cert header?&lt;/span&gt;&lt;/b&gt;&lt;span class="answers"&gt;&lt;br /&gt;The WL-Proxy-Client-Cert header can be spoofed (used) by any client which has direct access to WebLogic Server. WebLogic Server takes the certificate information from that header, trusting that is came from a secure source (the plug-in) and use that information to authenticate the user. In previous releases of WebLogic Server, the default behavior was to always trust that header. Now you need to explicitly define trust of the WL-Proxy-Client-Cert header. A new parameter clientCertProxy allows WebLogic Server to on the implicit trust of the certificate header. If you need an additional level of security, use a connection filter to limit all connections into WebLogic Server (therefore allowing WebLogic Server to only accept connections from the machine on which the plug-in is running).&lt;br /&gt;The clientCertProxy parameter has been added to the HTTPClusterServlet and Web applications.&lt;br /&gt;For the HTTPClusterServlet, add the parameter to the web.xml file as follows:&lt;br /&gt;&lt;context-param&gt;&lt;br /&gt;&lt;/span&gt;&lt;&lt;span class="answers"&gt;param-name&gt;clientCertProxy&lt;/param-name&gt;&lt;br /&gt;&lt;/span&gt;&lt;&lt;span class="answers"&gt;param-value&gt;true&lt;/param-value&gt;&lt;br /&gt;&lt;/context-param&gt;&lt;br /&gt;&lt;br /&gt;For Web applications, add the parameter to the web.xml file as follows:&lt;br /&gt;&lt;br /&gt;ServletRequestImpl context-param&lt;br /&gt;&lt;context-param&gt;&lt;br /&gt;&lt;/span&gt;&lt;&lt;span class="answers"&gt;param-name&gt;weblogic.http.clientCertProxy&lt;/param-name&gt;&lt;br /&gt;&lt;/span&gt;&lt;&lt;span class="answers"&gt;param-value&gt;true&lt;/param-value&gt;&lt;br /&gt;&lt;/context-param&gt;&lt;br /&gt;&lt;br /&gt;You can also use this parameter in a cluster as follows:&lt;br /&gt;&lt;Cluster ClusterAddress="127.0.0.1" Name="MyCluster"&lt;br /&gt;ClientCertProxyHeader="true"/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;Which XML parser comes with WebLogic Server 6.1?&lt;/span&gt;&lt;/b&gt;&lt;span class="answers"&gt;&lt;br /&gt;We bundle a parser, based on Apache's Xerces 1.3.1 parser, in WebLogic Server 6.1. In addition, we include a WebLogic proprietary high-performance non-validating parser that you can use for small to medium sized XML documents. The WebLogic XML Registry allows you to configure the parser you want to use for specific document types.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;span class="answers"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;span class="answers"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-8516114003501745646?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/8516114003501745646/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=8516114003501745646' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/8516114003501745646'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/8516114003501745646'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/06/weblogic-interview-questions-4.html' title='Weblogic Interview questions -4'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-8591938854283611314</id><published>2008-06-23T09:48:00.000-07:00</published><updated>2008-06-23T09:53:38.703-07:00</updated><title type='text'>Weblogic Interview questions -3</title><content type='html'>&lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;The Multicast TTL setting for a cluster in the WebLogic Admin console sets which of the following values?&lt;/span&gt;&lt;br /&gt;a. Maximum time taken for multicast messages to reach their final destination&lt;br /&gt;b. The number of routers a multicast message can pass through before the packet can be discarded&lt;br /&gt;c. The multicast address to be used by the messages sent from the cluster&lt;br /&gt;d. Minimum time taken for broadcasting a multicast message from the cluster&lt;/b&gt;&lt;br /&gt;&lt;span class="answers"&gt;&lt;br /&gt;Choice B is correct. The Multicast TTL(TTL-Time to Live) setting specifies the number of routers a multicast message can pass through before the packet can be discarded. To configure the multicast TTL for a cluster, you should change the Multicast TTL value in the WebLogic Server administration console. This sets the number of network hops a multicast message makes before the packet can be discarded.&lt;br /&gt;If you choose to distribute a cluster over a WAN (or across multiple subnets), you must plan and configure your network topology to ensure that multicast messages are reliably transmitted to all servers in the cluster. One of the requirements to be met by the network is that the multicast Time To Live (TTL) value must be high enough to ensure that routers do not discard multicast packets before they reach their final destination.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;Which of the following algorithms is used by the WebLogic Server as the default load balancing strategy for clustered object stubs when no algorithm is specified ?&lt;/span&gt;&lt;br /&gt;a. Round-robin&lt;br /&gt;b. Weight-based&lt;br /&gt;c. Random&lt;br /&gt;d. None of the above&lt;/b&gt;&lt;br /&gt;&lt;span class="answers"&gt;&lt;br /&gt;8. Choice A is correct. The basic idea behind load balancing is that by distributing the load proportionally among all the servers in the cluster, the servers can each run at full capacity. WebLogic Server clusters support several algorithms for load balancing clustered objects. The particular algorithm you choose is maintained within the replica-aware stub obtained for the clustered object. Configurable algorithms for load balancing clustered objects are: Round-robin, Weight-based and Random.&lt;br /&gt;WebLogic Server uses the round-robin algorithm as the default load balancing strategy for clustered object stubs when no algorithm is specified. Round-robin is the only load balancing strategy used by WebLogic proxy plug-ins for HTTP session state clustering. The round-robin algorithm cycles through a list of WebLogic Server instances in order. For clustered objects, the server list consists of WebLogic Server instances that host the clustered object. For proxy plug-ins, the list consists of all WebLogic Servers that host the clustered servlet or JSP.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;Which of the following attributes in the Monitoring tab for a JDBC connection pool in the Administrative console tell us how many clients are currently waiting for a connection?&lt;/span&gt;&lt;br /&gt;a. Waiters high&lt;br /&gt;b. Waiters&lt;br /&gt;c. Connections high&lt;br /&gt;d. Clients&lt;br /&gt;e. Wait seconds high&lt;/b&gt;&lt;br /&gt;&lt;span class="answers"&gt;&lt;br /&gt;Choice B is correct. JDBC subsystem resources can also be monitored via the Administration Console. The Monitoring tab for a JDBC connection pool allows you to access a table listing statistics for the instances of that pool. These attributes provide important information for managing client database access.&lt;br /&gt;The Waiters High field indicates the highest number of clients waiting for a connection at one time. The Waiters field tells you how many clients are currently waiting for a connection. The Connections High field indicates the highest number of connections that have occurred at one time. The Wait Seconds High field tells you the longest duration a client has had to wait for a database connection. These attributes allow you to gauge the effectiveness of the current configuration in responding to client requests.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;How do I do HTTP tunneling?&lt;/span&gt;&lt;/b&gt;&lt;span class="answers"&gt;&lt;br /&gt;If you want to use HTTP tunneling (wrap every message in HTTP to get through a firewall), you need to add TunnelingEnabled="true" into your &amp;lr;ver&gt; definition in the config.xml file or check the appropriate box on the console. Then use a URL like http://localhost:7001 instead of t3://localhost:7001 for Context.PROVIDER_URL when getting your InitialContext. If you want HTTP tunneling with SSL, use https://localhost:7002 (where https uses HTTP tunneling with SSL and 7002 is the secure port that you configured). You will pay a performance penalty for doing this, so only use tunneling it if you really need to (i.e., need to go through a firewall).&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;The MaxPostTimeSecs attribute set in the Administration console under Servers or virtual hosts section corresponds to which of the following?&lt;/span&gt;&lt;br /&gt;a. The amount of time that WebLogic Server waits between receiving chunks of data in an HTTP POST.&lt;br /&gt;b. The total amount of time that WebLogic Server spends receiving HTTP POST data.&lt;br /&gt;c. The time spent by WebLogic server to post data to other servers in the cluster.&lt;br /&gt;d. The number of bytes of data received in a POST from a single request.&lt;/b&gt;&lt;br /&gt;&lt;span class="answers"&gt;&lt;br /&gt;Choice B is correct. Web servers may face denial-of-service attacks, which is usually carried out by sending huge amounts of data in an HTTP POST method. You can set three attributes in WebLogic Server that help prevent this type of attack. These attributes are set in the console, under Servers or virtual hosts. You can limit the amount of time that WebLogic Server waits between receiving chunks of data in an HTTP POST by setting the attribute PostTimeoutSecs.&lt;br /&gt;The MaxPostTimeSecs attribute limits the total amount of time that WebLogic Server spends receiving post data. If this limit is triggered, a PostTimeoutException is thrown and a message is sent to the server log. MaxPostSize attribute limits the number of bytes of data received in a POST from a single request. If this limit is triggered, a MaxPostSizeExceeded exception is thrown and a message is sent to the server log.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;How do I get a thread dump to help track down a problem?&lt;/span&gt;&lt;/b&gt;&lt;span class="answers"&gt;&lt;br /&gt;Ways to get a thread dump:&lt;br /&gt;* Try running this from the command line (after running the setEnv script in /bea/wlserver6.1/config/mydomain/):&lt;br /&gt;&lt;br /&gt;java weblogic.Admin -url t3://localhost:7001 THREAD_DUMP&lt;br /&gt;&lt;br /&gt;* On Windows, from the console window, enter Ctrl+Break.&lt;br /&gt;* On UNIX, signal the server using kill -3.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-8591938854283611314?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/8591938854283611314/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=8591938854283611314' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/8591938854283611314'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/8591938854283611314'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/06/weblogic-interview-questions-3.html' title='Weblogic Interview questions -3'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-9002389412889360694</id><published>2008-06-23T09:43:00.000-07:00</published><updated>2008-06-23T09:48:51.806-07:00</updated><title type='text'>Weblogic Interview questions -2</title><content type='html'>&lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;&lt;span style="font-family:Verdana;"&gt;Why do I get the following exception when viewing the JNDI tree?&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;isSerializable(class.javax.naming.Binding)&lt;br /&gt;java.io.NotSerializableException:&lt;br /&gt;java.io.PrintWriter at&lt;br /&gt;java.io.ObjectOutputStream.OutputObject&lt;/span&gt;&lt;/b&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;&lt;span class="answers"&gt;&lt;br /&gt;The Weblogic Server JNDI implementation requires objects to be serializable, not referencable. A PrintWriter cannot be serialized and therefore should be declared transient.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;&lt;span style="font-family:Verdana;"&gt;When deploying a resource adapter (.rar) to WebLogic Server, are its classes placed in the WebLogic classpath?&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="font-family:Verdana;"&gt;&lt;span class="for_questions_blue"&gt;&lt;br /&gt;&lt;/span&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;For instance, I am deploying an EJB and a resource adapter (.rar), the EJB has no dependencies on the .rar because the EJB is writing to the common client interface (CCI). The EJB client application has sends/marshals as parameter classes that are defined in the .rar. For some reason the EJB's class loader hierarchy cannot find the definition of this .rar-specific class, even though the .rar is deploying successfully. I receive the following error on the EJB client:&lt;br /&gt;java.rmi.UnmarshalException: error unmarshalling arguments; nested&lt;/span&gt;&lt;br /&gt;exception&lt;br /&gt;is:&lt;br /&gt;java.lang.ClassNotFoundException:&lt;br /&gt;com.mycompany.InteractionSpecImpl&lt;/b&gt;&lt;span class="answers"&gt;&lt;br /&gt;&lt;br /&gt;When you pass an instance of com.myclientcompany.server.eai.InteractionSpecImpl as an argument to your EJB, the appServer needs to de-serialize (unmarshal) the object under the EJB context, and it needs the required class for unmarshalling, inside the ejb-jar(raTester.jar). So if you include the interactionspecimpl class in your ejb-jar file, then you do not need to include those classes in your server's classpath.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="for_questions_blue"&gt;&lt;b&gt;&lt;span style="font-family:Verdana;"&gt;How is security handled in the WebLogic J2EE Connector Architecture?&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt;&lt;span class="answers"&gt;&lt;br /&gt;Due to the fact that the current configuration and packaging requirements for resource adapters in WebLogic Server require the hand-editing of the weblogic-ra.xml file, any new passwords specified in the security-principal-map entries are done in clear-text.&lt;br /&gt;BEA understands the importance of protecting security passwords. Hence, we provide a Converter Tool that allows for the encryption of all passwords present in the weblogic-ra.xml file. The Converter Tool is shipped in the standard weblogic.jar file.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;&lt;span style="font-family:Verdana;"&gt;Can I enable requests to a JDBC connection pool for a database connection to wait until a connection is available?&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="font-family:Verdana;"&gt;&lt;span class="answers"&gt;&lt;br /&gt;No, there's no way to allow a request to wait for a pool connection, and from the system point of view there should not be. Each requests that waits for a connection ties up one of the fixed number of execute threads in the server, which could otherwise be running another server task. Too many waiting requests could tie up all of the execute threads and freeze the server.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;&lt;span style="font-family:Verdana;"&gt;How do I use multibyte character sets with WebLogic jDriver for Informix?&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="font-family:Verdana;"&gt;&lt;span class="answers"&gt;&lt;br /&gt;Currently, multibyte character sets are not supported for the WebLogic jDriver for Informix driver.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="for_questions_blue"&gt;&lt;b&gt;&lt;span style="font-family:Verdana;"&gt;How do I connect to an SQL Server instance that is running on a machine with multiple instances of SQL Server 2000?&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;"&gt;&lt;span class="answers"&gt;&lt;br /&gt;Each instance of MS SQL Server must be listening on a different port. So, you can use the port number in the properties that you pass to the getConnection() method or, in case of connection pools, you can specify the port property in the following properties:&lt;br /&gt;server=machineName&lt;br /&gt;port=instancePort&lt;br /&gt;&lt;br /&gt;To find the port number where each MS SQL Server instance is running, run the server network utility (in the Microsoft SQL Server program group), select the server instance, select TCP/IP, and click the properties button.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;How do I limit the number of Oracle database connections generated by WebLogic Server?&lt;/span&gt;&lt;/b&gt;&lt;span class="answers"&gt;&lt;br /&gt;You can use connection pools to limit the number of Oracle database connections generated by WebLogic Server in response to client requests. Connection pools allow T3 applications to share a fixed number of database connections. For information on how to set up connection pools,&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;How do I call Oracle stored procedures that take no parameters?&lt;/span&gt;&lt;span class="answers"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;span class="answers"&gt;Here is what we use that works:&lt;br /&gt;CallableStatement cstmt = conn.prepareCall("Begin procName;&lt;br /&gt;END;");&lt;br /&gt;cstmt.execute();&lt;br /&gt;&lt;br /&gt;where procName is the name of an Oracle stored procedure. This is standard Oracle SQL syntax that works with any Oracle DBMS. You might also use the following syntax:&lt;br /&gt;&lt;br /&gt;CallableStatement cstmt = conn.prepareCall("{call procName};");&lt;br /&gt;cstmt.execute();&lt;br /&gt;&lt;br /&gt;This code, which conforms to the Java Extended SQL spec, will work with any DBMS, not just Oracle.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;Why do I get unexpected characters from 8-bit character sets in WebLogic jDriver for Oracle?&lt;/span&gt;&lt;/b&gt;&lt;span class="answers"&gt;&lt;br /&gt;If you are using an Oracle database with an 8-bit character set on Solaris, make sure you set NLS_LANG to the proper value on the client. If NLS_LANG is unset, it defaults to a 7-bit ASCII character set, and tries to map characters greater than ASCII 128 to a reasonable approximation (for example, á, à, â would all map to a). Other characters are mapped to a question mark (?).&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;How many deployment descriptor files does a CMP entity bean deployed on the WebLogic Server have?&lt;/span&gt;&lt;br /&gt;a. One J2EE specific deployment descriptor and two WebLogic specific deployment descriptors&lt;br /&gt;b. One J2EE specific deployment descriptor and one WebLogic specific deployment descriptors&lt;br /&gt;c. One J2EE specific deployment descriptor only&lt;br /&gt;d. One WebLogic specific deployment descriptor only&lt;br /&gt;&lt;span class="answers"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;span class="answers"&gt;Choice A is correct. Deployment descriptors are text documents formatted with XML tags. The J2EE specifications define standard, portable deployment descriptors for J2EE components and applications. BEA defines additional WebLogic-specific deployment descriptors required to deploy a component or application in the WebLogic Server environment.&lt;br /&gt;When packaging an enterprise bean, we need to create an ejb-jar.xml deployment descriptor in the META-INF subdirectory and add entries for the bean. We also need to create a weblogic-ejb-jar.xml deployment descriptor in the META-INF subdirectory and add entries for the bean. If the bean is an entity bean with container-managed persistence, first we create a weblogic-rdbms-cmp-jar-bean_name.xml deployment descriptor in the META-INF directory with entries for the bean. Then we map the bean to this CMP deployment descriptor with a attribute in the weblogic-ejb-jar.xml file.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;Why do I get an error while trying to retrieve the text for ORA-12705?&lt;/span&gt;&lt;span class="answers"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;span class="answers"&gt;This error occurs when you have not set the ORACLE_home environment variable properly — a common mistake. In order to use WebLogic jDriver for Oracle, the Oracle client software needs to be installed and ORACLE_home must be set.&lt;br /&gt;You may also see this error message if you try to use WebLogic jDriver for Oracle's internationalization capabilities with a language/codeset combination that is not installed on your system. If you get the ORA-12705 error with the correct error text, then either you have set NLS_LANG improperly, or you do not have the right codesets installed on your system.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;span class="for_questions_blue"&gt;&lt;b&gt;Why do I run out of resources during updates with Oracle's database link?&lt;/b&gt;&lt;/span&gt;&lt;span class="answers"&gt;&lt;br /&gt;When you use Oracle's database link to update your database, you may get error "maximum number of temporary table locks exceeded" even if you close your result sets and statements when you finish.&lt;br /&gt;The database link is an object in the local database that allows you to access tables, views, and such in a remote database. The database link is controlled by the Oracle server, so the driver has no control over its use of resources. The link appears to perform the commit (since other processes could see the records that were being created), but it doesn't free any resources until the connection is closed. The solution is to remove the database link and use the JDBC driver to do your selects, inserts, and updates.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;Why am I getting an "ORA-01000: maximum open cursors exceeded" error, even though I closed all ResultSet, Statement, and Connection objects?&lt;/span&gt;&lt;/b&gt;&lt;span class="answers"&gt;&lt;br /&gt;This is an Oracle issue. According to Oracle's documentation, dynamic cursors can remain open from run to run in a session and are not closeable when a procedure closes. To work around this issue, you can increase the number of open cursors allowed in the database or you can reset the connection pool (close and reopen database connections in the connection pool).&lt;br /&gt;To reset the connection pool, you can untarget and retarget the connection pool using the Administration Console. You can also use the reset() method through the JMX API or the RESET_POOL command on the WebLogic Server command line interface.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;span class="answers"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-9002389412889360694?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/9002389412889360694/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=9002389412889360694' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/9002389412889360694'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/9002389412889360694'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/06/weblogic-interview-questions-2.html' title='Weblogic Interview questions -2'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-8018928052506062429</id><published>2008-06-23T09:40:00.000-07:00</published><updated>2008-06-23T09:43:42.142-07:00</updated><title type='text'>Weblogic Interview questions -1</title><content type='html'>&lt;p align="justify"&gt;&lt;span style="font-family:Verdana;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;&lt;span style="font-size:85%;"&gt;What is BEA Weblogic?&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span class="answers"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="answers"&gt;BEA WebLogic is a J2EE application server and also an HTTP web server by BEA Systems of San Jose, California, for Unix, Linux, Microsoft Windows, and other platforms. WebLogic supports Oracle, DB2, Microsoft SQL Server, and other JDBC-compliant databases. WebLogic Server supports WS-Security and is compliant with J2EE 1.3.&lt;br /&gt;BEA WebLogic Server is part of the BEA WebLogic Platform™. The other parts of WebLogic Platform are:&lt;br /&gt;* Portal, which includes Commerce Server and Personalization Server (which is built on a BEA-produced Rete rules engine),&lt;br /&gt;* WebLogic Integration,&lt;br /&gt;* WebLogic Workshop, an IDE for Java, and&lt;br /&gt;* JRockit, a JVM for Intel CPUs.&lt;br /&gt;&lt;br /&gt;WebLogic Server includes .NET interoperability and supports the following native integration capabilities:&lt;br /&gt;* Native enterprise-grade JMS messaging&lt;br /&gt;* J2EE Connector Architecture&lt;br /&gt;* WebLogic/Tuxedo Connector&lt;br /&gt;* COM+ Connectivity&lt;br /&gt;* CORBA connectivity&lt;br /&gt;* IBM WebSphere MQ connectivity&lt;br /&gt;&lt;br /&gt;BEA WebLogic Server Process Edition also includes Business Process Management and Data Mapping functionality.&lt;br /&gt;WebLogic supports security policies managed by Security Administrators. The BEA WebLogic Server Security Model includes:&lt;br /&gt;* Separate application business logic from security code&lt;br /&gt;* Complete scope of security coverage for all J2EE and non-J2EE components&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;Which of the following statements are true regarding MDBs (Message Driven Beans) on version 6.0 of WebLogic App Server?&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;br /&gt;a. MDBs support concurrent processing for both Topics and Queues.&lt;br /&gt;b. MDBs support concurrent processing for only Topics.&lt;br /&gt;c. MDBs support concurrent processing for only Queues.&lt;br /&gt;d. MDBs support concurrent processing neither Topics nor Queues.&lt;/span&gt;&lt;/b&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;br /&gt;Choice A is correct. MDBs support concurrent processing for both Topics and Queues. Previously, only concurrent processing for Queues was supported. To ensure concurrency, change the weblogic-ejb-jar.xml deployment descriptor max-beans-in-free-pool setting to &gt;1. If this element is set to more than one, the container will spawn as many threads as specified. WebLogic Server maintains a free pool of EJBs for every stateless session bean and message driven bean class.&lt;br /&gt;The max-beans-in-free-pool element defines the size of this pool. By default, max-beans-in-free-pool has no limit; the maximum number of beans in the free pool is limited only by the available memory.&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;he two primary cluster services provided by WebLogic Server are?&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;br /&gt;a. Http Session State Clustering&lt;br /&gt;b. File Service Clustering&lt;br /&gt;c. Time Service Clustering&lt;br /&gt;d. Object Clustering&lt;br /&gt;e. Event Clustering&lt;/span&gt;&lt;/b&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;span class="answers"&gt;&lt;br /&gt;Choices A and D are correct. A WebLogic Server cluster is a group of servers that work together to provide a more scalable and reliable application platform than a single server. A clustered service is an API or interface that is available on multiple servers in the cluster. HTTP session state clustering and object clustering are the two primary cluster services that WebLogic Server provides. WebLogic Server also provides cluster support for JMS destinations and JDBC connections. WebLogic Server provides clustering support for servlets and JSPs by replicating the HTTP session state of clients that access clustered servlets and JSPs. To benefit from HTTP session state clustering, you must ensure that the session state is persistent, either by configure in-memory replication, file system persistence, or JDBC persistence. If an object is clustered, instances of the object are deployed on all WebLogic Servers in the cluster. The client has a choice about which instance of the object to call. This is Object Clustering. The APIs and internal services that cannot be clustered in WebLogic Server version6.0 are File services, Time services, WebLogic Events, Workspaces and ZAC.&lt;/span&gt;&lt;/span&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span class="for_questions_blue"&gt;&lt;b&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;How do stubs work in a WebLogic Server cluster?&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;span class="answers"&gt;&lt;br /&gt;Clients that connect to a WebLogic Server cluster and look up a clustered object obtain a replica-aware stub for the object. This stub contains the list of available server instances that host implementations of the object. The stub also contains the load balancing logic for distributing the load among its host servers.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span class="for_questions_blue"&gt;&lt;b&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;What happens when a failure occurs and the stub cannot connect to a WebLogic Server instance?&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;span class="answers"&gt;&lt;br /&gt;When the failure occurs, the stub removes the failed server instance from its list. If there are no servers left in its list, the stub uses DNS again to find a running server and obtain a current list of running instances. Also, the stub periodically refreshes its list of available server instances in the cluster; this allows the stub to take advantage of new servers as they are added to the cluster.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span class="for_questions_blue"&gt;&lt;b&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;Why did my JDBC code throw a rollback SQLException?&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;b&gt;&lt;br /&gt;Your JDBC code may throw the following exception:&lt;br /&gt;"The coordinator has rolled back the transaction.&lt;br /&gt;No further JDBC access is allowed within this transaction."&lt;/b&gt;&lt;span class="answers"&gt;&lt;br /&gt;The WebLogic JTS JDBC driver throws this exception when the current JDBC connection transaction rolls back prior to or during the JDBC call. This exception indicates that the transaction in which the JDBC connection was participating was rolled back at some point prior to or during the JDBC call.&lt;br /&gt;The rollback may have happened in an earlier EJB invoke that was part of the transaction, or the rollback may have occurred because the transaction timed out. In either case, the transaction will be rolled back, the connection returned to the pool and the database resources released. In order to proceed, the JTS JDBC connection must be closed and reopened in a new transaction.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span class="for_questions_blue"&gt;&lt;b&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;Must my bean-managed persistence mechanism use the WebLogic JTS driver?&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;span class="answers"&gt;&lt;br /&gt;Use the TxDataSource for bean-managed persistence.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span class="for_questions_blue"&gt;&lt;b&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;Why is there no polymorphic-type response from a create() or find() method?&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;span class="answers"&gt;&lt;br /&gt;The EJB Specification prohibits this behavior, and the weblogic.ejbc compiler checks for this behavior and prohibits any polymorphic type of response from a create() or find() method.&lt;br /&gt;The reason the create() and find() methods are not polymorphic is similar to the reason constructors are not polymorphic in Java. The derived classes generally do not know or cannot initialize the base class properly.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span class="for_questions_blue"&gt;&lt;b&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;Must EJBs be homogeneously deployed across a cluster? Why?&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;span class="answers"&gt;&lt;br /&gt;Yes. Beginning with WebLogic Server version 6.0, EJBs must be homogeneously deployed across a cluster for the following reasons:&lt;br /&gt;* To keep clustering EJBs simple&lt;br /&gt;* To avoid cross server calls which results in more efficiency. If EJBs are not deployed on all servers, cross server calls are much more likely.&lt;br /&gt;* To ensure that every EJB is available locally&lt;br /&gt;* To ensure that all classes are loaded in an undeployable way&lt;br /&gt;* Every server must have access to each EJB's classes so that it can be bound into the local JNDI tree. If only a subset of the servers deploys the bean, the other servers will have to load the bean's classes in their respective system classpaths which makes it impossible to undeploy the beans.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;Which of the following are recommended practices to be performed in the ejbPassivate() method of a stateful session bean?&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;br /&gt;a. Close any open resources, like database connections&lt;br /&gt;b. All non-transient, non-serializable fields(except some special types) should be set to null.&lt;br /&gt;c. All transient fields should be set to null&lt;br /&gt;d. Make all database connection reference fields transient&lt;br /&gt;e. All primitive type fields should be set to null&lt;/span&gt;&lt;/b&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;span class="answers"&gt;&lt;br /&gt;&lt;br /&gt;Choices A, B and D are correct. When a bean is about to be passivated, its ejbPassivate() method is invoked, alerting the bean instance that it is about to enter the Passivated state. At this time, the bean instance should close any open resources and set all non transient, non serializable fields to null. This will prevent problems from occurring when the bean is serialized. Transient fields will simply be ignored.Serializable fields will be saved. Open resources such as sockets or JDBC connections must be closed whenever the bean is passivated. In stateful session beans, open resources will not be maintained for the life of the bean instance. When a stateful session bean is passivated, any open resource can cause problems with the activation mechanism.&lt;br /&gt;A bean's conversational state may consist of only primitive values, objects that are serializable, and the following special types-SessionContext, EJBhome, EJBObject, UserTransaction and Context (only when it references the JNDI ENC) . The types in this list (and their subtypes) are handled specially by the passivation mechanism. They don't need to be serializable; they will be maintained through passivation and restored automatically to the bean instance when it is activated&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span style="font-family:Verdana;"&gt;&lt;b&gt;&lt;span class="for_questions_blue"&gt;&lt;span style="font-size:85%;"&gt;While packaging the Web Application DefaultWebApp for deployment into the WebLogic server, the home and remote interfaces of the enterprise beans used by the servlets should reside in which directory?&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size:85%;"&gt;&lt;b&gt;a. DefaultWebApp/META_INF/classes&lt;br /&gt;b. DefaultWebApp/META_INF/lib&lt;br /&gt;c. DefaultWebApp/WEB_INF/lib&lt;br /&gt;d. DefaultWebApp/WEB_INF/classes&lt;br /&gt;e. DefaultWebApp/classes&lt;/b&gt;&lt;span class="answers"&gt;&lt;br /&gt;Choice D is correct. When packaging a web application create META-INF and WEB-INF subdirectories in the application directory to hold deployment descriptors and compiled Java classes. All servlet classes and helper classes should reside in the WEB-INF/classes subdirectory. The home and remote interface classes for enterprise beans used by the servlets into the WEB-INF/classes subdirectory.&lt;br /&gt;All the HTML files, JSP files, images, and any other files that these Web pages reference should exist in the application directory, maintaining the directory structure for referenced files. The META_INF directory contains the deployment descriptors for the enterprise beans, but not the classes.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p align="justify"&gt;&lt;span class="for_questions_blue"&gt;&lt;b&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;How do I set up my CLASSPATH?&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;span class="answers"&gt;&lt;br /&gt;Setting up your CLASSPATH correctly depends on what you are trying to do. The most common tasks are described below:&lt;br /&gt;* Starting WebLogic Server. See Setting the Classpath Option in the Starting and Stopping WebLogic Servers section of the Administration Guide. In addition, your WebLogic distribution includes shell scripts that you can use to start the server. These scripts, which are located in the domain directories under the config directory of your WebLogic Server distribution, automatically set up the CLASSPATH variable in the shell before starting the server.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-family:Verdana;font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-8018928052506062429?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/8018928052506062429/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=8018928052506062429' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/8018928052506062429'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/8018928052506062429'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/06/weblogic-interview-questions-1.html' title='Weblogic Interview questions -1'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-1726774566165136324</id><published>2008-06-19T08:29:00.000-07:00</published><updated>2008-06-19T08:58:05.343-07:00</updated><title type='text'></title><content type='html'>&lt;span style="font-weight: bold;"&gt; What is Struts and how it helps in web development?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Apache Struts is a free open-source framework for creating Java web applications.Struts helps in providing dynamism to a web based application in contrast with many websites that deliver only static pages.A web application interacts with databases and business logic engines to customize a response.&lt;br /&gt;Struts is based on MVC(Model-View-Controller) architecture based and it clearly segregate business logic from presentation which is somehow difficult to achieve with JavaServer Pages that sometimes mingle database code, page design code, and control flow code. Unless these components are not separated then it becomes quite difficult to maintain in large web based applications. The Model represents the business or database code, the View represents the page design code, and the Controller represents the business logic or navigational code.&lt;br /&gt;&lt;br /&gt;The framework provides three key components:&lt;br /&gt;&lt;br /&gt;   * A "request" handler provided by the application developer.It maps to a standard URI.&lt;br /&gt;   * A "response" handler that transfers control to another resource which completes the response.&lt;br /&gt;   * A tag library that helps developers create interactive form-based applications with server pages.&lt;br /&gt;&lt;br /&gt;Struts works well with conventional REST applications and with new technologies like SOAP and AJAX.&lt;br /&gt;&lt;br /&gt;By the time posting of this article,the latest version of Apache Struts is 'Struts 2.0.6', according to Apache it is an elegant, extensible framework for creating enterprise-ready Java web applications.,was originally known as WebWork 2.You can find out more information about Struts2 here.&lt;br /&gt;&lt;br /&gt; Explain Struts1.x in a nutshell?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Struts is consisted of technologies like Java Servlets, JavaBeans, ResourceBundles, and XML, as well as various Jakarta Commons packages, like BeanUtils and Chain of Responsibility. It helps one create an extensible development environment for one's application, based on published standards and proven design patterns.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Struts Flow&lt;br /&gt;&lt;br /&gt;Whenever a request comes from web browser then application's controller handles this request.When request is received then Controller invokes an Action class.This Action class object then communicates with Model class(which actually is a set of JavaBeans representation) to examine or update the application's state..The Struts ActionForm class helps in data exchange between Model and View layers.&lt;br /&gt;&lt;img src="file:///C:/DOCUME%7E1/SMSINS%7E1/LOCALS%7E1/Temp/moz-screenshot-32.jpg" alt="" /&gt;&lt;img src="file:///C:/DOCUME%7E1/SMSINS%7E1/LOCALS%7E1/Temp/moz-screenshot-33.jpg" alt="" /&gt;&lt;br /&gt;A web application uses 'web.xml', a deployment descriptor to initialize resources like servlets and taglibs. Similarly, Struts uses a configuration file( struts-config.xml) to initialize its own resources. These resources include ActionForms to collect input from users, ActionMappings to direct input to server-side Actions, and ActionForwards to select output pages.Moreover,one can specify validations for the ActionForms in an XML descriptor, using the Struts Validator. A standard extension, Tiles, helps you build pages from smaller fragments.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp3.blogger.com/_o-aO_ImO6Ec/Rmv3TS_x5MI/AAAAAAAAAow/rh48Ia7M7SU/s1600-h/struts_flow.gif"&gt;&lt;img style="cursor: pointer;" src="http://bp3.blogger.com/_o-aO_ImO6Ec/Rmv3TS_x5MI/AAAAAAAAAow/rh48Ia7M7SU/s400/struts_flow.gif" alt="" id="BLOGGER_PHOTO_ID_5074421316051920066" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Struts may not be a useful option for each type of web development application.If the application is huge and complex then Struts fits the bill in best way but if you are developing a web application which requires very little of web pages and business logic then MVC-1 based approach will be best rather MVC-2 based like Struts.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; What are the methods in Action class?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;An Action class in the struts application extends Struts 'org.apache.struts.action.Action" class. Action class acts as wrapper around the business logic and provides an interface to the application's Model layer. Action class mediates between the View and Model layer in both directions it means it transfers data to and fro from the view layer and the specific business process layer.&lt;br /&gt;&lt;br /&gt;If you look at the sequence diagram, it gives you a correct picture how an Action class instance is invoked.When it is invoked then overridden execute() method is invoked.It is advisable not to put the business process logic inside execute method which should ideally have navigational logic details, instead move the database and business process logic to DAO layer.&lt;br /&gt;&lt;br /&gt;Struts Sequence Diagram&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_o-aO_ImO6Ec/RmvztC_x5LI/AAAAAAAAAoo/O6U3DWVVq6o/s1600-h/SequenceStruts1_1.gif"&gt;&lt;img style="cursor: pointer;" src="http://bp2.blogger.com/_o-aO_ImO6Ec/RmvztC_x5LI/AAAAAAAAAoo/O6U3DWVVq6o/s400/SequenceStruts1_1.gif" alt="" id="BLOGGER_PHOTO_ID_5074417360387040434" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;The return type of the execute() method is ActionForward which is used by the Struts Framework to forward the request to the file as per the value of the returned ActionForward object,mapping of which is provided in struts-config.xml file.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;package dpun.action;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import javax.servlet.http.HttpServletRequest;&lt;br /&gt;import javax.servlet.http.HttpServletResponse;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import org.apache.struts.action.Action;&lt;br /&gt;import org.apache.struts.action.ActionForm;&lt;br /&gt;import org.apache.struts.action.ActionForward;&lt;br /&gt;import org.apache.struts.action.ActionMapping;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class MyAction extends Action&lt;br /&gt;{&lt;br /&gt; public ActionForward execute(&lt;br /&gt;   ActionMapping mapping,&lt;br /&gt;   ActionForm actionForm,&lt;br /&gt;   HttpServletRequest request,&lt;br /&gt;   HttpServletResponse response) throws Exception{&lt;br /&gt;     return mapping.findForward("myAction");&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Action class has two execute methods ,one HTTP specific and the other protocol independent.The HTTP based execute method has following parameters:&lt;br /&gt;ActionMapping mapping:This object is used to refer this instance.&lt;br /&gt;ActionForm actionForm:It refers ActionForm bean class associated with this request. HttpServletRequest request:It represents HTTP request.&lt;br /&gt;HttpServletResponse response:It represents HTTP response.&lt;br /&gt;&lt;br /&gt;While protocol independent execute has ServletRequest and ServletResponse instead of HttpServletRequest and HttpServletResponse parameters.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; How you will handle errors and exceptions in Struts?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;An efficient error and exception handling makes an application behave gracefully under abnormal conditions.Struts has errors and exception handling done in different ways.The form validations using Struts require a proper mechanism.For handling errors in Struts,it has two objects ActionError and ActionErrors.Whenever a form is submitted then cotroller receives request and then create ActionForm object which calls reset() method and stores ActionForm object to required scope and then it loads ActionForm object from request and calls validate() method.If validate method fails then errors are displayed on the form itself through  &lt;html:errors&gt; tags.&lt;br /&gt;&lt;br /&gt;Exception Handling can be done in following ways:&lt;br /&gt;&lt;br /&gt;-try-catch block within&lt;br /&gt;&lt;br /&gt;-Using declarative exception handling.In struts-config.xml we can declare on which type of exception, a request should be redirected to.&lt;br /&gt;&lt;br /&gt;Use Global Exceptions tag in struts-config.xml&lt;br /&gt;&lt;br /&gt;&lt;global-exceptions&gt;&lt;br /&gt;&lt;br /&gt;&lt;exception key="errors.MyException" type="java.lang.MyException" path="/myExcption.jsp"&gt;&lt;br /&gt;&lt;br /&gt; So whenever MyException occurs then Struts framework will display 'myException.jsp' page.&lt;br /&gt;The interpretation of this is that if MyException is caught by Struts' ActionServlet then it should redirect to myExcption.jsp. The key is as usual a pointer to the message resource file.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; How does Validator framework work in Struts ?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Validator framework is an open source project and is part of the Jakarta Commons subproject. The Commons project was created for the purpose of providing reusable components like the Validator. Other well-known Commons components include BeanUtils, Digester, and the Logging framework.It was first released in November 2002.&lt;br /&gt;Validator framework consists of the following components:-&lt;br /&gt;&lt;br /&gt;-Validators&lt;br /&gt;-Configuration Files&lt;br /&gt;-Resource Bundle&lt;br /&gt;-JSP Custom Tags&lt;br /&gt;-Validator Form Classes&lt;br /&gt;&lt;br /&gt;Validators are Java classes which execute validation rule.The framework knows how to invoke a Validator class based on its method signature, as defined in a configuration file. Typically, each Validator provides a single validation rule, and these rules can be chained together to form a more complex set of rules.&lt;br /&gt;&lt;br /&gt;Configuration Files:There are two configuration files&lt;br /&gt;-validator.xml and&lt;br /&gt;-validator-rules.xml&lt;br /&gt;&lt;br /&gt;validator-rules.xml contains all possible validations available to an application. These validations are present as definitions in this file. The controlling document of Validator-rules.xml is Validator-rules_1_1.dtd.All the elements defined in this file are defined according to the above DTD.&lt;br /&gt;&lt;br /&gt;The required validation is applied to mandatory fields, such as employee id(one example).The has many attributes. These attributes are,Name,Classname,MethodMethodparams,Msg&lt;br /&gt;&lt;br /&gt;A simple validator-rule.xml file.click here.&lt;br /&gt;&lt;br /&gt;Another configuration file is validation.xml file.It is where you couple the individual Validators defined in the validator-rules.xml to components within your application. Since we are talking about using the Validator with Struts, the coupling occurs between the Validators and Struts ActionForm classes.ActionForm also provide a convenient spot to validate the user input before passing it to the business layer. Here is a simple validation.xml file.&lt;br /&gt;&lt;br /&gt;Resource Bundle: Resource Bundle forms the base of localization. The error messages created when a rule fails come from the resource bundles. For the common Validators provided by the Validator framework, the default messages can be placed in the Struts application's message resources. Some of these messages are:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; What is DispatchAction?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;org.apache.struts.actions.DispatchAction is responsible for&lt;br /&gt;&lt;br /&gt;-Dispatches to a public method named on a request parameter&lt;br /&gt;-Method name corresponds to the 'parameter' property of corresponding ActionMapping&lt;br /&gt;-useful when multiple similar actions are to be clubbed within a singe Action class in order to simplify the design.&lt;br /&gt;&lt;br /&gt;If you want to to insert,update and delete all actions on a database from a JSP with the same Action class in such case it will come quite handy.&lt;br /&gt;Here is how this JSP looks like:&lt;br /&gt;&lt;html:form action="/saveSubscription"&gt;&lt;br /&gt;&lt;html:submit&gt;&lt;br /&gt;&lt;bean:message key="insert"&gt;&lt;br /&gt;&lt;/html:submit&gt;&lt;br /&gt;&lt;html:submit&gt;&lt;br /&gt;&lt;bean:message key="update"&gt;&lt;br /&gt;&lt;/html:submit&gt;&lt;br /&gt;&lt;html:submit&gt;&lt;br /&gt;&lt;bean:message key="delete"&gt;&lt;br /&gt;&lt;/html:submit&gt;&lt;br /&gt;&lt;/html:form&gt;&lt;br /&gt;To configure the use of this action in your struts-config.xml file, create an entry like this:&lt;br /&gt;&lt;br /&gt;&lt;action path="/saveSubscription" type="org.apache.struts.actions.DispatchAction" name="subscriptionForm" scope="request" input="/subscription.jsp" parameter="submit"&gt;&lt;br /&gt;&lt;br /&gt;It will use the value of the request parameter named "submit" to pick the appropriate "execute" method, which must have the same signature (other than method name) of the standard Action.execute method. For example, you might have the following three methods in the same action:&lt;br /&gt;&lt;br /&gt;* public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception&lt;br /&gt;* public ActionForward insert(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception&lt;br /&gt;* public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception&lt;br /&gt;&lt;br /&gt;In our JSP, we can refer to the buttons in the usual way.Later, when the user selects a button, the form will pass the submit parameter, along with whatever message is Struts finds for "insert" or "delete" in the resource bundle.&lt;br /&gt;Using the conventional DispatchAction, this approach would be problematic, not necessarily each message will map to a valid Java identifier. This is where the magic of the LookupDispatchAction comes into play.&lt;br /&gt;&lt;br /&gt;When you create your LookupDispatchAction subclass, along with the methods for the dispatch operations you must also implement a getKeyMethodMap method. This is a "hotspot" that the LookupDispatchAction will call.&lt;br /&gt;&lt;br /&gt;Here's an example of the methods you might declare in your subclass:&lt;br /&gt;&lt;br /&gt;protected Map getKeyMethodMap(ActionMapping mapping,&lt;br /&gt;ActionForm form,&lt;br /&gt;HttpServletRequest request) {&lt;br /&gt;Map map = new HashMap();&lt;br /&gt;map.put("button.add", "add");&lt;br /&gt;map.put("button.delete", "delete");&lt;br /&gt;return map;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Internally, the base action will lookup the messages for 'insert' and 'delete', and match those against the submit parameter. When it finds a match, it will then use either "insert" or "delete" to call the corresponding methods.&lt;br /&gt;&lt;br /&gt;So while the LookupDispatchAction means adding an extra method to your Action, it lets you skip putting a JavaScript in your form.&lt;br /&gt;&lt;br /&gt;Both the DispatchAction and LookupDispatchAction are an excellent way to streamline your Struts action classes, and group several related operations into a single umbrella action. So, how many dispatch actions do you need? Can you use a dispatch action to collect everything into a single action?&lt;br /&gt;&lt;br /&gt;In practice, you can easily use one dispatch action for any forms that share a common validation. It is not advisable to have sharing of dispatch action between different form beans, or form beans that are validated differently,as it can start to make things harder rather than simpler. But the use of a dispatch action can easily half or quarter the number of action classes in most Struts application.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#Error messages used by the Validator&lt;br /&gt;errors.required={0} is required.&lt;br /&gt;errors.minlength={0} can not be less than {1} characters.&lt;br /&gt;errors.maxlength={0} can not be greater than {1} characters.&lt;br /&gt;errors.invalid={0}  is invalid.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The parameter in place of {0} and {1} is inserted automatically by the framework when the rules fail. These values are corresponding to the parameters comes from the Validator-rules.xml and validation.xml files.&lt;br /&gt;&lt;br /&gt;JSP Custom Tags&lt;br /&gt;Like errors and javascript Struts HTML tags required in case of validations. The former is for server-side validation while the latter is for client side validation.&lt;br /&gt;&lt;br /&gt;Validator Form Class&lt;br /&gt;In Struts data is passed from the JSP page (view layer) to Action class (controller layer) by means of ActionForm objects. The standard Struts ActionForm won't suffice to impose validation framework.The specially designed classes for this purpose come quite handy. It comes in two varieties- ValidatorForm and DynaValidatorForm. The former is used in place of ActionForm while the latter is used with the DynaActionForm. Whatever the variety being used, two methods used for performing validation which are present in both of them are- reset() and validate().&lt;br /&gt;Integrating validator to Struts is done by introducing the following piece of data inside strust-config.xml:&lt;br /&gt;The Validator framework is easily extensible and the effort required is minimal.&lt;br /&gt;-Create your own validation classes.&lt;br /&gt;-Hook it up inside validation-rules.xml file&lt;br /&gt;&lt;br /&gt;Apart from using in Struts application,the Validator framework can be used as a separate unit for validation of applications.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-1726774566165136324?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/1726774566165136324/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=1726774566165136324' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/1726774566165136324'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/1726774566165136324'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/06/what-is-struts-and-how-it-helps-in-web.html' title=''/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp3.blogger.com/_o-aO_ImO6Ec/Rmv3TS_x5MI/AAAAAAAAAow/rh48Ia7M7SU/s72-c/struts_flow.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-5637294218041211396</id><published>2008-06-19T08:10:00.000-07:00</published><updated>2008-06-19T08:23:52.078-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate Interview questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>Hibernate</title><content type='html'>&lt;b style="font-weight: bold;"&gt; W&lt;/b&gt;&lt;span style="font-weight: bold;"&gt;hat is Hibernate?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Hibernate is a powerful, high performance object/relational persistence and query service.It is an open-source technology which fits well both with Java and .NET technologies.Hibernate lets developers write persistence classes with hibernate query features of HQL within principles of Object Oriented paradigm.It means one can include association,inheritance,polymorphism,composition and collection of these persisting objects to build applications.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Hibernate Architecture&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The main objective of Hibernate is to relieve the developers from manual handling of SQLs,JDBC APIs for resultsets handling and it helps in keeping your data portable to various SQL databases,just by switching the delegate and driver details in hibernate.cfg.xml file.&lt;br /&gt;Hibernate offers sophisticated query options, you can write plain SQL, object-oriented HQL (Hibernate Query Language), or create programmatic criteria and example queries. Hibernate can optimize object loading all the time, with various fetching and caching options.&lt;br /&gt;Some snapshots of Hibernate:&lt;br /&gt;-Free open source&lt;br /&gt;-OO Concepts can be implemented.&lt;br /&gt;-A rich variety of mappings for collections and dependent objects&lt;br /&gt;-No extra code generation or bytecode processing steps in your build procedure&lt;br /&gt;-Great performance, has a dual-layer cache architecture, and may be used in a cluster&lt;br /&gt;-Its own query language support&lt;br /&gt;-Efficient transaction handling&lt;br /&gt;-The Java Persistence API is the standard object/relational mapping and persistence management interface of the Java EE 5.0 platform which are implemented with the Hibernate Annotations and Hibernate EntityManager modules, on top of the Hibernate Core.(As part of EJB3.0 spec)&lt;b&gt;&lt;br /&gt;&lt;br /&gt; Why Hibernate?&lt;br /&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;The reasons are plenty,weighing in favor of Hibernate clearly.&lt;br /&gt;-Cost effective.Just imagine when you are using EJBs instead of Hibernate.One has to invest in Application Server(Websphere,Weblogic etc.),learning curve for EJB is slow and requires special training if your developers are not equipped with the EJB know-how.&lt;br /&gt;-The developers get rid of writing complex SQLs and no more need of JDBC APIs for resultset handling.Even less code than JDBC.In fact the OO developers work well when they have to deal with object then writing lousy queries.&lt;br /&gt;-High performance then EJBs(if we go by their industry reputation),which itself a container managed,heavyweight solution.&lt;br /&gt;-Switching to other SQL database requires few changes in Hibernate configuration file and requires least clutter than EJBs.&lt;br /&gt;-EJB itself has modeled itself on Hibernate principle in its latest version i.e. EJB3 because of apparent reasons.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; What is ORM ?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Object Relational Mapping(ORM) is a technique/solution that provides an object-based view of data to applications which it can manipulate.The basic purpose of ORM is to allow an application written in an object oriented language to deal with the information it manipulates in terms of objects, rather than in terms of database-specific concepts such as rows, columns and tables.&lt;br /&gt;&lt;br /&gt;In the Java world, ORM's first appearance was under the form of entity beans. But entity beans have limited scope in Java EE domain,they can not be exploited for Java SE based applications.The mapping of class lever attributes is done to table columns.For example a String variabe of a class will directly map onto a VARCHAR column. A relationship mapping is the one that you use when you have an attribute of a class that holds a reference to an instance of some other class in your domain model. The most common types of relationship mappings are "one to one", "one to many" or "many to many".&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; What are core interfaces for Hibernate framework?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Most Hibernate-related application code primarily interacts with four interfaces provided by Hibernate Core:&lt;br /&gt;&lt;br /&gt;org.hibernate.Session&lt;br /&gt;org.hibernate.SessionFactory&lt;br /&gt;org.hibernate.Criteria&lt;br /&gt;org.hibernate.Query&lt;br /&gt;&lt;br /&gt;The Session is a persistence manager that manages operation like storing and retrieving objects. Instances of Session are inexpensive to create and destroy. They are not thread safe.&lt;br /&gt;&lt;br /&gt;The application obtains Session instances from a SessionFactory. SessionFactory instances are not lightweight and typically one instance is created for the whole application. If the application accesses multiple databases, it needs one per database.&lt;br /&gt;&lt;br /&gt;The Criteria provides a provision for conditional search over the resultset.One can retrieve entities by composing Criterion objects. The Session is a factory for Criteria.Criterion instances are usually obtained via the factory methods on Restrictions.&lt;br /&gt;Query represents object oriented representation of a Hibernate query. A Query instance is obtained by calling Session.createQuery().&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; What is dirty checking in Hibernate?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Hibernate automatically detects object state changes in order to synchronize the updated state with the database, this is called dirty checking. An important note here is, Hibernate will compare objects by value, except for Collections, which are compared by identity. For this reason you should return exactly the same collection instance as Hibernate passed to the setter method to prevent unnecessary database updates.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; What are different fetch strategies Hibernate have?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A fetching strategy in Hibernate is used for retrieving associated objects if the application needs to navigate the association. They may be declared in the O/R mapping metadata, or over-ridden by a particular HQL or Criteria query.&lt;br /&gt;&lt;br /&gt;Hibernate3 defines the following fetching strategies:&lt;br /&gt;&lt;br /&gt;Join fetching - Hibernate retrieves the associated instance or collection in the same SELECT, using an OUTER JOIN.&lt;br /&gt;&lt;br /&gt;Select fetching - a second SELECT is used to retrieve the associated entity or collection. Unless you explicitly disable lazy fetching by specifying lazy="false", this second select will only be executed when you actually access the association.&lt;br /&gt;&lt;br /&gt;Subselect fetching - a second SELECT is used to retrieve the associated collections for all entities retrieved in a previous query or fetch. Unless you explicitly disable lazy fetching by specifying lazy="false", this second select will only be executed when you actually access the association.&lt;br /&gt;&lt;br /&gt;Batch fetching - an optimization strategy for select fetching - Hibernate retrieves a batch of entity instances or collections in a single SELECT, by specifying a list of primary keys or foreign keys.&lt;br /&gt;&lt;br /&gt;Hibernate also distinguishes between:&lt;br /&gt;Immediate fetching - an association, collection or attribute is fetched immediately, when the owner is loaded.&lt;br /&gt;&lt;br /&gt;Lazy collection fetching - a collection is fetched when the application invokes an operation upon that collection. (This is the default for collections.)&lt;br /&gt;&lt;br /&gt;"Extra-lazy" collection fetching - individual elements of the collection are accessed from the database as needed. Hibernate tries not to fetch the whole collection into memory unless absolutely needed (suitable for very large collections)&lt;br /&gt;&lt;br /&gt;Proxy fetching - a single-valued association is fetched when a method other than the identifier getter is invoked upon the associated object.&lt;br /&gt;&lt;br /&gt;"No-proxy" fetching - a single-valued association is fetched when the instance variable is accessed. Compared to proxy fetching, this approach is less lazy (the association is fetched even when only the identifier is accessed) but more transparent, since no proxy is visible to the application. This approach requires buildtime bytecode instrumentation and is rarely necessary.&lt;br /&gt;&lt;br /&gt;Lazy attribute fetching - an attribute or single valued association is fetched when the instance variable is accessed. This approach requires buildtime bytecode instrumentation and is rarely necessary.&lt;br /&gt;&lt;br /&gt;We use fetch to tune performance. We may use lazy to define a contract for what data is always available in any detached instance of a particular class.&lt;br /&gt;&lt;br /&gt;[Source:Hibernate Reference Documentation]&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; Can you compare JDBC/DAO with Hibernate?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Hibernate and straight SQL through JDBC are different approaches.They both have their specific significance in different scenarios.If your application is not to big and complex,not too many tables and queries involved then it will be better to use JDBC. While Hibernate is a POJO based ORM tool,using JDBC underneath to connect to database, which lets one to get rid of writing SQLs and associated JDBC code to fetch resultset,meaning less LOC but more of configuration work.It will suit better when you have large application involving large volume of data and queries.Moreover lazy loading,caching of data helps in having better performance and you need not call the database every time rather data stays in object form which can be reused.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; Explain different inheritance mapping models in Hibernate.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;There can be three kinds of inheritance mapping in hibernate&lt;br /&gt;&lt;br /&gt;1. Table per concrete class with unions&lt;br /&gt;2. Table per class hierarchy&lt;br /&gt;3. Table per subclass&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;We can take an example of three Java classes like Vehicle, which is an abstract class and two subclasses of Vehicle as Car and UtilityVan.&lt;br /&gt;&lt;br /&gt;1. Table per concrete class with unions&lt;br /&gt;In this scenario there will be 2 tables&lt;br /&gt;Tables: Car, UtilityVan, here in this case all common attributes will be duplicated.&lt;br /&gt;&lt;br /&gt;2. Table per class hierarchy&lt;br /&gt;Single Table can be mapped to a class hierarchy&lt;br /&gt;There will be only one table in database named 'Vehicle' which will represent all attributes required for all three classes.&lt;br /&gt;Here it is be taken care of that discriminating columns to differentiate between Car and UtilityVan&lt;br /&gt;&lt;br /&gt;3. Table per subclass&lt;br /&gt;Simply there will be three tables representing Vehicle, Car and UtilityVan&lt;br /&gt;&lt;b&gt;Q. How will you configure Hibernate? &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Answer: &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The configuration files hibernate.cfg.xml (or hibernate.properties) and mapping files *.hbm.xml are used by the Configuration class to create (i.e. configure and bootstrap hibernate) the SessionFactory, which in turn creates the Session instances. Session instances are the primary interface for the persistence service.&lt;br /&gt;&lt;br /&gt;• hibernate.cfg.xml (alternatively can use hibernate.properties): These two files are used to configure the hibernate sevice (connection driver class, connection URL, connection username, connection password, dialect etc). If both files are present in the classpath then hibernate.cfg.xml file overrides the settings found in the hibernate.properties file.&lt;br /&gt;&lt;br /&gt;• Mapping files (*.hbm.xml): These files are used to map persistent objects to a relational database. It is the best practice to store each object in an individual mapping file (i.e mapping file per class) because storing large number of persistent classes into one mapping file can be difficult to manage and maintain. The naming convention is to use the same name as the persistent (POJO) class name. For example Account.class will have a mapping file named Account.hbm.xml. Alternatively hibernate annotations can be used as part of your persistent class code instead of the *.hbm.xml files.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q. What is a SessionFactory? Is it a thread-safe object? &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Answer: &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;SessionFactory is Hibernate’s concept of a single datastore and is threadsafe so that many threads can access it concurrently and request for sessions and immutable cache of compiled mappings for a single database. A SessionFactory is usually only built once at startup. SessionFactory should be wrapped in some kind of singleton so that it can be easily accessed in an application code.&lt;br /&gt;&lt;br /&gt;SessionFactory sessionFactory = new Configuration().configure().buildSessionfactory();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q. What is a Session? Can you share a session object between different theads? &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Answer: &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Session is a light weight and a non-threadsafe object (No, you cannot share it between threads) that represents a single unit-of-work with the database. Sessions are opened by a SessionFactory and then are closed when all work is complete. Session is the primary interface for the persistence service. A session obtains a database connection lazily (i.e. only when required). To avoid creating too many sessions ThreadLocal class can be used as shown below to get the current session no matter how many times you make call to the currentSession() method.&lt;br /&gt;&lt;br /&gt;…&lt;br /&gt;public class HibernateUtil {&lt;br /&gt;…&lt;br /&gt;public static final ThreadLocal local = new ThreadLocal();&lt;br /&gt;&lt;br /&gt;public static Session currentSession() throws HibernateException {&lt;br /&gt; Session session = (Session) local.get();&lt;br /&gt; //open a new session if this thread has no session&lt;br /&gt; if(session == null) {&lt;br /&gt;  session = sessionFactory.openSession();&lt;br /&gt;  local.set(session);&lt;br /&gt; }&lt;br /&gt; return session;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;It is also vital that you close your session after your unit of work completes. Note: Keep your Hibernate Session API handy.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q. What are the benefits of detached objects? &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Answer: &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Detached objects can be passed across layers all the way up to the presentation layer without having to use any DTOs (Data Transfer Objects). You can later on re-attach the detached objects to another session.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q. What are the pros and cons of detached objects? &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Answer: &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Pros: &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;• When long transactions are required due to user think-time, it is the best practice to break the long transaction up into two or more transactions. You can use detached objects from the first transaction to carry data all the way up to the presentation layer. These detached objects get modified outside a transaction and later on re-attached to a new transaction via another session.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Cons &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;• In general, working with detached objects is quite cumbersome, and better to not clutter up the session with them if possible. It is better to discard them and re-fetch them on subsequent requests. This approach is not only more portable but also more efficient because - the objects hang around in Hibernate's cache anyway.&lt;br /&gt;&lt;br /&gt;• Also from pure rich domain driven design perspective it is recommended to use DTOs (DataTransferObjects) and DOs (DomainObjects) to maintain the separation between Service and UI tiers.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q. How does Hibernate distinguish between transient (i.e. newly instantiated) and detached objects? &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Answer &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;• Hibernate uses the “version” property, if there is one.&lt;br /&gt;• If not uses the identifier value. No identifier value means a new object. This does work only for Hibernate managed surrogate keys. Does not work for natural keys and assigned (i.e. not managed by Hibernate) surrogate keys.&lt;br /&gt;• Write your own strategy with Interceptor.isUnsaved().&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q.  What is the difference between the session.get() method and the session.load() method? &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Both the session.get(..) and session.load() methods create a persistent object by loading the required object from the database. But if there was not such object in the database then the method session.load(..) throws an exception whereas session.get(…) returns null.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q. What is the difference between the session.update() method and the session.lock() method? &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Both of these methods and saveOrUpdate() method are intended for reattaching a detached object. The session.lock() method simply reattaches the object to the session without checking or updating the database on the assumption that the database in sync with the detached object. It is the best practice to use either session.update(..) or session.saveOrUpdate(). Use session.lock() only if you are absolutely sure that the detached object is in sync with your detached object or if it does not matter because you will be overwriting all the columns that would have changed later on within the same transaction.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note: &lt;/b&gt; When you reattach detached objects you need to make sure that the dependent objects are reatched as well.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q. How would you reatach detached objects to a session when the same object has already been  loaded into the session? &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;You can use the session.merge() method call.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Q. What are the general considerations or best practices for defining your Hibernate persistent classes? &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1.You must have a default no-argument constructor for your persistent classes and there should be getXXX() (i.e accessor/getter) and setXXX( i.e. mutator/setter) methods for all your persistable instance variables.&lt;br /&gt;&lt;br /&gt;2.You should implement the equals() and hashCode() methods based on your business key and it is important not to use the id field in your equals() and hashCode() definition if the id field is a surrogate key (i.e. Hibernate managed identifier). This is because the Hibernate only generates and sets the field when saving the object.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3. It is recommended to implement the Serializable interface. This is potentially useful if you want to migrate around a multi-processor cluster.&lt;br /&gt;&lt;br /&gt;4.The persistent class should not be final because if it is final then lazy loading cannot be used by creating proxy objects.&lt;br /&gt;&lt;br /&gt;5.Use XDoclet tags for generating your *.hbm.xml files or Annotations (JDK 1.5 onwards), which are less verbose than *.hbm.xml files.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;How can I count the number of query results without actually returning them? &lt;/h2&gt; &lt;pre class="code"&gt;Integer count = (Integer) session.createQuery("select count(*) from ....").uniqueResult();&lt;br /&gt;&lt;/pre&gt; &lt;a name="A3" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;How can I find the size of a collection without initializing it? &lt;/h2&gt; &lt;pre class="code"&gt;Integer size = (Integer) s.createFilter( collection, "select count(*)" ).uniqueResult();&lt;br /&gt;&lt;/pre&gt; &lt;a name="A4" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;How can I order by the size of a collection? &lt;/h2&gt;&lt;p&gt;Use a &lt;tt&gt;left join&lt;/tt&gt;, together with &lt;tt&gt;group by&lt;/tt&gt;&lt;/p&gt; &lt;pre class="code"&gt;select user&lt;br /&gt;from User user&lt;br /&gt;left join user.messages msg&lt;br /&gt;group by user&lt;br /&gt;order by count(msg)&lt;br /&gt;&lt;/pre&gt; &lt;a name="A5" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;How can I place a condition upon a collection size?&lt;/h2&gt;&lt;p&gt;If your database supports subselects:&lt;/p&gt; &lt;pre class="code"&gt;from User user where size(user.messages) &gt;= 1&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;or:&lt;/p&gt; &lt;pre class="code"&gt;from User user where exists elements(user.messages)&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;If not, and in the case of a one-to-many or many-to-many association:&lt;/p&gt; &lt;pre class="code"&gt;select user&lt;br /&gt;from User user&lt;br /&gt;join user.messages msg&lt;br /&gt;group by user&lt;br /&gt;having count(msg) &gt;= 1&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Because of the inner join, this form can't be used to return a &lt;tt&gt;User&lt;/tt&gt; with zero messages, so the following form is also useful&lt;/p&gt; &lt;pre class="code"&gt;select user&lt;br /&gt;from User as user&lt;br /&gt;left join user.messages as msg&lt;br /&gt;group by user&lt;br /&gt;having count(msg) = 0&lt;br /&gt;&lt;/pre&gt; &lt;a name="A6" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;How can I query for entities with empty collections?&lt;/h2&gt; &lt;pre class="code"&gt;from Box box&lt;br /&gt;where box.balls is empty&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Or, try this:&lt;/p&gt; &lt;pre class="code"&gt;select box&lt;br /&gt;from Box box&lt;br /&gt;left join box.balls ball&lt;br /&gt;where ball is null&lt;br /&gt;&lt;/pre&gt; &lt;a name="A7" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;How can I sort / order collection elements?&lt;/h2&gt;&lt;p&gt;There are three different approaches: &lt;/p&gt; &lt;blockquote&gt;&lt;p&gt;1. Use a &lt;tt&gt;SortedSet&lt;/tt&gt; or &lt;tt&gt;SortedMap&lt;/tt&gt;, specifying a comparator class in the &lt;tt&gt;sort&lt;/tt&gt; attribute or &lt;tt&gt;&lt;set&gt;&lt;/set&gt;&lt;/tt&gt; or &lt;tt&gt;&lt;map&gt;&lt;/map&gt;&lt;/tt&gt;. This solution does a sort in memory.&lt;/p&gt;&lt;/blockquote&gt; &lt;blockquote&gt;&lt;p&gt;2. Specify an &lt;tt&gt;order-by&lt;/tt&gt; attribute of &lt;tt&gt;&lt;set&gt;&lt;/set&gt;&lt;/tt&gt;, &lt;tt&gt;&lt;map&gt;&lt;/map&gt;&lt;/tt&gt; or &lt;tt&gt;&lt;bag&gt;&lt;/bag&gt;&lt;/tt&gt;, naming a list of table columns to sort by. This solution works only in JDK 1.4+.&lt;/p&gt;&lt;/blockquote&gt; &lt;blockquote&gt;&lt;p&gt;3. Use a filter &lt;tt&gt;session.createFilter( collection, "order by ...." ).list()&lt;/tt&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;a name="A8" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;Are collections pageable?&lt;/h2&gt; &lt;pre class="code"&gt;Query q = s.createFilter( collection, "" ); // the trivial filter&lt;br /&gt;q.setMaxResults(PAGE_SIZE);&lt;br /&gt;q.setFirstResult(PAGE_SIZE * pageNumber);&lt;br /&gt;List page = q.list();&lt;br /&gt;&lt;/pre&gt; &lt;a name="A9" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;I have a one-to-one association between two classes. Ensuring that associated objects have matching identifiers is bugprone. Is there a better way?&lt;/h2&gt; &lt;pre class="code"&gt;&lt;generator class="foreign"&gt;&lt;br /&gt;  &lt;param name="property"&gt;parent&lt;br /&gt;&lt;/generator&gt;&lt;br /&gt;&lt;/pre&gt; &lt;a name="A10" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;I have a many-to-many association between two tables, but the association table has some extra columns (apart from the foreign keys). What kind of mapping should I use?&lt;/h2&gt;&lt;p&gt;Use a composite-element to model the association table. For example, given the following association table: &lt;/p&gt; &lt;pre class="code"&gt;create table relationship (&lt;br /&gt; fk_of_foo bigint not null,&lt;br /&gt; fk_of_bar bigint not null,&lt;br /&gt; multiplicity smallint,&lt;br /&gt; created date )&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;you could use this collection mapping (inside the mapping for class Foo):&lt;/p&gt; &lt;pre class="code"&gt;&lt;set name="relationship"&gt;&lt;br /&gt; &lt;key column="fk_of_foo"&gt;&lt;br /&gt; &lt;composite-element class="Relationship"&gt;&lt;br /&gt;     &lt;property name="multiplicity" type="short" null="true"&gt;&lt;br /&gt;     &lt;property name="created" type="date" null="true"&gt;&lt;br /&gt;     &lt;many-to-one name="bar" class="Bar" null="true"&gt;&lt;br /&gt; &lt;/many-to-one&gt;&lt;br /&gt;&lt;/property&gt;&lt;br /&gt;&lt;/property&gt;&lt;/composite-element&gt;&lt;/key&gt;&lt;/set&gt;&lt;/pre&gt;&lt;p&gt;You may also use an &lt;idbag&gt; with a surrogate key column for the collection table. This would allow you to have nullable columns.&lt;/idbag&gt;&lt;/p&gt;&lt;p&gt;An alternative approach is to simply map the association table as a normal entity class with two bidirectional one-to-many associations.&lt;/p&gt; &lt;a name="A11" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;In an MVC application, how can we ensure that all proxies and lazy collections will be initialized when the view tries to access them? &lt;/h2&gt;&lt;p&gt;One possible approach is to leave the session open (and transaction uncommitted) when forwarding to the view. The session/transaction would be closed/committed after the view is rendered in, for example, a servlet filter (another example would by to use the &lt;tt&gt;ModelLifetime.discard()&lt;/tt&gt; callback in Maverick). One difficulty with this approach is making sure the session/transaction is closed/rolled back if an exception occurs rendering the view.&lt;/p&gt;&lt;p&gt;Another approach is to simply force initialization of all needed objects using &lt;tt&gt;Hibernate.initialize()&lt;/tt&gt;. This is often more straightforward than it sounds.&lt;/p&gt; &lt;a name="A12" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;How can I bind a dynamic list of values into an &lt;tt&gt;in&lt;/tt&gt; query expression?&lt;/h2&gt; &lt;pre class="code"&gt;Query q = s.createQuery("from foo in class Foo where foo.id in (:id_list)");&lt;br /&gt;q.setParameterList("id_list", fooIdList);&lt;br /&gt;List foos = q.list();&lt;br /&gt;&lt;/pre&gt; &lt;a name="A13" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;How can I bind properties of a JavaBean to named query parameters?&lt;/h2&gt; &lt;pre class="code"&gt;Query q = s.createQuery("from foo in class Foo where foo.name=:name and foo.size=:size");&lt;br /&gt;q.setProperties(fooBean); // fooBean has getName() and getSize()&lt;br /&gt;List foos = q.list();&lt;br /&gt;&lt;/pre&gt; &lt;a name="A14" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;Can I map an inner class?&lt;/h2&gt;&lt;p&gt;You may persist any &lt;em&gt;static&lt;/em&gt; inner class. You should specify the class name using the standard form ie. &lt;tt&gt;eg.Foo$Bar&lt;/tt&gt;&lt;/p&gt; &lt;a name="A15" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;How can I assign a default value to a property when the database column is null?&lt;/h2&gt;&lt;p&gt;Use a &lt;tt&gt;UserType&lt;/tt&gt;.&lt;/p&gt; &lt;a name="A16" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;How can I trucate &lt;tt&gt;String&lt;/tt&gt; data?&lt;/h2&gt;&lt;p&gt;Use a &lt;tt&gt;UserType&lt;/tt&gt;.&lt;/p&gt; &lt;a name="A17" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;How can I trim spaces from &lt;tt&gt;String&lt;/tt&gt; data persisted to a &lt;tt&gt;CHAR&lt;/tt&gt; column?&lt;/h2&gt;&lt;p&gt;Use a &lt;tt&gt;UserType&lt;/tt&gt;.&lt;/p&gt; &lt;a name="A18" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;How can I convert the type of a property to/from the database column type?&lt;/h2&gt;&lt;p&gt;Use a &lt;tt&gt;UserType&lt;/tt&gt;.&lt;/p&gt; &lt;a name="A19" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;How can I get access to O/R mapping information such as table and column names at runtime?&lt;/h2&gt;&lt;p&gt;This information is available via the &lt;tt&gt;Configuration&lt;/tt&gt; object. For example, entity mappings may be obtained using &lt;tt&gt;Configuration.getClassMapping()&lt;/tt&gt;. It is even possible to manipulate this metamodel at runtime and then build a new &lt;tt&gt;SessionFactory&lt;/tt&gt;.&lt;/p&gt; &lt;a name="A20" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;How can I create an association to an entity without fetching that entity from the database (if I know the identifier)?&lt;/h2&gt;&lt;p&gt;If the entity is proxyable (&lt;tt&gt;lazy="true"&lt;/tt&gt;), simply use &lt;tt&gt;load()&lt;/tt&gt;. The following code does not result in any &lt;tt&gt;SELECT&lt;/tt&gt; statement:&lt;/p&gt; &lt;pre class="code"&gt;Item itemProxy = (Item) session.load(Item.class, itemId);&lt;br /&gt;Bid bid = new Bid(user, amount, itemProxy);&lt;br /&gt;session.save(bid);&lt;br /&gt;&lt;/pre&gt; &lt;a name="A21" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;How can I retrieve the identifier of an associated object, without fetching the association?&lt;/h2&gt;&lt;p&gt;Just do it. The following code does not result in any &lt;tt&gt;SELECT&lt;/tt&gt; statement, even if the &lt;tt&gt;item&lt;/tt&gt; association is lazy.&lt;/p&gt; &lt;pre class="code"&gt;Long itemId = bid.getItem().getId();&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;This works if &lt;tt&gt;getItem()&lt;/tt&gt; returns a proxy and if you mapped the identifier property with regular accessor methods. If you enabled direct field access for the &lt;tt&gt;id&lt;/tt&gt; of an &lt;tt&gt;Item&lt;/tt&gt;, the &lt;tt&gt;Item&lt;/tt&gt; proxy will be initialized if you call &lt;tt&gt;getId()&lt;/tt&gt;. This method is then treated like any other business method of the proxy, initialization is required if it is called.&lt;/p&gt; &lt;a name="A22" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;How can I manipulate mappings at runtime?&lt;/h2&gt;&lt;p&gt;You can access (and modify) the Hibernate metamodel via the &lt;tt&gt;Configuration&lt;/tt&gt; object, using &lt;tt&gt;getClassMapping()&lt;/tt&gt;, &lt;tt&gt;getCollectionMapping()&lt;/tt&gt;, etc.&lt;/p&gt;&lt;p&gt;Note that the &lt;tt&gt;SessionFactory&lt;/tt&gt; is &lt;em&gt;immutable&lt;/em&gt; and does not retain any reference to the &lt;tt&gt;Configuration&lt;/tt&gt; instance, so you must re-build it if you wish to activate the modified mappings.&lt;/p&gt; &lt;a name="A23" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;How can I avoid n+1 SQL &lt;tt&gt;SELECT&lt;/tt&gt; queries when running a Hibernate query?&lt;/h2&gt;&lt;p&gt;Follow the best practices guide! Ensure that all &lt;tt&gt;&lt;class&gt;&lt;/class&gt;&lt;/tt&gt; and &lt;tt&gt;&lt;collection&gt;&lt;/collection&gt;&lt;/tt&gt; mappings specify &lt;tt&gt;lazy="true"&lt;/tt&gt; in Hibernate2 (this is the new default in Hibernate3). Use HQL &lt;tt&gt;LEFT JOIN FETCH&lt;/tt&gt; to specify which associations you need to be retrieved in the initial SQL &lt;tt&gt;SELECT&lt;/tt&gt;.&lt;/p&gt;&lt;p&gt;A second way to avoid the n+1 selects problem is to use &lt;tt&gt;fetch="subselect"&lt;/tt&gt; in Hibernate3.&lt;/p&gt;&lt;p&gt;If you are still unsure, refer to the Hibernate documentation and &lt;em&gt;Hibernate in Action&lt;/em&gt;.&lt;/p&gt; &lt;a name="A24" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;I have a collection with second-level cache enabled, and Hibernate retrieves the collection elements one at a time with a SQL query per element!&lt;/h2&gt;&lt;p&gt;Enable second-level cache for the associated entity class. Don't cache collections of uncached entity types.&lt;/p&gt; &lt;a name="A25" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;How can I insert XML data into Oracle using the &lt;tt&gt;xmltype()&lt;/tt&gt; function?&lt;/h2&gt;&lt;p&gt;Specify custom SQL &lt;tt&gt;INSERT&lt;/tt&gt; (and &lt;tt&gt;UPDATE&lt;/tt&gt;) statements using &lt;tt&gt;&lt;sql-insert&gt;&lt;/sql-insert&gt;&lt;/tt&gt; and &lt;tt&gt;&lt;sql-update&gt;&lt;/sql-update&gt;&lt;/tt&gt; in Hibernate3, or using a custom persister in Hibernate 2.1.&lt;/p&gt;&lt;p&gt;You will also need to write a &lt;tt&gt;UserType&lt;/tt&gt; to perform binding to/from the &lt;tt&gt;PreparedStatement&lt;/tt&gt;.&lt;/p&gt; &lt;a name="A26" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;How can I execute arbitrary SQL using Hibernate?&lt;/h2&gt; &lt;pre class="code"&gt;PreparedStatement ps = session.connection().prepareStatement(sqlString);&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Or, if you wish to retrieve managed entity objects, use &lt;tt&gt;session.createSQLQuery()&lt;/tt&gt;.&lt;/p&gt;&lt;p&gt;Or, in Hibernate3, override generated SQL using &lt;tt&gt;&lt;sql-insert&gt;&lt;/sql-insert&gt;&lt;/tt&gt;, &lt;tt&gt;&lt;sql-update&gt;&lt;/sql-update&gt;&lt;/tt&gt;, &lt;tt&gt;&lt;sql-delete&gt;&lt;/sql-delete&gt;&lt;/tt&gt; and &lt;tt&gt;&lt;loader&gt;&lt;/loader&gt;&lt;/tt&gt; in the mapping document.&lt;/p&gt; &lt;a name="A27" _base_href="http://www.hibernate.org/"&gt;&lt;/a&gt;&lt;h2&gt;I want to call an SQL function from HQL, but the HQL parser does not recognize it!&lt;/h2&gt;&lt;p&gt;Subclass your Dialect, and call registerFunction() from the constructor.&lt;/p&gt;&lt;br /&gt;&lt;h3 class="post-title"&gt;      More Hibernate Questions        &lt;/h3&gt;  &lt;br /&gt;&lt;br /&gt;      &lt;!-- 336x280 Large Rectangle Ad Starts --&gt; &lt;div style="margin: 3px; float: right;"&gt; &lt;script type="text/javascript"&gt;&lt;!-- google_ad_client = "pub-8148979630051682"; google_ad_width = 336; google_ad_height = 280; google_ad_format = "336x280_as"; google_ad_type = "text_image"; //2007-06-07: IQJSquare google_ad_channel = "9549346289"; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "4C4C4C"; google_color_text = "FFFFFF"; google_color_url = "666666"; //--&gt; &lt;/script&gt; &lt;script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt; &lt;/script&gt;&lt;iframe name="google_ads_frame" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-8148979630051682&amp;amp;dt=1213888959578&amp;amp;lmt=1213880880&amp;amp;prev_fmts=728x15_0ads_al%2C120x600_as%2C200x90_0ads_al_s%2C200x90_0ads_al_s&amp;amp;format=336x280_as&amp;amp;output=html&amp;amp;correlator=1213888957234&amp;amp;channel=9549346289&amp;amp;url=http%3A%2F%2Finterviewjava.blogspot.com%2F2007%2F06%2Fmore-hibernate-questions.html&amp;amp;color_bg=FFFFFF&amp;amp;color_text=FFFFFF&amp;amp;color_link=4C4C4C&amp;amp;color_url=666666&amp;amp;color_border=FFFFFF&amp;amp;ad_type=text_image&amp;amp;ref=http%3A%2F%2Finterviewjava.blogspot.com%2F2007%2F06%2Finterview-questions-on-hibernate.html&amp;amp;frm=0&amp;amp;cc=100&amp;amp;ga_vid=3477443889759733000.1213888185&amp;amp;ga_sid=1213888185&amp;amp;ga_hid=2111351382&amp;amp;ga_fc=true&amp;amp;flash=9.0.16&amp;amp;u_h=800&amp;amp;u_w=1280&amp;amp;u_ah=740&amp;amp;u_aw=1280&amp;amp;u_cd=32&amp;amp;u_tz=-240&amp;amp;u_his=1&amp;amp;u_java=true&amp;amp;u_nplug=17&amp;amp;u_nmime=31" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" frameborder="0" height="280" scrolling="no" width="336"&gt;&lt;/iframe&gt; &lt;/div&gt; &lt;!-- 336x280 Large Rectangle Ad Ends --&gt;                      &lt;p&gt;&lt;span style="font-weight: bold;"&gt;Question&lt;/span&gt;: What are common mechanisms of &lt;span style="font-weight: bold;"&gt;configuring Hibernate&lt;/span&gt;?&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Answer&lt;/span&gt;: 1. By placing hibernate.properties file in the classpath.&lt;br /&gt;2. Including &lt;property&gt; elements in hibernate.cfg.xml in the classpath.&lt;/property&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-weight: bold;"&gt;Question&lt;/span&gt;:How can you create a primary key using Hibernate?&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Answer&lt;/span&gt;: The 'id' tag in &lt;span style="font-weight: bold; font-style: italic;"&gt;.hbm file&lt;/span&gt; corresponds to primary key of the table:&lt;hibernate-mapping&gt;&lt;class name="Employee" table="EMPLOYEE" value="s"&gt;&lt;id name="empid" type="string"&gt;&lt;/id&gt;&lt;/class&gt;&lt;/hibernate-mapping&gt;&lt;/p&gt;&lt;p&gt;&lt;hibernate-mapping&gt;&lt;class name="Employee" table="EMPLOYEE" value="s"&gt;&lt;id name="empid" type="string"&gt;Here Id ="empid", that will act as primary key of the table "EMPLOYEE".&lt;/id&gt;&lt;/class&gt;&lt;/hibernate-mapping&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-weight: bold;"&gt;Question&lt;/span&gt;: In how many ways one can map files to be configured in &lt;span style="font-weight: bold;"&gt;Hibernate&lt;/span&gt;?&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Answer&lt;/span&gt;: 1. Either mapping files are added to configuration in the application code or,&lt;br /&gt;2.hibernate.cfg.xml can be used for configuring in &lt;mapping&gt;. &lt;/mapping&gt;&lt;/p&gt;   &lt;p&gt;&lt;span style="font-weight: bold;"&gt;Question&lt;/span&gt;: How to set Hibernate to log all generated SQL to the console?&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Answer&lt;/span&gt;: By setting the hibernate.show_sql property to true.&lt;/p&gt;  &lt;p&gt;&lt;span style="font-weight: bold;"&gt;Question&lt;/span&gt;: What happens when both &lt;span style="font-style: italic;"&gt;hibernate.properties &lt;/span&gt;and &lt;span style="font-style: italic;"&gt;hibernate.cfg.xml&lt;/span&gt; are in the classpath?&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Answer&lt;/span&gt;: The settings of the XML configuration file will override the settings used in the properties.&lt;/p&gt; &lt;p&gt;&lt;span style="font-weight: bold;"&gt;Question&lt;/span&gt;: What methods must the persistent classes implement in &lt;span style="font-weight: bold;"&gt;Hibernate&lt;/span&gt;?&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Answer&lt;/span&gt;: Since Hibernate instantiates persistent classes using &lt;span style="font-style: italic;"&gt;Constructor.newInstance()&lt;/span&gt;, it requires a constructor with no arguments for every persistent class. And getter and setter methods for all the instance variables. &lt;/p&gt;    &lt;p&gt;&lt;span style="font-weight: bold;"&gt;Question&lt;/span&gt;: How can &lt;span style="font-weight: bold;"&gt;Hibernate &lt;/span&gt;be configured to access an instance variable directly and not through a setter method?&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Answer&lt;/span&gt;: 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.&lt;br /&gt;&lt;hibernate-mapping&gt;&lt;/hibernate-mapping&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Question&lt;/span&gt;: How to declare mappings for multiple classes in one mapping file?&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Answer&lt;/span&gt;:Use multiple &lt;class&gt; elements. But, the recommended practice is to use one mapping file per persistent class. &lt;/class&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-weight: bold;"&gt;Question&lt;/span&gt;: How are the individual properties mapped to different table columns?&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Answer&lt;/span&gt;: By using multiple &lt;property&gt; elements inside the &lt;class&gt; element.&lt;/class&gt;&lt;/property&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-weight: bold;"&gt;Question&lt;/span&gt;: What are derived properties?&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Answer&lt;/span&gt;: 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 &lt;property&gt; element. &lt;/property&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-weight: bold;"&gt;Question&lt;/span&gt;: How can you make a property be read from the database but not modified in anyway (make it immutable)?&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Answer&lt;/span&gt;: Use insert="false" and update="false" attributes.&lt;/p&gt; &lt;p&gt;&lt;span style="font-weight: bold;"&gt;Question&lt;/span&gt;: How can a whole class be mapped as immutable?&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Answer&lt;/span&gt;: By using the mutable="false" attribute in the class mapping.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-5637294218041211396?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/5637294218041211396/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=5637294218041211396' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/5637294218041211396'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/5637294218041211396'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/06/hibernate-interview-questions.html' title='Hibernate'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-3383215571598902819</id><published>2008-06-19T08:04:00.001-07:00</published><updated>2008-06-19T08:04:45.577-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ShellScriptingquestions'/><category scheme='http://www.blogger.com/atom/ns#' term='Unix'/><title type='text'>Shell Scripting questions</title><content type='html'>&lt;h1 class="title"&gt;&lt;a href="http://www.techinterviews.com/?p=336" rel="bookmark" title="Basic shell scripting questions"&gt;Basic shell scripting questions&lt;/a&gt;&lt;/h1&gt;            &lt;ol&gt;&lt;li&gt;&lt;b&gt;How do you find out what’s your shell?&lt;/b&gt; - echo $SHELL&lt;/li&gt;&lt;li&gt;&lt;b&gt;What’s the command to find out today’s date?&lt;/b&gt; - date&lt;/li&gt;&lt;li&gt;&lt;b&gt;What’s the command to find out users on the system?&lt;/b&gt; - who&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you find out the current directory you’re in?&lt;/b&gt; - pwd&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you remove a file?&lt;/b&gt; - rm&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you remove a &lt;directory with="" all="" the="" files="" in=""&gt;&lt;/directory&gt;&lt;/b&gt; - rm -rf&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you find out your own username?&lt;/b&gt; - whoami&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you send a mail message to somebody?&lt;/b&gt; - mail &lt;a href="mailto:somebody@techinterviews.com"&gt;somebody@techinterviews.com&lt;/a&gt; -s ‘Your subject’ -c &lt;a href="mailto:%27cc@techinterviews.com"&gt;‘cc@techinterviews.com&lt;/a&gt;‘&lt;/li&gt;&lt;p&gt;&lt;span id="more-336"&gt;&lt;/span&gt; &lt;/p&gt;&lt;li&gt;&lt;b&gt;How do you count words, lines and characters in a file?&lt;/b&gt; - wc&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you search for a string inside a given file?&lt;/b&gt; - grep string filename&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you search for a string inside a directory?&lt;/b&gt; - grep string *&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you search for a string in a directory with the subdirectories recursed?&lt;/b&gt; - grep -r string *&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are PIDs?&lt;/b&gt; - They are process IDs given to processes. A PID can vary from 0 to 65535.&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you list currently running process?&lt;/b&gt; - ps&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you stop a process?&lt;/b&gt; - kill pid&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you find out about all running processes?&lt;/b&gt; - ps -ag&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you stop all the processes, except the shell window?&lt;/b&gt; - kill 0&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you fire a process in the background?&lt;/b&gt; - ./process-name &amp;amp;&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you refer to the arguments passed to a shell script?&lt;/b&gt; - $1, $2 and so on. $0 is your script name.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What’s the conditional statement in shell scripting?&lt;/b&gt; - if {condition} then … fi&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you do number comparison in shell scripts?&lt;/b&gt; - -eq, -ne, -lt, -le, -gt, -ge&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you test for file properties in shell scripts?&lt;/b&gt; - -s filename tells you if the file is not empty, -f filename tells you whether the argument is a file, and not a directory, -d filename tests if the argument is a directory, and not a file, -w filename tests for writeability, -r filename tests for readability, -x filename tests for executability&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you do Boolean logic operators in shell scripting?&lt;/b&gt; - ! tests for logical not, -a tests for logical and, and -o tests for logical or.&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you find out the number of arguments passed to the shell script?&lt;/b&gt; - $#&lt;/li&gt;&lt;li&gt;&lt;b&gt;What’s a way to do multilevel if-else’s in shell scripting?&lt;/b&gt; - if {condition} then {statement} elif {condition} {statement} fi&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you write a for loop in shell?&lt;/b&gt; - for {variable name} in {list} do {statement} done&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you write a while loop in shell?&lt;/b&gt; - while {condition} do {statement} done&lt;/li&gt;&lt;li&gt;&lt;b&gt;How does a case statement look in shell scripts?&lt;/b&gt; - case {variable} in {possible-value-1}) {statement};; {possible-value-2}) {statement};; esac&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you read keyboard input in shell scripts?&lt;/b&gt; - read {variable-name}&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you define a function in a shell script?&lt;/b&gt; - function-name() { #some code here return }&lt;/li&gt;&lt;li&gt;&lt;b&gt;How does getopts command work?&lt;/b&gt; - The parameters to your script can be passed as -n 15 -x 20. Inside the script, you can iterate through the getopts array as while getopts n:x option, and the variable $option contains the value of the entered option.&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-3383215571598902819?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/3383215571598902819/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=3383215571598902819' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/3383215571598902819'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/3383215571598902819'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/06/shell-scripting-questions.html' title='Shell Scripting questions'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-7206912046563839502</id><published>2008-06-19T08:01:00.000-07:00</published><updated>2008-06-19T08:02:18.536-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaInterviewQuestions'/><title type='text'>Java Interview Questions</title><content type='html'>&lt;ol&gt;&lt;li&gt;&lt;b&gt;What is the difference between procedural and object-oriented programs?&lt;/b&gt;- a) In procedural program, programming logic follows certain procedures and the instructions are executed one after another. In OOP program, unit of program is object, which is nothing but combination of data and code. b) In procedural program, data is exposed to the whole program whereas in OOPs program, it is accessible with in the object and which in turn assures the security of the code.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are Encapsulation, Inheritance and Polymorphism?&lt;/b&gt;- Encapsulation is the mechanism that binds together code and data it manipulates and keeps both safe from outside interference and misuse. Inheritance is the process by which one object acquires the properties of another object. Polymorphism is the feature that allows one interface to be used for general class actions.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the difference between Assignment and Initialization?&lt;/b&gt;- Assignment can be done as many times as desired whereas initialization can be done only once.&lt;/li&gt;&lt;p&gt;&lt;span id="more-214"&gt;&lt;/span&gt;&lt;/p&gt;&lt;li&gt;&lt;b&gt;What is OOPs?&lt;/b&gt;- Object oriented programming organizes a program around its data, i. e. , objects and a set of well defined interfaces to that data. An object-oriented program can be characterized as data controlling access to code.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are Class, Constructor and Primitive data types?&lt;/b&gt;- Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created. Primitive data types are 8 types and they are: byte, short, int, long, float, double, boolean, char.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is an Object and how do you allocate memory to it?&lt;/b&gt;- Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data. When an object is created using new operator, memory is allocated to it.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the difference between constructor and method?&lt;/b&gt;- Constructor will be automatically invoked when an object is created whereas method has to be called explicitly.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are methods and how are they defined?&lt;/b&gt;- Methods are functions that operate on instances of classes in which they are defined. Objects can communicate with each other using methods and can call methods in other classes. Method definition has four parts. They are name of the method, type of object or primitive type the method returns, a list of parameters and the body of the method. A method’s signature is a combination of the first three parts mentioned above.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the use of bin and lib in JDK?&lt;/b&gt;- Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and all packages.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is casting?&lt;/b&gt;- Casting is used to convert the value of one type to another.&lt;/li&gt;&lt;li&gt;&lt;b&gt;How many ways can an argument be passed to a subroutine and explain them?&lt;/b&gt;- An argument can be passed in two ways. They are passing by value and passing by reference. Passing by value: This method copies the value of an argument into the formal parameter of the subroutine. Passing by reference: In this method, a reference to an argument (not the value of the argument) is passed to the parameter.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the difference between an argument and a parameter?&lt;/b&gt;- While defining method, variables passed in the method are called parameters. While using those methods, values passed to those variables are called arguments.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are different types of access modifiers?&lt;/b&gt;- public: Any thing declared as public can be accessed from anywhere. private: Any thing declared as private can’t be seen outside of its class. protected: Any thing declared as protected can be accessed by classes in the same package and subclasses in the other packages. default modifier : Can be accessed only to classes in the same package.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is final, finalize() and finally?&lt;/b&gt;- final : final keyword can be used for class, method and variables. A final class cannot be subclassed and it prevents other programmers from subclassing a secure class to invoke insecure methods. A final method can’t be overridden. A final variable can’t change from its initialized value. finalize() : finalize() method is used just before an object is destroyed and can be called just prior to garbage collection. finally : finally, a key word used in exception handling, creates a block of code that will be executed after a try/catch block has completed and before the code following the try/catch block. The finally block will execute whether or not an exception is thrown. For example, if a method opens a file upon exit, then you will not want the code that closes the file to be bypassed by the exception-handling mechanism. This finally keyword is designed to address this contingency.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is UNICODE?&lt;/b&gt;- Unicode is used for internal representation of characters and strings and it uses 16 bits to represent each other.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is Garbage Collection and how to call it explicitly?&lt;/b&gt;- When an object is no longer referred to by any variable, java automatically reclaims memory used by that object. This is known as garbage collection. System. gc() method may be used to call it explicitly.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is finalize() method?&lt;/b&gt;- finalize () method is used just before an object is destroyed and can be called just prior to garbage collection.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are Transient and Volatile Modifiers?&lt;/b&gt;- Transient: The transient modifier applies to variables only and it is not stored as part of its object’s Persistent state. Transient variables are not serialized. Volatile: Volatile modifier applies to variables only and it tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of the program.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is method overloading and method overriding?&lt;/b&gt;- Method overloading: When a method in a class having the same method name with different arguments is said to be method overloading. Method overriding : When a method in a class having the same method name with same arguments is said to be method overriding.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is difference between overloading and overriding?&lt;/b&gt;- a) In overloading, there is a relationship between methods available in the same class whereas in overriding, there is relationship between a superclass method and subclass method. b) Overloading does not block inheritance from the superclass whereas overriding blocks inheritance from the superclass. c) In overloading, separate methods share the same name whereas in overriding, subclass method replaces the superclass. d) Overloading must have different method signatures whereas overriding must have same signature.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is meant by Inheritance and what are its advantages?&lt;/b&gt;- Inheritance is the process of inheriting all the features from a class. The advantages of inheritance are reusability of code and accessibility of variables and methods of the super class by subclasses.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the difference between this() and super()?&lt;/b&gt;- this() can be used to invoke a constructor of the same class whereas super() can be used to invoke a super class constructor.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the difference between superclass and subclass?&lt;/b&gt;- A super class is a class that is inherited whereas sub class is a class that does the inheriting.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What modifiers may be used with top-level class?&lt;/b&gt;- public, abstract and final can be used for top-level class.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are inner class and anonymous class?&lt;/b&gt;- Inner class : classes defined in other classes, including those defined in methods are called inner classes. An inner class can have any accessibility including private. Anonymous class : Anonymous class is a class defined inside a method without a name and is instantiated and declared in the same place and cannot have explicit constructors.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is a package?&lt;/b&gt;- A package is a collection of classes and interfaces that provides a high-level layer of access protection and name space management.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is a reflection package?&lt;/b&gt;- java. lang. reflect package has the ability to analyze itself in runtime.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is interface and its use?&lt;/b&gt;- Interface is similar to a class which may contain method’s signature only but not bodies and it is a formal set of method and constant declarations that must be defined by the class that implements it. Interfaces are useful for: a)Declaring methods that one or more classes are expected to implement b)Capturing similarities between unrelated classes without forcing a class relationship. c)Determining an object’s programming interface without revealing the actual body of the class.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is an abstract class?&lt;/b&gt;- An abstract class is a class designed with implementation gaps for subclasses to fill in and is deliberately incomplete.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the difference between Integer and int?&lt;/b&gt;- a) Integer is a class defined in the java. lang package, whereas int is a primitive data type defined in the Java language itself. Java does not automatically convert from one to the other. b) Integer can be used as an argument for a method that requires an object, whereas int can be used for calculations.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is a cloneable interface and how many methods does it contain?&lt;/b&gt;- It is not having any method because it is a TAGGED or MARKER interface.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the difference between abstract class and interface?&lt;/b&gt;- a) All the methods declared inside an interface are abstract whereas abstract class must have at least one abstract method and others may be concrete or abstract. b) In abstract class, key word abstract must be used for the methods whereas interface we need not use that keyword for the methods. c) Abstract class must have subclasses whereas interface can’t have subclasses.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Can you have an inner class inside a method and what variables can you access?&lt;/b&gt;- Yes, we can have an inner class inside a method and final variables can be accessed.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the difference between String and String Buffer?&lt;/b&gt;- a) String objects are constants and immutable whereas StringBuffer objects are not. b) String class supports constant strings whereas StringBuffer class supports growable and modifiable strings.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the difference between Array and vector?&lt;/b&gt;- Array is a set of related data type and static whereas vector is a growable array of objects and dynamic.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the difference between exception and error?&lt;/b&gt;- The exception class defines mild error conditions that your program encounters. Exceptions can occur when trying to open the file, which does not exist, the network connection is disrupted, operands being manipulated are out of prescribed ranges, the class file you are interested in loading is missing. The error class defines serious error conditions that you should not attempt to recover from. In most cases it is advisable to let the program terminate when such an error is encountered.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the difference between process and thread?&lt;/b&gt;- Process is a program in execution whereas thread is a separate path of execution in a program.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is multithreading and what are the methods for inter-thread communication and what is the class in which these methods are defined?&lt;/b&gt;- Multithreading is the mechanism in which more than one thread run independent of each other within the process. wait (), notify () and notifyAll() methods can be used for inter-thread communication and these methods are in Object class. wait() : When a thread executes a call to wait() method, it surrenders the object lock and enters into a waiting state. notify() or notifyAll() : To remove a thread from the waiting state, some other thread must make a call to notify() or notifyAll() method on the same object.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the class and interface in java to create thread and which is the most advantageous method?&lt;/b&gt;- Thread class and Runnable interface can be used to create threads and using Runnable interface is the most advantageous method to create threads because we need not extend thread class here.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are the states associated in the thread?&lt;/b&gt;- Thread contains ready, running, waiting and dead states.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is synchronization?&lt;/b&gt;- Synchronization is the mechanism that ensures that only one thread is accessed the resources at a time.&lt;/li&gt;&lt;li&gt;&lt;b&gt;When you will synchronize a piece of your code?&lt;/b&gt;- When you expect your code will be accessed by different threads and these threads may change a particular data causing data corruption.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is deadlock?&lt;/b&gt;- When two threads are waiting each other and can’t precede the program is said to be deadlock.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is daemon thread and which method is used to create the daemon thread?&lt;/b&gt;- Daemon thread is a low priority thread which runs intermittently in the back ground doing the garbage collection operation for the java runtime system. setDaemon method is used to create a daemon thread.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Are there any global variables in Java, which can be accessed by other part of your program?&lt;/b&gt;- No, it is not the main method in which you define variables. Global variables is not possible because concept of encapsulation is eliminated here.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is an applet?&lt;/b&gt;- Applet is a dynamic and interactive program that runs inside a web page displayed by a java capable browser.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the difference between applications and applets?&lt;/b&gt;- a)Application must be run on local machine whereas applet needs no explicit installation on local machine. b)Application must be run explicitly within a java-compatible virtual machine whereas applet loads and runs itself automatically in a java-enabled browser. d)Application starts execution with its main method whereas applet starts execution with its init method. e)Application can run with or without graphical user interface whereas applet must run within a graphical user interface.&lt;/li&gt;&lt;li&gt;&lt;b&gt;How does applet recognize the height and width?&lt;/b&gt;- Using getParameters() method.&lt;/li&gt;&lt;li&gt;&lt;b&gt;When do you use codebase in applet?&lt;/b&gt;- When the applet class file is not in the same directory, codebase is used.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the lifecycle of an applet?&lt;/b&gt;- init() method - Can be called when an applet is first loaded start() method - Can be called each time an applet is started. paint() method - Can be called when the applet is minimized or maximized. stop() method - Can be used when the browser moves off the applet’s page. destroy() method - Can be called when the browser is finished with the applet.&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you set security in applets?&lt;/b&gt;- using setSecurityManager() method&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is an event and what are the models available for event handling?&lt;/b&gt;- An event is an event object that describes a state of change in a source. In other words, event occurs when an action is generated, like pressing button, clicking mouse, selecting a list, etc. There are two types of models for handling events and they are: a) event-inheritance model and b) event-delegation model&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are the advantages of the model over the event-inheritance model?&lt;/b&gt;- The event-delegation model has two advantages over the event-inheritance model. They are: a)It enables event handling by objects other than the ones that generate the events. This allows a clean separation between a component’s design and its use. b)It performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to be repeatedly process unhandled events as is the case of the event-inheritance.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is source and listener?&lt;/b&gt;- source : A source is an object that generates an event. This occurs when the internal state of that object changes in some way. listener : A listener is an object that is notified when an event occurs. It has two major requirements. First, it must have been registered with one or more sources to receive notifications about specific types of events. Second, it must implement methods to receive and process these notifications.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is adapter class?&lt;/b&gt;- An adapter class provides an empty implementation of all methods in an event listener interface. Adapter classes are useful when you want to receive and process only some of the events that are handled by a particular event listener interface. You can define a new class to act listener by extending one of the adapter classes and implementing only those events in which you are interested. For example, the MouseMotionAdapter class has two methods, mouseDragged()and mouseMoved(). The signatures of these empty are exactly as defined in the MouseMotionListener interface. If you are interested in only mouse drag events, then you could simply extend MouseMotionAdapter and implement mouseDragged() .&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is meant by controls and what are different types of controls in AWT?&lt;/b&gt;- Controls are components that allow a user to interact with your application and the AWT supports the following types of controls: Labels, Push Buttons, Check Boxes, Choice Lists, Lists, Scrollbars, Text Components. These controls are subclasses of Component.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the difference between choice and list?&lt;/b&gt;- A Choice is displayed in a compact form that requires you to pull it down to see the list of available choices and only one item may be selected from a choice. A List may be displayed in such a way that several list items are visible and it supports the selection of one or more list items.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the difference between scrollbar and scrollpane?&lt;/b&gt;- A Scrollbar is a Component, but not a Container whereas Scrollpane is a Conatiner and handles its own events and perform its own scrolling.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is a layout manager and what are different types of layout managers available in java AWT?&lt;/b&gt;- A layout manager is an object that is used to organize components in a container. The different layouts are available are FlowLayout, BorderLayout, CardLayout, GridLayout and GridBagLayout.&lt;/li&gt;&lt;li&gt;&lt;b&gt;How are the elements of different layouts organized?&lt;/b&gt;- FlowLayout: The elements of a FlowLayout are organized in a top to bottom, left to right fashion. BorderLayout: The elements of a BorderLayout are organized at the borders (North, South, East and West) and the center of a container. CardLayout: The elements of a CardLayout are stacked, on top of the other, like a deck of cards. GridLayout: The elements of a GridLayout are of equal size and are laid out using the square of a grid. GridBagLayout: The elements of a GridBagLayout are organized according to a grid. However, the elements are of different size and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Which containers use a Border layout as their default layout?&lt;/b&gt;- Window, Frame and Dialog classes use a BorderLayout as their layout.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Which containers use a Flow layout as their default layout?&lt;/b&gt;- Panel and Applet classes use the FlowLayout as their default layout.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are wrapper classes?&lt;/b&gt;- Wrapper classes are classes that allow primitive types to be accessed as objects.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are Vector, Hashtable, LinkedList and Enumeration?&lt;/b&gt;- Vector : The Vector class provides the capability to implement a growable array of objects. Hashtable : The Hashtable class implements a Hashtable data structure. A Hashtable indexes and stores objects in a dictionary using hash codes as the object’s keys. Hash codes are integer values that identify objects. LinkedList: Removing or inserting elements in the middle of an array can be done using LinkedList. A LinkedList stores each object in a separate link whereas an array stores object references in consecutive locations. Enumeration: An object that implements the Enumeration interface generates a series of elements, one at a time. It has two methods, namely hasMoreElements() and nextElement(). HasMoreElemnts() tests if this enumeration has more elements and nextElement method returns successive elements of the series.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the difference between set and list?&lt;/b&gt;- Set stores elements in an unordered way but does not contain duplicate elements, whereas list stores elements in an ordered way but may contain duplicate elements.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is a stream and what are the types of Streams and classes of the Streams?&lt;/b&gt;- A Stream is an abstraction that either produces or consumes information. There are two types of Streams and they are: Byte Streams: Provide a convenient means for handling input and output of bytes. Character Streams: Provide a convenient means for handling input &amp;amp; output of characters. Byte Streams classes: Are defined by using two abstract classes, namely InputStream and OutputStream. Character Streams classes: Are defined by using two abstract classes, namely Reader and Writer.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the difference between Reader/Writer and InputStream/Output Stream?&lt;/b&gt;- The Reader/Writer class is character-oriented and the InputStream/OutputStream class is byte-oriented.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is an I/O filter?&lt;/b&gt;- An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is serialization and deserialization?&lt;/b&gt;- Serialization is the process of writing the state of an object to a byte stream. Deserialization is the process of restoring these objects.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is JDBC?&lt;/b&gt;- JDBC is a set of Java API for executing SQL statements. This API consists of a set of classes and interfaces to enable programs to write pure Java Database applications.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are drivers available?&lt;/b&gt;- a) JDBC-ODBC Bridge driver b) Native API Partly-Java driver c) JDBC-Net Pure Java driver d) Native-Protocol Pure Java driver&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the difference between JDBC and ODBC?&lt;/b&gt;- a) OBDC is for Microsoft and JDBC is for Java applications. b) ODBC can’t be directly used with Java because it uses a C interface. c) ODBC makes use of pointers which have been removed totally from Java. d) ODBC mixes simple and advanced features together and has complex options for simple queries. But JDBC is designed to keep things simple while allowing advanced capabilities when required. e) ODBC requires manual installation of the ODBC driver manager and driver on all client machines. JDBC drivers are written in Java and JDBC code is automatically installable, secure, and portable on all platforms. f) JDBC API is a natural Java interface and is built on ODBC. JDBC retains some of the basic features of ODBC.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are the types of JDBC Driver Models and explain them?&lt;/b&gt;- There are two types of JDBC Driver Models and they are: a) Two tier model and b) Three tier model Two tier model: In this model, Java applications interact directly with the database. A JDBC driver is required to communicate with the particular database management system that is being accessed. SQL statements are sent to the database and the results are given to user. This model is referred to as client/server configuration where user is the client and the machine that has the database is called as the server. Three tier model: A middle tier is introduced in this model. The functions of this model are: a) Collection of SQL statements from the client and handing it over to the database, b) Receiving results from database to the client and c) Maintaining control over accessing and updating of the above.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are the steps involved for making a connection with a database or how do you connect to a database?&lt;/b&gt;a) Loading the driver : To load the driver, Class. forName() method is used. Class. forName(”sun. jdbc. odbc. JdbcOdbcDriver”); When the driver is loaded, it registers itself with the java. sql. DriverManager class as an available database driver. b) Making a connection with database: To open a connection to a given database, DriverManager. getConnection() method is used. Connection con = DriverManager. getConnection (”jdbc:odbc:somedb”, “user”, “password”); c) Executing SQL statements : To execute a SQL query, java. sql. statements class is used. createStatement() method of Connection to obtain a new Statement object. Statement stmt = con. createStatement(); A query that returns data can be executed using the executeQuery() method of Statement. This method executes the statement and returns a java. sql. ResultSet that encapsulates the retrieved data: ResultSet rs = stmt. executeQuery(”SELECT * FROM some table”); d) Process the results : ResultSet returns one row at a time. Next() method of ResultSet object can be called to move to the next row. The getString() and getObject() methods are used for retrieving column values: while(rs. next()) { String event = rs. getString(”event”); Object count = (Integer) rs. getObject(”count”);&lt;/li&gt;&lt;li&gt;&lt;b&gt;What type of driver did you use in project?&lt;/b&gt;- JDBC-ODBC Bridge driver (is a driver that uses native(C language) libraries and makes calls to an existing ODBC driver to access a database engine).&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are the types of statements in JDBC?&lt;/b&gt;- Statement: to be used createStatement() method for executing single SQL statement PreparedStatement — To be used preparedStatement() method for executing same SQL statement over and over. CallableStatement — To be used prepareCall() method for multiple SQL statements over and over.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is stored procedure?&lt;/b&gt;- Stored procedure is a group of SQL statements that forms a logical unit and performs a particular task. Stored Procedures are used to encapsulate a set of operations or queries to execute on database. Stored procedures can be compiled and executed with different parameters and results and may have any combination of input/output parameters.&lt;/li&gt;&lt;li&gt;&lt;b&gt;How to create and call stored procedures?&lt;/b&gt;- To create stored procedures: Create procedure procedurename (specify in, out and in out parameters) BEGIN Any multiple SQL statement; END; To call stored procedures: CallableStatement csmt = con. prepareCall(”{call procedure name(?,?)}”); csmt. registerOutParameter(column no. , data type); csmt. setInt(column no. , column name) csmt. execute();&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is servlet?&lt;/b&gt;- Servlets are modules that extend request/response-oriented servers, such as java-enabled web servers. For example, a servlet might be responsible for taking data in an HTML order-entry form and applying the business logic used to update a company’s order database.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are the classes and interfaces for servlets?&lt;/b&gt;- There are two packages in servlets and they are javax. servlet and&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the difference between an applet and a servlet?&lt;/b&gt;- a) Servlets are to servers what applets are to browsers. b) Applets must have graphical user interfaces whereas servlets have no graphical user interfaces.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the difference between doPost and doGet methods?&lt;/b&gt;- a) doGet() method is used to get information, while doPost() method is used for posting information. b) doGet() requests can’t send large amount of information and is limited to 240-255 characters. However, doPost()requests passes all of its data, of unlimited length. c) A doGet() request is appended to the request URL in a query string and this allows the exchange is visible to the client, whereas a doPost() request passes directly over the socket connection as part of its HTTP request body and the exchange are invisible to the client.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the life cycle of a servlet?&lt;/b&gt;- Each Servlet has the same life cycle: a) A server loads and initializes the servlet by init () method. b) The servlet handles zero or more client’s requests through service() method. c) The server removes the servlet through destroy() method.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Who is loading the init() method of servlet?&lt;/b&gt;- Web server&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are the different servers available for developing and deploying Servlets?&lt;/b&gt;- a) Java Web Server b) JRun g) Apache Server h) Netscape Information Server i) Web Logic&lt;/li&gt;&lt;li&gt;&lt;b&gt;How many ways can we track client and what are they?&lt;/b&gt;- The servlet API provides two ways to track client state and they are: a) Using Session tracking and b) Using Cookies.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is session tracking and how do you track a user session in servlets?&lt;/b&gt;- Session tracking is a mechanism that servlets use to maintain state about a series requests from the same user across some period of time. The methods used for session tracking are: a) User Authentication - occurs when a web server restricts access to some of its resources to only those clients that log in using a recognized username and password. b) Hidden form fields - fields are added to an HTML form that are not displayed in the client’s browser. When the form containing the fields is submitted, the fields are sent back to the server. c) URL rewriting - every URL that the user clicks on is dynamically modified or rewritten to include extra information. The extra information can be in the form of extra path information, added parameters or some custom, server-specific URL change. d) Cookies - a bit of information that is sent by a web server to a browser and which can later be read back from that browser. e) HttpSession- places a limit on the number of sessions that can exist in memory. This limit is set in the session. maxresidents property.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is Server-Side Includes (SSI)?&lt;/b&gt;- Server-Side Includes allows embedding servlets within HTML pages using a special servlet tag. In many servlets that support servlets, a page can be processed by the server to include output from servlets at certain points inside the HTML page. This is accomplished using a special internal SSINCLUDE, which processes the servlet tags. SSINCLUDE servlet will be invoked whenever a file with an. shtml extension is requested. So HTML files that include server-side includes must be stored with an . shtml extension.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are cookies and how will you use them?&lt;/b&gt;- Cookies are a mechanism that a servlet uses to have a client hold a small amount of state-information associated with the user. a) Create a cookie with the Cookie constructor: public Cookie(String name, String value) b) A servlet can send a cookie to the client by passing a Cookie object to the addCookie() method of HttpServletResponse: public void HttpServletResponse. addCookie(Cookie cookie) c) A servlet retrieves cookies by calling the getCookies() method of HttpServletRequest: public Cookie[ ] HttpServletRequest. getCookie().&lt;/li&gt;&lt;li&gt;&lt;b&gt;Is it possible to communicate from an applet to servlet and how many ways and how?&lt;/b&gt;- Yes, there are three ways to communicate from an applet to servlet and they are: a) HTTP Communication(Text-based and object-based) b) Socket Communication c) RMI Communication&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is connection pooling?&lt;/b&gt;- With servlets, opening a database connection is a major bottleneck because we are creating and tearing down a new connection for every page request and the time taken to create connection will be more. Creating a connection pool is an ideal approach for a complicated servlet. With a connection pool, we can duplicate only the resources we need to duplicate rather than the entire servlet. A connection pool can also intelligently manage the size of the pool and make sure each connection remains valid. A number of connection pool packages are currently available. Some like DbConnectionBroker are freely available from Java Exchange Works by creating an object that dispenses connections and connection Ids on request. The ConnectionPool class maintains a Hastable, using Connection objects as keys and Boolean values as stored values. The Boolean value indicates whether a connection is in use or not. A program calls getConnection() method of the ConnectionPool for getting Connection object it can use; it calls returnConnection() to give the connection back to the pool.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Why should we go for interservlet communication?&lt;/b&gt;- Servlets running together in the same server communicate with each other in several ways. The three major reasons to use interservlet communication are: a) Direct servlet manipulation - allows to gain access to the other currently loaded servlets and perform certain tasks (through the ServletContext object) b) Servlet reuse - allows the servlet to reuse the public methods of another servlet. c) Servlet collaboration - requires to communicate with each other by sharing specific information (through method invocation)&lt;/li&gt;&lt;li&gt;&lt;b&gt;Is it possible to call servlet with parameters in the URL?&lt;/b&gt;- Yes. You can call a servlet with parameters in the syntax as (?Param1 = xxx || m2 = yyy).&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is Servlet chaining?&lt;/b&gt;- Servlet chaining is a technique in which two or more servlets can cooperate in servicing a single request. In servlet chaining, one servlet’s output is piped to the next servlet’s input. This process continues until the last servlet is reached. Its output is then sent back to the client.&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do servlets handle multiple simultaneous requests?&lt;/b&gt;- The server has multiple threads that are available to handle requests. When a request comes in, it is assigned to a thread, which calls a service method (for example: doGet(), doPost() and service()) of the servlet. For this reason, a single servlet object can have its service methods called by many threads at once.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is the difference between TCP/IP and UDP?&lt;/b&gt;- TCP/IP is a two-way communication between the client and the server and it is a reliable and there is a confirmation regarding reaching the message to the destination. It is like a phone call. UDP is a one-way communication only between the client and the server and it is not a reliable and there is no confirmation regarding reaching the message to the destination. It is like a postal mail.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is Inet address?&lt;/b&gt;- Every computer connected to a network has an IP address. An IP address is a number that uniquely identifies each computer on the Net. An IP address is a 32-bit number.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is Domain Naming Service(DNS)?&lt;/b&gt;- It is very difficult to remember a set of numbers(IP address) to connect to the Internet. The Domain Naming Service(DNS) is used to overcome this problem. It maps one particular IP address to a string of characters. For example, www. mascom. com implies com is the domain name reserved for US commercial sites, moscom is the name of the company and www is the name of the specific computer, which is mascom’s server.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is URL?&lt;/b&gt;- URL stands for Uniform Resource Locator and it points to resource files on the Internet. URL has four components: http://www. address. com:80/index.html, where http - protocol name, address - IP address or host name, 80 - port number and index.html - file path.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is RMI and steps involved in developing an RMI object?&lt;/b&gt;- Remote Method Invocation (RMI) allows java object that executes on one machine and to invoke the method of a Java object to execute on another machine. The steps involved in developing an RMI object are: a) Define the interfaces b) Implementing these interfaces c) Compile the interfaces and their implementations with the java compiler d) Compile the server implementation with RMI compiler e) Run the RMI registry f) Run the application&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is RMI architecture?&lt;/b&gt;- RMI architecture consists of four layers and each layer performs specific functions: a) Application layer - contains the actual object definition. b) Proxy layer - consists of stub and skeleton. c) Remote Reference layer - gets the stream of bytes from the transport layer and sends it to the proxy layer. d) Transportation layer - responsible for handling the actual machine-to-machine communication.&lt;/li&gt;&lt;li&gt;&lt;b&gt;what is UnicastRemoteObject?&lt;/b&gt;- All remote objects must extend UnicastRemoteObject, which provides functionality that is needed to make objects available from remote machines.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Explain the methods, rebind() and lookup() in Naming class?&lt;/b&gt;- rebind() of the Naming class(found in java. rmi) is used to update the RMI registry on the server machine. Naming. rebind(”AddSever”, AddServerImpl); lookup() of the Naming class accepts one argument, the rmi URL and returns a reference to an object of type AddServerImpl.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is a Java Bean?&lt;/b&gt;- A Java Bean is a software component that has been designed to be reusable in a variety of different environments.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is a Jar file?&lt;/b&gt;- Jar file allows to efficiently deploying a set of classes and their associated resources. The elements in a jar file are compressed, which makes downloading a Jar file much faster than separately downloading several uncompressed files. The package java. util. zip contains classes that read and write jar files.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is BDK?&lt;/b&gt;- BDK, Bean Development Kit is a tool that enables to create, configure and connect a set of set of Beans and it can be used to test Beans without writing a code.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is JSP?&lt;/b&gt;- JSP is a dynamic scripting capability for web pages that allows Java as well as a few special tags to be embedded into a web file (HTML/XML, etc). The suffix traditionally ends with .jsp to indicate to the web server that the file is a JSP files. JSP is a server side technology - you can’t do any client side validation with it. The advantages are: a) The JSP assists in making the HTML more functional. Servlets on the other hand allow outputting of HTML but it is a tedious process. b) It is easy to make a change and then let the JSP capability of the web server you are using deal with compiling it into a servlet and running it.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are JSP scripting elements?&lt;/b&gt;- JSP scripting elements lets to insert Java code into the servlet that will be generated from the current JSP page. There are three forms: a) Expressions of the form &lt;%= expression %&gt; that are evaluated and inserted into the output, b) Scriptlets of the form&lt;% code %&gt;that are inserted into the servlet’s service method, and c) Declarations of the form &lt;%! Code %&gt;that are inserted into the body of the servlet class, outside of any existing methods.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are JSP Directives?&lt;/b&gt;- A JSP directive affects the overall structure of the servlet class. It usually has the following form:&lt;%@ directive attribute=”value” %&gt; However, you can also combine multiple attribute settings for a single directive, as follows:&lt;%@ directive attribute1=”value1″ attribute 2=”value2″ . . . attributeN =”valueN” %&gt; There are two main types of directive: page, which lets to do things like import classes, customize the servlet superclass, and the like; and include, which lets to insert a file into the servlet class at the time the JSP file is translated into a servlet&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are Predefined variables or implicit objects?&lt;/b&gt;- To simplify code in JSP expressions and scriptlets, we can use eight automatically defined variables, sometimes called implicit objects. They are request, response, out, session, application, config, pageContext, and page.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are JSP ACTIONS?&lt;/b&gt;- JSP actions use constructs in XML syntax to control the behavior of the servlet engine. You can dynamically insert a file, reuse JavaBeans components, forward the user to another page, or generate HTML for the Java plugin. Available actions include: jsp:include - Include a file at the time the page is requested. jsp:useBean - Find or instantiate a JavaBean. jsp:setProperty - Set the property of a JavaBean. jsp:getProperty - Insert the property of a JavaBean into the output. jsp:forward - Forward the requester to a newpage. Jsp: plugin - Generate browser-specific code that makes an OBJECT or EMBED&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you pass data (including JavaBeans) to a JSP from a servlet?&lt;/b&gt;- (1) Request Lifetime: Using this technique to pass beans, a request dispatcher (using either “include” or forward”) can be called. This bean will disappear after processing this request has been completed. Servlet: request. setAttribute(”theBean”, myBean); RequestDispatcher rd = getServletContext(). getRequestDispatcher(”thepage. jsp”); rd. forward(request, response); JSP PAGE:&lt;jsp: id="”theBean”" scope="”request”" class="”."&gt;(2) Session Lifetime: Using this technique to pass beans that are relevant to a particular session (such as in individual user login) over a number of requests. This bean will disappear when the session is invalidated or it times out, or when you remove it. Servlet: HttpSession session = request. getSession(true); session. putValue(”theBean”, myBean); /* You can do a request dispatcher here, or just let the bean be visible on the next request */ JSP Page:&lt;jsp:usebean id="”theBean”" scope="”session”" class="”."&gt; 3) Application Lifetime: Using this technique to pass beans that are relevant to all servlets and JSP pages in a particular app, for all users. For example, I use this to make a JDBC connection pool object available to the various servlets and JSP pages in my apps. This bean will disappear when the servlet engine is shut down, or when you remove it. Servlet: GetServletContext(). setAttribute(”theBean”, myBean); JSP PAGE:&lt;jsp:usebean id="”theBean”" scope="”application”" class="”."&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;How can I set a cookie in JSP?&lt;/b&gt;- response. setHeader(”Set-Cookie”, “cookie string”); To give the response-object to a bean, write a method setResponse (HttpServletResponse response) - to the bean, and in jsp-file:&lt;% bean. setResponse (response); %&gt; &lt;/li&gt;&lt;li&gt;&lt;b&gt;How can I delete a cookie with JSP?&lt;/b&gt;- Say that I have a cookie called “foo, ” that I set a while ago &amp;amp; I want it to go away. I simply: &lt;% Cookie killCookie = new Cookie(”foo”, null); KillCookie. setPath(”/”); killCookie. setMaxAge(0); response. addCookie(killCookie); %&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;How are Servlets and JSP Pages related?&lt;/b&gt;- JSP pages are focused around HTML (or XML) with Java codes and JSP tags inside them. When a web server that has JSP support is asked for a JSP page, it checks to see if it has already compiled the page into a servlet. Thus, JSP pages become servlets and are transformed into pure Java and then compiled, loaded into the server and executed.&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-7206912046563839502?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/7206912046563839502/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=7206912046563839502' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/7206912046563839502'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/7206912046563839502'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/06/java-interview-questions.html' title='Java Interview Questions'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-5255930158159869473</id><published>2008-06-19T07:58:00.000-07:00</published><updated>2008-06-19T07:59:03.944-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JSP interview questions'/><title type='text'>JSP interview questions</title><content type='html'>JSP interview questions&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What are the most common techniques for reusing functionality in object-oriented systems?&lt;/span&gt;&lt;br /&gt;A: The two most common techniques for reusing functionality in object-oriented systems are class inheritance and object composition.&lt;br /&gt;&lt;br /&gt;Class inheritance lets you define the implementation of one class in terms of another’s. Reuse by subclassing is often referred to as white-box reuse.&lt;br /&gt;Object composition is an alternative to class inheritance. Here, new functionality is obtained by assembling or composing objects to get more complex functionality. This is known as black-box reuse.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: Why would you want to have more than one catch block associated with a single try block in Java?&lt;/span&gt;&lt;br /&gt;A: Since there are many things can go wrong to a single executed statement, we should have more than one catch(s) to catch any errors that might occur.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What language is used by a relational model to describe the structure of a database?&lt;/span&gt;&lt;br /&gt;A: The Data Definition Language.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What is JSP? Describe its concept.&lt;/span&gt;&lt;br /&gt;A: JSP is Java Server Pages. The JavaServer Page concept is to provide an HTML document with the ability to plug in content at selected locations in the document. (This content is then supplied by the Web server along with the rest of the HTML document at the time the document is downloaded).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What does the JSP engine do when presented with a JavaServer Page to process?&lt;/span&gt;&lt;br /&gt;A: The JSP engine builds a servlet. The HTML portions of the JavaServer Page become Strings transmitted to print methods of a PrintWriter object. The JSP tag portions result in calls to methods of the appropriate JavaBean class whose output is translated into more calls to a println method to place the result in the HTML document.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-5255930158159869473?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/5255930158159869473/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=5255930158159869473' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/5255930158159869473'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/5255930158159869473'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/06/jsp-interview-questions.html' title='JSP interview questions'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-47601231220743295</id><published>2008-06-19T07:45:00.000-07:00</published><updated>2008-06-19T07:55:10.518-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScriptAJAXinterview'/><title type='text'>JavaScript &amp; AJAX interview questions</title><content type='html'>            &lt;p style="margin: 0in 0in 0pt;"&gt;1.&lt;span&gt;  &lt;/span&gt;Why so JavaScript and Java have similar name? &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;A.&lt;span&gt;  &lt;/span&gt;JavaScript is a stripped-down version of Java&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;&lt;b&gt;B.&lt;span&gt;  &lt;/span&gt;JavaScript's syntax is loosely based on Java's &lt;/b&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;C.&lt;span&gt;  &lt;/span&gt;They both originated on the island of Java&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;D.&lt;span&gt;  &lt;/span&gt;None of the above&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.25in; text-indent: -0.25in; text-align: justify;"&gt;2.&lt;span&gt;  &lt;/span&gt;When a user views a page containing a JavaScript program, which machine actually executes the script? &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in; text-align: justify;"&gt;&lt;b&gt;A.&lt;span&gt;  &lt;/span&gt;The User's machine running a Web browser &lt;/b&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;B.&lt;span&gt;   &lt;/span&gt;The Web server&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;C.&lt;span&gt;  &lt;/span&gt;A central machine deep within Netscape's corporate offices&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;D.&lt;span&gt;  &lt;/span&gt;None of the above&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt;&lt;span id="more-321"&gt;&lt;/span&gt;3.&lt;span&gt;  &lt;/span&gt;______ JavaScript is also called client-side JavaScript. &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in; text-align: justify;"&gt;A.&lt;span&gt;  &lt;/span&gt;Microsoft&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in; text-align: justify;"&gt;&lt;b&gt;B.&lt;span&gt;  &lt;/span&gt;Navigator&lt;/b&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in; text-align: justify;"&gt;C.&lt;span&gt;  &lt;/span&gt;LiveWire&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in; text-align: justify;"&gt;D.&lt;span&gt;  &lt;/span&gt;Native&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt;4.&lt;span&gt;  &lt;/span&gt;__________ JavaScript is also called server-side JavaScript. &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in; text-align: justify;"&gt;A.&lt;span&gt;  &lt;/span&gt;Microsoft&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;B.&lt;span&gt;   &lt;/span&gt;Navigator&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;&lt;b&gt;C.&lt;span&gt;  &lt;/span&gt;LiveWire&lt;/b&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;D.&lt;span&gt;  &lt;/span&gt;Native&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt;5.&lt;span&gt;  &lt;/span&gt;What are variables used for in JavaScript Programs? &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in; text-align: justify;"&gt;&lt;b&gt;A.&lt;span&gt;  &lt;/span&gt;Storing numbers, dates, or other values &lt;/b&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;B.&lt;span&gt;   &lt;/span&gt;Varying randomly&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;C.&lt;span&gt;  &lt;/span&gt;Causing high-school algebra flashbacks&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;D.&lt;span&gt;  &lt;/span&gt;None of the above&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.25in; text-indent: -0.25in; text-align: justify;"&gt;6.&lt;span&gt;  &lt;/span&gt;_____ JavaScript statements embedded in an HTML page can respond to user events such as mouse-clicks, form input, and page navigation. &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in; text-align: justify;"&gt;&lt;b&gt;A.&lt;span&gt;  &lt;/span&gt;Client-side &lt;/b&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;B.&lt;span&gt;   &lt;/span&gt;Server-side&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;C.&lt;span&gt;  &lt;/span&gt;Local&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;D.&lt;span&gt;  &lt;/span&gt;Native&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.25in; text-indent: -0.25in; text-align: justify;"&gt;7.&lt;span&gt;  &lt;/span&gt;What should appear at the very end of your JavaScript? &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.25in;"&gt;The &lt;script language="JavaScript"&gt;tag&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;&lt;b&gt;A.&lt;span&gt;   &lt;/span&gt;The &lt;/script&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;&lt;span&gt;B.    The &lt;script&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;C.&lt;span&gt;  &lt;/span&gt;The END statement &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;D.&lt;span&gt;  &lt;/span&gt;None of the above &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt; &lt;/p&gt; &lt;p&gt;&lt;span style="font-size:12pt;"&gt;&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p style="margin: 0in 0in 0pt;"&gt;8.&lt;span&gt;  &lt;/span&gt;Which of the following can't be done with client-side JavaScript? &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;A.&lt;span&gt;  &lt;/span&gt;Validating a form &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;B.&lt;span&gt;   &lt;/span&gt;Sending a form's contents by email &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;&lt;b&gt;C.&lt;span&gt;  &lt;/span&gt;Storing the form's contents to a database file on the server &lt;/b&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;D.&lt;span&gt;  &lt;/span&gt;None of the above &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt;9.&lt;span&gt;  &lt;/span&gt;Which of the following are capabilities of functions in JavaScript? &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;A.&lt;span&gt;  &lt;/span&gt;Return a value &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;B.&lt;span&gt;   &lt;/span&gt;Accept parameters and Return a value &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;&lt;b&gt;C.&lt;span&gt;  &lt;/span&gt;Accept parameters &lt;/b&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;D.&lt;span&gt;  &lt;/span&gt;None of the above &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.5in; text-indent: -41.75pt;"&gt;10.&lt;span&gt;  &lt;/span&gt;Which of the following is not a valid JavaScript variable name? &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;&lt;b&gt;A.&lt;span&gt;  &lt;/span&gt;2names&lt;/b&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;B.&lt;span&gt;   &lt;/span&gt;_first_and_last_names &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;C.&lt;span&gt;  &lt;/span&gt;FirstAndLast&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;D.&lt;span&gt;  &lt;/span&gt;None of the above &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.5in; text-indent: -41.75pt;"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.5in; text-indent: -41.75pt; text-align: justify;"&gt;11.&lt;span&gt;  &lt;/span&gt;______ tag is an extension to HTML that can enclose any number of JavaScript statements. &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;&lt;b&gt;A.&lt;span&gt;  &lt;/span&gt;&lt;script&gt; &lt;/b&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;B.&lt;span&gt;   &lt;/span&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;C.&lt;span&gt;  &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;D.&lt;span&gt;  &lt;/span&gt;&lt;title&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.5in; text-indent: -41.75pt;"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.5in; text-indent: -41.75pt;"&gt;12.&lt;span&gt;  &lt;/span&gt;How does JavaScript store dates in a date object? &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;&lt;b&gt;A.&lt;span&gt;  &lt;/span&gt;The number of milliseconds since January 1st, 1970 &lt;/b&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;B.&lt;span&gt;   &lt;/span&gt;The number of days since January 1st, 1900 &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;C.&lt;span&gt;  &lt;/span&gt;The number of seconds since Netscape's public stock offering. &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;D.&lt;span&gt;  &lt;/span&gt;None of the above &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt;13.&lt;span&gt;  &lt;/span&gt;Which of the following attribute can hold the JavaScript version? &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;&lt;b&gt;A.&lt;span&gt;  &lt;/span&gt;LANGUAGE&lt;/b&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;B.&lt;span&gt;   &lt;/span&gt;SCRIPT&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;C.&lt;span&gt;  &lt;/span&gt;VERSION&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;D.&lt;span&gt;  &lt;/span&gt;None of the above &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt;14. &lt;span&gt; &lt;/span&gt;What is the correct JavaScript syntax to write "Hello World"? &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;A.&lt;span&gt;  &lt;/span&gt;System.out.println("Hello World")&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;B.&lt;span&gt;   &lt;/span&gt;println ("Hello World")&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;&lt;span style="font-family:Times New Roman;"&gt;C.&lt;span&gt;  &lt;/span&gt;document.write("Hello World") &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;D.&lt;span&gt;  &lt;/span&gt;response.write("Hello World") &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.25in; text-indent: -0.25in; text-align: justify;"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt;15.&lt;span&gt;  &lt;/span&gt;Which of the following way can be used to indicate the LANGUAGE attribute? &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;A.&lt;span&gt;  &lt;/span&gt;&lt;language="javascriptversion"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;B.&lt;span&gt;   &lt;/span&gt;&lt;script language="JavaScriptVersion"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;&lt;b&gt;C.&lt;span&gt;  &lt;/span&gt;&lt;script language="JavaScriptVersion"&gt; &lt;span&gt;   &lt;/span&gt;JavaScript statements…&lt;/script&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;D.&lt;span&gt;  &lt;/span&gt;&lt;script language="JavaScriptVersion"&gt; &lt;span&gt;   &lt;/span&gt;JavaScript statements…&lt;/script&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt;16.&lt;span&gt;  &lt;/span&gt;Inside which HTML element do we put the JavaScript? &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;A.&lt;span&gt;  &lt;/span&gt;&lt;js&gt; &lt;/js&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;B.&lt;span&gt;   &lt;/span&gt;&lt;scripting&gt; &lt;/scripting&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;&lt;b&gt;C.&lt;span&gt;  &lt;/span&gt;&lt;script&gt;&lt;/script&gt; &lt;/b&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;D.&lt;span&gt;  &lt;/span&gt;&lt;javascript&gt; &lt;/javascript&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt;17.&lt;span&gt;  &lt;/span&gt;What is the correct syntax for referring to an external script called " abc.js"?&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;A.&lt;span&gt;  &lt;/span&gt;&lt;script href="%20abc.js"&gt;&lt;/script&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;B.&lt;span&gt;   &lt;/span&gt;&lt;script name=" abc.js"&gt;&lt;/script&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;&lt;b&gt;C.&lt;span&gt;  &lt;/span&gt;&lt;script src="%20abc.js"&gt;&lt;/script&gt;&lt;/b&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;D.&lt;span&gt;  &lt;/span&gt;None of the above &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt;18.&lt;span&gt;  &lt;/span&gt;Which types of image maps can be used with JavaScript? &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;A.&lt;span&gt;  &lt;/span&gt;Server-side image maps &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;&lt;b&gt;B.&lt;span&gt;  &lt;/span&gt;Client-side image maps &lt;/b&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;C.&lt;span&gt;  &lt;/span&gt;Server-side image maps and Client-side image maps &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;D.&lt;span&gt;  &lt;/span&gt;None of the above &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt;19.&lt;span&gt;  &lt;/span&gt;Which of the following navigator object properties is the same in both &lt;span&gt;  &lt;/span&gt;Netscape and IE?&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;&lt;b&gt;A.&lt;span&gt;  &lt;/span&gt;navigator.appCodeName&lt;/b&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;B.&lt;span&gt;   &lt;/span&gt;navigator.appName &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;C.&lt;span&gt;  &lt;/span&gt;navigator.appVersion &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;D.&lt;span&gt;  &lt;/span&gt;None of the above &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt;20.&lt;span&gt;  &lt;/span&gt;Which is the correct way to write a JavaScript array? &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;A.&lt;span&gt;  &lt;/span&gt;var txt = new Array(1:"tim",2:"kim",3:"jim") &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;B.&lt;span&gt;   &lt;/span&gt;var txt = new Array:1=("tim")2=("kim")3=(&lt;wbr&gt;"jim") &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;&lt;b&gt;C.&lt;span&gt;  &lt;/span&gt;var txt = new Array("tim","kim","jim") &lt;/b&gt;&lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 0.75in; text-indent: -0.25in;"&gt;D.&lt;span&gt;  &lt;/span&gt;var txt = new Array="tim","kim","jim" &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt 78pt; text-indent: -0.25in;"&gt; &lt;/p&gt; &lt;p style="margin: 0in 0in 0pt;"&gt;&lt;noscript&gt;&lt;br /&gt;&lt;/noscript&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;noscript&gt;&lt;/noscript&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;b&gt;What’s relationship between JavaScript and ECMAScript?&lt;/b&gt; - ECMAScript is yet another name for JavaScript (other names include LiveScript). The current JavaScript that you see supported in browsers is ECMAScript revision 3.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What are JavaScript types?&lt;/b&gt; - Number, String, Boolean, Function, Object, Null, Undefined.&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you convert numbers between different bases in JavaScript?&lt;/b&gt; - 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 ("3F", 16);&lt;/li&gt;&lt;li&gt;&lt;b&gt;What does isNaN function do?&lt;/b&gt; - Return true if the argument is not a number.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is negative infinity?&lt;/b&gt; - It’s a number in JavaScript, derived by dividing negative number by zero.&lt;/li&gt;&lt;p&gt;&lt;span id="more-288"&gt;&lt;/span&gt; &lt;/p&gt;&lt;li&gt;&lt;b&gt;What boolean operators does JavaScript support?&lt;/b&gt; - &amp;amp;&amp;amp;, || and !&lt;/li&gt;&lt;li&gt;&lt;b&gt;What does "1"+2+4 evaluate to?&lt;/b&gt; - Since 1 is a string, everything is a string, so the result is 124.&lt;/li&gt;&lt;li&gt;&lt;b&gt;How about 2+5+"8"?&lt;/b&gt; - Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, it’s concatenation, so 78 is the result.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What looping structures are there in JavaScript?&lt;/b&gt; - for, while, do-while loops, but no foreach.&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you create a new object in JavaScript?&lt;/b&gt; - var obj = new Object(); or var obj = {};&lt;/li&gt;&lt;li&gt;&lt;b&gt;How do you assign object properties?&lt;/b&gt; - obj["age"] = 17 or obj.age = 17.&lt;/li&gt;&lt;li&gt;&lt;b&gt;What’s a way to append a value to an array?&lt;/b&gt; - arr[arr.length] = value;&lt;/li&gt;&lt;li&gt;&lt;b&gt;What is this keyword?&lt;/b&gt; - It refers to the current object.&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3839600004564876445-47601231220743295?l=javaprepare.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaprepare.blogspot.com/feeds/47601231220743295/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3839600004564876445&amp;postID=47601231220743295' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/47601231220743295'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3839600004564876445/posts/default/47601231220743295'/><link rel='alternate' type='text/html' href='http://javaprepare.blogspot.com/2008/06/javascript-ajax-interview-questions.html' title='JavaScript &amp; AJAX interview questions'/><author><name>GreatZero</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3839600004564876445.post-3503679689377833549</id><published>2008-06-19T07:41:00.000-07:00</published><updated>2008-06-19T07:43:32.127-07:00</updated><title type='text'>SQL Notes</title><content type='html'>&lt;p&gt;&lt;span style="font-weight: bold;"&gt;SQL&lt;/span&gt;&lt;br /&gt;SQL is an English like language consisting of commands to store, retrieve, maintain &amp;amp; regulate access to your database.&lt;/p&gt; &lt;p&gt;&lt;span style="font-weight: bold;"&gt;SQL*Plus&lt;/span&gt;&lt;br /&gt;SQL*Plus is an application that recognizes &amp;amp; executes SQL commands &amp;amp; specialized SQL*Plus commands that can customize reports, provide help &amp;amp; edit facility &amp;amp; maintain system variables.&lt;span id="more-323"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-weight: bold;"&gt;NVL&lt;/span&gt;&lt;br /&gt;NVL : Null value function converts a null value to a non-null value for the purpose of evaluating an expression. Numeric Functions accept numeric I/P &amp;amp; return numeric values. They are MOD, SQRT, ROUND, TRUNC &amp;amp; POWER.&lt;/p&gt; &lt;p&gt;&lt;span style="font-weight: bold;"&gt;Date Functions&lt;/span&gt;&lt;br /&gt;Date Functions are ADD_MONTHS, LAST_DAY, NEXT_DAY, MONTHS_BETWEEN &amp;amp; SYSDATE.&lt;/p&gt; &lt;p&gt;&lt;span style="font-weight: bold;"&gt;Character Functions&lt;/span&gt;&lt;br /&gt;Character Functions are INITCAP, UPPER, LOWER, S
