<?xml version="1.0" encoding="UTF-8" standalone="no"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:gd="http://schemas.google.com/g/2005" xmlns:georss="http://www.georss.org/georss" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-8416704684944966974</atom:id><lastBuildDate>Tue, 04 Nov 2025 11:22:15 +0000</lastBuildDate><category>xml</category><category>ExtractValue</category><category>Operations</category><category>UpdateXML</category><category>XPath expression</category><category>evaluate</category><category>expression</category><category>mysql</category><category>transformation</category><category>validation</category><category>xmlutility</category><category>xpath</category><category>xsd</category><category>xsl</category><title>Know More About Java</title><description>Welcome to the Java Blog, written by me with the sole purpose of talking about Java &amp;amp; Web technologies.
I&amp;#39;m aiming this blog at other Java developers with the deeper aspects of writing code and resolving technical issues. Hopefully I can blog about some really interesting topics as I come across them. Mr. Patricia Seybold said, &amp;quot;If you learn to program in Java, you’ll never be without a job!&amp;quot;</description><link>http://javadevelopershelp.blogspot.com/</link><managingEditor>noreply@blogger.com (Unknown)</managingEditor><generator>Blogger</generator><openSearch:totalResults>30</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><language>en-us</language><itunes:explicit>no</itunes:explicit><itunes:summary>Welcome to the Java Blog, written by me with the sole purpose of talking about Java &amp;amp; Web technologies. I&amp;#39;m aiming this blog at other Java developers with the deeper aspects of writing code and resolving technical issues. Hopefully I can blog about some really interesting topics as I come across them. Mr. Patricia Seybold said, &amp;quot;If you learn to program in Java, you’ll never be without a job!&amp;quot;</itunes:summary><itunes:subtitle>Welcome to the Java Blog, written by me with the sole purpose of talking about Java &amp;amp; Web technologies. I&amp;#39;m aiming this blog at other Java developers with the deeper aspects of writing code and resolving technical issues. Hopefully I can blog abou</itunes:subtitle><itunes:owner><itunes:email>noreply@blogger.com</itunes:email></itunes:owner><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-150782059633209242</guid><pubDate>Fri, 29 May 2009 10:27:00 +0000</pubDate><atom:updated>2009-05-29T03:28:08.653-07:00</atom:updated><title>NavigableMap &amp; NavigableSet interface</title><description>The NavigableMap interface extends the SortedMap interface in which the elements are ordered either by natural ordering or by using a Comparator. It contains methods to find out the closest matches for given search targets. All keys inserted into a sorted map must implement the Comparable interface and must be mutually comparable. The elements of the NavigableSet interface can be accessed and traversed in either ascending or descending order.&lt;br /&gt;&lt;br /&gt;The NavigableSet interface extends the SortedSet interface in which the elements are ordered either by natural ordering or using a Comparator. It contains methods to find out the closest matches for given search targets. The elements of the NavigableSet interface must be mutually comparable. The elements of the NavigableSet interface can be accessed and traversed in either ascending or descending order.</description><link>http://javadevelopershelp.blogspot.com/2009/05/navigablemap-navigableset-interface.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-2827441909987568802</guid><pubDate>Fri, 29 May 2009 10:03:00 +0000</pubDate><atom:updated>2009-05-29T03:27:31.092-07:00</atom:updated><title>Matcher class</title><description>&lt;div&gt;   &lt;p&gt;Matcher is a final class present in the java.util.regex package. It is used to match a regular expression using the pattern defined by the Pattern class.&lt;br /&gt;&lt;br /&gt;The Matcher class defines no public constructors. It is created from a pattern by invoking the Pattern's matcher method as follows:&lt;br /&gt;&lt;br /&gt;&lt;uc:stx&gt;public Matcher matcher(CharSequence input)&lt;/uc:stx&gt;&lt;br /&gt;&lt;br /&gt;This method creates a matcher that will match the given input against the given pattern.&lt;br /&gt;&lt;br /&gt;The other important methods of the Matcher class are as follows:&lt;br /&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;uc:stx&gt;int start()&lt;/uc:stx&gt;: This method returns the index of the first character matched.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;uc:stx&gt;public int end()&lt;/uc:stx&gt;: This method returns the index of the last character matched, plus one. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;uc:stx&gt;boolean find()&lt;/uc:stx&gt;: This method searches the subsequence of the input sequence that matches the pattern. It returns true if the match is found; otherwise, it returns false.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;uc:stx&gt;boolean lookingAt()&lt;/uc:stx&gt;: This method searches through the input sequence to match the pattern. It returns true if the match is found; otherwise, it returns false.&lt;/li&gt;&lt;/ul&gt;  &lt;/div&gt;</description><link>http://javadevelopershelp.blogspot.com/2009/05/matcher-class.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-5505358082103832147</guid><pubDate>Fri, 29 May 2009 10:02:00 +0000</pubDate><atom:updated>2009-05-29T03:03:34.496-07:00</atom:updated><title>Externalizable interface</title><description>&lt;div&gt;   &lt;p&gt;The Externalizable interface allows a programmer to have a complete control over the serialization and deserialization processes.&lt;br /&gt;&lt;br /&gt;The Externalizable interface has the following two methods:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;uc:stx&gt;public void writeExternal(ObjectOutput objout)&lt;/uc:stx&gt;: This method is used to save the contents of an object by calling the methods of the DataOutput interface for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, arrays, etc. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;&lt;uc:stx&gt;public void readExternal(ObjectInput objin)&lt;/uc:stx&gt;: This method is used to restore the contents of an object that was saved using the writeExternal() method. It calls the methods of the DataInput interface for primitive types and the readObject() method for objects, strings, arrays, etc. &lt;/li&gt;&lt;/ul&gt;  &lt;/div&gt;</description><link>http://javadevelopershelp.blogspot.com/2009/05/externalizable-interface.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-4285362902336435635</guid><pubDate>Fri, 29 May 2009 10:00:00 +0000</pubDate><atom:updated>2009-05-29T03:02:20.724-07:00</atom:updated><title>Comparable &amp; Comparator interface</title><description>&lt;div&gt;   &lt;p&gt;The Comparable interface is used to sort collections and arrays of objects using the Collections.sort() and java.utils.Arrays.sort() methods respectively. The objects of the class implementing the Comparable interface can be ordered.&lt;br /&gt;&lt;br /&gt;The Comparable interface in the generic form is written as follows:&lt;br /&gt;&lt;br /&gt;&lt;uc:stx&gt;interface Comparable&lt;t&gt;&lt;/uc:stx&gt;, where T is the name of the type parameter.&lt;br /&gt;&lt;br /&gt;All classes implementing the Comparable interface must implement the compareTo() method that has the return type as an integer. The signature of the compareTo() method is as follows:&lt;br /&gt;&lt;br /&gt;&lt;uc:stx&gt;int i = object1.compareTo(object2)&lt;/uc:stx&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;If object1 &lt;&gt;&lt;br /&gt;&lt;li&gt; If object1 &gt; object2: The value of i returned will be positive. &lt;/li&gt;&lt;br /&gt;&lt;li&gt; If object1 = object2: The value of i returned will be zero.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;The Comparator interface is used to sort the elements of collections and arrays. It differs from the Comparable interface in that the Comparable interface sorts the elements only in the natural order. In contrast, the Comparator interface sorts the collections and arrays in a number of different ways.&lt;br /&gt;&lt;br /&gt;The Comparator interface has a single compare() method, which returns an integer. It has the following signature:&lt;br /&gt;&lt;br /&gt;&lt;uc:hed&gt;int Obj1.compare(Obj1, Obj2)&lt;/uc:hed&gt;: This method compares the order of the method arguments and returns the following results:&lt;br /&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;negative if Obj1 &lt;&gt;&lt;br /&gt;&lt;li&gt;positive if Obj1 &gt; Obj2&lt;/li&gt;&lt;br /&gt;&lt;li&gt;zero if Obj1 == Obj2&lt;/li&gt;&lt;/ul&gt;&lt;uc:hed&gt;equals(Object obj)&lt;/uc:hed&gt;: This method is used to compare the equality of two objects. The objects being compared must also implement the Comparator interface.&lt;br /&gt;&lt;br /&gt;The Comparator interface can sort only the mutually comparable objects. It cannot be used to sort primitives. Sorting elements using the Comparator interface requires building a class separate from the class whose instances are to be sorted. This is in contrast to the Comparable interface, in which case the class to be sorted itself uses the Comparable interface.&lt;br /&gt; &lt;/div&gt;</description><link>http://javadevelopershelp.blogspot.com/2009/05/comparable-comparator-interface.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-8276818598982730824</guid><pubDate>Fri, 29 May 2009 09:59:00 +0000</pubDate><atom:updated>2009-05-29T03:00:30.368-07:00</atom:updated><title>Serializable</title><description>Serializable is a marker interface. (A marker interface is one without any method). The classes that do not implement this interface will not have any of their states serialized or deserialized. Serialization is the process of converting an object into byte stream, so that it can be transferred over a network and stored into a persistent medium such as a file.&lt;br /&gt;&lt;br /&gt;Serialization is the process of converting the state of an object into a form that can be transported or stored. In this process, an object's state is written to a temporary or persistent storage. Later, the object can be recreated by deserializing or reading the object's state from the storage.</description><link>http://javadevelopershelp.blogspot.com/2009/05/serializable.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-3726679191174221577</guid><pubDate>Fri, 29 May 2009 09:58:00 +0000</pubDate><atom:updated>2009-05-29T02:59:15.692-07:00</atom:updated><title>Coupling</title><description>&lt;div&gt;   &lt;p&gt;Coupling is a term that describes the degree to which one module relies on another module for its proper functioning. Coupling is mainly of the following two types:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;uc:hed&gt;Loose coupling&lt;/uc:hed&gt;: Loose or weak coupling implies that a change in one module does not require changes in the implementation of another module.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;uc:hed&gt;Tight coupling&lt;/uc:hed&gt;: Tight or strong coupling implies that a module relies on another module so strongly that a small change in one will require an implementation change in the other.&lt;br /&gt; &lt;/li&gt;&lt;/ul&gt;For a good object-oriented design, loose coupling is desirable.  &lt;/div&gt;</description><link>http://javadevelopershelp.blogspot.com/2009/05/coupling.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-5613867845458773150</guid><pubDate>Fri, 29 May 2009 09:57:00 +0000</pubDate><atom:updated>2009-05-29T02:58:52.013-07:00</atom:updated><title>Cohesion</title><description>&lt;p&gt;Cohesion is a measure of degree of how strongly a class focuses on its responsibilities. It is of the following two types:&lt;/p&gt;&lt;ul&gt;&lt;li&gt; &lt;uc:hed&gt;High cohesion:&lt;/uc:hed&gt; This means that a class is designed to carry on a specific and precise task. Using high cohesion, methods are easier to understand, as they perform a single task. &lt;/li&gt;&lt;li&gt;&lt;uc:hed&gt;Low cohesion:&lt;/uc:hed&gt; This means that a class is designed to carry on various tasks. Using low cohesion, methods are difficult to understand and maintain. &lt;/li&gt;&lt;/ul&gt;In object-oriented design, high cohesion is desirable, as it is easy to understand and maintain. Moreover, it is easier to reuse.</description><link>http://javadevelopershelp.blogspot.com/2009/05/cohesion.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-6250850732978531718</guid><pubDate>Fri, 29 May 2009 09:51:00 +0000</pubDate><atom:updated>2009-05-29T02:57:26.918-07:00</atom:updated><title>Differences between exceptions and assertions</title><description>&lt;table border="1"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;Exceptions&lt;/th&gt;&lt;th&gt;Assertions&lt;/th&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt; An exception tells the user of the program that something in the program went wrong.&lt;/td&gt;&lt;td&gt;An assertion documents a program. When it fails, it informs that the program has a bug.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; Exceptions are created to deal with problems that might occur in the program.&lt;/td&gt;&lt;td&gt; Assertions are written to state the concepts of a program.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Exceptions are used to test input/output as well as whether parameters are legal or not.&lt;/td&gt;&lt;td&gt;Assertions are documentations that can be checked by running the program.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;</description><link>http://javadevelopershelp.blogspot.com/2009/05/differences-between-exceptions-and.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-1314570059650232750</guid><pubDate>Fri, 29 May 2009 09:50:00 +0000</pubDate><atom:updated>2009-05-29T02:51:06.166-07:00</atom:updated><title>checked and unchecked exceptions</title><description>&lt;uc:hed&gt;Unchecked Exceptions:&lt;/uc:hed&gt; Exceptions that are defined by the Error and RuntimeException classes and their subclasses are known as unchecked exceptions. It is not necessary that a method must deal with these kinds of exceptions. If the exceptions are irrecoverable, the program should not attempt to deal with them. The method can only deal with the exceptions that are recoverable.&lt;br /&gt;&lt;br /&gt;&lt;uc:hed&gt;Checked Exceptions:&lt;/uc:hed&gt; All exceptions except the Error and RuntimeException classes and their subclasses are known as checked exceptions. If a method throws a checked exception, it is necessary that the method must explicitly deal with the exception. The method must catch the exception and take the necessary action.</description><link>http://javadevelopershelp.blogspot.com/2009/05/checked-and-unchecked-exceptions.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-4495485934186511393</guid><pubDate>Fri, 29 May 2009 09:50:00 +0000</pubDate><atom:updated>2009-05-29T02:50:40.996-07:00</atom:updated><title>Closeable and Flushable interfaces</title><description>The Closeable and Flushable interfaces define a uniform way for specifying that a stream can be closed or flushed.&lt;br /&gt;&lt;br /&gt;&lt;uc:stx&gt;Closeable:&lt;/uc:stx&gt; The objects that implement the Closeable interface can be closed. This interface defines the close() method.&lt;br /&gt;&lt;br /&gt;&lt;uc:stx&gt;void close() throws IOException&lt;/uc:stx&gt;&lt;br /&gt;&lt;br /&gt;It closes the invoking stream and releases all the resources. It is implemented by all the I/O classes that open a stream.&lt;br /&gt;&lt;br /&gt;&lt;uc:hed&gt;Flushable:&lt;/uc:hed&gt; The objects that implement the Flushable interface can force buffered output to be written to a stream to which the objects are attached. This interface defines the flush() method.&lt;br /&gt;&lt;br /&gt;&lt;uc:stx&gt;void flush() throws IOException&lt;/uc:stx&gt;</description><link>http://javadevelopershelp.blogspot.com/2009/05/closeable-and-flushable-interfaces.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-4578261969012891308</guid><pubDate>Fri, 29 May 2009 09:49:00 +0000</pubDate><atom:updated>2009-05-29T02:50:13.722-07:00</atom:updated><title>JavaBeans setter and getter methods</title><description>JavaBeans are Java classes that have properties. Properties are private instance variables. According to JavaBeans, the methods that set the values of these variables are known as setter methods, and the methods that retrieve the values of these variables are known as getter methods.&lt;br /&gt;&lt;br /&gt;The naming convention for setter methods is that they should be prefixed with set and the name of the variable. The name of the variable should begin with upper case.&lt;br /&gt;&lt;br /&gt;The naming convention for getter methods is similar to that of setter. It should begin with get and the name of the variable. The name of the variable should begin with upper case.&lt;br /&gt;&lt;br /&gt;The setter method must be declared public, with a void return type and an argument that represents the property type.&lt;br /&gt;&lt;br /&gt;The getter method must be declared public. It takes no arguments, and should have a return type that matches the argument type of the setter method for that property.</description><link>http://javadevelopershelp.blogspot.com/2009/05/javabeans-setter-and-getter-methods.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-8134192634391430328</guid><pubDate>Fri, 29 May 2009 09:47:00 +0000</pubDate><atom:updated>2009-05-29T02:49:16.400-07:00</atom:updated><title>Properties of synchronization</title><description>&lt;div&gt;   &lt;p&gt;Synchronization is a process through which multiple threads share access to common objects. Java coordinates the actions of multiple threads using synchronized methods and statements. Following are the properties of synchronization:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;If a thread contains some locks and goes to sleep, then it does not release the locks.&lt;/li&gt;&lt;li&gt;Only methods can be synchronized, not variables and constants.&lt;/li&gt;&lt;li&gt;If two threads invoke the same method, then only one thread at a time can invoke a method.&lt;/li&gt;&lt;li&gt;A thread can invoke a synchronized method on multiple objects.&lt;/li&gt;&lt;li&gt;A class can have both synchronized and non-synchronized methods.&lt;/li&gt;&lt;li&gt;If a class has synchronized and non-synchronized methods, then multiple threads can still access the non-synchronized methods of the class.&lt;/li&gt;&lt;/ol&gt;  &lt;/div&gt;</description><link>http://javadevelopershelp.blogspot.com/2009/05/properties-of-synchronization.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-1985900741544071979</guid><pubDate>Fri, 29 May 2009 09:46:00 +0000</pubDate><atom:updated>2009-05-29T02:47:20.016-07:00</atom:updated><title>Different states of a thread</title><description>&lt;div&gt;   &lt;p&gt;The job of the thread scheduler is to move a thread from one state to another state. A thread can be in one of the following states:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;uc:hed&gt;New:&lt;/uc:hed&gt; It is the state when the thread instance has been created, but the start method has not been invoked on the thread. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;&lt;uc:hed&gt; Runnable:&lt;/uc:hed&gt; It is the state when the thread is eligible to run. In this state, the thread is not selected by the scheduler for execution. A thread enters the Runnable state when the start() method is invoked. A thread can return to the Runnable state from the blocked, waiting, or sleeping state.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;&lt;uc:hed&gt;Running:&lt;/uc:hed&gt; It is the state when the thread scheduler selects the thread to be the currently executing process. A thread can transition out of a running state through the compiler.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;&lt;uc:hed&gt;Waiting:&lt;/uc:hed&gt; It is also known as blocked or sleeping state. In this state, the thread is not eligible to run, but it might return to the runnable state if a particular event occurs. A thread can be blocked if it is waiting for a resource. It can be in the waiting state if its code causes it to wait.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;&lt;uc:hed&gt;Dead:&lt;/uc:hed&gt; A thread is considered dead when its run() method completes. Once a thread is dead, it can never be brought back to life.&lt;/li&gt;&lt;/ol&gt;  &lt;/div&gt;</description><link>http://javadevelopershelp.blogspot.com/2009/05/different-states-of-thread.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-8795078396882263077</guid><pubDate>Fri, 29 May 2009 09:46:00 +0000</pubDate><atom:updated>2009-05-29T02:46:44.528-07:00</atom:updated><title>Differences between the BufferedReader and BufferedWriter</title><description>&lt;table border="1"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;BufferedReader&lt;/th&gt;&lt;th&gt;BufferedWriter&lt;/th&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;It extends from the reader class.&lt;/td&gt;&lt;td&gt;It extends from the writer class. &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Its key constructor arguments are Reader.&lt;/td&gt;&lt;td&gt;Its key constructor arguments are Writer.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;It provides the read() and readLine() methods.&lt;/td&gt;&lt;td&gt;It provides the close(), flush(), newLine(), and write() methods.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;It implements the mark() and reset() methods.&lt;/td&gt;&lt;td&gt; It does not implement the mark() and reset() methods.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;</description><link>http://javadevelopershelp.blogspot.com/2009/05/differences-between-bufferedreader-and.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>4</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-1475027915980778520</guid><pubDate>Fri, 29 May 2009 09:45:00 +0000</pubDate><atom:updated>2009-05-29T02:46:07.291-07:00</atom:updated><title>Differences between the Comparable and Comparator interfaces</title><description>&lt;table border="1"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;Comparable Interface&lt;/th&gt;&lt;th&gt;Comparator Interface&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;It uses the compareTo() method.&lt;br /&gt;&lt;br /&gt;&lt;uc:stx&gt;int objectOne.compareTo(objectTwo)&lt;/uc:stx&gt;&lt;/td&gt;&lt;td&gt;It uses the compare() method.&lt;br /&gt;&lt;br /&gt;&lt;uc:stx&gt;int compare(ObjOne, ObjTwo)&lt;/uc:stx&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;It is necessary to modify the class whose instance is going to be sorted.&lt;/td&gt;&lt;td&gt;A separate class can be created in order to sort the instances.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Only one sort sequence can be created. &lt;/td&gt;&lt;td&gt;Many sort sequences can be created.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;It is frequently used by the API classes.&lt;/td&gt;&lt;td&gt;It it used by third-party classes to sort instances.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;</description><link>http://javadevelopershelp.blogspot.com/2009/05/differences-between-comparable-and.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-866733201977574358</guid><pubDate>Fri, 29 May 2009 09:45:00 +0000</pubDate><atom:updated>2009-05-29T02:45:37.427-07:00</atom:updated><title>Differences between StringBuffer and String</title><description>&lt;table border="1"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;StringBuffer&lt;/th&gt;&lt;th&gt;String&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt; &lt;td&gt;It provides a mutable character sequence.&lt;/td&gt;&lt;td&gt; It provides an immutable character sequence.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;It is possible to insert characters and substrings in the middle or at the end of the string.&lt;/td&gt;&lt;td&gt;It is not possible to insert characters and substrings in the middle or at the end of the string.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;It reserves room for 16 characters without reallocation.&lt;/td&gt;&lt;td&gt;It does not reserve room for characters.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;It uses the ensureCapacity(), delete(), deleteCharAt(), append(), insert(), and reverse() methods.&lt;/td&gt;&lt;td&gt;It is not possible to use these methods on strings because they are immutable.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;</description><link>http://javadevelopershelp.blogspot.com/2009/05/differences-between-stringbuffer-and.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-2544170064962324752</guid><pubDate>Fri, 29 May 2009 09:44:00 +0000</pubDate><atom:updated>2009-05-29T02:45:07.083-07:00</atom:updated><title>Differences between method overriding and method overloading</title><description>&lt;table border="1"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;Method Overriding&lt;/th&gt;&lt;th&gt;Method Overloading&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Arguments of overloaded methods cannot be changed.&lt;/td&gt;&lt;td&gt;Arguments of overloaded methods can be changed.&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Method return types cannot be changed except covariant return types.&lt;/td&gt; &lt;td&gt;Return types can be changed.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Exceptions must not throw new or broader checked exceptions.&lt;/td&gt;&lt;td&gt;Exceptions can be changed.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;It happens at runtime.&lt;/td&gt;&lt;td&gt;It happens at compile-time. &lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td&gt;An object type determines which method is selected.&lt;/td&gt;&lt;td&gt;A reference type determines which method is selected.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;</description><link>http://javadevelopershelp.blogspot.com/2009/05/differences-between-method-overriding.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-7194390133656525344</guid><pubDate>Wed, 22 Apr 2009 08:12:00 +0000</pubDate><atom:updated>2009-05-08T00:00:25.117-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">evaluate</category><category domain="http://www.blogger.com/atom/ns#">expression</category><category domain="http://www.blogger.com/atom/ns#">transformation</category><category domain="http://www.blogger.com/atom/ns#">validation</category><category domain="http://www.blogger.com/atom/ns#">xml</category><category domain="http://www.blogger.com/atom/ns#">xmlutility</category><category domain="http://www.blogger.com/atom/ns#">xpath</category><category domain="http://www.blogger.com/atom/ns#">xsd</category><category domain="http://www.blogger.com/atom/ns#">xsl</category><title>Smart and Simple XML Utility - v1.0</title><description>&lt;span style="font-weight: bold;"&gt;Smart and Simple XML Utility - v1.0&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I have developed one small XML utility as well as eclipse plug-in that enables user to perform necessary operations on XML schema&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXTxH99L5m-mJJvlT3oT5Z7vzDnTLAfKITdMyiwg500wDfXn2JnexdHb4QBj4L5m6YM3rj-6Ml9ulv9RXwVibAOyTTqOexZAIp1jhQ_pypoOhwo7rj0sFpPma4SbYmsmwzzD-tb7BEnRw/s1600-h/1.bmp"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 218px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXTxH99L5m-mJJvlT3oT5Z7vzDnTLAfKITdMyiwg500wDfXn2JnexdHb4QBj4L5m6YM3rj-6Ml9ulv9RXwVibAOyTTqOexZAIp1jhQ_pypoOhwo7rj0sFpPma4SbYmsmwzzD-tb7BEnRw/s320/1.bmp" alt="" id="BLOGGER_PHOTO_ID_5327424412553797490" border="0" /&gt;&lt;/a&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;Overview&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A Smart and Simple XML utility performs following things,&lt;br /&gt;1. XML validation with XSD schema.&lt;br /&gt;2. Transform XML schema using XSL schema.&lt;br /&gt;3. and Evaluate XPath Expressions.&lt;br /&gt;&lt;br /&gt;This is an open source application that is written completely in Java SWT (Standard Widget Toolkit) which is fast, more responsive and lighter .&lt;br /&gt;&lt;br /&gt;Standard Widget Toolkit (SWT) is a graphical widget toolkit for use with the Java platform. It was originally developed by IBM and is now maintained by the Eclipse Foundation in tandem with the Eclipse IDE. It is an alternative to the AWT and Swing Java GUI toolkits provided by Sun Microsystems as part of the Java Platform, Standard Edition.&lt;br /&gt;&lt;br /&gt;SWT is written in Java. To display GUI elements, the SWT implementation accesses the native GUI libraries of the operating system using JNI (Java Native Interface) in a manner that is similar to those programs written using operating system-specific APIs. Programs that call SWT are portable, but the implementation of the toolkit, despite the fact that it is written in Java, is unique for each platform.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;Release Notes :&lt;/span&gt;&lt;br /&gt;This application still has a number of gaps in the functionality, but improvements are occurring all the time&lt;br /&gt;&lt;br /&gt;Version 1.1.0&lt;br /&gt;Feature:&lt;br /&gt;Added Pretty Formatter to format the contents with correct indentation.&lt;br /&gt;&lt;br /&gt;Version 1.0.0&lt;br /&gt;Features:&lt;br /&gt;1. XML validation with XSD.&lt;br /&gt;2. XML Transformation using XSL.&lt;br /&gt;3. XPath Evaluation.&lt;br /&gt;4. Export all the data (XML, XSL/XSD &amp;amp; Result) to a file.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;License:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1. Common Public License&lt;br /&gt;2. Eclipse Public License 1.0&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;Download :&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Version 1.1.0&lt;br /&gt;&lt;br /&gt;&lt;a href="https://xmlutility.dev.java.net/files/documents/10222/134058/XMLUtility_1.1.0.jar"&gt;https://xmlutility.dev.java.net/files/documents/10222/134058/XMLUtility_1.1.0.jar&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Version 1.0.0&lt;br /&gt;&lt;br /&gt;&lt;a href="https://xmlutility.dev.java.net/files/documents/10222/132835/XMLUtility_1.0.0.jar"&gt;https://xmlutility.dev.java.net/files/documents/10222/132835/XMLUtility_1.0.0.jar&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;Requirements&lt;/span&gt; :&lt;br /&gt;&lt;br /&gt;JDK 1.4 or higher installed on your system.&lt;br /&gt; &lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;Help wanted!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;mailto: xmlutility[at]dev[dot]java[dot]com</description><link>http://javadevelopershelp.blogspot.com/2009/04/smart-and-simple-xml-utility-v10.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXTxH99L5m-mJJvlT3oT5Z7vzDnTLAfKITdMyiwg500wDfXn2JnexdHb4QBj4L5m6YM3rj-6Ml9ulv9RXwVibAOyTTqOexZAIp1jhQ_pypoOhwo7rj0sFpPma4SbYmsmwzzD-tb7BEnRw/s72-c/1.bmp" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-6331673133981331704</guid><pubDate>Wed, 22 Apr 2009 07:44:00 +0000</pubDate><atom:updated>2009-04-22T07:12:15.854-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">ExtractValue</category><category domain="http://www.blogger.com/atom/ns#">mysql</category><category domain="http://www.blogger.com/atom/ns#">Operations</category><category domain="http://www.blogger.com/atom/ns#">UpdateXML</category><category domain="http://www.blogger.com/atom/ns#">xml</category><category domain="http://www.blogger.com/atom/ns#">XPath expression</category><title>MySQL :: Supports XML Operations.</title><description>&lt;span style="font-weight: bold;"&gt;MySQL :: Supports XML Operations.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;As of version 5.1.5, MySQL supports some functions for handling XML Data. Working with XML tends to be very data-oriented. In alot of cases, only a trivial mapping is required between the relational data and the xml representation. In these cases, it is certainly quite convenient to have all the tools that implement the mapping close at hand.&lt;br /&gt;&lt;br /&gt;MySQL XML capabilities up to 5.0&lt;br /&gt;&lt;br /&gt;In prior versions, MySQL XML support was limited to exporting data in XML format using the MySQL command line client. All you need to do is start the mysql client utilitiy with the --xml or -X option.&lt;br /&gt;&gt;mysql -u root -p root -X&lt;br /&gt;&lt;br /&gt;This will shows you a query results in an XML format and its very convenient method for quick formatting. A possible disadvantage is that the mapping from relational data to XML is fixed - there is no way you can change the tagnames, control wheter data should be formatted as element content or as an attribute, set the namespace, etcetera.&lt;br /&gt;&lt;br /&gt;MySQL XML capabilities as of 5.1.5&lt;br /&gt;&lt;br /&gt;XML support in MySQL 5.1 has been extended with:&lt;br /&gt;   * ExtractValue(): Query and Retrieve data from XML formatted text strings&lt;br /&gt;   * UpdateXML(): Update data in XML formatted text strings&lt;br /&gt;&lt;br /&gt;Both functions accept a string that represents fragment of XML, and an XPath expression. The XPath expression acts as a query operator on the xml, identifying the nodes (that is, the elements, attributes, text contents etc.) that the function needs to handle.&lt;br /&gt;&lt;br /&gt;In the case of ExtractValue(), the text nodes specified by, or ocurring within the nodes identified by the XPath expression is returned:&lt;br /&gt;&lt;br /&gt;mysql&gt; select extractValue('&lt;tag&gt;text&lt;/tag&gt;','tag') as `tag`&lt;br /&gt;   -&gt; ,      extractValue('&lt;tag&gt;text&lt;/tag&gt;','tag/text()') as `text()`&lt;br /&gt;   -&gt; ;&lt;br /&gt;+------+--------+&lt;br /&gt;| tag  | text() |&lt;br /&gt;+------+--------+&lt;br /&gt;| text | text   |&lt;br /&gt;+------+--------+&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;In first call to ExtractValue() the XPath expression, tag selects the &lt;tag&gt;text&lt;/tag&gt; bit, but only the text content is returned. The XPath expression in second call to ExtractValue(), tag/text() explicitly specifies that text content should be selected. The result is the same in both cases.&lt;br /&gt;If multiple nodes are identified, the text contents are concatenated, separated by a single space character:&lt;br /&gt;&lt;br /&gt;mysql&gt; select extractValue('&lt;tag&gt;text1&lt;/tag&gt;&lt;tag&gt;text2&lt;/tag&gt;','tag') as `tag`;&lt;br /&gt;+-------------+&lt;br /&gt;| tag         |&lt;br /&gt;+-------------+&lt;br /&gt;| text1 text2 |&lt;br /&gt;+-------------+&lt;br /&gt;1 row in set (0.00 sec)&lt;br /&gt;&lt;br /&gt;In the case of UpdateXML(), the selected node is replaced by the third supplied argument.&lt;br /&gt;&lt;br /&gt;Importing XML using ExtractValue&lt;br /&gt;&lt;br /&gt;We can write a single XPath expression for each field in both of the store records, and once we have the values, it's of course a piece of cake to write an insert around that:&lt;br /&gt;&lt;br /&gt;set @xml := "&lt;parent&gt;&lt;child&gt;text2&lt;/child&gt;&lt;/parent&gt;";&lt;br /&gt;insert into store values (extractValue(@xml,'/parent/child/text()'));&lt;br /&gt;&lt;br /&gt;Even we can use these functions in the stored procedure where we have to deal with larger xml schema and do the extraction of data.</description><link>http://javadevelopershelp.blogspot.com/2009/04/mysql-supports-xml-operations.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-6887065719550024566</guid><pubDate>Thu, 12 Mar 2009 08:58:00 +0000</pubDate><atom:updated>2009-03-13T04:59:23.515-07:00</atom:updated><title>Java Thread</title><description>&lt;span style="font-weight: bold;"&gt;Thread&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A thread is a lightweight process which exist within a program and executed to perform a special task. Several threads of execution may be associated with a single process. Thus a process that has only one thread is referred to as a single-threaded process, while a process with multiple threads is referred to as a multi-threaded process. Every thread maintains its own separate stack, called Runtime Stack but they share the same memory. Elements of the stack are the method invocations,&lt;br /&gt;called activation records or stack frame. The activation record contains pertinent information about a method like local variables.&lt;br /&gt;&lt;br /&gt;In Java Programming language,  thread is a sequential path of code execution within a program. Each thread has its own local variables, program counter and lifetime. In single threaded runtime environment, operations are executes sequentially i.e. next operation can execute only when the previous one is complete. It exists in a common memory space and can share both data and code of a program. Threading concept is very important in Java through which we can increase the speed of any application.&lt;br /&gt;&lt;br /&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=javadevelhelp-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=0321349601&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="width: 120px; height: 240px;" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=javadevelhelp-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=0449004139&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="width: 120px; height: 240px;" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=javadevelhelp-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=1416570632&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="width: 120px; height: 240px;" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=javadevelhelp-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=0842342710&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="width: 120px; height: 240px;" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=javadevelhelp-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=0672315858&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="width: 120px; height: 240px;" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Main Thread&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;When any standalone application is running, it firstly execute the main() method runs in a one thread, called the main thread. If no other threads are created by the main thread, then program terminates when the main() method complete its execution. The main thread creates some other threads called child threads. The main() method execution can finish, but the program will keep running until the all threads have complete its execution.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Life Cycle of A Thread&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1.  New state – After the creations of Thread instance the thread is in this state but before the start() method invocation. At this point, the thread is considered not alive.&lt;br /&gt;  &lt;br /&gt;2. Runnable (Ready-to-run) state – A thread start its life from Runnable state. A thread first enters runnable state after the invoking of start() method but a thread can return to this state after either running, waiting, sleeping or coming back from blocked state also. On this state a thread is waiting for a turn on the processor.&lt;br /&gt;  &lt;br /&gt;3. Running state – A thread is in running state that means the thread is currently executing. There are several ways to enter in Runnable state but there is only one way to enter in Running state: the scheduler select a thread from runnable pool.&lt;br /&gt;  &lt;br /&gt;4. Dead state – A thread can be considered dead when its run() method completes. If any thread comes on this state that means it cannot ever run again.&lt;br /&gt;&lt;br /&gt;5. Blocked - A thread can enter in this state because of waiting the resources that are hold by another thread.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Thread Implementation&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I. Extending the java.lang.Thread Class&lt;br /&gt;&lt;br /&gt;For creating a thread a class have to extend the Thread Class. For creating a thread by this procedure you have to follow these steps:&lt;br /&gt;&lt;br /&gt;1. Extend the java.lang.Thread Class.&lt;br /&gt;2. Override the run( ) method in the subclass from the Thread class to define the code executed by the thread.&lt;br /&gt;3. Create an instance of this subclass. This subclass may call a Thread class constructor by subclass constructor.&lt;br /&gt;4. Invoke the start( ) method on the instance of the class to make the thread eligible for running.&lt;br /&gt;&lt;br /&gt;II. Implementing the java.lang.Runnable Interface&lt;br /&gt;&lt;br /&gt;The procedure for creating threads by implementing the Runnable Interface is as follows:&lt;br /&gt;&lt;br /&gt;1. A Class implements the Runnable Interface, override the run() method  to define the code executed by thread. An object of this class is Runnable Object.&lt;br /&gt;2. Create an object of Thread Class by passing a Runnable object as argument.&lt;br /&gt;3. Invoke the start( ) method on the instance of the Thread class.&lt;br /&gt;&lt;br /&gt;There are two reasons for implementing a Runnable interface preferable to extending the Thread Class:&lt;br /&gt;&lt;br /&gt;1. If you extend the Thread Class, that means that subclass cannot extend any other Class, but if you implement Runnable interface then you can do this.&lt;br /&gt;2. The class implementing the Runnable interface can avoid the full overhead of Thread class which can be excessive.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Daemon threads&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Daemon threads are threads with low priority and runs in the back ground doing the garbage collection operation for the java runtime system. The setDaemon() method is used to create a daemon thread. These threads run without the intervention of the user. To determine if a thread is a daemon thread, use the accessor method isDaemon()&lt;br /&gt;&lt;br /&gt;When a standalone application is run then as long as any user threads are active the JVM cannot terminate, otherwise the JVM terminates along with any daemon threads which might be active. Thus a daemon thread is at the mercy of the runtime system. Daemon threads exist only to serve user threads.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Synchronization &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;With respect to multithreading, Synchronization is a process of controlling the access of shared resources by the multiple threads in such a manner that only one thread can access a particular resource at a time. In non synchronized multithreaded application, it is possible for one thread to modify a shared object while another thread is in the process of using or updating the object's value. Synchronization prevents such type of data corruption which may otherwise lead to dirty reads and significant errors.&lt;br /&gt;E.g. synchronizing a function:&lt;br /&gt;public synchronized void Method1 () {&lt;br /&gt;// method code.&lt;br /&gt;}&lt;br /&gt;E.g. synchronizing a block of code inside a function:&lt;br /&gt;public Method2 (){&lt;br /&gt;synchronized (this) {&lt;br /&gt;// synchronized code here.&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;Synchronized methods are methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement. Synchronized blocks place locks for shorter periods than synchronized methods.&lt;br /&gt;&lt;br /&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=javadevelhelp-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=0471725048&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="width: 120px; height: 240px;" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=javadevelhelp-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=1846288428&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="width: 120px; height: 240px;" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=javadevelhelp-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=1893115100&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="width: 120px; height: 240px;" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=javadevelhelp-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=1423901231&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="width: 120px; height: 240px;" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=javadevelhelp-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=B00008CM3F&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="width: 120px; height: 240px;" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Mutual exclusion&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Mutual exclusion is a phenomenon where no two processes can access critical regions of memory at the same time. Using Java multithreading we can arrive at mutual exclusion. For mutual exclusion, you can simply use the synchronized keyword and explicitly or implicitly provide an Object, any Object, to synchronize on. The synchronized keyword can be applied to a class, to a method, or to a block of code. There are several methods in Java used for communicating mutually exclusive threads such as wait( ), notify( ), or notifyAll( ). For example, the notifyAll( ) method wakes up all threads that are in the wait list of an object.</description><link>http://javadevelopershelp.blogspot.com/2009/03/java-thread.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-8113282442797818217</guid><pubDate>Wed, 04 Mar 2009 08:05:00 +0000</pubDate><atom:updated>2009-03-04T00:06:31.754-08:00</atom:updated><title>XML and Java Technologies</title><description>XML and Java Technologies&lt;br /&gt;&lt;br /&gt;    * Extensible Markup Language(XML)&lt;br /&gt;&lt;br /&gt;    XML stands for EXtensible Markup Language. Its a markup language much like HTML. XML was designed to carry data, not to display data. XML tags are not predefined. You must define your own tags. XML is designed to be self-descriptive. XML is a W3C Recommendation&lt;br /&gt;   &lt;br /&gt;    * Java API for XML Processing (JAXP), v 1.3&lt;br /&gt;   &lt;br /&gt;    The Java API for XML Processing, or JAXP for short, enables applications to parse and transform XML documents using an API that is independent of a particular XML processor implementation. JAXP also provides a pluggability feature which enables applications to easily switch between particular XML processor implementations.&lt;br /&gt;    To achieve the goal of XML processor independence, an application should limit itself to the JAXP API and avoid implementation-dependent APIs and behavior. This may or may not be easy depending on the application. See this question for more information. JAXP includes industry standard APIs such as DOM and SAX. See these slides (PDF) for more information.&lt;br /&gt;    The reason for the existance of JAXP is to facilitate the use of XML on the Java platform. For example, current APIs such as DOM Level 2 do not provide a method to bootstrap a DOM Document object from an XML input document, JAXP does. (When DOM Level 3 provides this functionality, a new version of the JAXP specification will probably support the new Level 3 scheme also.) Other parts of JAXP such as the javax.xml.transform portion do not have any other equivalent XSLT processor-independent APIs.&lt;br /&gt;&lt;br /&gt;    * Java Architecture for XML Binding (JAXB), v 1.0 and 2.0&lt;br /&gt;   &lt;br /&gt;    Java Architecture for XML Binding (JAXB) provides an API and tool that allow automatic two-way mapping between XML documents and Java objects. With a given Document Type Definition (DTD) and a schema definition, the JAXB compiler can generate a set of Java classes that allow developers to build applications that can read, manipulate and recreate XML documents without writing any logic to process XML elements. The generated codes provide an abstraction layer by exposing a public interface that allows access to the XML data without any specific knowledge about the underlying data structure. In addition to DTD support, future versions of JAXB will add support for other schema languages, such as the W3C XML Schema. These features enable the JAXB to provide many benefits for the developers, which are further explained in the next section.&lt;br /&gt;   &lt;br /&gt;    * JAX-RPC v 1.1&lt;br /&gt;   &lt;br /&gt;    To aid developers in building XML-based requests such as SOAP requests, The JCP is developing the Java APIs for XML based RPC (JAX/RPC). JAX/RPC is used for sending and receiving (including marshalling and unmarshalling) method calls using XML-based protocols such as SOAP, or others such as XMLP (XML Protocol. For more information, see http://www.w3.org/2000/xp/). JAX/RPC isolates you from the specifics of these protocols, enabling rapid application development. There is no longer any need for developers to interact directly with the XML representation of the call.&lt;br /&gt;   &lt;br /&gt;    * JAX-WS v 2.0&lt;br /&gt;   &lt;br /&gt;    JAX-WS (Java API for XML Web Services) is a technology designed to simplify the construction of web services and web service clients in Java. The latest version, JAX-WS 2.0, which is part of the new Java EE 5 platform, provides powerful new tools and techniques to facilitate web service development.&lt;br /&gt;   &lt;br /&gt;    * SAAJ (SOAP with Attachments API for Java)&lt;br /&gt;   &lt;br /&gt;    SOAP with Attachments API for Java (SAAJ) is used mainly for the SOAP messaging that goes on behind the scenes in JAX-RPC and JAXR implementations. Secondarily, it is an API that developers can use when they choose to write SOAP messaging applications directly rather than use JAX-RPC. The SAAJ API allows you to do XML messaging from the Java platform: By simply making method calls using the SAAJ API, you can read and write SOAP-based XML messages, and you can optionally send and receive such messages over the Internet (some implementations may not support sending and receiving). This chapter will help you learn how to use the SAAJ API.&lt;br /&gt;    The SAAJ API conforms to the Simple Object Access Protocol (SOAP) 1.1 specification and the SOAP with Attachments specification. The SAAJ 1.2 specification defines the javax.xml.soap package, which contains the API for creating and populating a SOAP message.&lt;br /&gt;&lt;br /&gt;    * Java API for XML Registries (JAXR)&lt;br /&gt;   &lt;br /&gt;    The Java API for XML Registries (JAXR) API provides a uniform and standard Java API for accessing different kinds of XML Registries. XML registries are an enabling infrastructure for building, deployment, and discovery of Web services.&lt;br /&gt;    An abstraction-based JAXR API gives developers the ability to write registry client programs that are portable across different target registries. This is consistent with the Java philosophy of Write Once, Run Anywhere. It also enables value-added capabilities beyond what the underlying registries are capable of. For example, a non-JAXR UDDI client does not have the ability to do taxonomy browsing and taxonomy-aware smart queries, which are available to a JAXR client for UDDI.&lt;br /&gt;   &lt;br /&gt;    * Java API for XML Messaging (JAXM) - Optional&lt;br /&gt;   &lt;br /&gt;    When receiving a web service request from say a business partner, we need a Java API to process XML messages, in a similar way to how we processed SOAP requests using JAX/RPC. The Java API for XML Messaging (JAXM) is a forthcoming specification for interacting with XML messaging standards such as ebXML messaging and SOAP messaging. This API is designed to facilitate the processing of XML message protocols, particularly those where a predetermined “contract” exists (ebXML in particular) to determine the format and constraints of the message. This API will handle all the “envelope” information, such as routing information and the “cargo” manifest, in an intuitive way separate from the actual payload of the message. This allows developers to focus on interacting with the payload and not worry about the other message administrivia.</description><link>http://javadevelopershelp.blogspot.com/2009/03/xml-and-java-technologies.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-7391794103001571505</guid><pubDate>Wed, 04 Mar 2009 07:02:00 +0000</pubDate><atom:updated>2009-03-03T23:34:48.889-08:00</atom:updated><title>Implementing AJAX using Java</title><description>&lt;div style="text-align: left;"&gt;&lt;span style="font-weight: bold;"&gt;AJAX&lt;/span&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrDUnOx4zuxGvMvgDNA8mkgYujV1iMtaS_k_cYyt2-Z-6KHyN0GdnBgD2opOdLuv33EErYdbSis0Udzky5qNt8qW-s6dFCy-o1RCjmdl0xdhE4GliD3kvhQwMldIIkY90avuNW5wY6w1k/s1600-h/AJAXSequence.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 354px; height: 214px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrDUnOx4zuxGvMvgDNA8mkgYujV1iMtaS_k_cYyt2-Z-6KHyN0GdnBgD2opOdLuv33EErYdbSis0Udzky5qNt8qW-s6dFCy-o1RCjmdl0xdhE4GliD3kvhQwMldIIkY90avuNW5wY6w1k/s320/AJAXSequence.jpg" alt="" id="BLOGGER_PHOTO_ID_5309232624617956258" border="0" /&gt;&lt;/a&gt;AJAX stands for Asynchronous JavaScript and XML. AJAX is a new technique for creating better, faster, and more interactive web applications with the help of XML, HTML, CSS and Java Script. Ajax uses XHTML for content and CSS for presentation, as well as the Document Object Model and JavaScript for dynamic content display. Conventional web application trasmit information to and from the sever using synchronous requests. This means you fill out a form, hit submit, and get directed to a new page with new information from the server. With AJAX when submit is pressed, JavaScript will make a request to the server, interpret the results and update the current screen. In the purest sense, the user would never know that anything was even transmitted to the server. XML is commonly used as the format for receiving server data, although any format, including plain text, can be used. AJAX is a web browser technology independent of web server software. A user can continue to use the application while the client program requests information from the server in the background. Intuitive and natural user interaction. No clicking required only Mouse movement is a sufficient event trigger. Ajax is Data-driven as opposed to page-driven.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;AJAX is based on the following open standards:&lt;br /&gt;&lt;br /&gt; * Browser-based presentation using HTML and Cascading Style Sheets (CSS)&lt;br /&gt; * Data stored in XML format and fetched from the server&lt;br /&gt; * Behind-the-scenes data fetches using XMLHttpRequest objects in the browser&lt;br /&gt; * JavaScript to make everything happen&lt;br /&gt;&lt;br /&gt;The XMLHttpRequest object is the key to AJAX. It has been available ever since Internet Explorer 5.5 was released in July 2000, but not fully discovered before people started to talk about AJAX and Web 2.0 in 2005.&lt;br /&gt;&lt;br /&gt;XMLHttpRequest (XHR) is an API that can be used by JavaScript, JScript, VBScript and other web browser scripting languages to transfer and manipulate XML data to and from a web server using HTTP, establishing an independent connection channel between a web page's Client-Side and Server-Side.&lt;br /&gt;&lt;br /&gt;The data returned from XMLHttpRequest calls will often be provided by back-end databases. Besides XML, XMLHttpRequest can be used to fetch data in other formats.&lt;br /&gt;&lt;br /&gt;You already have seen couple of examples on how to create a XMLHttpRequest object.&lt;br /&gt;&lt;br /&gt;Below is listed some of the methods and properties you have to become familiar with.&lt;br /&gt;XMLHttpRequest Methods&lt;br /&gt;&lt;br /&gt; * abort() : Cancels the current request.&lt;br /&gt; * getAllResponseHeaders() : Returns the complete set of HTTP headers as a string.&lt;br /&gt; * getResponseHeader( headerName ) : Returns the value of the specified HTTP header.&lt;br /&gt; * open( method, URL )&lt;br /&gt;   open( method, URL, async )&lt;br /&gt;   open( method, URL, async, userName )&lt;br /&gt;   open( method, URL, async, userName, password ) : Specifies the method, URL, and other optional attributes of a request.&lt;br /&gt;&lt;br /&gt;   The method parameter can have a value of "GET", "POST", or "HEAD". Other HTTP methods, such as "PUT" and "DELETE" (primarily used in REST applications), may be possible&lt;br /&gt;&lt;br /&gt;   The "async" parameter specifies whether the request should be handled asynchronously or not . "true" means that script processing carries on after the send() method, without waiting for a response, and "false" means that the script waits for a response before continuing script processing.&lt;br /&gt; * send( content ) : Sends the request.&lt;br /&gt; * setRequestHeader( label, value ) : Adds a label/value pair to the HTTP header to be sent.&lt;br /&gt;&lt;br /&gt;XMLHttpRequest Properties&lt;br /&gt;&lt;br /&gt; * onreadystatechange : An event handler for an event that fires at every state change.&lt;br /&gt; * readyState :&lt;br /&gt;   The readyState property defines the current state of the XMLHttpRequest object.&lt;br /&gt;   Here are the possible values for the readyState propery:&lt;br /&gt;   State    Description&lt;br /&gt;   0    The request is not initialized&lt;br /&gt;   1    The request has been set up&lt;br /&gt;   2    The request has been sent&lt;br /&gt;   3    The request is in process&lt;br /&gt;   4    The request is completed&lt;br /&gt;&lt;br /&gt;   readyState=0 after you have created the XMLHttpRequest object, but before you have called the open() method.&lt;br /&gt;   readyState=1 after you have called the open() method, but before you have called send().&lt;br /&gt;   readyState=2 after you have called send().&lt;br /&gt;   readyState=3 after the browser has established a communication with the server, but before the server has completed the response.&lt;br /&gt;   readyState=4 after the request has been completed, and the response data have been completely received from the server.&lt;br /&gt; * responseText : Returns the response as a string.&lt;br /&gt; * responseXML : Returns the response as XML. This property returns an XML document object, which can be examined and parsed using W3C DOM node tree methods and properties.&lt;br /&gt; * status : Returns the status as a number (e.g. 404 for "Not Found" and 200 for "OK").&lt;br /&gt; * statusText : Returns the status as a string (e.g. "Not Found" or "OK").&lt;br /&gt;&lt;br /&gt;Steps of AJAX Operation&lt;br /&gt;&lt;br /&gt; 1. A client event occurs&lt;br /&gt;&lt;br /&gt; A JavaScript function is called as the result of an event&lt;br /&gt;&lt;br /&gt; 2. An XMLHttpRequest object is created&lt;br /&gt;&lt;br /&gt; var ajaxRequest;  // The variable that makes Ajax possible!&lt;br /&gt; function ajaxFunction(){&lt;br /&gt;     try{&lt;br /&gt;         xmlHttp = new XMLHttpRequest();&lt;br /&gt;     }catch (e){&lt;br /&gt;         try{&lt;br /&gt;             xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");&lt;br /&gt;         }catch (e) {&lt;br /&gt;             try{&lt;br /&gt;                 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");&lt;br /&gt;             }catch (e){&lt;br /&gt;                 // Something went wrong&lt;br /&gt;                 return false;&lt;br /&gt;             }&lt;br /&gt;         }&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; 3. The XMLHttpRequest object is configured&lt;br /&gt;&lt;br /&gt; In this step we will write a function which will be triggered by the client event and a callback function processRequest() will be registered&lt;br /&gt;&lt;br /&gt; function searchUser() {&lt;br /&gt;     // Here processRequest() is the callback function.&lt;br /&gt;     xmlHttp.onreadystatechange = processRequest;&lt;br /&gt;     if (!target) target = document.getElementById("userid");&lt;br /&gt;     var url = "validate?id=" + escape(target.value);&lt;br /&gt;     xmlHttp.open("GET", url, true);&lt;br /&gt;     xmlHttp.send(null);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; 4. The XMLHttpRequest object makes an asynchronous request to the Webserver.&lt;br /&gt;&lt;br /&gt; ource code is available in the above piece of code. Code written in blue color is responsible to make a request to the web server. This is all being done using XMLHttpRequest object ajaxRequest&lt;br /&gt;&lt;br /&gt; 5. Webserver returns the result containing XML document.&lt;br /&gt;&lt;br /&gt; You can implement your server side script in any language.&lt;br /&gt;&lt;br /&gt; If we assume that you are going to write a servlet then here is the piece of code&lt;br /&gt;&lt;br /&gt; public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException&lt;br /&gt; {&lt;br /&gt;     String targetId = request.getParameter("id");&lt;br /&gt;&lt;br /&gt;     if ((targetId != null) &amp;amp;&amp;amp; !accounts.containsKey(targetId.trim()))&lt;br /&gt;     {&lt;br /&gt;         response.setContentType("text/xml");&lt;br /&gt;         response.setHeader("Cache-Control", "no-cache");&lt;br /&gt;         response.getWriter().write("true");&lt;br /&gt;     }&lt;br /&gt;     else&lt;br /&gt;     {&lt;br /&gt;         response.setContentType("text/xml");&lt;br /&gt;         response.setHeader("Cache-Control", "no-cache");&lt;br /&gt;         response.getWriter().write("false");&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; 6. The XMLHttpRequest object calls the callback() function and processes the result.&lt;br /&gt;&lt;br /&gt; The XMLHttpRequest object was configured to call the processRequest() function when there is a state change to the readyState of the XMLHttpRequest object. Now this function will recieve the result from the server and will do required processing. As in the following example it sets a variable message on true or false based on retruned value from the Webserver.&lt;br /&gt;&lt;br /&gt; function processRequest() {&lt;br /&gt;     if (req.readyState == 4) {&lt;br /&gt;         if (req.status == 200) {&lt;br /&gt;             var message = ...;&lt;br /&gt;         ...&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;7. The HTML DOM is updated&lt;br /&gt;&lt;br /&gt; This is the final step and in this step your HTML page will be updated. It happens in the following way&lt;br /&gt;&lt;br /&gt; * JavaScript technology gets a reference to any element in a page using DOM API&lt;br /&gt; * The recommended way to gain a reference to an element is to call.&lt;br /&gt;&lt;br /&gt;The Disadvantages of AJAX&lt;br /&gt;&lt;br /&gt;1. Building an AJAX-powered application can increase development time and costs.&lt;br /&gt;2. Although AJAX relies on existing and mature technologies like Javascript, HTML and CSS, the available frameworks and components still need to completely mature.&lt;br /&gt;3. Not all concerns regarding security and user privacy have been answered. This fueled a wave of criticism about how safe is the AJAX way of building applications.&lt;br /&gt;4. Using AJAX to asynchronously load bits of content into an existing page conflicts with the way we are used to navigate and create bookmarks in modern browsers.&lt;br /&gt;5. AJAX is not meant to be used in every application. One of the main reasons for this stays in the fact that Google cannot index it.&lt;br /&gt;6. The biggest concern with AJAX is accessibility. This is because not all browsers (especially older ones) have complete support for JavaScript or the XMLHttpRequest object.&lt;br /&gt;7. Due to security constraints, you can only use it to access information from the host that served the initial page. If you need to display information from another server, it is not possible within the AJAX paradigm.</description><link>http://javadevelopershelp.blogspot.com/2009/03/implementing-ajax-using-java.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" height="72" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrDUnOx4zuxGvMvgDNA8mkgYujV1iMtaS_k_cYyt2-Z-6KHyN0GdnBgD2opOdLuv33EErYdbSis0Udzky5qNt8qW-s6dFCy-o1RCjmdl0xdhE4GliD3kvhQwMldIIkY90avuNW5wY6w1k/s72-c/AJAXSequence.jpg" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-7647092079317145986</guid><pubDate>Tue, 03 Mar 2009 11:44:00 +0000</pubDate><atom:updated>2009-03-03T20:15:54.495-08:00</atom:updated><title>Java JUnit</title><description>JUnit is an open source framework that has been designed for the purpose of writing and running tests in the Java programming language. JUnit was originally written by Erich Gamma and Kent Beck. There are many ways to write test cases. A test case is a code fragment that checks that another code unit (method) works as expected. So if we want an accurate and efficient testing process then using a good testing framework is recommended. JUnit has established a good reputation in this scenario.&lt;br /&gt;&lt;br /&gt;JUnit is a regression-testing framework that developers can use to write unit tests as they develop systems. Unit testing belongs to test a single unit of code, which can be a single class for Java. This framework creates a relationship between development and testing. You start coding according to the specification and need and use the JUnit test runners to verify how much it deviates from the intended goal. Typically, in a unit testing, we start testing after completing a module but JUnit helps us to code and test both during the development. So it sets more focus on testing the  fundamental building blocks of a system i.e. one block at a time rather than module level functional testing. This really helps to develop test suites that can be run any time when you make any changes in your code.  This all process will make you sure that the modifications in the code will not break your system without your knowledge.&lt;br /&gt;&lt;br /&gt;JUnit provides also a graphical user interface (GUI) which makes it possible to write and test source code quickly and easily. JUnit shows test progress in a bar that is  green if testing is going fine and it turns  red when a test fails. There is a lot of pleasure in seeing the green bars grow in the GUI output.  A list of unsuccessful tests appears at the bottom of the display window. We can run  multiple tests  concurrently. The simplicity of JUnit makes it possible for the software developer&lt;br /&gt;to easily correct bugs as they are found.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;JUnit Installation&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  1. First, download the latest version of JUnit from http://www.junit.org/ in zip format.&lt;br /&gt;  2. Then install JUnit on your platform of choice:&lt;br /&gt;       Windows&lt;br /&gt;       To install JUnit on Windows, follow these steps:&lt;br /&gt;           1. Unzip junit distribution file to a directory referred to as %JUNIT_HOME%.&lt;br /&gt;           2. Add JUnit to the classpath:&lt;br /&gt;               set CLASSPATH=%CLASSPATH%;%JUNIT_HOME%\junit-4.x.x.jar&lt;br /&gt;&lt;br /&gt;       Unix (bash)&lt;br /&gt;       To install JUnit on Unix, follow these steps:&lt;br /&gt;           1. Unzip junit distribution file to a directory referred to as $JUNIT_HOME.&lt;br /&gt;           2. Add JUnit to the classpath:&lt;br /&gt;               export CLASSPATH=$CLASSPATH:$JUNIT_HOME/junit-4.x.x.jar&lt;br /&gt;   3. (Optional) Unzip the $JUNIT_HOME/src.jar file.&lt;br /&gt;   4. Test the installation by running the sample tests distributed with JUnit. Note that the sample tests are located in the installation directory directly, not the junit.jar file. Therefore, make sure that the JUnit installation directory is on your CLASSPATH. Then simply type:&lt;br /&gt;       java org.junit.runner.JUnitCore org.junit.tests.AllTests&lt;br /&gt;       All the tests should pass with an "OK" message.&lt;br /&gt;       If the tests don't pass, verify that junit.jar is in the CLASSPATH.&lt;br /&gt;  5. Finally, read the documentation.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Writing Tests&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   1. Create a class:&lt;br /&gt;   &lt;br /&gt;       import org.junit.*;&lt;br /&gt;       import static org.junit.Assert.*;&lt;br /&gt;&lt;br /&gt;       import java.util.*;&lt;br /&gt;     &lt;br /&gt;       public class SimpleTest {&lt;br /&gt;         &lt;br /&gt;   2. Write a test method (annotated with @Test) that asserts expected results on the object under test:&lt;br /&gt;&lt;br /&gt;         @Test&lt;br /&gt;         public void testEmptyCollection() {&lt;br /&gt;             Collection collection = new ArrayList();&lt;br /&gt;             assertTrue(collection.isEmpty());&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;   3. If you are running your JUnit 4 tests with a JUnit 3.x runner, write a suite() method that uses the JUnit4TestAdapter class to create a suite containing all of your test methods:&lt;br /&gt;&lt;br /&gt;           public static junit.framework.Test suite() {&lt;br /&gt;               return new junit.framework.JUnit4TestAdapter(SimpleTest.class);&lt;br /&gt;           }&lt;br /&gt;   4. Although writing a main() method to run the test is much less important with the advent of IDE runners, it's still possible:&lt;br /&gt;&lt;br /&gt;         public static void main(String args[]) {&lt;br /&gt;           org.junit.runner.JUnitCore.main("junitfaq.SimpleTest");&lt;br /&gt;         }&lt;br /&gt;       }&lt;br /&gt;         &lt;br /&gt;   5. Run the test:&lt;br /&gt;         * To run the test from the console, type:&lt;br /&gt;           java org.junit.runner.JUnitCore SimpleTest&lt;br /&gt;&lt;br /&gt;         * To run the test with the test runner used in main(), type:&lt;br /&gt;           java SimpleTest&lt;br /&gt;&lt;br /&gt;     The passing test results in the following textual output:&lt;br /&gt;&lt;br /&gt;         Time: 0&lt;br /&gt;         OK (1 tests)&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Run JUnit using Ant&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  1. Define any necessary Ant properties like source folder path, library folder path or class name etc.&lt;br /&gt;       &lt;property name="src" value="./src"&gt;&lt;br /&gt;       &lt;property name="lib" value="./lib"&gt;&lt;property name="src" value="./src"&gt;&lt;br /&gt;&lt;property name="lib" value="./lib"&gt;&lt;br /&gt;&lt;property name="classes" value="./classes"&gt;&lt;br /&gt;&lt;property name="test.class.name" value="com.xyz.MyTestSuite"&gt;&lt;br /&gt;       &lt;property name="classes" value="./classes"&gt;&lt;property name="test.class.name" value="com.xyz.MyTestSuite"&gt;&lt;br /&gt;   2. Set up the CLASSPATH to be used by JUnit:&lt;br /&gt;       &lt;path id="test.classpath"&gt;&lt;br /&gt;       &lt;pathelement location="${classes}"&gt;&lt;path id="test.classpath"&gt;&lt;br /&gt;&lt;pathelement location="${classes}"&gt;&lt;br /&gt;&lt;pathelement location="/path/to/junit.jar"&gt;&lt;br /&gt;&lt;fileset dir="${lib}"&gt;&lt;br /&gt;&lt;include name="**/*.jar"&gt;&lt;br /&gt;&lt;/fileset&gt;&lt;br /&gt;&lt;/path&gt;&lt;br /&gt;       &lt;pathelement location="/path/to/junit.jar"&gt;&lt;fileset dir="${lib}"&gt;&lt;include name="**/*.jar"&gt;&lt;/include&gt;&lt;/fileset&gt;&lt;br /&gt;   3. Define the Ant task for running JUnit:&lt;br /&gt;       &lt;target name="test"&gt;&lt;br /&gt;       &lt;junit fork="yes" haltonfailure="yes"&gt;&lt;target name="test"&gt;&lt;br /&gt;&lt;junit fork="yes" haltonfailure="yes"&gt;&lt;br /&gt;&lt;test name="${test.class.name}"&gt;&lt;br /&gt;&lt;formatter type="plain" usefile="false"&gt;&lt;br /&gt;&lt;classpath refid="test.classpath"&gt;&lt;br /&gt;&lt;/junit&gt;&lt;br /&gt;&lt;/target&gt;&lt;br /&gt;         &lt;test name="${test.class.name}"&gt;&lt;formatter type="plain" usefile="false"&gt;&lt;classpath refid="test.classpath"&gt;&lt;/classpath&gt;&lt;/formatter&gt;&lt;br /&gt;   4. Run the test:&lt;br /&gt;     ant test&lt;/test&gt;&lt;/junit&gt;&lt;/target&gt;&lt;/pathelement&gt;&lt;/pathelement&gt;&lt;/path&gt;&lt;/property&gt;&lt;/property&gt;&lt;/property&gt;&lt;/property&gt;</description><link>http://javadevelopershelp.blogspot.com/2009/03/java-junit.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-5135767697272039854</guid><pubDate>Thu, 26 Feb 2009 10:47:00 +0000</pubDate><atom:updated>2009-02-26T02:48:33.476-08:00</atom:updated><title>Java Collections</title><description>&lt;span style="font-style: italic;"&gt;Collections API&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The Collections API is a set of classes and interfaces that support operations on collections of objects.&lt;br /&gt;Example of classes: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap.&lt;br /&gt;Example of interfaces: Collection, Set, List and Map.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;DIFFERENCE : Iterator and ListIterator&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Iterator : Enables you to cycle through a collection in the forward direction only, for obtaining or removing elements&lt;br /&gt;ListIterator : It extends Iterator, allow bidirectional traversal of list and the modification of elements&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;DIFFERENCE : HashMap and HashTable&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1. The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. (HashMap allows null values as key and value whereas Hashtable doesn’t allow nulls).&lt;br /&gt;2. HashMap does not guarantee that the order of the map will remain constant over time.&lt;br /&gt;3. HashMap is non synchronized whereas Hashtable is synchronized.&lt;br /&gt;4. Iterator in the HashMap is fail-safe while the enumerator for the Hashtable isn't.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;DIFFERENCE : Set and list&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A Set stores elements in an unordered way and does not contain duplicate elements, whereas a list stores elements in an ordered way but may contain duplicate elements.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;DIFFERENCE : Vector and ArrayList&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Vector is synchronized whereas ArrayList is not. The Vector class provides the capability to implement a growable array of objects. ArrayList and Vector class both implement the List interface. Both classes are implemented using dynamically resizable arrays, providing fast random access and fast traversal. In vector the data is retrieved using the elementAt() method while in ArrayList, it is done using the get() method. ArrayList has no default size while vector has a default size of 10. when you want programs to run in multithreading environment then use concept of vector because it is synchronized. But ArrayList is not synchronized so, avoid use of it in a multithreading environment.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;DIFFERENCE : Array and Arraylist&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;An ArrayList is resizable, where as, an array is not. ArrayList is a part of the Collection Framework. We can store any type of objects, and we can deal with only objects. It is growable. Array is collection of similar data items. We can have array of primitives or objects. It is of fixed size. We can have multi dimensional arrays.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;DIFFERENCE : Enumeration and Iterator&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The functionality of Enumeration interface is duplicated by the Iterator interface. Iterator has a remove() method while Enumeration doesn't. Enumeration acts as Read-only interface, because it has the methods only to traverse and fetch the objects, where as using Iterator we can manipulate the objects also like adding and removing the objects.So Enumeration is used when ever we want to make Collection objects as Read-only.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;DIFFERENCE : Enumeration, ArrayList, Hashtable and Collections and Collection&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Enumeration: It is series of elements. It can be use to enumerate through the elements of a vector, keys or values of a hashtable. You can not remove elements from Enumeration.&lt;br /&gt;&lt;br /&gt;ArrayList: It is re-sizable array implementation. Belongs to 'List' group in collection. It permits all elements, including null. It is not thread -safe.&lt;br /&gt;&lt;br /&gt;Hashtable: It maps key to value. You can use non-null value for key or value. It is part of group Map in collection.&lt;br /&gt;&lt;br /&gt;Collections: It implements Polymorphic algorithms which operate on collections.&lt;br /&gt;&lt;br /&gt;Collection: It is the root interface in the collection hierarchy.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;HOW : Make hashmap synchronized&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Note on Some Important Terms&lt;br /&gt;1) Synchronized means only one thread can modify a hash table at one point of time. Basically, it means that any thread before performing an update on a hashtable will have to acquire a lock on the object while others will wait for lock to be released.&lt;br /&gt;&lt;br /&gt;2) Fail-safe is relevant from the context of iterators. If an iterator has been created on a collection object and some other thread tries to modify the collection object "structurally”, a concurrent modification exception will be thrown. It is possible for other threads though to invoke "set" method since it doesn’t modify the collection "structurally”. However, if prior to calling "set", the collection has been modified structurally, "IllegalArgumentException" will be thrown.&lt;br /&gt;&lt;br /&gt;HashMap can be synchronized by&lt;br /&gt;&lt;br /&gt;Map m = Collections.synchronizeMap(hashMap);</description><link>http://javadevelopershelp.blogspot.com/2009/02/java-collections.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>4</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-8416704684944966974.post-5829029025202145092</guid><pubDate>Thu, 26 Feb 2009 09:27:00 +0000</pubDate><atom:updated>2009-02-26T01:54:08.046-08:00</atom:updated><title>Java Garbage Collection</title><description>Garbage collection is one of the most important features of Java. The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used. Garbage collection is also called automatic memory management as JVM automatically removes the unused variables/objects (value is null) from the memory. Every class inherits finalize() method from java.lang.Object, the finalize() method is called by garbage collector when it determines no more references to the object exists.&lt;br /&gt;&lt;br /&gt;In Java, it is good idea to explicitly assign null into a variable when no more in use. In Java on calling System.gc() and Runtime.gc(), JVM tries to recycle the unused objects, but there is no guarantee when all the objects will garbage collected. Garbage collection is an automatic process and can't be forced. There is no guarantee that Garbage collection will start immediately upon request of System.gc(). Once an object is garbage collected, It can no longer become reachable again.&lt;br /&gt;&lt;br /&gt;Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection.</description><link>http://javadevelopershelp.blogspot.com/2009/02/java-garbage-collection.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>3</thr:total></item></channel></rss>