<?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-4685305606629949031</id><updated>2012-02-15T23:27:52.101-08:00</updated><category term='Java Threads Questions'/><category term='Java Wrapper Classes'/><category term='Abstract Class and Interface'/><category term='JAVA  Code Examples'/><category term='Java Exceptions'/><category term='Java Swings Questions'/><category term='Java Questions'/><category term='About Java'/><category term='Java Packages'/><category term='Java Collections'/><category term='Object Serialization'/><category term='Java Interview Questions'/><category term='Java Garbage Collection'/><category term='Core Java Questions'/><category term='JAVA Classes and Objects'/><category term='JSP Interview Question'/><title type='text'>JAVA Interview Questions</title><subtitle type='html'>advanced JAVA interview questions, j2ee interview questions, java tutorial, Core Java Job Interview Questions, JAVA, JSP, SERVLETS, EJB, STRUTS, XML, ANT, LOG4J, WEBLOGIC, Interview questions for different java technologies like Core Java, JSP, servlets, EJB, JMS&lt; JNDI, JMS</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default?start-index=101&amp;max-results=100'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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>253</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4685305606629949031.post-6432902623053004094</id><published>2008-03-06T09:33:00.000-08:00</published><updated>2008-03-06T09:35:16.033-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What is Overriding?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;When a class defines a method using the same name, return type, and arguments as a method in its superclass, the method in the class overrides the method in the superclass.&lt;br /&gt;&lt;br /&gt;When the method is invoked for an object of the class, it is the new definition of the method that is called, and not the method definition from superclass. Methods may be overridden to be more public, not more private. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-6432902623053004094?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/6432902623053004094/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=6432902623053004094' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6432902623053004094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6432902623053004094'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/03/what-is-overriding.html' title='What is Overriding?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-3116856551769111020</id><published>2008-03-06T09:31:00.000-08:00</published><updated>2008-03-06T09:33:27.415-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>Top Java Questions</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;p lohuf="1" eaggd="0"&gt;&lt;strong lohuf="0" eaggd="0"&gt;What restrictions are placed  on method overloading?&lt;/strong&gt;Two methods may not have the same name and  argument list but different return types.&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;What is the difference between String and  StringBuffer?&lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;String objects are immutable whereas StringBuffer objects  are not. StringBuffer unlike Strings support growable and modifiable  strings.&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;Can a private method of a superclass be declared  within a subclass?&lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="2" eaggd="0"&gt;Sure. A private field or method or inner class belongs to  its declared class and hides from its subclasses.&lt;br /&gt;There is no way for private  stuff to have a runtime overloading or overriding (polymorphism) features.&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;What is the default value of an object reference  declared as an instance variable?&lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;null unless we define it explicitly.&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;What is the difference between a constructor and  a method?&lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;A constructor is a member function of a class that is  used to create objects of that class, invoked using the new operator. It has the  same name as the class and has no return type. They are only called once,  whereas member functions can be called many times. A method is an ordinary  member function of a class. It has its own name, a return type (which may be  void), and is invoked using the dot operator. Constructor will be automatically  invoked when an object is created whereas method has to be called  explicitly.&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;super.method(); is used to call a super class method from  a sub class. To call a constructor of the super class, we use the super();  statement as the first line of the subclass’s constructor.&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;Can a top-level class be private or  protected?&lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;No. A top-level class cannot be private or protected. It  can have either “public” or no modifier. If it does not have a modifier it is  supposed to have a default access. If a top level class is declared as  private/protected the compiler will complain that the “modifier private is not  allowed here”.&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;Why &lt;span class="kLink" style="position: static; text-decoration: underline ! important;"&gt;&lt;span style="font-weight: 700; color: red ! important; font-family: Georgia,serif; position: static;color:red;" &gt;&lt;span class="kLink" style="font-weight: 700; color: red ! important; font-family: Georgia,serif; position: relative;"&gt;Java&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;  does not support multiple inheritance? &lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;Java does support multiple inheritance via interface  implementation.&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;Where and how can you use a private  constructor?&lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;Private constructor can be used if you do not want any  other class to instantiate the class. This concept is generally used in  Singleton &lt;span class="kLink" style="position: static; text-decoration: underline ! important;"&gt;&lt;span style="font-weight: 400; color: red ! important; font-family: Georgia,serif; position: static;color:red;" &gt;&lt;span class="kLink" style="font-weight: 400; color: red ! important; font-family: Georgia,serif; position: relative;"&gt;Design  &lt;/span&gt;&lt;span class="kLink" style="font-weight: 400; color: red ! important; font-family: Georgia,serif; position: relative;"&gt;Pattern&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;.  The instantiation of such classes is done from a static public method.&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;How are this() and super() used with  constructors?&lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;this() is used to invoke a constructor of the same class.  super() is used to invoke a superclass constructor.&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;What is Method Overriding? What restrictions are  placed on method overriding?&lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="10" eaggd="0"&gt;When a class defines a method using the same name,  return type, and argument list as that of a method in its superclass, the method  in the subclass is said to override the method present in the Superclass. When  the method is invoked for an object of the&lt;br /&gt;class, it is the new definition of  the method that is called, and not the method definition from  superclass.&lt;br /&gt;&lt;span class="style7" lohuf="0" eaggd="0"&gt;Restrictions placed on  method overriding&lt;/span&gt;&lt;br /&gt;• Overridden methods must have the same name,  argument list, and return type.&lt;br /&gt;• The overriding method may not limit the  access of the method it overrides. Methods may be overridden to be more public,  not more private.&lt;br /&gt;• The overriding method may not throw any exceptions that  may not be thrown by the overridden method.&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;What are the Object and Class classes used for?  Which class should you use to obtain &lt;span class="kLink" style="position: static; text-decoration: underline ! important;"&gt;&lt;span style="font-weight: 700; color: red ! important; font-family: Georgia,serif; position: static;color:red;" &gt;&lt;span class="kLink" style="font-weight: 700; color: red ! important; font-family: Georgia,serif; position: relative;"&gt;design  &lt;/span&gt;&lt;span class="kLink" style="font-weight: 700; color: red ! important; font-family: Georgia,serif; position: relative;"&gt;information&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;  about an object?&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;Differentiate between a Class and an  Object?&lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;The Object class is the highest-level class in the Java  class hierarchy. The Class class is used to represent the classes and interfaces  that are loaded by a &lt;span class="kLink" style="position: static; text-decoration: underline ! important;"&gt;&lt;span style="font-weight: 400; color: red ! important; font-family: Georgia,serif; position: static;color:red;" &gt;&lt;span class="kLink" style="font-weight: 400; color: red ! important; font-family: Georgia,serif; position: relative;"&gt;Java  &lt;/span&gt;&lt;span class="kLink" style="font-weight: 400; color: red ! important; font-family: Georgia,serif; position: relative;"&gt;program&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;.  The Class class is used to obtain information about an object’s design. A Class  is only a definition or prototype of real life object. Whereas an object is an  instance or living representation of real life object. Every object belongs to a  class and every class contains one or more related objects.&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;What is a singleton class?&lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;This design pattern is used by an application to ensure  that at any time there is only one instance of a class created. You can achieve  this by having the private constructor in the class and having a getter method  which returns an object of the class and creates one for the first time if its  null.&lt;strong lohuf="0" eaggd="0"&gt;What is method overloading and method  overriding?&lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="1" eaggd="0"&gt;&lt;span class="style7" lohuf="0" eaggd="0"&gt;Method  overloading:&lt;/span&gt; When 2 or more methods in a class have the same method names  with different arguments, it is said to be method overloading. Overloading does  not block inheritance from the superclass. Overloaded methods must have  different method signatures&lt;/p&gt; &lt;p lohuf="3" eaggd="0"&gt;&lt;span class="style7" lohuf="0" eaggd="0"&gt;Method overriding  :&lt;/span&gt; When a method in a class has the same method name with same arguments  as that of the superclass,&lt;br /&gt;it is said to be method overriding. Overriding  blocks inheritance from the superclass. Overridden methods must have same  signature.&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;Basically overloading and overriding are different  aspects of polymorphism.&lt;/p&gt; &lt;p lohuf="3" eaggd="0"&gt;static/early binding polymorphism: &lt;strong lohuf="0" eaggd="0"&gt;overloading&lt;/strong&gt;&lt;br /&gt;dynamic/late binding polymorphism: &lt;strong lohuf="0" eaggd="0"&gt;overriding&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;If a class is declared without any access  modifiers, where may the class be accessed?&lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;A class that is declared without any access modifiers is  said to have package or default access. This means that the class can only be  accessed by other classes and interfaces that are defined within the same  package.&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;Does a class inherit the constructors of its  superclass?&lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;A class does not inherit constructors from any of its  super classes.&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;Which java.util classes and interfaces support &lt;span class="kLink" style="position: static; text-decoration: underline ! important;"&gt;&lt;span style="font-weight: 700; color: red ! important; font-family: Georgia,serif; position: static;color:red;" &gt;&lt;span class="kLink" style="font-weight: 700; color: red ! important; font-family: Georgia,serif; position: relative;"&gt;event  &lt;/span&gt;&lt;span class="kLink" style="font-weight: 700; color: red ! important; font-family: Georgia,serif; position: relative;"&gt;handling&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;?&lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;The EventObject class and the EventListener interface  support event processing&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;Can an object’s finalize() method be invoked  while it is reachable?&lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;An object’s finalize() method cannot be invoked by the  garbage collector while the object is still reachable. However, an object’s  finalize() method may be invoked by other objects.&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;What is the purpose of the Runtime  class?&lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;The purpose of the Runtime class is to provide access to  the Java runtime system.&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;It returns the runtime information like memory  availability.&lt;/p&gt; &lt;p lohuf="4" eaggd="0"&gt;* Runtime.freeMemory() –&gt; Returns &lt;span class="kLink" style="position: static; text-decoration: underline ! important;"&gt;&lt;span style="font-weight: 400; color: red ! important; font-family: Georgia,serif; position: static;color:red;" &gt;&lt;span class="kLink" style="font-weight: 400; color: red ! important; font-family: Georgia,serif; position: relative;"&gt;JVM&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;  Free Memory&lt;br /&gt;* Runtime.maxMemory() –&gt; Returns the maximum amount of memory  that the JVM will attempt to use. It also helps to run the garbage  collector&lt;br /&gt;* Runtime.gc()&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;What is the purpose of the System  class?&lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;The purpose of the System class is to provide access to  system resources.&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;Can an unreachable object become reachable  again?&lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;An unreachable object may become reachable again. This  can happen when the object’s finalize() method is invoked and the object  performs an operation which causes it to become accessible to reachable  object.&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;What is a bean? Where can it be  used?&lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;A Bean is a reusable and self-contained &lt;span class="kLink" style="position: static; text-decoration: underline ! important;"&gt;&lt;span style="font-weight: 400; color: red ! important; font-family: Georgia,serif; position: static;color:red;" &gt;&lt;span class="kLink" style="font-weight: 400; color: red ! important; font-family: Georgia,serif; position: relative;"&gt;software&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;  component. Beans created using java take advantage of all the security and  platform independent features of java. Bean can be plugged into any software  application. Bean is a simple class which has set and get methods. It could be  used within a &lt;span class="kLink" style="position: static; text-decoration: underline ! important;"&gt;&lt;span style="font-weight: 400; color: red ! important; font-family: Georgia,serif; position: static;color:red;" &gt;&lt;span class="kLink" style="font-weight: 400; color: red ! important; font-family: Georgia,serif; position: relative;"&gt;JSP&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;  using JSP tags to use them.&lt;/p&gt; &lt;p lohuf="2" eaggd="0"&gt;&lt;strong lohuf="0" eaggd="0"&gt;What is the functionality of  instanceOf() ?&lt;/strong&gt;&lt;br /&gt;instanceOf opertaor is used to check whether an  object can be cast to a specific type without throwing ClassCastException.&lt;/p&gt; &lt;p&gt;&lt;strong lohuf="0" eaggd="0"&gt;What would happen if you say this =  null?&lt;/strong&gt;&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;It will come up with Error Message&lt;/p&gt; &lt;p lohuf="0" eaggd="0"&gt;“The left-hand side of an assignment must be a variable”.  &lt;/p&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-3116856551769111020?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/3116856551769111020/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=3116856551769111020' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3116856551769111020'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3116856551769111020'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/03/top-java-questions.html' title='Top Java Questions'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-564599179479291042</id><published>2008-03-06T09:29:00.000-08:00</published><updated>2008-03-06T09:30:53.312-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>Java EE,Open Source,Advanced Technologies Interview Questions</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Java EE technologies(erstwhile J2EE).Apart from Java EE, I will also be covering interview questions on most widely used open source technologies like Struts,Hibernate,Spring and Velocity and more.&lt;br /&gt;&lt;br /&gt;I have constantly been asked by my readers to put something on personal interview questions, consequently, you may like to read my post on personal interview questions prior talking about Java Enterprise Edition.&lt;br /&gt;&lt;br /&gt;Sun Microsystems introduced Java EE 5 specification under JSR 244 and the final release was made public on May ,2006.Java EE has become a cornerstone technology for enterprise level web based solution development.It has more than three million downloads and more than twenty six vendors' application servers support this specification.I believe,it is significant to go through an introduction of Java EE 5 before jumping to questions list straightaway.You can capture essence of Java EE 5 here.&lt;br /&gt;&lt;br /&gt;If you directly want to access Master List of Java EE Interview Questions(Release II) then click here.&lt;br /&gt;&lt;br /&gt;The list of questions on various topics covered under Java EE hood is as follows(on the basis of different technologies covered under Java EE umbrella) :&lt;br /&gt;&lt;br /&gt;Java EE 5(Click To Access Questions' List)&lt;br /&gt;Java Servlets&lt;br /&gt;Java Server Pages and JSP Standard Tag Libraries&lt;br /&gt;Enterprise Java Beans&lt;br /&gt;Java Message Services&lt;br /&gt;Java APIs for XML Parsing&lt;br /&gt;Java Connector Architecture&lt;br /&gt;Java Mail&lt;br /&gt;Java Transaction APIs&lt;br /&gt;&lt;br /&gt;Open Source Technologies:&lt;br /&gt;Struts&lt;br /&gt;Hibernate&lt;br /&gt;Spring&lt;br /&gt;Velocity&lt;br /&gt;Apache AXIS&lt;br /&gt;Architectures:&lt;br /&gt;Service Oriented Architecture&lt;br /&gt;Others&lt;br /&gt;Java Design Patterns&lt;br /&gt;&lt;br /&gt;I am keen on listening from you all for any kind of feedback,positive or negative.Apart from technical questions,I have prepared a list of personal questions too.I have written in detail about how to approach such questions.The answers to these questions are very critical on your chances to come out with flying colors.&lt;br /&gt;&lt;br /&gt;If anyone of you has come across a very unique experience in terms of technical and personal questions asked, feel free to share your experience.&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-564599179479291042?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/564599179479291042/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=564599179479291042' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/564599179479291042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/564599179479291042'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/03/java-eeopen-sourceadvanced-technologies.html' title='Java EE,Open Source,Advanced Technologies Interview Questions'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-6533623686677958086</id><published>2008-03-06T09:28:00.000-08:00</published><updated>2008-03-06T09:29:25.084-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>Java Interview Questions</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Question: What if the main method is declared as private? &lt;br /&gt;&lt;br /&gt;Question: What if the static modifier is removed from the signature of the main method? &lt;br /&gt;&lt;br /&gt;Question: What if I write static public void instead of public static void?&lt;br /&gt;&lt;br /&gt;Q:Question: What if I do not provide the String array as the argument to the method? &lt;br /&gt;&lt;br /&gt;Question: What is the first argument of the String array in main method? &lt;br /&gt;&lt;br /&gt;Question: If I do not provide any arguments on the command line, then the String array of Main method will be empty of null?&lt;br /&gt;&lt;br /&gt;Question: How can one prove that the array is not null but empty?&lt;br /&gt;&lt;br /&gt;Question: What environment variables do I need to set on my machine in order to be able to run Java programs?&lt;br /&gt;&lt;br /&gt;Question: Can an application have multiple classes having main method?&lt;br /&gt;&lt;br /&gt;Question: Can I have multiple main methods in the same class? &lt;br /&gt;&lt;br /&gt;Question: Do I need to import java.lang package any time? Why ?&lt;br /&gt;&lt;br /&gt;Question: Can I import same package/class twice? Will the JVM load the package twice at runtime?&lt;br /&gt;&lt;br /&gt;Question: What are Checked and UnChecked Exception?&lt;br /&gt;&lt;br /&gt;Question: What is Overriding? &lt;br /&gt;&lt;br /&gt;Question: What are different types of inner classes? &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: What if the main method is declared as private?&lt;br /&gt;A: The program compiles properly but at runtime it will give "Main method not public." message.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: What if the static modifier is removed from the signature of the main method?&lt;br /&gt;A: Program compiles. But at runtime throws an error "NoSuchMethodError". &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: What if I write static public void instead of public static void?&lt;br /&gt;A: Program compiles and runs properly. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: What if I do not provide the String array as the argument to the method?&lt;br /&gt;A: Program compiles but throws a runtime error "NoSuchMethodError". &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: What is the first argument of the String array in main method?&lt;br /&gt;A: The String array is empty. It does not have any element. This is unlike C/C++ where the first element by default is the program name.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: If I do not provide any arguments on the command line, then the String array of Main method will be empty of null?&lt;br /&gt;A: It is empty. But not null.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: How can one prove that the array is not null but empty?&lt;br /&gt;A: Print args.length. It will print 0. That means it is empty. But if it would have been null then it would have thrown a NullPointerException on attempting to print args.length.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: What environment variables do I need to set on my machine in order to be able to run Java programs?&lt;br /&gt;A: CLASSPATH and PATH are the two variables.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: Can an application have multiple classes having main method?&lt;br /&gt;A: Yes it is possible. While starting the application we mention the class name to be run. The JVM will look for the Main method only in the class whose name you have mentioned. Hence there is not conflict amongst the multiple classes having main method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: Can I have multiple main methods in the same class?&lt;br /&gt;A: No the program fails to compile. The compiler says that the main method is already defined in the class.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: Do I need to import java.lang package any time? Why ?&lt;br /&gt;A: No. It is by default loaded internally by the JVM.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: Can I import same package/class twice? Will the JVM load the package twice at runtime?&lt;br /&gt;A: One can import the same package or same class multiple times. Neither compiler nor JVM complains abt it. And the JVM will internally load the class only once no matter how many times you import the same class.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: What are Checked and UnChecked Exception?&lt;br /&gt;A: A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses.&lt;br /&gt;Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown. eg, IOException thrown by java.io.FileInputStream's read() method•&lt;br /&gt;Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked. With an unchecked exception, however, the compiler doesn't force client programmers either to catch the&lt;br /&gt;exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String's charAt() method• Checked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: What is Overriding?&lt;br /&gt;A: When a class defines a method using the same name, return type, and arguments as a method in its superclass, the method in the class overrides the method in the superclass.&lt;br /&gt;When the method is invoked for an object of the class, it is the new definition of the method that is called, and not the method definition from superclass. Methods may be overridden to be more public, not more private. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Q: What are different types of inner classes?&lt;br /&gt;A: Nested -level classes, Member classes, Local classes, Anonymous classes&lt;br /&gt;Nested -level classes- If you declare a class within a class and specify the static modifier, the compiler treats the class just like any other -level class.&lt;br /&gt;Any class outside the declaring class accesses the nested class with the declaring class name acting similarly to a package. eg, outer.inner. -level inner classes implicitly have access only to static variables.There can also be inner interfaces. All of these are of the nested -level variety.&lt;br /&gt;&lt;br /&gt;Member classes - Member inner classes are just like other member methods and member variables and access to the member class is restricted, just like methods and variables. This means a public member class acts similarly to a nested -level class. The primary difference between member classes and nested -level classes is that member classes have access to the specific instance of the enclosing class.&lt;br /&gt;&lt;br /&gt;Local classes - Local classes are like local variables, specific to a block of code. Their visibility is only within the block of their declaration. In order for the class to be useful beyond the declaration block, it would need to implement a&lt;br /&gt;more publicly available interface.Because local classes are not members, the modifiers public, protected, private, and static are not usable.&lt;br /&gt;&lt;br /&gt;Anonymous classes - Anonymous inner classes extend local inner classes one level further. As anonymous classes have no name, you cannot provide a constructor&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-6533623686677958086?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/6533623686677958086/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=6533623686677958086' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6533623686677958086'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6533623686677958086'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/03/java-interview-questions.html' title='Java Interview Questions'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-1595649074341457639</id><published>2008-03-06T09:23:00.000-08:00</published><updated>2008-03-06T09:27:50.866-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Core Java Questions'/><title type='text'>Core Java Interview Questions</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Every year many thousand technocrats choose Java careers across the globe,after formally taking Java training classes,courses and/or Java certifications like SCJP etc.While appearing for technical interviews,these budding Java programmers face variety of technical questions, are asked to write code snippets to prove their mettle in relevant topics of Java.They are not only assessed on language basics but also on their familiarity with Java development tools, optimization of Java code,load tests,securing code through Java obfuscation and more. It is their performance in these interviews which decides their career fate and is highly dependent on to-the-point and not too verbose answers.&lt;br /&gt;&lt;br /&gt;What prompted me to create a blog on frequently asked and and not so frequently asked tricky Java interview questions? The answer is,as I have been through various technical interviews on Java and related technologies for all my career spent with this fascinating technology so I thought of sharing these questions,code snippets etc. with all.&lt;br /&gt;&lt;br /&gt;If you want to test your hands on skills on Java programming, which I am sure most of you have additionally faced during an interview process , then betterprogrammer can help you a great extent.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Apart from technical questions, an interviewee faces a spate of personal questions as well.In my post, I tried to share my views and experience on the Personal Interview Questions.&lt;br /&gt;&lt;br /&gt;In wired world, it is very important to know where your resources are lying and how credible are they.Check out this cool widget which provides a quick access to several free online resources which you may find quite useful and handy.Anyone from my audiences is free to use widgets being posted here in one's website/blog :&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-1595649074341457639?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/1595649074341457639/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=1595649074341457639' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/1595649074341457639'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/1595649074341457639'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/03/core-java-interview-questions.html' title='Core Java Interview Questions'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-7259228230250134535</id><published>2008-02-26T08:38:00.003-08:00</published><updated>2008-02-26T08:38:36.783-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What are synchronized methods and synchronized statements?</title><content type='html'>&lt;span class="fullpost"&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. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-7259228230250134535?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/7259228230250134535/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=7259228230250134535' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/7259228230250134535'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/7259228230250134535'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-are-synchronized-methods-and_26.html' title='What are synchronized methods and synchronized statements?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-8756435607809361285</id><published>2008-02-26T08:38:00.001-08:00</published><updated>2008-02-26T08:38:14.040-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What is synchronization and why is it important?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object's value. This often leads to significant errors.&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-8756435607809361285?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/8756435607809361285/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=8756435607809361285' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/8756435607809361285'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/8756435607809361285'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-synchronization-and-why-is-it_26.html' title='What is synchronization and why is it important?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-5358778890976530834</id><published>2008-02-26T08:37:00.005-08:00</published><updated>2008-02-26T08:37:58.195-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>How are Observer and Observable used?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-5358778890976530834?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/5358778890976530834/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=5358778890976530834' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5358778890976530834'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5358778890976530834'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-are-observer-and-observable-used_26.html' title='How are Observer and Observable used?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-3645394616850309167</id><published>2008-02-26T08:37:00.003-08:00</published><updated>2008-02-26T08:37:40.605-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What are the different ways to handle exceptions?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;There are two ways to handle exceptions, &lt;br /&gt;1. By wrapping the desired code in a try block followed by a catch block to catch the exceptions. and &lt;br /&gt;2. List the desired exceptions in the throws clause of the method and let the caller of the method handle those exceptions. &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-3645394616850309167?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/3645394616850309167/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=3645394616850309167' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3645394616850309167'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3645394616850309167'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-are-different-ways-to-handle.html' title='What are the different ways to handle exceptions?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-2545391552305797903</id><published>2008-02-26T08:37:00.001-08:00</published><updated>2008-02-26T08:37:22.323-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What are runtime exceptions?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Runtime exceptions are those exceptions that are thrown at runtime because of either wrong input data or because of wrong business logic etc. These are not checked by the compiler at compile time. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-2545391552305797903?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/2545391552305797903/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=2545391552305797903' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2545391552305797903'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2545391552305797903'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-are-runtime-exceptions.html' title='What are runtime exceptions?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-5736916986764203171</id><published>2008-02-26T08:36:00.004-08:00</published><updated>2008-02-26T08:37:00.562-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>Why do we need wrapper classes?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;It is sometimes easier to deal with primitives as objects. Moreover most of the collection classes store objects and not primitive data types. And also the wrapper classes provide many utility methods also. Because of these reasons we need wrapper classes. And since we create instances of these classes we can store them in any of the collection classes and pass them around as a collection. Also we can pass them around as method parameters where a method expects an object. &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-5736916986764203171?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/5736916986764203171/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=5736916986764203171' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5736916986764203171'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5736916986764203171'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/why-do-we-need-wrapper-classes.html' title='Why do we need wrapper classes?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-1358637220901906670</id><published>2008-02-26T08:36:00.003-08:00</published><updated>2008-02-26T08:36:44.046-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What is Externalizable interface?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Externalizable is an interface which contains two methods readExternal and writeExternal. These methods give you a control over the serialization mechanism. Thus if your class implements this interface, you can customize the serialization process by implementing these methods. &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-1358637220901906670?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/1358637220901906670/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=1358637220901906670' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/1358637220901906670'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/1358637220901906670'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-externalizable-interface.html' title='What is Externalizable interface?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-1271003388934745235</id><published>2008-02-26T08:36:00.001-08:00</published><updated>2008-02-26T08:36:15.368-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What is Session Facade pattern?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Session facade is one design pattern that is often used while developing enterprise applications. It is implemented as a higher level component (i.e.: Session EJB), and it contains all the iteractions between low level components (i.e.: Entity EJB). It then provides a single interface for the functionality of an application or part of it, and it decouples lower level components simplifying the design. Think of a bank situation, where you have someone that would like to transfer money from one account to another. In this type of scenario, the client has to check that the user is authorized, get the status of the two accounts, check that there are enough money on the first one, and then call the transfer. The entire transfer has to be done in a single transaction otherwise is something goes south, the situation has to be restored. &lt;br /&gt;As you can see, multiple server-side objects need to be accessed and possibly modified. Multiple fine-grained invocations of Entity (or even Session) Beans add the overhead of network calls, even multiple transaction. In other words, the risk is to have a solution that has a high network overhead, high coupling, poor reusability and mantainability. &lt;br /&gt;The best solution is then to wrap all the calls inside a Session Bean, so the clients will have a single point to access (that is the session bean) that will take care of handling all the rest. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-1271003388934745235?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/1271003388934745235/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=1271003388934745235' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/1271003388934745235'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/1271003388934745235'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-session-facade-pattern.html' title='What is Session Facade pattern?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-151809219506834466</id><published>2008-02-26T08:35:00.005-08:00</published><updated>2008-02-26T08:35:58.243-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What is Service Locator pattern?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;The Service Locator pattern locates J2EE (Java 2 Platform, Enterprise Edition) services for clients and thus abstracts the complexity of network operation and J2EE service lookup as EJB (Enterprise JavaBean) Interview Questions - Home and JMS (Java Message Service) component factories. The Service Locator hides the lookup process's implementation details and complexity from clients. To improve application performance, Service Locator caches service objects to eliminate unnecessary JNDI (Java Naming and Directory Interface) activity that occurs in a lookup operation.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-151809219506834466?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/151809219506834466/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=151809219506834466' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/151809219506834466'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/151809219506834466'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-service-locator-pattern.html' title='What is Service Locator pattern?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-3910923642773287986</id><published>2008-02-26T08:35:00.003-08:00</published><updated>2008-02-26T08:35:40.979-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What are ClassLoaders?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;A class loader is an object that is responsible for loading classes. The class ClassLoader is an abstract class. Given the name of a class, a class loader should attempt to locate or generate data that constitutes a definition for the class. A typical strategy is to transform the name into a file name and then read a "class file" of that name from a file system. &lt;br /&gt;Every Class object contains a reference to the ClassLoader that defined it. &lt;br /&gt;Class objects for array classes are not created by class loaders, but are created automatically as required by the Java runtime. The class loader for an array class, as returned by Class.getClassLoader() is the same as the class loader for its element type; if the element type is a primitive type, then the array class has no class loader. &lt;br /&gt;Applications implement subclasses of ClassLoader in order to extend the manner in which the Java virtual machine dynamically loads classes. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-3910923642773287986?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/3910923642773287986/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=3910923642773287986' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3910923642773287986'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3910923642773287986'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-are-classloaders.html' title='What are ClassLoaders?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-2201007106747995042</id><published>2008-02-26T08:35:00.001-08:00</published><updated>2008-02-26T08:35:23.344-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What is JIT?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;JIT stands for Just In Time compiler. It compiles java byte code to native code.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-2201007106747995042?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/2201007106747995042/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=2201007106747995042' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2201007106747995042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2201007106747995042'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-jit.html' title='What is JIT?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-8496178912601433940</id><published>2008-02-26T08:34:00.004-08:00</published><updated>2008-02-26T08:35:07.058-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What is JVM?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;JVM stands for Java Virtual Machine. It is the run time for java programs. All are java programs are running inside this JVM only. It converts java byte code to OS specific commands. In addition to governing the execution of an application's byte codes, the virtual machine handles related tasks such as managing the system's memory, providing security against malicious code, and managing multiple threads of program execution.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-8496178912601433940?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/8496178912601433940/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=8496178912601433940' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/8496178912601433940'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/8496178912601433940'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-jvm.html' title='What is JVM?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-141622173611902428</id><published>2008-02-26T08:34:00.003-08:00</published><updated>2008-02-26T08:34:47.945-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What is covariant return type?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;A covariant return type lets you override a superclass method with a return type that subtypes the superclass method's return type. So we can use covariant return types to minimize upcasting and downcasting. &lt;br /&gt;class Parent { &lt;br /&gt;Parent foo () { &lt;br /&gt;System.out.println ("Parent foo() called"); &lt;br /&gt;return this; &lt;br /&gt;} &lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;class Child extends Parent { &lt;br /&gt;Child foo () { &lt;br /&gt;System.out.println ("Child foo() called"); &lt;br /&gt;return this; &lt;br /&gt;} &lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;class Covariant { &lt;br /&gt;public static void main(String[] args) { &lt;br /&gt;Child c = new Child(); &lt;br /&gt;Child c2 = c.foo(); // c2 is Child &lt;br /&gt;Parent c3 = c.foo(); // c3 points to Child &lt;br /&gt;} &lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-141622173611902428?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/141622173611902428/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=141622173611902428' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/141622173611902428'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/141622173611902428'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-covariant-return-type.html' title='What is covariant return type?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-2537918693542555995</id><published>2008-02-26T08:34:00.001-08:00</published><updated>2008-02-26T08:34:29.063-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What are new language features in J2SE 5.0?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Generally: &lt;br /&gt;1. generics &lt;br /&gt;2. static imports &lt;br /&gt;3. annotations &lt;br /&gt;4. typesafe enums &lt;br /&gt;5. enhanced for loop &lt;br /&gt;6. autoboxing/unboxing &lt;br /&gt;7. varargs &lt;br /&gt;8. covariant return types &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-2537918693542555995?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/2537918693542555995/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=2537918693542555995' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2537918693542555995'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2537918693542555995'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-are-new-language-features-in-j2se.html' title='What are new language features in J2SE 5.0?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-5654251096125481126</id><published>2008-02-26T08:33:00.004-08:00</published><updated>2008-02-26T08:34:09.905-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>Why are the interfaces more flexible than abstract classes?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;An interface-defined type can be implemented by any class in a class hierarchy and can be extended by another interface. In contrast, an abstract-class-defined type can be implemented only by classes that subclass the abstract class. &lt;br /&gt;--An interface-defined type can be used well in polymorphism. The so-called interface type vs. implementation types. &lt;br /&gt;--Abstract classes evolve more easily than interfaces. If you add a new concrete method to an abstract class, the hierarchy system is still working. If you add a method to an interface, the classes that rely on the interface will break when recompiled. &lt;br /&gt;--Generally, use interfaces for flexibility; use abstract classes for ease of evolution (like expanding class functionality). &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-5654251096125481126?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/5654251096125481126/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=5654251096125481126' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5654251096125481126'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5654251096125481126'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/why-are-interfaces-more-flexible-than.html' title='Why are the interfaces more flexible than abstract classes?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-3662255114915017027</id><published>2008-02-26T08:33:00.003-08:00</published><updated>2008-02-26T08:33:52.560-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>Describe the wrapper classes in Java.</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Wrapper class is wrapper around a primitive data type. An instance of a wrapper class contains, or wraps, a primitive value of the corresponding type. &lt;br /&gt;&lt;br /&gt;Following table lists the primitive types and the corresponding wrapper classes: &lt;br /&gt;&lt;br /&gt;Primitive Wrapper &lt;br /&gt;boolean java.lang.Boolean &lt;br /&gt;byte java.lang.Byte &lt;br /&gt;char java.lang.Character &lt;br /&gt;double java.lang.Double &lt;br /&gt;float java.lang.Float &lt;br /&gt;int java.lang.Integer &lt;br /&gt;long java.lang.Long &lt;br /&gt;short java.lang.Short &lt;br /&gt;void java.lang.Void &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-3662255114915017027?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/3662255114915017027/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=3662255114915017027' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3662255114915017027'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3662255114915017027'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/describe-wrapper-classes-in-java.html' title='Describe the wrapper classes in Java.'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-673937643636262016</id><published>2008-02-26T08:33:00.001-08:00</published><updated>2008-02-26T08:33:35.273-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What are Access Specifiers available in Java?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;ccess specifiers are keywords that determines the type of access to the member of a class. These are: &lt;br /&gt;Public &lt;br /&gt;Protected &lt;br /&gt;Private &lt;br /&gt;Defaults &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-673937643636262016?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/673937643636262016/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=673937643636262016' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/673937643636262016'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/673937643636262016'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-are-access-specifiers-available-in.html' title='What are Access Specifiers available in Java?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-6484733310812719902</id><published>2008-02-26T08:32:00.002-08:00</published><updated>2008-02-26T08:33:02.345-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>Explain garbage collection?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Garbage collection is one of the most important feature of Java. Garbage collection is also called automatic memory management as JVM automatically removes the unused variables/objects (value is null) from the memory. User program cann't directly free the object from memory, instead it is the job of the garbage collector to automatically free the objects that are no longer referenced by a program. 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. In Java, it is good idea to explicitly assign null into a variable when no more in use. I 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.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-6484733310812719902?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/6484733310812719902/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=6484733310812719902' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6484733310812719902'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6484733310812719902'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/explain-garbage-collection_26.html' title='Explain garbage collection?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-3189313160734217656</id><published>2008-02-26T08:32:00.001-08:00</published><updated>2008-02-26T08:32:38.791-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>Explain the new Features of JDBC 2.0 Core API?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;The JDBC 2.0 API includes the complete JDBC API, which includes both core and Optional Package API, and provides inductrial-strength database computing capabilities. &lt;br /&gt;New Features in JDBC 2.0 Core API: &lt;br /&gt;&lt;br /&gt;Scrollable result sets- using new methods in the ResultSet interface allows programmatically move the to particular row or to a position relative to its current position &lt;br /&gt;JDBC 2.0 Core API provides the Batch Updates functionality to the java applications. &lt;br /&gt;Java applications can now use the ResultSet.updateXXX methods. &lt;br /&gt;New data types - interfaces mapping the SQL3 data types &lt;br /&gt;Custom mapping of user-defined types (UTDs) &lt;br /&gt;Miscellaneous features, including performance hints, the use of character streams, full precision for java.math.BigDecimal values, additional security, and support for time zones in date, time, and timestamp values. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-3189313160734217656?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/3189313160734217656/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=3189313160734217656' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3189313160734217656'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3189313160734217656'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/explain-new-features-of-jdbc-20-core.html' title='Explain the new Features of JDBC 2.0 Core API?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-7777291556826345659</id><published>2008-02-26T08:31:00.003-08:00</published><updated>2008-02-26T08:31:22.151-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What does it mean that a method or class is abstract?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;An abstract class cannot be instantiated. Only its subclasses can be instantiated. You indicate that a class is abstract with the abstract keyword like this: &lt;br /&gt;public abstract class Container extends Component { &lt;br /&gt;Abstract classes may contain abstract methods. A method declared abstract is not actually implemented in the current class. It exists only to be overridden in subclasses. It has no body. For example, &lt;br /&gt;public abstract float price(); &lt;br /&gt;Abstract methods may only be included in abstract classes. However, an abstract class is not required to have any abstract methods, though most of them do. &lt;br /&gt;Each subclass of an abstract class must override the abstract methods of its superclasses or itself be declared abstract. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-7777291556826345659?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/7777291556826345659/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=7777291556826345659' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/7777291556826345659'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/7777291556826345659'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-does-it-mean-that-method-or-class_3580.html' title='What does it mean that a method or class is abstract?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-1415366605949321322</id><published>2008-02-26T08:31:00.001-08:00</published><updated>2008-02-26T08:31:20.247-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What does it mean that a method or class is abstract?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;An abstract class cannot be instantiated. Only its subclasses can be instantiated. You indicate that a class is abstract with the abstract keyword like this: &lt;br /&gt;public abstract class Container extends Component { &lt;br /&gt;Abstract classes may contain abstract methods. A method declared abstract is not actually implemented in the current class. It exists only to be overridden in subclasses. It has no body. For example, &lt;br /&gt;public abstract float price(); &lt;br /&gt;Abstract methods may only be included in abstract classes. However, an abstract class is not required to have any abstract methods, though most of them do. &lt;br /&gt;Each subclass of an abstract class must override the abstract methods of its superclasses or itself be declared abstract. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-1415366605949321322?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/1415366605949321322/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=1415366605949321322' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/1415366605949321322'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/1415366605949321322'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-does-it-mean-that-method-or-class_26.html' title='What does it mean that a method or class is abstract?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-443555846767071399</id><published>2008-02-26T08:30:00.005-08:00</published><updated>2008-02-26T08:30:57.595-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What does it mean that a class or member is final?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;A final class can no longer be subclassed. Mostly this is done for security reasons with basic classes like String and Integer. It also allows the compiler to make some optimizations, and makes thread safety a little easier to achieve. Methods may be declared final as well. This means they may not be overridden in a subclass. &lt;br /&gt;Fields can be declared final, too. However, this has a completely different meaning. A final field cannot be changed after it's initialized, and it must include an initializer statement where it's declared. For example, &lt;br /&gt;public final double c = 2.998; &lt;br /&gt;It's also possible to make a static field final to get the effect of C++'s const statement or some uses of C's #define, e.g. public static final double c = 2.998; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-443555846767071399?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/443555846767071399/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=443555846767071399' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/443555846767071399'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/443555846767071399'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-does-it-mean-that-class-or-member.html' title='What does it mean that a class or member is final?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-5914929468249277155</id><published>2008-02-26T08:30:00.003-08:00</published><updated>2008-02-26T08:30:40.918-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>Why are there no global variables in Java?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Global variables are considered bad form for a variety of reasons: · Adding state variables breaks referential transparency (you no longer can understand a statement or expression on its own: you need to understand it in the context of the settings of the global variables). &lt;br /&gt;· State variables lessen the cohesion of a program: you need to know more to understand how something works. A major point of Object-Oriented programming is to break up global state into more easily understood collections of local state. &lt;br /&gt;· When you add one variable, you limit the use of your program to one instance. What you thought was global, someone else might think of as local: they may want to run two copies of your program at once. &lt;br /&gt;For these reasons, Java decided to ban global variables. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-5914929468249277155?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/5914929468249277155/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=5914929468249277155' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5914929468249277155'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5914929468249277155'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/why-are-there-no-global-variables-in.html' title='Why are there no global variables in Java?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-146316119520381130</id><published>2008-02-26T08:30:00.001-08:00</published><updated>2008-02-26T08:30:25.142-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>Why can't I say just abs() or sin() instead of Math.abs() and Math.sin()?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;The import statement does not bring methods into your local name space. It lets you abbreviate class names, but not get rid of them altogether. That's just the way it works, you'll get used to it. It's really a lot safer this way. &lt;br /&gt;However, there is actually a little trick you can use in some cases that gets you what you want. If your top-level class doesn't need to inherit from anything else, make it inherit from java.lang.Math. That *does* bring all the methods into your local name space. But you can't use this trick in an applet, because you have to inherit from java.awt.Applet. And actually, you can't use it on java.lang.Math at all, because Math is a "final" class which means it can't be extended. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-146316119520381130?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/146316119520381130/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=146316119520381130' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/146316119520381130'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/146316119520381130'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/why-cant-i-say-just-abs-or-sin-instead.html' title='Why can&apos;t I say just abs() or sin() instead of Math.abs() and Math.sin()?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-3055952861327176475</id><published>2008-02-26T08:29:00.004-08:00</published><updated>2008-02-26T08:30:05.467-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What is the difference between notify() and notifyAll()?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;notify() is used to unblock one waiting thread; notifyAll() is used to unblock all of them. Using notify() is preferable (for efficiency) when only one blocked thread can benefit from the change (for example, when freeing a buffer back into a pool). notifyAll() is necessary (for correctness) if multiple threads should resume (for example, when releasing a "writer" lock on a file might permit all "readers" to resume). &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-3055952861327176475?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/3055952861327176475/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=3055952861327176475' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3055952861327176475'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3055952861327176475'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-difference-between-notify-and.html' title='What is the difference between notify() and notifyAll()?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-1808033611691854493</id><published>2008-02-26T08:29:00.003-08:00</published><updated>2008-02-26T08:29:46.614-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What does it mean that a method or field is "static"?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class. &lt;br /&gt;Static methods can be referenced with the name of the class rather than the name of a particular object of the class (though that works too). That's how library methods like System.out.println() work. out is a static field in the java.lang.System class. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-1808033611691854493?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/1808033611691854493/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=1808033611691854493' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/1808033611691854493'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/1808033611691854493'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-does-it-mean-that-method-or-field.html' title='What does it mean that a method or field is &quot;static&quot;?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-6505650855409163676</id><published>2008-02-26T08:29:00.001-08:00</published><updated>2008-02-26T08:29:29.424-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>Why isn't there operator overloading?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Because C++ has proven by example that operator overloading makes code almost impossible to maintain. In fact there very nearly wasn't even method overloading in Java, but it was thought that this was too useful for some very basic methods like print(). Note that some of the classes like DataOutputStream have unoverloaded methods like writeInt() and writeByte(). &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-6505650855409163676?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/6505650855409163676/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=6505650855409163676' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6505650855409163676'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6505650855409163676'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/why-isnt-there-operator-overloading.html' title='Why isn&apos;t there operator overloading?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-8086988222117802266</id><published>2008-02-26T08:28:00.001-08:00</published><updated>2008-02-26T08:28:49.870-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What is the difference between interface and abstract class?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;interface contains methods that must be abstract; abstract class may contain concrete methods. interface contains variables that must be static and final; abstract class may contain non-final and final variables. members in an interface are public by default, abstract class may contain non-public members. interface is used to "implements"; whereas abstract class is used to "extends". interface can be used to achieve multiple inheritance; abstract class can be used as a single inheritance. interface can "extends" another interface, abstract class can "extends" another class and "implements" multiple interfaces. interface is absolutely abstract; abstract class can be invoked if a main() exists. interface is more flexible than abstract class because one class can only "extends" one super class, but "implements" multiple interfaces. If given a choice, use interface instead of abstract class. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-8086988222117802266?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/8086988222117802266/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=8086988222117802266' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/8086988222117802266'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/8086988222117802266'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-difference-between-interface.html' title='What is the difference between interface and abstract class?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-7370208201833061713</id><published>2008-02-26T08:26:00.000-08:00</published><updated>2008-02-26T08:28:11.480-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What is synchronization and why is it important?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object's value. This often causes dirty data and leads to significant errors.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-7370208201833061713?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/7370208201833061713/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=7370208201833061713' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/7370208201833061713'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/7370208201833061713'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-synchronization-and-why-is-it.html' title='What is synchronization and why is it important?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-315956849545926237</id><published>2008-02-26T08:25:00.004-08:00</published><updated>2008-02-26T08:26:02.235-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>How are Observer and Observable used?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated, it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-315956849545926237?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/315956849545926237/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=315956849545926237' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/315956849545926237'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/315956849545926237'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-are-observer-and-observable-used.html' title='How are Observer and Observable used?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-8703045687095433702</id><published>2008-02-26T08:25:00.003-08:00</published><updated>2008-02-26T08:25:45.457-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>Which containers use a border layout as their default layout?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;The Window, Frame and Dialog classes use a border layout as their default layout.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-8703045687095433702?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/8703045687095433702/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=8703045687095433702' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/8703045687095433702'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/8703045687095433702'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/which-containers-use-border-layout-as.html' title='Which containers use a border layout as their default layout?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-851665400524231100</id><published>2008-02-26T08:25:00.001-08:00</published><updated>2008-02-26T08:25:29.299-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What is a transient variable?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;A transient variable is a variable that may not be serialized. If you don't want some field to be serialized, you can mark that field transient or static. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-851665400524231100?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/851665400524231100/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=851665400524231100' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/851665400524231100'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/851665400524231100'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-transient-variable_26.html' title='What is a transient variable?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-6176826554308619862</id><published>2008-02-26T08:24:00.004-08:00</published><updated>2008-02-26T08:25:08.801-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What is the difference between Serializalble and Externalizable interface?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;When you use Serializable interface, your class is serialized automatically by default. But you can override writeObject() and readObject() two methods to control more complex object serailization process. When you use Externalizable interface, you have a complete control over your class's serialization process. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-6176826554308619862?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/6176826554308619862/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=6176826554308619862' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6176826554308619862'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6176826554308619862'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-difference-between_26.html' title='What is the difference between Serializalble and Externalizable interface?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-4831649753574691348</id><published>2008-02-26T08:24:00.003-08:00</published><updated>2008-02-26T08:24:50.185-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>How many methods in the Externalizable interface?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;There are two methods in the Externalizable interface. You have to implement these two methods in order to make your class externalizable. These two methods are readExternal() and writeExternal(). &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-4831649753574691348?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/4831649753574691348/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=4831649753574691348' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/4831649753574691348'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/4831649753574691348'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-many-methods-in-externalizable.html' title='How many methods in the Externalizable interface?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-8292901106308986173</id><published>2008-02-26T08:24:00.001-08:00</published><updated>2008-02-26T08:24:32.755-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>How many methods in the Serializable interface?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;There is no method in the Serializable interface. The Serializable interface acts as a marker, telling the object serialization tools that your class is serializable. &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-8292901106308986173?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/8292901106308986173/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=8292901106308986173' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/8292901106308986173'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/8292901106308986173'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-many-methods-in-serializable_26.html' title='How many methods in the Serializable interface?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-8365256412766162569</id><published>2008-02-26T08:23:00.004-08:00</published><updated>2008-02-26T08:24:13.916-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>If a class is located in a package, what do you need to change in the OS environment to be able to use it?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;You need to add a directory or a jar file that contains the package directories to the CLASSPATH environment variable. Let's say a class Employee belongs to a package com.xyz.hr; and is located in the file c:\dev\com\xyz\hr\Employee.java. In this case, you'd need to add c:\dev to the variable CLASSPATH. If this class contains the method main(), you could test it from a command prompt window as follows: &lt;br /&gt;c:\&gt;java com.xyz.hr.Employee &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-8365256412766162569?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/8365256412766162569/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=8365256412766162569' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/8365256412766162569'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/8365256412766162569'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/if-class-is-located-in-package-what-do.html' title='If a class is located in a package, what do you need to change in the OS environment to be able to use it?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-4776962763583811731</id><published>2008-02-26T08:23:00.003-08:00</published><updated>2008-02-26T08:23:55.917-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>How to define an Interface?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;In Java Interface defines the methods but does not implement them. Interface can include constants. A class that implements the interfaces is bound to implement all the methods defined in Interface. &lt;br /&gt;Emaple of Interface: &lt;br /&gt;&lt;br /&gt;public interface sampleInterface { &lt;br /&gt;public void functionOne(); &lt;br /&gt;&lt;br /&gt;public long CONSTANT_ONE = 1000; &lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-4776962763583811731?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/4776962763583811731/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=4776962763583811731' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/4776962763583811731'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/4776962763583811731'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-to-define-interface_26.html' title='How to define an Interface?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-4460249450429871724</id><published>2008-02-26T08:23:00.001-08:00</published><updated>2008-02-26T08:23:32.918-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>How to define an Abstract class?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;A class containing abstract method is called Abstract class. An Abstract class can't be instantiated. &lt;br /&gt;Example of Abstract class: &lt;br /&gt;abstract class testAbstractClass { &lt;br /&gt;protected String myString; &lt;br /&gt;public String getMyString() { &lt;br /&gt;return myString; &lt;br /&gt;} &lt;br /&gt;public abstract string anyAbstractFunction(); &lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-4460249450429871724?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/4460249450429871724/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=4460249450429871724' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/4460249450429871724'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/4460249450429871724'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-to-define-abstract-class.html' title='How to define an Abstract class?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-3133411378495232921</id><published>2008-02-26T08:22:00.002-08:00</published><updated>2008-02-26T08:23:12.300-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What is similarities/difference between an Abstract class and Interface?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Differences are as follows: &lt;br /&gt;Interfaces provide a form of multiple inheritance. A class can extend only one other class. Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc. &lt;br /&gt;A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class. Interfaces are slow as it requires extra indirection to to find corresponding method in in the actual class. Abstract classes are fast. &lt;br /&gt;Similarities: &lt;br /&gt;&lt;br /&gt;Neither Abstract classes or Interface can be instantiated&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-3133411378495232921?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/3133411378495232921/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=3133411378495232921' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3133411378495232921'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3133411378495232921'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-similaritiesdifference-between.html' title='What is similarities/difference between an Abstract class and Interface?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-7760374252663668996</id><published>2008-02-26T08:22:00.001-08:00</published><updated>2008-02-26T08:22:41.988-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What is Collection API ?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;The Collection API is a set of classes and interfaces that support operation on collections of objects. These classes and interfaces are more flexible, more powerful, and more regular than the vectors, arrays, and hashtables if effectively replaces. &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;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-7760374252663668996?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/7760374252663668996/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=7760374252663668996' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/7760374252663668996'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/7760374252663668996'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-collection-api.html' title='What is Collection API ?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-8951700845899720527</id><published>2008-02-26T08:21:00.000-08:00</published><updated>2008-02-26T08:22:20.563-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Questions'/><title type='text'>What is Java?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Java is an object-oriented programming language developed initially by James Gosling and colleagues at Sun Microsystems. The language, initially called Oak (named after the oak trees outside Gosling's office), was intended to replace C++, although the feature set better resembles that of Objective C. Java should not be confused with JavaScript, which shares only the name and a similar C-like syntax. Sun Microsystems currently maintains and updates Java regularly. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-8951700845899720527?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/8951700845899720527/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=8951700845899720527' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/8951700845899720527'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/8951700845899720527'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-java.html' title='What is Java?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-3753919683846627017</id><published>2008-02-26T08:18:00.000-08:00</published><updated>2008-02-26T08:20:38.742-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><title type='text'>What is data encapsulation?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Encapsulation may be used by creating 'get' and 'set' methods in a class (JAVABEAN) which are used to access the fields of the object. Typically the fields are made private while the get and set methods are public. Encapsulation can be used to validate the data that is to be stored, to do calculations on data that is stored in a field or fields, or for use in introspection (often the case when using javabeans in Struts, for instance). Wrapping of data and function into a single unit is called as data encapsulation. Encapsulation is nothing but wrapping up the data and associated methods into a single unit in such a way that data can be accessed with the help of associated methods. Encapsulation provides data security. It is nothing but data hiding.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-3753919683846627017?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/3753919683846627017/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=3753919683846627017' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3753919683846627017'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3753919683846627017'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-data-encapsulation_26.html' title='What is data encapsulation?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-241060116733937253</id><published>2008-02-05T11:03:00.000-08:00</published><updated>2008-02-05T11:04:46.731-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='About Java'/><title type='text'>Learn About Java Technology</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Java technology was created as a computer programming tool in a small, secret effort called "the Green Project" at Sun Microsystems in 1991.&lt;br /&gt;&lt;br /&gt;The secret "Green Team," fully staffed at 13 people and led by James Gosling, locked themselves away in an anonymous office on Sand Hill Road in Menlo Park, cut off all regular communications with Sun, and worked around the clock for 18 months.&lt;br /&gt;&lt;br /&gt;They were trying to anticipate and plan for the "next wave" in computing. Their initial conclusion was that at least one significant trend would be the convergence of digitally controlled consumer devices and computers.&lt;br /&gt;&lt;br /&gt;A device-independent programming language code-named "Oak" was the result.&lt;br /&gt;&lt;br /&gt;To demonstrate how this new language could power the future of digital devices, the Green Team developed an interactive, handheld home-entertainment device controller targeted at the digital cable television industry. But the idea was too far ahead of its time, and the digital cable television industry wasn't ready for the leap forward that Java technology offered them.&lt;br /&gt;&lt;br /&gt;As it turns out, the Internet was ready for Java technology, and just in time for its initial public introduction in 1995, the team was able to announce that the Netscape Navigator Internet browser would incorporate Java technology.&lt;br /&gt;&lt;br /&gt;Now, nearing its twelfth year, the Java platform has attracted over 5 million software developers, worldwide use in every major industry segment, and a presence in a wide range of devices, computers, and networks of any programming technology.&lt;br /&gt;&lt;br /&gt;In fact, its versatility, efficiency, platform portability, and security have made it the ideal technology for network computing, so that today, Java powers more than 4.5 billion devices:&lt;br /&gt;over 800 million PCs&lt;br /&gt;over 1.5 billion mobile phones and other handheld devices (source: Ovum)&lt;br /&gt;2.2 billion smart cards&lt;br /&gt;plus set-top boxes, printers, web cams, games, car navigation systems, lottery terminals, medical devices, parking payment stations, etc.&lt;br /&gt;Today, you can find Java technology in networks and devices that range from the Internet and scientific supercomputers to laptops and cell phones, from Wall Street market simulators to home game players and credit cards -- just about everywhere.&lt;br /&gt;&lt;br /&gt;The best way to preview these applications is to explore java.com, the ultimate marketplace, showcase, and central information resource for businesses, consumers, and software developers who use Java technology.&lt;br /&gt;&lt;br /&gt;Why Software Developers Choose Java Technology&lt;br /&gt;&lt;br /&gt;The Java programming language has been thoroughly refined, extended, tested, and proven by an active community of over five million software developers.&lt;br /&gt;&lt;br /&gt;Mature, extremely robust, and surprisingly versatile Java technology has become invaluable in allowing developers to:&lt;br /&gt;Write software on one platform and run it on practically any other platform&lt;br /&gt;Create programs to run within a web browser and web services&lt;br /&gt;Develop server-side applications for online forums, stores, polls, HTML forms processing, and more&lt;br /&gt;Combine Java technology-based applications or services to create highly customized applications or services&lt;br /&gt;Write powerful and efficient applications for mobile phones, remote processors, low-cost consumer products, and practically any device with a digital heartbeat&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-241060116733937253?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/241060116733937253/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=241060116733937253' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/241060116733937253'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/241060116733937253'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/learn-about-java-technology.html' title='Learn About Java Technology'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-1167161224687580531</id><published>2008-02-05T11:01:00.000-08:00</published><updated>2008-02-05T11:02:15.165-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Interview Questions'/><title type='text'>How many ways can one write an infinite loop ?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Personally I would recommend following ways to implement infinite loop in Java but their can be other ways like calling a method recursively , though I never tested that.&lt;br /&gt;&lt;br /&gt;- while (true)&lt;br /&gt;&lt;br /&gt;- for (;;) { } &lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-1167161224687580531?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/1167161224687580531/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=1167161224687580531' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/1167161224687580531'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/1167161224687580531'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-many-ways-can-one-write-infinite.html' title='How many ways can one write an infinite loop ?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-6163771505793260674</id><published>2008-02-05T10:53:00.000-08:00</published><updated>2008-02-05T10:54:19.237-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>How do I set the look and feel for swing application?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;import java.awt.*;&lt;br /&gt;import java.awt.event.ActionListener;&lt;br /&gt;import java.awt.event.ActionEvent;&lt;br /&gt; &lt;br /&gt;public class LookAndFeelDemo extends JFrame {&lt;br /&gt;    public LookAndFeelDemo() {&lt;br /&gt;        initComponents();&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    public void initComponents() {&lt;br /&gt;        setSize(200, 200);&lt;br /&gt;        setTitle("LAF Demo");&lt;br /&gt;        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);&lt;br /&gt;        getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT));&lt;br /&gt; &lt;br /&gt;        JMenuBar menuBar = new JMenuBar();&lt;br /&gt;        JMenu menu = new JMenu("Look and Feel");&lt;br /&gt; &lt;br /&gt;        final JFrame frame = this;&lt;br /&gt; &lt;br /&gt;        //&lt;br /&gt;        // Get all the available look and feel that we are going to use for &lt;br /&gt;        // creating the JMenuItem and assign the action listener to handle&lt;br /&gt;        // the selection of menu item to change the look and feel.&lt;br /&gt;        //&lt;br /&gt;        UIManager.LookAndFeelInfo[] lookAndFeelInfos = UIManager.getInstalledLookAndFeels();&lt;br /&gt;        for (int i = 0; i &lt; lookAndFeelInfos.length; i++) {&lt;br /&gt;            final UIManager.LookAndFeelInfo lookAndFeelInfo = lookAndFeelInfos[i];&lt;br /&gt;            JMenuItem item = new JMenuItem(lookAndFeelInfo.getName());&lt;br /&gt;            item.addActionListener(new ActionListener() {&lt;br /&gt;                public void actionPerformed(ActionEvent e) {&lt;br /&gt;                    try {&lt;br /&gt;                        //&lt;br /&gt;                        // Set the look and feel for the frame and update the UI &lt;br /&gt;                        // to use a new selected look and feel.&lt;br /&gt;                        //&lt;br /&gt;                        UIManager.setLookAndFeel(lookAndFeelInfo.getClassName());&lt;br /&gt;                        SwingUtilities.updateComponentTreeUI(frame);&lt;br /&gt;                    } catch (ClassNotFoundException e1) {&lt;br /&gt;                        e1.printStackTrace();&lt;br /&gt;                    } catch (InstantiationException e1) {&lt;br /&gt;                        e1.printStackTrace();&lt;br /&gt;                    } catch (IllegalAccessException e1) {&lt;br /&gt;                        e1.printStackTrace();&lt;br /&gt;                    } catch (UnsupportedLookAndFeelException e1) {&lt;br /&gt;                        e1.printStackTrace();&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            });&lt;br /&gt;            menu.add(item);&lt;br /&gt;        }&lt;br /&gt; &lt;br /&gt;        menuBar.add(menu);&lt;br /&gt; &lt;br /&gt;        getContentPane().add(menuBar);&lt;br /&gt;        getContentPane().add(new JButton("Hello"));&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    public static void main(String[] args) {&lt;br /&gt;        SwingUtilities.invokeLater(new Runnable() {&lt;br /&gt;            public void run() {&lt;br /&gt;                new LookAndFeelDemo().setVisible(true);&lt;br /&gt;            }&lt;br /&gt;        });&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-6163771505793260674?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/6163771505793260674/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=6163771505793260674' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6163771505793260674'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6163771505793260674'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-do-i-set-look-and-feel-for-swing.html' title='How do I set the look and feel for swing application?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-281572426415348886</id><published>2008-02-05T10:50:00.000-08:00</published><updated>2008-02-05T10:51:29.346-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>How do I make a centered JFrame?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;p&gt;If you have a &lt;span class="code"&gt;JFrame&lt;/span&gt; and you want to center the  position in the screen you can use the following formula. Let's say you have a  class called &lt;span class="code"&gt;MainForm&lt;/span&gt;.&lt;/p&gt;&lt;table cellpadding="0" cellspacing="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre class="java5"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;awt&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;*&lt;/span&gt;;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; javax.&lt;span style="color: rgb(0, 102, 0);"&gt;swing&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;*&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;class&lt;/span&gt; MainForm &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;extends&lt;/span&gt; &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JFrame.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;JFrame&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;  &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(153, 51, 51);"&gt;void&lt;/span&gt; main&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt; args&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;      &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/SwingUtilities.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;SwingUtilities&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;invokeLater&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;new&lt;/span&gt; &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runnable.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Runnable&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;          &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(153, 51, 51);"&gt;void&lt;/span&gt; run&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;              &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// Get the size of our screen&lt;/span&gt;&lt;br /&gt;              &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Dimension.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Dimension&lt;/span&gt;&lt;/a&gt; screenSize =&lt;br /&gt;                  &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Toolkit.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Toolkit&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;getDefaultToolkit&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;getScreenSize&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;              MainForm mainForm = &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;new&lt;/span&gt; MainForm&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;              mainForm.&lt;span style="color: rgb(0, 102, 0);"&gt;setDefaultCloseOperation&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;br /&gt;                  &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JFrame.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;JFrame&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;EXIT_ON_CLOSE&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;            &lt;br /&gt;              mainForm.&lt;span style="color: rgb(0, 102, 0);"&gt;setSize&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(204, 102, 204);"&gt;250&lt;/span&gt;, &lt;span style="color: rgb(204, 102, 204);"&gt;250&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;              &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// Calculates the position where the MainForm&lt;/span&gt;&lt;br /&gt;              &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// should be paced on the screen.&lt;/span&gt;&lt;br /&gt;              mainForm.&lt;span style="color: rgb(0, 102, 0);"&gt;setLocation&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;screenSize.&lt;span style="color: rgb(0, 102, 0);"&gt;width&lt;/span&gt; -&lt;br /&gt;                  mainForm.&lt;span style="color: rgb(0, 102, 0);"&gt;getWidth&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt; / &lt;span style="color: rgb(204, 102, 204);"&gt;2&lt;/span&gt;,&lt;br /&gt;                  &lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;screenSize.&lt;span style="color: rgb(0, 102, 0);"&gt;height&lt;/span&gt; -&lt;br /&gt;                  mainForm.&lt;span style="color: rgb(0, 102, 0);"&gt;getHeight&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt; / &lt;span style="color: rgb(204, 102, 204);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;              mainForm.&lt;span style="color: rgb(0, 102, 0);"&gt;pack&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;              mainForm.&lt;span style="color: rgb(0, 102, 0);"&gt;setVisible&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(177, 51, 102);"&gt;true&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;          &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;  &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;  &lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-281572426415348886?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/281572426415348886/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=281572426415348886' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/281572426415348886'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/281572426415348886'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-do-i-make-centered-jframe.html' title='How do I make a centered JFrame?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-5232394725808444890</id><published>2008-02-05T10:49:00.000-08:00</published><updated>2008-02-05T10:50:40.866-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>How do I create a connection to database?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;p&gt;An example for obtaining a connection to MySQL database. For connecting to  other database all you have to do is change the url to match to url format for a  particular database and of course you have to register a correct JDBC driver of  the database you are using.&lt;/p&gt;&lt;table cellpadding="0" cellspacing="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre class="java5"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;sql&lt;/span&gt;.&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/sql/DriverManager.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;DriverManager&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;sql&lt;/span&gt;.&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Connection.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Connection&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;class&lt;/span&gt; ConnectionSample&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// Below is the format of jdbc url for MySql database.&lt;/span&gt;&lt;br /&gt;  &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;static&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;final&lt;/span&gt; &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt; &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/URL.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;URL&lt;/span&gt;&lt;/a&gt; =&lt;br /&gt;      &lt;span style="color: rgb(255, 0, 0);"&gt;"jdbc:mysql://localhost/testdb"&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// The username for connecting to the database&lt;/span&gt;&lt;br /&gt;  &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;static&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;final&lt;/span&gt; &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt; USERNAME = &lt;span style="color: rgb(255, 0, 0);"&gt;"root"&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// The password for connecting to the database&lt;/span&gt;&lt;br /&gt;  &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;static&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;final&lt;/span&gt; &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt; PASSWORD = &lt;span style="color: rgb(255, 0, 0);"&gt;""&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;  &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(153, 51, 51);"&gt;void&lt;/span&gt; main&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt; args&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;throws&lt;/span&gt; &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Exception.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Exception&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;  &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;      &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Connection.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Connection&lt;/span&gt;&lt;/a&gt; connection = &lt;span style="color: rgb(177, 51, 102);"&gt;null&lt;/span&gt;;&lt;br /&gt;      &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;try&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;          &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// Register a database jdbc driver to be used by &lt;/span&gt;&lt;br /&gt;          &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// our program. In this example I choose a MySQL &lt;/span&gt;&lt;br /&gt;          &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// driver. &lt;/span&gt;&lt;br /&gt;          &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Class&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;forName&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"com.mysql.jdbc.Driver"&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;        &lt;br /&gt;          &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// Get the connection object from the driver manager &lt;/span&gt;&lt;br /&gt;          &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// by passing the url of our database, username and &lt;/span&gt;&lt;br /&gt;          &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// the password.&lt;/span&gt;&lt;br /&gt;          connection = &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/sql/DriverManager.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;DriverManager&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;getConnection&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/URL.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;URL&lt;/span&gt;&lt;/a&gt;,&lt;br /&gt;              USERNAME, PASSWORD&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;          &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// Do what ever you want to do with the connection &lt;/span&gt;&lt;br /&gt;          &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// object, such as reading some records from database, &lt;/span&gt;&lt;br /&gt;          &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// updating or deleting a row. But don't for get the &lt;/span&gt;&lt;br /&gt;          &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// close the connection right after you've finished &lt;/span&gt;&lt;br /&gt;          &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// using it.&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;finally&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;          &lt;span style="color: rgb(177, 177, 0);"&gt;if&lt;/span&gt; &lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;connection != &lt;span style="color: rgb(177, 51, 102);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;          &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;              connection.&lt;span style="color: rgb(0, 102, 0);"&gt;close&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;          &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-5232394725808444890?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/5232394725808444890/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=5232394725808444890' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5232394725808444890'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5232394725808444890'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-do-i-create-connection-to-database.html' title='How do I create a connection to database?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-7535677411048138152</id><published>2008-02-05T10:48:00.002-08:00</published><updated>2008-02-05T10:49:49.569-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>What is Autoboxing?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;p&gt;Autoboxing is a new feature offered in the Tiger (1.5) release of Java SDK.  In sort auto boxing is a capability to convert or cast between object wrapper  and it's primitive type.&lt;/p&gt; &lt;p&gt;Previously when placing a primitive data into one of the Java Collection  Framework we have to wrap it to an object because the collection cannot work  with primitive data. Also when calling a method that requires an instance of  object than an int or long, than we have to convert it too.&lt;/p&gt; &lt;p&gt;But now, starting from version 1.5 we were offered a new feature in the Java  Language, which automate this process, this is call the Autoboxing. When we  place an int value into a collection it will be converted into an Integer object  behind the scene, on the other we can read the Integer value as an int type. In  most way this simplify the way we code, no need to do an explisit object  casting.&lt;/p&gt; &lt;p&gt;Here an example how it will look like using the Autoboxing feature:&lt;/p&gt; &lt;table cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="java5"&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(153, 51, 51);"&gt;void&lt;/span&gt; main&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt; args&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;  Map&lt;string,&gt; map = &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;new&lt;/span&gt; HashMap&lt;string,&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// Here we put an int into the Map, and it accepted&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// as it will be autoboxed or converted into the wrapper&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// of this type, in this case the Integer object.&lt;/span&gt;&lt;br /&gt;  map.&lt;span style="color: rgb(0, 102, 0);"&gt;put&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"Age"&lt;/span&gt;, &lt;span style="color: rgb(204, 102, 204);"&gt;25&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// Here we can just get the value from the map, no need&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// to cast it from Integer to int.&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: rgb(153, 51, 51);"&gt;int&lt;/span&gt; age = map.&lt;span style="color: rgb(0, 102, 0);"&gt;get&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"Age"&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// Here we simply do the math on the primitive type&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// and got the result as an Integer.&lt;/span&gt;&lt;br /&gt;  &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Integer.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Integer&lt;/span&gt;&lt;/a&gt; newAge = age + &lt;span style="color: rgb(204, 102, 204);"&gt;10&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/string,&gt;&lt;/string,&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-7535677411048138152?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/7535677411048138152/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=7535677411048138152' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/7535677411048138152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/7535677411048138152'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-autoboxing.html' title='What is Autoboxing?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-456165110863014069</id><published>2008-02-05T10:48:00.001-08:00</published><updated>2008-02-05T10:48:50.364-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>How do I create a zip file?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;import java.io.File;&lt;br /&gt;import java.io.FileInputStream;&lt;br /&gt;import java.io.FileOutputStream;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.util.zip.ZipEntry;&lt;br /&gt;import java.util.zip.ZipOutputStream;&lt;br /&gt; &lt;br /&gt;public class ZippingFileExample {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  try {&lt;br /&gt;   String source = "text.txt";&lt;br /&gt;   String target = "example.zip";&lt;br /&gt;   &lt;br /&gt;   ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(target));&lt;br /&gt;   FileInputStream fis = new FileInputStream(source);&lt;br /&gt;   &lt;br /&gt;   // put a new ZipEntry in the ZipOutputStream&lt;br /&gt;   zos.putNextEntry(new ZipEntry(source));&lt;br /&gt;   &lt;br /&gt;   int size = 0;&lt;br /&gt;   byte[] buffer = new byte[1024];&lt;br /&gt;   &lt;br /&gt;   // read data to the end of the source file and write it to the zip&lt;br /&gt;   // output stream.&lt;br /&gt;   while ((size = fis.read(buffer)) &gt; 0) {&lt;br /&gt;    zos.write(buffer);&lt;br /&gt;   }&lt;br /&gt;   &lt;br /&gt;   zos.closeEntry();&lt;br /&gt;   fis.close();&lt;br /&gt;   &lt;br /&gt;   // Finish zip process&lt;br /&gt;   zos.close();&lt;br /&gt;   &lt;br /&gt;   &lt;br /&gt;  } catch (IOException e) {&lt;br /&gt;   e.printStackTrace();&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-456165110863014069?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/456165110863014069/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=456165110863014069' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/456165110863014069'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/456165110863014069'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-do-i-create-zip-file.html' title='How do I create a zip file?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-5572512371639773275</id><published>2008-02-05T10:47:00.000-08:00</published><updated>2008-02-05T10:48:06.497-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>How do I create a beep sound?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt; &lt;br /&gt;import java.awt.*;&lt;br /&gt; &lt;br /&gt;public class BeepExample {&lt;br /&gt;    public static void main(String[] args) {&lt;br /&gt;        // This is the way we can send a beep audio out.&lt;br /&gt;        Toolkit.getDefaultToolkit().beep();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-5572512371639773275?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/5572512371639773275/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=5572512371639773275' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5572512371639773275'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5572512371639773275'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-do-i-create-beep-sound.html' title='How do I create a beep sound?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-4803111188215855497</id><published>2008-02-05T10:46:00.000-08:00</published><updated>2008-02-05T10:47:21.443-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>How do I split a string?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;p&gt;String class introduce a &lt;span class="code"&gt;String.split(String regex)&lt;/span&gt;  method that simplify this process.&lt;/p&gt; &lt;p&gt;Below is a code sample how to do it.&lt;/p&gt;&lt;table cellpadding="0" cellspacing="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre class="java5"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;class&lt;/span&gt; StringSplit&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;  &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(153, 51, 51);"&gt;void&lt;/span&gt; main&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt; args&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;      &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt; data = &lt;span style="color: rgb(255, 0, 0);"&gt;"1,Diego Maradona,Footballer,Argentina"&lt;/span&gt;;&lt;br /&gt;      &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt; items = data.&lt;span style="color: rgb(0, 102, 0);"&gt;split&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;","&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;      &lt;span style="color: rgb(177, 177, 0);"&gt;for&lt;/span&gt; &lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt; item : items&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;          &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"item = "&lt;/span&gt; + item&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;      &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-4803111188215855497?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/4803111188215855497/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=4803111188215855497' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/4803111188215855497'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/4803111188215855497'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-do-i-split-string.html' title='How do I split a string?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-5488321049685136658</id><published>2008-02-05T10:45:00.000-08:00</published><updated>2008-02-05T10:46:27.771-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>How do I reverse a string?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;p&gt;Below is an example code that reverse a string. Here we use a &lt;span class="code"&gt;StringBuffer.reverse()&lt;/span&gt; method to reverse a string. In a 1.5  version a new class called &lt;span class="code"&gt;StringBuilder&lt;/span&gt; also has a  &lt;span class="code"&gt;reverse()&lt;/span&gt; method that do just the same, one of the  difference is &lt;span class="code"&gt;StringBuffer&lt;/span&gt; class is synchronized while  &lt;span class="code"&gt;StringBuilder&lt;/span&gt; class does not.&lt;/p&gt; &lt;p&gt;Beside using this simple method you can try to reverse a string by converting  it to character array and then reverse the array order. So here is the string  reverse in the &lt;span class="code"&gt;StringBuffer&lt;/span&gt; way.&lt;/p&gt; &lt;table cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="java5"&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;class&lt;/span&gt; StringReverseExample&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;   &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(153, 51, 51);"&gt;void&lt;/span&gt; main&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt; args&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;   &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// The normal sentence that is going to be reversed.&lt;/span&gt;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt; words = &lt;span style="color: rgb(255, 0, 0);"&gt;"Morning of The World - The Last Paradise on Earth"&lt;/span&gt;;&lt;br /&gt;      &lt;br /&gt;       &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// To reverse the string we can use the reverse() method in the &lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// StringBuffer class. The reverse() method returns a StringBuffer so&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// we need to call the toString() method to get a string object.&lt;/span&gt;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt; reverse = &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;new&lt;/span&gt; &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StringBuffer.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;StringBuffer&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;words&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;reverse&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;toString&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;      &lt;br /&gt;       &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// Print the normal string&lt;/span&gt;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"Normal : "&lt;/span&gt; + words&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// Print the string in reversed order&lt;/span&gt;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"Reverse: "&lt;/span&gt; + reverse&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;   &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;And below is the result.&lt;/p&gt;&lt;pre&gt;Normal : Morning of The World - The Last Paradise on Earth&lt;br /&gt;Reverse: htraE no esidaraP tsaL ehT - dlroW ehT fo gninroM&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-5488321049685136658?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/5488321049685136658/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=5488321049685136658' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5488321049685136658'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5488321049685136658'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-do-i-reverse-string.html' title='How do I reverse a string?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-6838470097745229785</id><published>2008-02-05T10:44:00.000-08:00</published><updated>2008-02-05T10:45:14.395-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>How do I implement a Singleton pattern?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;p&gt;Singleton pattern used when we want to allow only a single instance of a  class can be created inside our application. Using this pattern ensures that a  class only have a single instance by protecting the class creation process, by  setting the class constructor into private access modifier.&lt;/p&gt; &lt;p&gt;To get the class instance, the singleton class can provide a method for  example a &lt;span class="code"&gt;getInstance()&lt;/span&gt; method, this will be the only  method that can be accessed to get the instance.&lt;/p&gt; &lt;table cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="java5"&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;class&lt;/span&gt; SingletonPattern&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;   &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;private&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;static&lt;/span&gt; SingletonPattern instance;&lt;br /&gt;&lt;br /&gt;   &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;private&lt;/span&gt; SingletonPattern&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;   &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;   &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;static&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;synchronized&lt;/span&gt; SingletonPattern getInstance&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;   &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(177, 177, 0);"&gt;if&lt;/span&gt; &lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;instance == &lt;span style="color: rgb(177, 51, 102);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;           instance = &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;new&lt;/span&gt; SingletonPattern&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;       &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;return&lt;/span&gt; instance;&lt;br /&gt;   &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;There are some rules that need to be followed when we want to implement a  singleton.&lt;/p&gt; &lt;ol&gt;&lt;li&gt;from the example code above you can see that a singleton has a static  variable to keep it sole instance.  &lt;/li&gt;&lt;li&gt;you need to set the class constructor into private access modifier. By this  you will not allowed any other class to create an instance of this singleton  because they have no access to the constructor.  &lt;/li&gt;&lt;li&gt;because no other class can instantiate this singleton how can we use it? the  answer is the singleton should provide a service to it users by providing some  method that returns the instance, for example &lt;span class="code"&gt;getInstance()&lt;/span&gt;.  &lt;/li&gt;&lt;li&gt;when we use our singleton in a multi threaded application we need to make  sure that instance creation process not resulting more that one instance, so we  add a &lt;span class="code"&gt;synchronized&lt;/span&gt; keywords to protect more than one  thread access this method at the same time. &lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-6838470097745229785?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/6838470097745229785/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=6838470097745229785' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6838470097745229785'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6838470097745229785'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-do-i-implement-singleton-pattern.html' title='How do I implement a Singleton pattern?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-7284532092636546420</id><published>2008-02-05T10:43:00.000-08:00</published><updated>2008-02-05T10:44:22.196-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>Hello World example in Java</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;p&gt;Hello World is a classic sample to start when we learn a new programming  language. Below is the Java version of Hello World program, it simple enough to  start.&lt;/p&gt; &lt;table cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="java5"&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;class&lt;/span&gt; HelloWorld&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;   &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(153, 51, 51);"&gt;void&lt;/span&gt; main&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt; args&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;   &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// say hello to the world&lt;/span&gt;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"Hello World!"&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;   &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;The code contains one class called &lt;span class="code"&gt;HelloWorld&lt;/span&gt;, a  &lt;span class="code"&gt;main(String[] args)&lt;/span&gt; method which is the execution entry  point of every Java application and a single line of code that write a Hello  World string to the console. That's all, we are done!&lt;/p&gt; &lt;p&gt;To run the application we need to compile it first. I assume that you have  your Java in your path. To compile it type&lt;/p&gt;&lt;pre&gt;% javac HelloWorld.java&lt;br /&gt;&lt;/pre&gt; &lt;p&gt;The compilation process will result a file called &lt;span class="code"&gt;HelloWorld.class&lt;/span&gt;, this is the binary version of our program.  As you can see that the file ends with &lt;span class="code"&gt;.class&lt;/span&gt; extension  because Java is everyting about class.&lt;/p&gt; &lt;p&gt;To run it type the command bellow, class name is written without it  extension.&lt;/p&gt;&lt;pre&gt;% java HelloWorld&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-7284532092636546420?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/7284532092636546420/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=7284532092636546420' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/7284532092636546420'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/7284532092636546420'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/hello-world-example-in-java.html' title='Hello World example in Java'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-2127440274005234052</id><published>2008-02-05T10:42:00.000-08:00</published><updated>2008-02-05T10:43:22.855-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>How do I write string data to file?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;import java.io.File;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import org.apache.commons.io.FileUtils;&lt;br /&gt; &lt;br /&gt;public class WriteToFileExample&lt;br /&gt;{&lt;br /&gt;  public static void main(String[] args)&lt;br /&gt;  {&lt;br /&gt;    try&lt;br /&gt;    {&lt;br /&gt;      // Here we'll write our data into a file called&lt;br /&gt;      // sample.txt, this is the output.&lt;br /&gt;      File file = new File("sample.txt");&lt;br /&gt;      // We'll write the string below into the file&lt;br /&gt;      String data = "Learning Java Programming";&lt;br /&gt; &lt;br /&gt;      // To write a file called the writeStringToFile&lt;br /&gt;      // method which require you to pass the file and&lt;br /&gt;      // the data to be written.&lt;br /&gt;      FileUtils.writeStringToFile(file, data);&lt;br /&gt;    } catch (IOException e)&lt;br /&gt;    {&lt;br /&gt;      e.printStackTrace();&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-2127440274005234052?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/2127440274005234052/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=2127440274005234052' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2127440274005234052'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2127440274005234052'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-do-i-write-string-data-to-file.html' title='How do I write string data to file?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-3993563295328057373</id><published>2008-02-05T10:41:00.000-08:00</published><updated>2008-02-05T10:42:38.003-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>How do I format a number?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;p&gt;If you want to display some numbers that is formatted to a certain pattern,  either in a Java Swing application or in a JSP file, you can utilize  NumberFormat and DecimalFormat class to give you the format that you want. Here  is a small example that will show you how to do it.&lt;/p&gt;&lt;table cellpadding="0" cellspacing="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre class="java5"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;text&lt;/span&gt;.&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/text/DecimalFormat.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;DecimalFormat&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;text&lt;/span&gt;.&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/text/NumberFormat.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;NumberFormat&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;class&lt;/span&gt; DecimalFormatExample&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;  &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(153, 51, 51);"&gt;void&lt;/span&gt; main&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt; args&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// We have some millons money here that we'll format its look.&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(153, 51, 51);"&gt;double&lt;/span&gt; money = &lt;span style="color: rgb(204, 102, 204);"&gt;100550000.75&lt;/span&gt;;&lt;br /&gt;    &lt;br /&gt;      &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// By default to toString() method of the Double data type will print&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// the money value using a scientific number format as it is greater&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// than 10^7 (10,000,000.00). To be able to display the number without&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// scientific number format we can use java.text.DecimalFormat wich&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// is a sub class of java.text.NumberFormat.&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;      &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// Below we create a formatter with a pattern of #0.00. The # symbol&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// means any number but leading zero will not be displayed. The 0 &lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// symbol will display the remaining digit and will display as zero&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// if no digit is available.&lt;/span&gt;&lt;br /&gt;      &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/text/NumberFormat.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;NumberFormat&lt;/span&gt;&lt;/a&gt; formatter = &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;new&lt;/span&gt; &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/text/DecimalFormat.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;DecimalFormat&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"#0.00"&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;    &lt;br /&gt;      &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// Print the number using scientific number format.&lt;/span&gt;&lt;br /&gt;      &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;money&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;    &lt;br /&gt;      &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// Print the number using our defined decimal format pattern as above.&lt;/span&gt;&lt;br /&gt;      &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;formatter.&lt;span style="color: rgb(0, 102, 0);"&gt;format&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;money&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;  &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;Here is the different result of the code above. &lt;/p&gt;&lt;pre&gt;1.0055000075E8&lt;br /&gt;100550000.75&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-3993563295328057373?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/3993563295328057373/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=3993563295328057373' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3993563295328057373'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3993563295328057373'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-do-i-format-number.html' title='How do I format a number?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-2830765051131061091</id><published>2008-02-05T10:40:00.000-08:00</published><updated>2008-02-05T10:41:37.114-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>How do I do a date add or substract?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;p&gt;The &lt;span class="code"&gt;java.util.Calendar&lt;/span&gt; allows us to do a date  arithmetic function such as add or substract a unit of time to the specified  date field.&lt;/p&gt; &lt;p&gt;The method that done this process is the &lt;span class="code"&gt;Calendar.add(int  field, int amount)&lt;/span&gt;. Where the value of the field can be Calendar.DATE,  Calendar.MONTH, Calendar.YEAR. So this mean if you want to substract in days,  months or years use Calendar.DATE, Calendar.MONTH or Calendar.YEAR  respectively.&lt;/p&gt; &lt;table cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="java5"&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;util&lt;/span&gt;.&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Calendar&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;class&lt;/span&gt; CalendarAddExample&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;   &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(153, 51, 51);"&gt;void&lt;/span&gt; main&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt; args&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;   &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Calendar&lt;/span&gt;&lt;/a&gt; cal = &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Calendar&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;getInstance&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"Today : "&lt;/span&gt; + cal.&lt;span style="color: rgb(0, 102, 0);"&gt;getTime&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// Substract 30 days from the calendar&lt;/span&gt;&lt;br /&gt;       cal.&lt;span style="color: rgb(0, 102, 0);"&gt;add&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Calendar&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;DATE&lt;/span&gt;, &lt;span style="color: rgb(204, 102, 204);"&gt;-30&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"30 days ago: "&lt;/span&gt; + cal.&lt;span style="color: rgb(0, 102, 0);"&gt;getTime&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// Add 10 months to the calendar&lt;/span&gt;&lt;br /&gt;       cal.&lt;span style="color: rgb(0, 102, 0);"&gt;add&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Calendar&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;MONTH&lt;/span&gt;, &lt;span style="color: rgb(204, 102, 204);"&gt;10&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"10 months later: "&lt;/span&gt; + cal.&lt;span style="color: rgb(0, 102, 0);"&gt;getTime&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// Substract 1 year from the calendar&lt;/span&gt;&lt;br /&gt;       cal.&lt;span style="color: rgb(0, 102, 0);"&gt;add&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Calendar&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;YEAR&lt;/span&gt;, &lt;span style="color: rgb(204, 102, 204);"&gt;-1&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"1 year ago: "&lt;/span&gt; + cal.&lt;span style="color: rgb(0, 102, 0);"&gt;getTime&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;   &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;In the code above we want to know what is the date back to 30 days ago.&lt;/p&gt; &lt;p&gt;The sample result of the code is shown below:&lt;/p&gt;&lt;pre&gt;Today : Tue Jan 03 06:53:03 ICT 2006&lt;br /&gt;30 days ago: Sun Dec 04 06:53:03 ICT 2005&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-2830765051131061091?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/2830765051131061091/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=2830765051131061091' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2830765051131061091'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2830765051131061091'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-do-i-do-date-add-or-substract.html' title='How do I do a date add or substract?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-2914172140806873184</id><published>2008-02-05T10:38:00.000-08:00</published><updated>2008-02-05T10:39:45.276-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>How do I use StringTokenizer to split a string?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;table cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="java5"&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;util&lt;/span&gt;.&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/StringTokenizer.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;StringTokenizer&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;class&lt;/span&gt; StringTokenizerSample&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;  &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(153, 51, 51);"&gt;void&lt;/span&gt; main&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt; args&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;      &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/StringTokenizer.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;StringTokenizer&lt;/span&gt;&lt;/a&gt; st =&lt;br /&gt;              &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;new&lt;/span&gt; &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/StringTokenizer.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;StringTokenizer&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"a stringtokenizer sample"&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;      &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// get how many tokens inside st object&lt;/span&gt;&lt;br /&gt;      &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"tokens count: "&lt;/span&gt; + st.&lt;span style="color: rgb(0, 102, 0);"&gt;countTokens&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;      &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// iterate st object to get more tokens from it&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(177, 177, 0);"&gt;while&lt;/span&gt; &lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;st.&lt;span style="color: rgb(0, 102, 0);"&gt;hasMoreElements&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;          &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt; token = st.&lt;span style="color: rgb(0, 102, 0);"&gt;nextElement&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;toString&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;          &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"token = "&lt;/span&gt; + token&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;      &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;      &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// split a date string using a forward slash as&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// delimiter&lt;/span&gt;&lt;br /&gt;      st = &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;new&lt;/span&gt; &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/StringTokenizer.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;StringTokenizer&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"2005/12/15"&lt;/span&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;"/"&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;      &lt;span style="color: rgb(177, 177, 0);"&gt;while&lt;/span&gt; &lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;st.&lt;span style="color: rgb(0, 102, 0);"&gt;hasMoreElements&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;          &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt; token = st.&lt;span style="color: rgb(0, 102, 0);"&gt;nextToken&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;          &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"token = "&lt;/span&gt; + token&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;      &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;The above code is an example of using &lt;span class="code"&gt;StringTokenizer&lt;/span&gt;  to split a string. In the current JDK this class is discourageg to be used,  using instead the &lt;span class="code"&gt;String.split(...)&lt;/span&gt; method or using a  new &lt;span class="code"&gt;java.util.regex&lt;/span&gt; package.&lt;/p&gt; &lt;p&gt;Here is the result of this sample code:&lt;/p&gt;&lt;pre&gt;tokens count: 3&lt;br /&gt;token = a&lt;br /&gt;token = stringtokenizer&lt;br /&gt;token = sample&lt;br /&gt;token = 2005&lt;br /&gt;token = 12&lt;br /&gt;token = 15&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-2914172140806873184?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/2914172140806873184/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=2914172140806873184' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2914172140806873184'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2914172140806873184'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-do-i-use-stringtokenizer-to-split.html' title='How do I use StringTokenizer to split a string?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-4966083432242155506</id><published>2008-02-05T10:37:00.000-08:00</published><updated>2008-02-05T10:38:45.536-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>How do I read a text file?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;p&gt;The code shown below is an example how to read a text file. This program will  read a file called test.txt and shown its content.&lt;/p&gt; &lt;table cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="java5"&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;io&lt;/span&gt;.&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/BufferedReader.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;BufferedReader&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;io&lt;/span&gt;.&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;File&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;io&lt;/span&gt;.&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/FileReader.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;FileReader&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;io&lt;/span&gt;.&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/FileNotFoundException.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;FileNotFoundException&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;io&lt;/span&gt;.&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/IOException.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;IOException&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;class&lt;/span&gt; ReadTextFileExample&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;   &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(153, 51, 51);"&gt;void&lt;/span&gt; main&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt; args&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;   &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;File&lt;/span&gt;&lt;/a&gt; file = &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;new&lt;/span&gt; &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;File&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"test.txt"&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StringBuffer.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;StringBuffer&lt;/span&gt;&lt;/a&gt; contents = &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;new&lt;/span&gt; &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StringBuffer.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;StringBuffer&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/BufferedReader.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;BufferedReader&lt;/span&gt;&lt;/a&gt; reader = &lt;span style="color: rgb(177, 51, 102);"&gt;null&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;try&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;           reader = &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;new&lt;/span&gt; &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/BufferedReader.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;BufferedReader&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;new&lt;/span&gt; &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/FileReader.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;FileReader&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;file&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;           &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt; text = &lt;span style="color: rgb(177, 51, 102);"&gt;null&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;           &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// repeat until all lines is read&lt;/span&gt;&lt;br /&gt;           &lt;span style="color: rgb(177, 177, 0);"&gt;while&lt;/span&gt; &lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;text = reader.&lt;span style="color: rgb(0, 102, 0);"&gt;readLine&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt; != &lt;span style="color: rgb(177, 51, 102);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;           &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;               contents.&lt;span style="color: rgb(0, 102, 0);"&gt;append&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;text&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;                   .&lt;span style="color: rgb(0, 102, 0);"&gt;append&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;getProperty&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;br /&gt;                       &lt;span style="color: rgb(255, 0, 0);"&gt;"line.separator"&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;           &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;catch&lt;/span&gt; &lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/FileNotFoundException.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;FileNotFoundException&lt;/span&gt;&lt;/a&gt; e&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;           e.&lt;span style="color: rgb(0, 102, 0);"&gt;printStackTrace&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;catch&lt;/span&gt; &lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/IOException.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;IOException&lt;/span&gt;&lt;/a&gt; e&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;           e.&lt;span style="color: rgb(0, 102, 0);"&gt;printStackTrace&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;finally&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;           &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;try&lt;/span&gt;&lt;br /&gt;           &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;               &lt;span style="color: rgb(177, 177, 0);"&gt;if&lt;/span&gt; &lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;reader != &lt;span style="color: rgb(177, 51, 102);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;               &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;                   reader.&lt;span style="color: rgb(0, 102, 0);"&gt;close&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;               &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;           &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;catch&lt;/span&gt; &lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/IOException.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;IOException&lt;/span&gt;&lt;/a&gt; e&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;           &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;               e.&lt;span style="color: rgb(0, 102, 0);"&gt;printStackTrace&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;           &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;      &lt;br /&gt;       &lt;span style="color: rgb(128, 128, 128); font-style: italic;"&gt;// show file contents here&lt;/span&gt;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;contents.&lt;span style="color: rgb(0, 102, 0);"&gt;toString&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;   &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt; &lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-4966083432242155506?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/4966083432242155506/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=4966083432242155506' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/4966083432242155506'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/4966083432242155506'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-do-i-read-text-file.html' title='How do I read a text file?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-2194429655566022475</id><published>2008-02-05T10:36:00.000-08:00</published><updated>2008-02-05T10:37:49.423-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>How do I convert collection into array?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;p&gt;To convert collection-based data into array we can use &lt;span class="code"&gt;toArray()&lt;/span&gt; method provided by the implementation of &lt;span class="code"&gt;Collection&lt;/span&gt; interface such as &lt;span class="code"&gt;java.util.ArrayList&lt;/span&gt;.&lt;/p&gt; &lt;table cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="java5"&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;util&lt;/span&gt;.&lt;a href="http://www.google.com/search?sitesearch=java.sun.com&amp;amp;q=allinurl%3Aj2se%2F1+5+0%2Fdocs%2Fapi+List"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;List&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;util&lt;/span&gt;.&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/ArrayList.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;ArrayList&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;class&lt;/span&gt; CollectionToArrayExample&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;  &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(153, 51, 51);"&gt;void&lt;/span&gt; main&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt; args&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;      &lt;a href="http://www.google.com/search?sitesearch=java.sun.com&amp;amp;q=allinurl%3Aj2se%2F1+5+0%2Fdocs%2Fapi+List"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;List&lt;/span&gt;&lt;/a&gt; list = &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;new&lt;/span&gt; &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/ArrayList.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;ArrayList&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;      list.&lt;span style="color: rgb(0, 102, 0);"&gt;add&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"Java"&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;      list.&lt;span style="color: rgb(0, 102, 0);"&gt;add&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"Sample"&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;      list.&lt;span style="color: rgb(0, 102, 0);"&gt;add&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"Code"&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;      &lt;a href="http://www.google.com/search?sitesearch=java.sun.com&amp;amp;q=allinurl%3Aj2se%2F1+5+0%2Fdocs%2Fapi+Object"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Object&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt; array = list.&lt;span style="color: rgb(0, 102, 0);"&gt;toArray&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;      &lt;span style="color: rgb(177, 177, 0);"&gt;for&lt;/span&gt; &lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(153, 51, 51);"&gt;int&lt;/span&gt; i = &lt;span style="color: rgb(204, 102, 204);"&gt;0&lt;/span&gt;; i &lt; style="color: rgb(0, 102, 0);"&gt;length; i++&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;          &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;array&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;i&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;toString&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;      &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;Our sample code result is shown below:&lt;/p&gt;&lt;pre&gt;&lt;br /&gt;Java&lt;br /&gt;Sample&lt;br /&gt;Code&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-2194429655566022475?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/2194429655566022475/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=2194429655566022475' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2194429655566022475'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2194429655566022475'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-do-i-convert-collection-into-array.html' title='How do I convert collection into array?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-5754835781199592463</id><published>2008-02-05T10:35:00.000-08:00</published><updated>2008-02-05T10:36:23.693-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>How do I get the current month name?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;p&gt;To get the current month name from the system we can use &lt;span class="code"&gt;java.util.Calendar&lt;/span&gt; class. The &lt;span class="code"&gt;Calendar.get(Calendar.MONTH)&lt;/span&gt; returns the month value as an  integer starting from 0 as the first month and 11 as the last month. This mean  January equals to 0, February equals to 1 and December equals to 11.&lt;/p&gt; &lt;p&gt;Let's see the code below:&lt;/p&gt; &lt;table cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="java5"&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;util&lt;/span&gt;.&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Calendar&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;class&lt;/span&gt; GetMonthNameExample&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;   &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(153, 51, 51);"&gt;void&lt;/span&gt; main&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt; args&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;   &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt; monthName = &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"January"&lt;/span&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;"February"&lt;/span&gt;,&lt;br /&gt;           &lt;span style="color: rgb(255, 0, 0);"&gt;"March"&lt;/span&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;"April"&lt;/span&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;"May"&lt;/span&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;"June"&lt;/span&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;"July"&lt;/span&gt;,&lt;br /&gt;           &lt;span style="color: rgb(255, 0, 0);"&gt;"August"&lt;/span&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;"September"&lt;/span&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;"October"&lt;/span&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;"November"&lt;/span&gt;,&lt;br /&gt;           &lt;span style="color: rgb(255, 0, 0);"&gt;"December"&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Calendar&lt;/span&gt;&lt;/a&gt; cal = &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Calendar&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;getInstance&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt; month = monthName&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;cal.&lt;span style="color: rgb(0, 102, 0);"&gt;get&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Calendar&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;MONTH&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"Month name: "&lt;/span&gt; + month&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;   &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;On the first line inside the main method we declare an array of string that  keep our month names. Next we get the integer value of the current month and at  the last step we look for the month name inside our previously defined  array.&lt;/p&gt; &lt;p&gt;The example result of this program is:&lt;/p&gt;&lt;pre&gt;Month name: January&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-5754835781199592463?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/5754835781199592463/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=5754835781199592463' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5754835781199592463'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5754835781199592463'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-do-i-get-current-month-name.html' title='How do I get the current month name?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-6415409344214329318</id><published>2008-02-05T10:34:00.000-08:00</published><updated>2008-02-05T10:35:27.710-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>How do I get day, month, year value from the current date?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;p&gt;What day, month, year, day of week, day of month, day of year is today? If we  want to answer these question we can use &lt;span class="code"&gt;java.util.Calendar&lt;/span&gt; and &lt;span class="code"&gt;java.util.GregorianCalendar&lt;/span&gt; which is the implementation of  &lt;span class="code"&gt;Calendar&lt;/span&gt; abstract class.&lt;/p&gt; &lt;p&gt;These classes can help us to get integer value such as day, month, year from  a &lt;span class="code"&gt;Date&lt;/span&gt; object. Let's see the example code.&lt;/p&gt; &lt;table cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="java5"&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;util&lt;/span&gt;.&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Calendar&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;class&lt;/span&gt; CalendarExample&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;   &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(153, 51, 51);"&gt;void&lt;/span&gt; main&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt; args&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;   &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Calendar&lt;/span&gt;&lt;/a&gt; cal = &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Calendar&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;getInstance&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;span style="color: rgb(153, 51, 51);"&gt;int&lt;/span&gt; day = cal.&lt;span style="color: rgb(0, 102, 0);"&gt;get&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Calendar&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;DATE&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;span style="color: rgb(153, 51, 51);"&gt;int&lt;/span&gt; month = cal.&lt;span style="color: rgb(0, 102, 0);"&gt;get&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Calendar&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;MONTH&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt; + &lt;span style="color: rgb(204, 102, 204);"&gt;1&lt;/span&gt;;&lt;br /&gt;       &lt;span style="color: rgb(153, 51, 51);"&gt;int&lt;/span&gt; year = cal.&lt;span style="color: rgb(0, 102, 0);"&gt;get&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Calendar&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;YEAR&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;span style="color: rgb(153, 51, 51);"&gt;int&lt;/span&gt; dow = cal.&lt;span style="color: rgb(0, 102, 0);"&gt;get&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Calendar&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;DAY_OF_WEEK&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;span style="color: rgb(153, 51, 51);"&gt;int&lt;/span&gt; dom = cal.&lt;span style="color: rgb(0, 102, 0);"&gt;get&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Calendar&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;DAY_OF_MONTH&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;span style="color: rgb(153, 51, 51);"&gt;int&lt;/span&gt; doy = cal.&lt;span style="color: rgb(0, 102, 0);"&gt;get&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Calendar&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;DAY_OF_YEAR&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"Current Date: "&lt;/span&gt; + cal.&lt;span style="color: rgb(0, 102, 0);"&gt;getTime&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"Day: "&lt;/span&gt; + day&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"Month: "&lt;/span&gt; + month&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"Year: "&lt;/span&gt; + year&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"Day of Week: "&lt;/span&gt; + dow&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"Day of Month: "&lt;/span&gt; + dom&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"Day of Year: "&lt;/span&gt; + doy&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;   &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;Here is the result of this example:&lt;/p&gt;&lt;pre&gt;Current Date: Thu Dec 29 13:41:09 ICT 2005&lt;br /&gt;Day: 29&lt;br /&gt;Month: 12&lt;br /&gt;Year: 2005&lt;br /&gt;Day of Week: 5&lt;br /&gt;Day of Month: 29&lt;br /&gt;Day of Year: 363&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-6415409344214329318?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/6415409344214329318/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=6415409344214329318' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6415409344214329318'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6415409344214329318'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-do-i-get-day-month-year-value-from.html' title='How do I get day, month, year value from the current date?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-5989989044477729992</id><published>2008-02-05T10:32:00.000-08:00</published><updated>2008-02-05T10:34:26.696-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>How do I convert array to collection?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;p&gt;To convert array based data into list / collection based we can use &lt;span class="code"&gt;java.util.Arrays&lt;/span&gt; class. This class provide a static method  &lt;span class="code"&gt;asList(Object[] a)&lt;/span&gt; that converts array into list /  collection.&lt;/p&gt; &lt;table cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="java5"&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;util&lt;/span&gt;.&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Arrays&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;util&lt;/span&gt;.&lt;a href="http://www.google.com/search?sitesearch=java.sun.com&amp;amp;q=allinurl%3Aj2se%2F1+5+0%2Fdocs%2Fapi+List"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;List&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;util&lt;/span&gt;.&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Iterator.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Iterator&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;class&lt;/span&gt; ArraysExample&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;   &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(153, 51, 51);"&gt;void&lt;/span&gt; main&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt; args&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;   &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt; array = &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"Happy"&lt;/span&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;"New"&lt;/span&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;"Year"&lt;/span&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;"2006"&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;;&lt;br /&gt;       &lt;a href="http://www.google.com/search?sitesearch=java.sun.com&amp;amp;q=allinurl%3Aj2se%2F1+5+0%2Fdocs%2Fapi+List"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;List&lt;/span&gt;&lt;/a&gt; list = &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Arrays&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;asList&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;array&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Iterator.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Iterator&lt;/span&gt;&lt;/a&gt; iterator = list.&lt;span style="color: rgb(0, 102, 0);"&gt;iterator&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;span style="color: rgb(177, 177, 0);"&gt;while&lt;/span&gt; &lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;iterator.&lt;span style="color: rgb(0, 102, 0);"&gt;hasNext&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;           &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt; iterator.&lt;span style="color: rgb(0, 102, 0);"&gt;next&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;   &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;The result of our code is:&lt;/p&gt;&lt;pre&gt;Happy&lt;br /&gt;New&lt;br /&gt;Year&lt;br /&gt;2006&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-5989989044477729992?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/5989989044477729992/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=5989989044477729992' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5989989044477729992'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5989989044477729992'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-do-i-convert-array-to-collection.html' title='How do I convert array to collection?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-5556808208125664302</id><published>2008-02-05T10:29:00.000-08:00</published><updated>2008-02-05T10:32:10.946-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>How do I convert String to Date object?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;p&gt;The following code shows how we can convert a string representation of date  into &lt;span class="code"&gt;java.util.Date&lt;/span&gt; object.  &lt;/p&gt;&lt;p&gt;To convert a string of date we can use the help from &lt;span class="code"&gt;java.text.SimpleDateFormat&lt;/span&gt; that extends &lt;span class="code"&gt;java.text.DateFormat&lt;/span&gt; abstract class.&lt;/p&gt;&lt;table cellpadding="0" cellspacing="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre class="java5"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;text&lt;/span&gt;.&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/text/DateFormat.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;DateFormat&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;text&lt;/span&gt;.&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;SimpleDateFormat&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;text&lt;/span&gt;.&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/text/ParseException.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;ParseException&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;import&lt;/span&gt; java.&lt;span style="color: rgb(0, 102, 0);"&gt;util&lt;/span&gt;.&lt;a href="http://www.google.com/search?sitesearch=java.sun.com&amp;amp;q=allinurl%3Aj2se%2F1+5+0%2Fdocs%2Fapi+Date"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Date&lt;/span&gt;&lt;/a&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;class&lt;/span&gt; StringToDate&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;  &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;public&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(153, 51, 51);"&gt;void&lt;/span&gt; main&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;]&lt;/span&gt; args&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;      &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/text/DateFormat.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;DateFormat&lt;/span&gt;&lt;/a&gt; df = &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;new&lt;/span&gt; &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;SimpleDateFormat&lt;/span&gt;&lt;/a&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"dd/MM/yyyy"&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;      &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;try&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;          &lt;a href="http://www.google.com/search?sitesearch=java.sun.com&amp;amp;q=allinurl%3Aj2se%2F1+5+0%2Fdocs%2Fapi+Date"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;Date&lt;/span&gt;&lt;/a&gt; today = df.&lt;span style="color: rgb(0, 102, 0);"&gt;parse&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"20/12/2005"&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;          &lt;br /&gt;          &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;System&lt;/span&gt;&lt;/a&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;out&lt;/span&gt;.&lt;span style="color: rgb(0, 102, 0);"&gt;println&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;"Today = "&lt;/span&gt; + df.&lt;span style="color: rgb(0, 102, 0);"&gt;format&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;today&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;      &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(0, 0, 0);"&gt;catch&lt;/span&gt; &lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/text/ParseException.html"&gt;&lt;span style="font-weight: bold; color: rgb(170, 170, 221);"&gt;ParseException&lt;/span&gt;&lt;/a&gt; e&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: rgb(102, 204, 102);"&gt;{&lt;/span&gt;&lt;br /&gt;          e.&lt;span style="color: rgb(0, 102, 0);"&gt;printStackTrace&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;;&lt;br /&gt;      &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;And here is the result of our code:&lt;/p&gt;&lt;pre&gt;Today = 20/12/2005&lt;br /&gt;&lt;/pre&gt; &lt;p&gt;The example starts by creating an instance of &lt;span class="code"&gt;SimpleDateFormat&lt;/span&gt; with "dd/MM/yyyy" format which mean that the  date string is formatted in day-month-year sequence.&lt;/p&gt; &lt;p&gt;Finally using the &lt;span class="code"&gt;parse(String source)&lt;/span&gt; method we can  get the &lt;span class="code"&gt;Date&lt;/span&gt; instance. Because parse method can throw  &lt;span class="code"&gt;java.text.ParseException&lt;/span&gt; exception if the supplied date  is not in a valid format; we need to catch it.&lt;/p&gt; &lt;p&gt;Here are the list of defined patterns that can be used to format the date  taken from the Java class documentation.&lt;/p&gt; &lt;table border="1" cellpadding="1" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align="left"&gt;Letter&lt;/td&gt; &lt;td align="left"&gt;Date / Time Component&lt;/td&gt; &lt;td align="left"&gt;Examples&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;G&lt;/td&gt; &lt;td&gt;Era designator&lt;/td&gt; &lt;td&gt;AD&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;y&lt;/td&gt; &lt;td&gt;Year&lt;/td&gt; &lt;td&gt;1996; 96&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;M&lt;/td&gt; &lt;td&gt;Month in year&lt;/td&gt; &lt;td&gt;July; Jul; 07&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;w&lt;/td&gt; &lt;td&gt;Week in year&lt;/td&gt; &lt;td&gt;27&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;W&lt;/td&gt; &lt;td&gt;Week in month&lt;/td&gt; &lt;td&gt;2&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;D&lt;/td&gt; &lt;td&gt;Day in year&lt;/td&gt; &lt;td&gt;189&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;d&lt;/td&gt; &lt;td&gt;Day in month&lt;/td&gt; &lt;td&gt;10&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;F&lt;/td&gt; &lt;td&gt;Day of week in month&lt;/td&gt; &lt;td&gt;2&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;E&lt;/td&gt; &lt;td&gt;Day in week&lt;/td&gt; &lt;td&gt;Tuesday; Tue&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;a&lt;/td&gt; &lt;td&gt;Am/pm marker&lt;/td&gt; &lt;td&gt;PM&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;H&lt;/td&gt; &lt;td&gt;Hour in day (0-23)&lt;/td&gt; &lt;td&gt;0&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;k&lt;/td&gt; &lt;td&gt;Hour in day (1-24)&lt;/td&gt; &lt;td&gt;24&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;K&lt;/td&gt; &lt;td&gt;Hour in am/pm (0-11)&lt;/td&gt; &lt;td&gt;0&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;h&lt;/td&gt; &lt;td&gt;Hour in am/pm (1-12)&lt;/td&gt; &lt;td&gt;12&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;m&lt;/td&gt; &lt;td&gt;Minute in hour&lt;/td&gt; &lt;td&gt;30&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;s&lt;/td&gt; &lt;td&gt;Second in minute&lt;/td&gt; &lt;td&gt;55&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;S&lt;/td&gt; &lt;td&gt;Millisecond&lt;/td&gt; &lt;td&gt;978&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;z&lt;/td&gt; &lt;td&gt;Time zone&lt;/td&gt; &lt;td&gt;Pacific Standard Time; PST; GMT-08:00&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Z&lt;/td&gt; &lt;td&gt;Time zone&lt;/td&gt; &lt;td&gt;-0800&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-5556808208125664302?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/5556808208125664302/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=5556808208125664302' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5556808208125664302'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5556808208125664302'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-do-i-convert-string-to-date-object.html' title='How do I convert String to Date object?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-4848311091295533693</id><published>2008-02-05T10:17:00.000-08:00</published><updated>2008-02-05T10:24:01.127-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JAVA  Code Examples'/><title type='text'>How do I send an email message?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import javax.mail.Session;&lt;br /&gt;import javax.mail.Message;&lt;br /&gt;import javax.mail.Transport;&lt;br /&gt;import javax.mail.MessagingException;&lt;br /&gt;import javax.mail.internet.MimeMessage;&lt;br /&gt;import javax.mail.internet.InternetAddress;&lt;br /&gt;import java.util.Properties;&lt;br /&gt;&lt;br /&gt;public class EmailSenderDemo {&lt;br /&gt;  public static void main(String[] args) {&lt;br /&gt;      String from = "user@some-domain.com";&lt;br /&gt;      String to = "user@some-domain.com";&lt;br /&gt;      String subject = "Hi There...";&lt;br /&gt;      String text = "How are you?";&lt;br /&gt;&lt;br /&gt;      //&lt;br /&gt;      // A properties to store mail server smtp information such as the host&lt;br /&gt;      // name and the port number. With this properties we create a Session&lt;br /&gt;      // object from which we'll create the Message object.&lt;br /&gt;      //&lt;br /&gt;      Properties properties = new Properties();&lt;br /&gt;      properties.put("mail.smtp.host", "smtp.some-domain.com");&lt;br /&gt;      properties.put("mail.smtp.port", "25");&lt;br /&gt;      Session session = Session.getDefaultInstance(properties, null);&lt;br /&gt;&lt;br /&gt;      try {&lt;br /&gt;          //&lt;br /&gt;          // Message is a mail message to be send through the Transport object.&lt;br /&gt;          // In the Message object we set the sender address and the recipent&lt;br /&gt;          // address. Both of this address is a type of InternetAddress. For&lt;br /&gt;          // the recipient address we can also set the type of recipient, the&lt;br /&gt;          // value can be TO, CC or BCC. In the next two lines we set the email&lt;br /&gt;          // subject and the content text.&lt;br /&gt;          //&lt;br /&gt;          Message message = new MimeMessage(session);&lt;br /&gt;          message.setFrom(new InternetAddress(from));&lt;br /&gt;          message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));&lt;br /&gt;          message.setSubject(subject);&lt;br /&gt;          message.setText(text);&lt;br /&gt;&lt;br /&gt;          //&lt;br /&gt;          // Send the message to the recipient.&lt;br /&gt;          //&lt;br /&gt;          Transport.send(message);&lt;br /&gt;      } catch (MessagingException e) {&lt;br /&gt;          e.printStackTrace();&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-4848311091295533693?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/4848311091295533693/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=4848311091295533693' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/4848311091295533693'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/4848311091295533693'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-do-i-send-email-message.html' title='How do I send an email message?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-3313158908948221524</id><published>2008-02-05T10:16:00.004-08:00</published><updated>2008-02-05T10:17:37.833-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Wrapper Classes'/><title type='text'>What are Wrapper Classes? Describe the wrapper classes in Java.</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;p&gt;Wrapper classes are classes that allow primitive types to be accessed as  objects. Wrapper class is wrapper around a primitive data type. &lt;/p&gt; &lt;p&gt;Following table lists the primitive types and the corresponding wrapper  classes:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt; &lt;table border="1" cellpadding="0" cellspacing="0" width="50%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td bgcolor="#97be17"&gt; &lt;p align="center"&gt;&lt;strong&gt;Primitive&lt;/strong&gt;&lt;/p&gt;&lt;/td&gt; &lt;td bgcolor="#97be17"&gt; &lt;p align="center"&gt;&lt;strong&gt;Wrapper&lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td bgcolor="#fafadf"&gt; &lt;p&gt;  Boolean&lt;/p&gt;&lt;/td&gt; &lt;td bgcolor="#fafadf"&gt; &lt;p&gt;  java.lang.Boolean&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td bgcolor="#fafadf"&gt; &lt;p&gt;  Byte&lt;/p&gt;&lt;/td&gt; &lt;td bgcolor="#fafadf"&gt; &lt;p&gt;  java.lang.Byte&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td bgcolor="#fafadf"&gt; &lt;p&gt;  Char&lt;/p&gt;&lt;/td&gt; &lt;td bgcolor="#fafadf"&gt; &lt;p&gt;  java.lang.Character&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td bgcolor="#fafadf"&gt; &lt;p&gt;  double&lt;/p&gt;&lt;/td&gt; &lt;td bgcolor="#fafadf"&gt; &lt;p&gt;  java.lang.Double&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td bgcolor="#fafadf"&gt; &lt;p&gt;  Float&lt;/p&gt;&lt;/td&gt; &lt;td bgcolor="#fafadf"&gt; &lt;p&gt;  java.lang.Float&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td bgcolor="#fafadf"&gt; &lt;p&gt;  Int&lt;/p&gt;&lt;/td&gt; &lt;td bgcolor="#fafadf"&gt; &lt;p&gt;  java.lang.Integer&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td bgcolor="#fafadf"&gt; &lt;p&gt;  Long&lt;/p&gt;&lt;/td&gt; &lt;td bgcolor="#fafadf"&gt; &lt;p&gt;  java.lang.Long&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td bgcolor="#fafadf"&gt; &lt;p&gt;  Short &lt;/p&gt;&lt;/td&gt; &lt;td bgcolor="#fafadf"&gt; &lt;p&gt;  java.lang.Short&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td bgcolor="#fafadf"&gt; &lt;p&gt;  Void &lt;/p&gt;&lt;/td&gt; &lt;td bgcolor="#fafadf"&gt; &lt;p&gt;  java.lang.Void&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-3313158908948221524?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/3313158908948221524/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=3313158908948221524' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3313158908948221524'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3313158908948221524'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-are-wrapper-classes-describe.html' title='What are Wrapper Classes? Describe the wrapper classes in Java.'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-6869721051596781792</id><published>2008-02-05T10:16:00.003-08:00</published><updated>2008-02-05T10:16:35.584-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>Is there a separate stack for each thread in Java?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Yes. 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;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-6869721051596781792?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/6869721051596781792/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=6869721051596781792' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6869721051596781792'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6869721051596781792'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/is-there-separate-stack-for-each-thread.html' title='Is there a separate stack for each thread in Java?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-6868982191506665597</id><published>2008-02-05T10:16:00.001-08:00</published><updated>2008-02-05T10:16:17.682-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>How would you implement a thread pool?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;public class ThreadPool implements ThreadPoolInt &lt;br /&gt;&lt;br /&gt;This class is an generic implementation of a thread pool, which takes the following input &lt;br /&gt;&lt;br /&gt;a) Size of the pool to be constructed &lt;br /&gt;&lt;br /&gt;b) Name of the class which implements Runnable and constructs a thread pool with active threads that are waiting for activation. Once the threads have finished processing they come back and wait once again in the pool. &lt;br /&gt;&lt;br /&gt;This thread pool engine can be locked i.e. if some internal operation is performed on the pool then it is preferable that the thread engine be locked. Locking ensures that no new threads are issued by the engine. However, the currently executing threads are allowed to continue till they come back to the passivePool.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-6868982191506665597?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/6868982191506665597/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=6868982191506665597' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6868982191506665597'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6868982191506665597'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-would-you-implement-thread-pool.html' title='How would you implement a thread pool?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-4196462567816044566</id><published>2008-02-05T10:15:00.005-08:00</published><updated>2008-02-05T10:15:56.488-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>What state does a thread enter when it terminates its processing?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;When a thread terminates its processing, it enters the dead state. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-4196462567816044566?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/4196462567816044566/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=4196462567816044566' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/4196462567816044566'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/4196462567816044566'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-state-does-thread-enter-when-it.html' title='What state does a thread enter when it terminates its processing?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-6813465428621146249</id><published>2008-02-05T10:15:00.003-08:00</published><updated>2008-02-05T10:15:38.610-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>Can a lock be acquired on a class?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-6813465428621146249?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/6813465428621146249/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=6813465428621146249' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6813465428621146249'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6813465428621146249'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/can-lock-be-acquired-on-class.html' title='Can a lock be acquired on a class?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-4813881980146582085</id><published>2008-02-05T10:15:00.001-08:00</published><updated>2008-02-05T10:15:21.194-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>What is an object's lock and which objects have locks?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Answer: An object's lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object's lock. All objects and classes have locks. A class's lock is acquired on the class's Class object.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-4813881980146582085?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/4813881980146582085/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=4813881980146582085' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/4813881980146582085'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/4813881980146582085'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-objects-lock-and-which-objects.html' title='What is an object&apos;s lock and which objects have locks?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-868028071125859297</id><published>2008-02-05T10:14:00.004-08:00</published><updated>2008-02-05T10:15:01.068-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>Why would you use a synchronized block vs. synchronized method?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Synchronized blocks place locks for shorter periods than synchronized methods.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-868028071125859297?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/868028071125859297/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=868028071125859297' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/868028071125859297'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/868028071125859297'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/why-would-you-use-synchronized-block-vs.html' title='Why would you use a synchronized block vs. synchronized method?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-6510825108108872634</id><published>2008-02-05T10:14:00.003-08:00</published><updated>2008-02-05T10:14:41.340-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>When you will synchronize a piece of your code?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;When you expect that your shared code will be accessed by different threads and these threads may change a particular data causing data corruption, then they are placed in a synchronized construct or a synchronized method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-6510825108108872634?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/6510825108108872634/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=6510825108108872634' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6510825108108872634'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6510825108108872634'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/when-you-will-synchronize-piece-of-your.html' title='When you will synchronize a piece of your code?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-3949796857558642041</id><published>2008-02-05T10:14:00.001-08:00</published><updated>2008-02-05T10:14:22.121-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>What is synchronization?</title><content type='html'>&lt;span class="fullpost"&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;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-3949796857558642041?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/3949796857558642041/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=3949796857558642041' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3949796857558642041'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3949796857558642041'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-synchronization.html' title='What is synchronization?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-1065521156885172781</id><published>2008-02-05T10:13:00.003-08:00</published><updated>2008-02-05T10:13:59.264-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>What is daemon thread and which method is used to create the daemon thread?</title><content type='html'>&lt;span class="fullpost"&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;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-1065521156885172781?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/1065521156885172781/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=1065521156885172781' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/1065521156885172781'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/1065521156885172781'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-daemon-thread-and-which-method.html' title='What is daemon thread and which method is used to create the daemon thread?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-4997081826242589132</id><published>2008-02-05T10:13:00.001-08:00</published><updated>2008-02-05T10:13:30.743-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>What is the difference between process and thread?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;A thread is a separate path of execution in a program. A Process is a program in execution.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-4997081826242589132?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/4997081826242589132/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=4997081826242589132' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/4997081826242589132'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/4997081826242589132'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-difference-between-process-and.html' title='What is the difference between process and thread?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-3633615844429075153</id><published>2008-02-05T10:12:00.004-08:00</published><updated>2008-02-05T10:13:11.081-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>What’s the difference between the methods sleep() and wait()?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;The sleep method is used when the thread has to be put aside for a fixed amount of time. Ex: sleep(1000), puts the thread aside for exactly one second. The wait method is used to put the thread aside for up to the specified time. It could wait for much lesser time if it receives a notify() or notifyAll() call. Ex: wait(1000), causes a wait of up to one second. The method wait() is defined in the Object and the method sleep() is defined in the class Thread.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-3633615844429075153?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/3633615844429075153/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=3633615844429075153' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3633615844429075153'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3633615844429075153'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/whats-difference-between-methods-sleep.html' title='What’s the difference between the methods sleep() and wait()?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-327906762072650434</id><published>2008-02-05T10:12:00.003-08:00</published><updated>2008-02-05T10:12:50.709-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>Can Java object be locked down for exclusive use by a given thread?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Yes. You can lock an object by putting it in a "synchronized" block. The locked object is inaccessible to any thread other than the one that explicitly claimed it. If a thread attempts to execute a synchronized method or synchronized statement and is unable to acquire an object's lock, it enters the waiting state until the lock becomes available.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-327906762072650434?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/327906762072650434/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=327906762072650434' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/327906762072650434'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/327906762072650434'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/can-java-object-be-locked-down-for.html' title='Can Java object be locked down for exclusive use by a given thread?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-2308353076751030186</id><published>2008-02-05T10:12:00.001-08:00</published><updated>2008-02-05T10:12:32.365-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>What are synchronized methods and synchronized statements?</title><content type='html'>&lt;span class="fullpost"&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.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-2308353076751030186?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/2308353076751030186/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=2308353076751030186' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2308353076751030186'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2308353076751030186'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-are-synchronized-methods-and.html' title='What are synchronized methods and synchronized statements?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-6592276588322356260</id><published>2008-02-05T10:11:00.002-08:00</published><updated>2008-02-05T10:12:11.644-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>How does multithreading take place on a computer with a single CPU?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;The operating system's task scheduler allocates execution time to multiple tasks. By quickly switching between executing tasks, it creates the impression that tasks execute sequentially.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-6592276588322356260?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/6592276588322356260/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=6592276588322356260' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6592276588322356260'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/6592276588322356260'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/how-does-multithreading-take-place-on.html' title='How does multithreading take place on a computer with a single CPU?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-1946844508491707633</id><published>2008-02-05T10:11:00.001-08:00</published><updated>2008-02-05T10:11:45.567-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>What is deadlock?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;When two threads are waiting for each other and can’t proceed until the first thread obtains a lock on the other thread or vice versa, the program is said to be in a deadlock.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-1946844508491707633?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/1946844508491707633/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=1946844508491707633' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/1946844508491707633'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/1946844508491707633'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-deadlock.html' title='What is deadlock?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-4589421346006813052</id><published>2008-02-05T10:10:00.004-08:00</published><updated>2008-02-05T10:11:07.865-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>What are the states associated in the thread?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;A thread is an independent path of execution in a system. The high-level thread states are ready, running, waiting and dead.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-4589421346006813052?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/4589421346006813052/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=4589421346006813052' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/4589421346006813052'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/4589421346006813052'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-are-states-associated-in-thread.html' title='What are the states associated in the thread?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-8124646705175534633</id><published>2008-02-05T10:10:00.003-08:00</published><updated>2008-02-05T10:10:42.338-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>What is the purpose of the wait(), notify(), and notifyAll() methods?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;The wait(), notify() and notifyAll() methods are used to provide an efficient way for thread inter-communication.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-8124646705175534633?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/8124646705175534633/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=8124646705175534633' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/8124646705175534633'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/8124646705175534633'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-purpose-of-wait-notify-and.html' title='What is the purpose of the wait(), notify(), and notifyAll() methods?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-7972823557778007626</id><published>2008-02-05T10:10:00.001-08:00</published><updated>2008-02-05T10:10:20.430-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>What invokes a thread's run() method?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;After a thread is started, via its start() method of the Thread class, the JVM invokes the thread's run() method when the thread is initially executed.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-7972823557778007626?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/7972823557778007626/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=7972823557778007626' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/7972823557778007626'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/7972823557778007626'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-invokes-threads-run-method.html' title='What invokes a thread&apos;s run() method?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-169698176953912109</id><published>2008-02-05T10:09:00.002-08:00</published><updated>2008-02-05T10:10:00.097-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>What is the difference between preemptive scheduling and time slicing?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then re-enters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-169698176953912109?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/169698176953912109/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=169698176953912109' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/169698176953912109'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/169698176953912109'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-difference-between-preemptive.html' title='What is the difference between preemptive scheduling and time slicing?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-8690861174340013562</id><published>2008-02-05T10:09:00.001-08:00</published><updated>2008-02-05T10:09:41.537-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>What is mutual exclusion? How can you take care of mutual exclusion using Java threads?</title><content type='html'>&lt;span class="fullpost"&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. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-8690861174340013562?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/8690861174340013562/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=8690861174340013562' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/8690861174340013562'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/8690861174340013562'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-mutual-exclusion-how-can-you.html' title='What is mutual exclusion? How can you take care of mutual exclusion using Java threads?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-7504280610491800986</id><published>2008-02-05T10:08:00.002-08:00</published><updated>2008-02-05T10:09:22.537-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>Extending Thread class or implementing Runnable Interface. Which is better?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;You have two ways to do so. First, making your class "extends" Thread class. The other way is making your class implement "Runnable" interface. The latter is more advantageous, cause when you are going for multiple inheritance, then only interface can help. . If you are already inheriting a different class, then you have to go for Runnable Interface. Otherwise you can extend Thread class. Also, if you are implementing interface, it means you have to implement all methods in the interface. Both Thread class and Runnable interface are provided for convenience and use them as per the requirement. But if you are not extending any class, better extend Thread class as it will save few lines of coding. Otherwise performance wise, there is no distinguishable difference. A thread is in the ready state after it has been created and started.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-7504280610491800986?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/7504280610491800986/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=7504280610491800986' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/7504280610491800986'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/7504280610491800986'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/extending-thread-class-or-implementing.html' title='Extending Thread class or implementing Runnable Interface. Which is better?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-1782765734833539942</id><published>2008-02-05T10:08:00.001-08:00</published><updated>2008-02-05T10:08:49.371-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>What is the difference between yielding and sleeping?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;When a task invokes its yield() method, it returns to the ready state, either from waiting, running or after its creation. When a task invokes its sleep() method, it returns to the waiting state from a running state.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-1782765734833539942?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/1782765734833539942/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=1782765734833539942' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/1782765734833539942'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/1782765734833539942'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-difference-between-yielding-and.html' title='What is the difference between yielding and sleeping?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-3624199418342647830</id><published>2008-02-05T10:07:00.000-08:00</published><updated>2008-02-05T10:08:25.613-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Threads Questions'/><title type='text'>What are three ways in which a thread can enter the waiting state?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Or&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;What are different ways in which a thread can enter the waiting  state?&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;A thread can enter the waiting state by the following ways:&lt;br /&gt;1. Invoking  its sleep() method,&lt;br /&gt;2. By blocking on I/O&lt;br /&gt;3. By unsuccessfully attempting  to acquire an object's lock&lt;br /&gt;4. By invoking an object's wait() method.&lt;br /&gt;5.  It can also enter the waiting state by invoking its (deprecated) suspend()  method.&lt;/p&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-3624199418342647830?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/3624199418342647830/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=3624199418342647830' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3624199418342647830'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/3624199418342647830'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-are-three-ways-in-which-thread-can.html' title='What are three ways in which a thread can enter the waiting state?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-7367039740757996894</id><published>2008-02-05T10:06:00.003-08:00</published><updated>2008-02-05T10:06:43.084-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Swings Questions'/><title type='text'>Which containers use a FlowLayout as their default layout?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;The Panel and Applet classes use the FlowLayout as their default layout.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-7367039740757996894?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/7367039740757996894/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=7367039740757996894' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/7367039740757996894'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/7367039740757996894'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/which-containers-use-flowlayout-as.html' title='Which containers use a FlowLayout as their default layout?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-5918724984275709346</id><published>2008-02-05T10:06:00.001-08:00</published><updated>2008-02-05T10:06:19.372-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Swings Questions'/><title type='text'>What is the preferred size of a component?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;The preferred size of a component is the minimum component size that will allow the component to display normally.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-5918724984275709346?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/5918724984275709346/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=5918724984275709346' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5918724984275709346'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/5918724984275709346'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-preferred-size-of-component.html' title='What is the preferred size of a component?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-2381137334405459737</id><published>2008-02-05T10:05:00.003-08:00</published><updated>2008-02-05T10:05:59.216-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Swings Questions'/><title type='text'>What do heavy weight components mean?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;Heavy weight components like Abstract Window Toolkit (AWT) depend on the local windowing toolkit. For example, java.awt .Button is a heavy weight component.&lt;br /&gt;&lt;br /&gt;What is the difference between a Scrollbar and a ScrollPane?&lt;br /&gt;&lt;br /&gt;A Scrollbar is just a Component, but not a Container. A ScrollPane is a Container. A ScrollPane handles its own events and performs its own scrolling.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-2381137334405459737?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/2381137334405459737/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=2381137334405459737' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2381137334405459737'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2381137334405459737'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-do-heavy-weight-components-mean.html' title='What do heavy weight components mean?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-8774492530297389792</id><published>2008-02-05T10:05:00.001-08:00</published><updated>2008-02-05T10:05:36.699-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Swings Questions'/><title type='text'>What is the difference between a Window and a Frame?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;The Frame class extends Window to define a main application window that can have a menu bar.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-8774492530297389792?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/8774492530297389792/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=8774492530297389792' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/8774492530297389792'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/8774492530297389792'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-difference-between-window-and.html' title='What is the difference between a Window and a Frame?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-2533010601065162364</id><published>2008-02-05T10:04:00.004-08:00</published><updated>2008-02-05T10:05:10.496-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Swings Questions'/><title type='text'>What is the purpose of the enableEvents() method?</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;The enableEvents() method is used to enable an event for a particular component. Normally, an event is enabled when a listener is added to an object for a particular event. The enableEvents() method is used by objects that handle events by overriding their event-dispatch methods. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-2533010601065162364?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/2533010601065162364/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=2533010601065162364' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2533010601065162364'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2533010601065162364'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/what-is-purpose-of-enableevents-method.html' title='What is the purpose of the enableEvents() method?'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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-4685305606629949031.post-2595378883742356189</id><published>2008-02-05T10:04:00.003-08:00</published><updated>2008-02-05T10:04:49.873-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Swings Questions'/><title type='text'>Name Component subclasses that support painting.</title><content type='html'>&lt;span class="fullpost"&gt;&lt;br /&gt;The Canvas, Frame, Panel, and Applet classes support painting.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4685305606629949031-2595378883742356189?l=java-papers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-papers.blogspot.com/feeds/2595378883742356189/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4685305606629949031&amp;postID=2595378883742356189' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2595378883742356189'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4685305606629949031/posts/default/2595378883742356189'/><link rel='alternate' type='text/html' href='http://java-papers.blogspot.com/2008/02/name-component-subclasses-that-support.html' title='Name Component subclasses that support painting.'/><author><name>jon</name><uri>http://www.blogger.com/profile/06240532027051749210</uri><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></feed>
