Skip to main content

Posts

Showing posts from June, 2010

Using Collections to sorting the specified list into ascending order, according to the natural ordering of its elements

package  collection.demos; import  java.util. ArrayList ; import  java.util. Collections ; public   class  SortingListDemo  {      public   static   void   main ( String []  args )   {          ArrayList < String >  names = new   ArrayList < String > () ;         names. add ( "Joy" ) ;         names. add ( "Bynod" ) ;         names. add ( "Jaxon" ) ;         names. add ( "Traimer" ) ;          System .out. println ( "Before Sorting : " + names ) ;          Collections . sort ( names ) ;          System .out. println ( "After Sorting : " + names ) ;      } } /* OUTPUT Before Sorting : [Joy, Bynod, Jaxon, Traimer] After Sorting : [Bynod, Jaxon, Joy, Traimer]  */

PriorityQueue

Queue is a collection of items in which only the earliest added item may be accessed. Basic operations are add (to the tail) or enqueue and delete (from the head) or dequeue. Delete returns the item removed. Also known as "first-in, first-out" or FIFO. DeQueue is a queue to be any data structure that can have items inserted and removed from either end. An unbounded priority queue based on a priority heap. The elements of the priority queue are ordered according to their natural ordering, or by a Comparator  provided at queue construction time, depending on which constructor is used. A priority queue does not permit null elements. A priority queue relying on natural ordering also does not permit insertion of non-comparable objects The head of this queue is the least element with respect to the specified ordering. If multiple elements are tied for least value, the head is one of those elements -- ties are broken arbitrarily. The queue retrieval operations poll, remove, peek

TreeSetDemo

It is concrete classes that extends AbstractSet<E> and implements NavigableSet<E>, Cloneable and Serializable interfaces. All elements added to treeset are ordered automatically using their natural ordering, or by a Comparator typically provided at sorted set creation time whether you follow order or not. It does not allows to added duplicate element to set. The set's iterator will traverse the set in ascending element order. Several additional operations are provided to take advantage of the ordering.  package  collection.demos; import  java.util. TreeSet ; public   class  TreeSetDemo  {      public   static   void   main ( String []  args )   {          TreeSet < String >  names = new   TreeSet < String > () ;         names. add ( "abc" ) ;         names. add ( "rit" ) ;         names. add ( "rit" ) ;         names. add ( "rit" ) ;         names. add ( "swek" ) ;         names. add ( "trog&

Logging

It is a process to tracking the different states of system while it is running. We record all the messages according to our observations in executions. It is a way to debugging your application in real time and provides required information to resolve problems. Because, you can set your logging statement at any executable place in you coding, so you can use this feature to test, debug, and profiling. The entire messages generated by logging are recorded at specified destination of logger and can be retrieved later. Mostly, all messages are redirected to standard output of system and you can view all logging information as you application starts to executes. Log4j is mostly used Logging tool in java that allows you to log at runtime without modifying the application binary. The log4j package is designed so that these statements can remain in shipped code without incurring a heavy performance cost. Logging behavior can be controlled by editing a configuration file, without touching t

Struts 2 Tags

Struts 2 Tags <%@ taglib   prefix = "s"   uri = "/struts-tags" %> < h3 > </ h3 > < h3 >  Conditionals  </ h3 > < s:if   test = 'name=="abc"' > you are  < s:property   value = "name" / > </ s:if > < s:else > you are not abc </ s:else > < h3 > collections and  Iteration (ArrayList)  </ h3 > < ul >      < s:iterator   value = "books"   var = "book" >      < li > < s:property   value = "book" / > </ li >      </ s:iterator > </ ul > < h3 > collections and  Iteration  (Map) </ h3 > < ul >      < s:iterator   value = "emails" >      < li > < s:property   value = "key" / >  :  < s:property   value = "value" / > </ li >      </ s:iterator > </ ul > < ul >   

Using form tags in Struts 2

Struts 2 provides various tags that simplifies our development.  Here is an example to create the form using struts2 form tags. These tags are processed by struts frame work and values are mapped to coreponding domaon object automatically. The name attribute of tag is used to map the value to data holder variable at server side.  Here, each name has been prefixed with "user" that specifies the object in action implementation. For example, The value of textfield having name "user.name" will mapped to the variable of object being referenced by user variable of action class. <%@   taglib   prefix = "s"   uri = "/struts-tags" %> < html > < head > </ head > < body >      < s:form   action = "send"   method = "post" >          < s:textfield   name = "user.name"   label = "Full Name"   title = "Use text only" / >          < s:textfield   name = &q

List dirvers and connection-urls for connecting java program to databases

DB2 Driver : "com.ibm.db2.jcc.DB2Driver" URL: "jdbc:db2://localhost:5021/database","user","password" Apache Derby driver: "org.apache.derby.jdbc.EmbeddedDriver" URL: "jdbc:derby://localhost/databasename","user","password" FrontBase Driver : "jdbc.frontbase.FBDriver" URL : "jdbc:frontbase:/DerbyDB/AssetDB","user","password" OpenBase Driver : "com.openbase.jdbc.ObDriver" URL : "jdbc:openbase://localhost/databasename","user","password" MySQL Driver : "com.mysql.jdbc.Driver" URL: "jdbc:mysql://localhost:3306/databasename","user","password" H2Database Driver : "org.h2.Driver" URL: " jdbc:h2:tcp://localhost//data/databasename ","user","password" More info. PostgreSQL Driver : "org.postgresql.Driver" URL: "jdbc:postgresql://localhos

Struts Simple Example

Here is a simple example of Struts2. Directory hierarchy   your-application │   result1.jsp │ └───WEB-INF            │         web.xml            │            └───classes                                 struts.xml First of all, configure strut2 filter into web.xml of your application < web-app >      < display-name > Struts  2  eg  1 </ display-name >      < filter >          < filter-name > struts2 </ filter-name >          < filter-class > org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </ filter-class >      </ filter >      < filter-mapping >          < filter-name > struts2 </ filter-name >          < url-pattern > /* </ url-pattern >      </ filter-mapping > </ web-app > Now, in struts.xml file which is located into classes folder of you web application, write following contetns < web-app >      < display-name &g