Skip to main content

Posts

Java Map

Maps in java are very useful for storing key value pairs. Map is an interface and is a part of Collections framework. However there are many implementations of Map interface, here I am discussing only java.util.HashMap and java.util.TreeMap. java.util.HashMap uses its own hashing algorithm to save the keys (You don't have to worry about it !) . The advantages of hashmap is almost equal time consumption in retrieving the keys. Suppose we a million objects as keys in a HashMap then, it takes almost equal time in getting any key (hasmap.get(any key)). This performance comes at a price . You do not get keys in order . The order is completely decided by java. Lets take an example. Let us make Person class whose objects we will store as keys in map. So here is our Person class class Person { private int age = 0; private String name = ""; public Person(String name,int age) { this.name = name; this.age = age; } public static Person[] getPersons(){ return n...
Recent posts

JMS with jboss 4

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBoss//EN" "http://www.jboss.org/j2ee/dtd/jboss.dtd"> <jboss> <enterprise-beans> <session> <ejb-name>ejbs/sessionBeans/MyTestSession</ejb-name> <jndi-name>ejb/MyTestSession</jndi-name> </session> <message-driven> <ejb-name>ejbs/mdbs/QueueMdb</ejb-name> <destination-jndi-name>queue/B</destination-jndi-name>             <resource-ref>                 <res-ref-name>QCF</res-ref-name>                 <jndi-name>ConnectionFactory</jndi-name>             </resource-ref>         </message-driven> <message-driven> <ejb-name>ejbs/mdbs/AnotherQueueMDB</ejb-name> <de...

EJB with jboss 4

Running EJB (EJB 2) with jboss (jboss 4) requires some setup. I am trying to explain the steps one needs to for EJB to work with jboss . File 1 :- MyTestSession.java package ejbs.sessionBeans; import java.rmi.RemoteException; import javax.ejb.EJBObject; public interface MyTestSession extends EJBObject{ public String sayHello() throws RemoteException; } File 2 :- MyTestSessionHome.java package ejbs.sessionBeans; import java.rmi.RemoteException; import java.sql.SQLException; import javax.ejb.EJBException; import javax.naming.NamingException; public interface MyTestSessionHome extends javax.ejb.EJBHome{ public MyTestSession create() throws javax.ejb.CreateException,EJBException, RemoteException, NamingException; } File 3 :- MyTestSessionBean.java package ejbs.sessionBeans; import java.rmi.RemoteException; import javax.ejb.EJBException; import javax.ejb.EJBHome; import javax.ejb.EJBObject; import javax.ejb.Handle; import javax.ejb.RemoveException; import ...

jQuery Selectors

In this post I would like to share what are the different ways by which we can select a particular DOM element. There are numerous ways of selecting an element, lets focus on the important ways. Let us consider the following HTML code. <div class="myClass" myAttribute="myAttributeValue"> <span>This is the first span in div </span> <span class="mySpanClass">This is second span in div </span> </div> If you have to get the attribute value of myAttribute of the first div with class="myClass" You can write in two ways - One $("div.myClass").attr('myAttribute'); //output will be myAttributeValue Two $(".myClass").attr('myAttribute'); //output will be myAttributeValue The above second way is not safe if you have elements other than div (such as span,td etc ) with the same class name. Selection by attribute If you want to know the class of the div you can write t...

Running PHP by command line on WAMP

There are a few simple steps one can follow to run php scripts by command line. Usually if you write "php" on the DOS prompt it will not recognize the command. In order to run php on command line in windows you have to do the following - Step 1 : Go to your wamp directory:\wamp\bin\php\php5.x.x (directory depends on your version). Copy this path Step 2 : Right click on My Computer and go to properties > Advanced > Environment Variables > System Variables . In that window select "path" click edit button. Go to the end of "Variable Value" and add a semi-colon ";" and after that paste the path copied. Click "Ok" and close. Step 3 : Open a fresh command prompt . Type php. Now it should run.

Get all dates between two dates

This is a PHP function to get all the dates between two dates. The function will return an array including both the starting and ending date. The returned date format will be Year-month-date(YYYY-MM-DD) just as MySQL standard date format. The function accepts two parameters 1. The start date. 2. The end date. The input date format must acceptable by PHP strtotime function function datesBetween($start_date=null,$end_date=null) { $dates=array(); $dates[0]=date('Y-m-d',strtotime($start_date)); $secs=strtotime($start_date); $i=1; while($secs

Ajax with Jquery

This time I wanted to write something for Jquery. Jquery is a very good Javascript library. It reduces much of your coding time. So here is how you do AJAX with Jquery Step 1 -: Download the latest version of jquery from here. This is Jquery 1.4 minified version. Step 2 -: $.get(url,'',function(data){ alert("Data from ajax is "+data); }); Done !!! Now I will explain it- 1.The "$" is nothing but a shorthand notation for jQuery. 2.Then comes "get" , this can be replaced with post as well, as this is the method by which the http request will be sent to the server. 3.Next is "url". This is the url of the page you are requesting. 4.After url I have the next parameter is left as '' . This parameter is just for adding the parameters (query strings) to the url. It is left to the programmer that he wants to use this parameter or not . You can club your query string in the Url also. 5.Finally we have a ...