Friday, March 26, 2010

Array List Sorting Issue

Hi,

Recently, i was coding for an application and came across a problem where i need to sort an ArrayList in an alphabetical order. However, that sounded quite easy as because sorting can easy with single arraylist. But, i was in a situation where i had two different ArrayLists with multiple attributes. So, what i did is that i kept a delimeter to distinct all my 3 values and then i added them into a temporary list.


for(int j=0;j
{
myBean=(MyBean)myList.get(j);
tempList.add(myBean.getOne() + "*" + myBean.getTwo() + "*" + myBean.getThree());
} 

then i used collection's sort method to sort them up in an alphabetical form.

Collections.sort(tempList,new MyComparator());  


I used inner class called Mycomparator to compare.


 class MyComparator implements Comparator {   
         
         public int compare(Object o1,   
                            Object o2) {   
            String s1 = o1.toString().toUpperCase();   
            String s2 = o2.toString().toUpperCase();   
    
            int counter = 0;   
    
            for (counter=0;counter
                               !Character.isDigit(s1.charAt(counter));counter++);   
    
            String temp1 = s1.substring(counter);   
    
            s1 = s1.substring(0,counter);   
    
            for (counter=0;counter
                           !Character.isDigit(s2.charAt(counter));counter++);   
    
            String temp2 = s2.substring(counter);   
    
            s2 = s2.substring(0,counter);   
    
            int max = (temp1.length() > temp2.length()) ? temp1.length() : temp2.length();   
    
            char[] pad = new char[max-temp1.length()];   
    
            Arrays.fill(pad,(char)48);   
    
            temp1 = String.valueOf(pad) + temp1;   
    
            pad = new char[max-temp2.length()];   
    
            Arrays.fill(pad,(char)48);   
    
            temp2 = String.valueOf(pad) + temp2;   
    
            s1 = s1 + temp1;   
            s2 = s2 + temp2;   
    
            return(s1.compareTo(s2));   
         }   
    
         public boolean equals(Object o1,   
                               Object o2) {   
            String s1 = o1.toString();   
            String s2 = o2.toString();   
    
            return(s1.equals(s2));   
         }   
    
      }   


And finally,. the problem got resolved, i got my list ordered in alphabetical form.



Thursday, February 25, 2010

Problems installing Myeclipse 8.0

Hi,

Today, i was installing Myeclipse 8.0, i faced some issues while installing that. It showed below errors.


Pulse has been unable to create a plan for Myeclipse 8.0 latest. Pleace check details below etc etc... 


Please provide a non pulse installation option. 

Details 
This profile can not be resolved because required software could not be located. 
Could not locate installable unit: com.genuitec.myeclipse.matisse.feature.group [7.1.0,7.5.0) 
Could not locate installable unit: com.genuitec.myeclipse.enterprise.workbench.feature.group [7.1.0,7.5.0) 
Could not locate installable unit: com.genuitec.myeclipse.tapestry.feature.group [7.1.0,7.5.0) 
Could not locate installable unit: com.genuitec.myeclipse.reports.feature.group [7.1.0,7.5.0) 
Could not locate installable unit: com.genuitec.myeclipse.icefaces.feature.feature.group [7.1.0,7.5.0) 
Checked update site http://download.eclipse.org/eclipse/updates/3.4 and found 1811 installable units. 



Checked update site http://download.eclipse.org/releases/ganymede and found 3799 installable units. 



Checked update site http://downloads2.poweredbypulse.com/downloads/products/pulse/client and found 116 installable units. 



Checked update site http://downloads2.poweredbypulse.com/downloads/products/pulse/eclipse34 and found 1 installable units. 



Checked update site http://downloads2.poweredbypulse.com/downloads/products/pulse/ganymede and found 104 installable units. 



Checked update site http://downloads3.myeclipseide.com/downloads/products/eworkbench/ganymede-latest and found 816 installable units. 



Checked update site http://downloads3.myeclipseide.com/downloads/products/eworkbench/ganymede-latest/supporting and found 20 installable units. 



Checked update site http://downloads3.myeclipseide.com/downloads/products/eworkbench/jdks and found 6 installable units. 



Checked update site http://www.poweredbypulse.com/installer/eclipse-base and found 2 installable units. 



Checked update site http://www.poweredbypulse.com/pulse/download/live and found 1 installable units.

Well, later on i discovered that pulse explorer that is a part of my eclipse tried to download some updated from internet, since my machine was under a firewall it failed and showed abover errors. So, then as a solution for that, i downloaded and installed pulse explorer seperately and then ran my myeclipse setup again and this time, i got it successfully installed.

Regards,


Ujjwal Soni
.

Sunday, January 31, 2010

10 Commandments for Java Developers

1. Add comments to your code
2. Do not complicate things - Means don’t come up with complicated solution for simplest problems
3. Keep in Mind "Less is more" is not always better - Means when necessary write all required code
4. No hard coding please.
5. Do not invent your own frameworks. - use available superb frameworks like Struts,JSF or Spring
6. Say no to Print lines and String Concatenations
7. Pay attention to the GUI - Look and Feel always matters
8. Always Prepare Document Requirements
9. Unit-test. Unit-test. Unit-test - Always do unit test
10. Remember quality, not quantity.

Tuesday, January 26, 2010

Framework for cloud computing using java

Hi,

Recently, i was searching for java based framework suitable for cloud computing and i suddenly came across grid gain.

GridGain is an ideal platform for Native Cloud Applications. GridGain provides developers with powerful and elegant technology to develop and run applications on private or public clouds.

GridGain is developed in Java and for Java developers and it is a natural extension of the latest Java development methodologies including annotations, integration of Spring and AOP-based grid-enabling.

For more details http://www.gridgain.com/

Friday, January 22, 2010

Getting square block characters when carriage return used in MS Excel 2003

Hi,

Recently i was facing a strange issue with JXL API for excel sheet generation using JAVA, the data entry screen was fine but when i was generating reports, i got some strange characters at each carriage return. This issue only happened in MS Excel 2003, this worked fine in other office versions.

Actually this issue only appeared in some European countries, worked fine in Asia.

So, i tried replaceAll method to replace this character with blank spaces like this ::

reportValue.replaceAll("[\\r\\n]", "");

This worked fine but it removed all my carriage returns too..

So, i tried below code which removed that square block character and restored my keystrokes.

reportValue..replace('\r',' ').replace('\'',' ');

This worked absolutely fine in All office versions and all countries for both europe and asia.

Cheers,

Ujjwal Soni

Thursday, January 14, 2010

what is 'is a' and 'has a' relationship:

The is a relationship is expressed with inheritance and has a relationship is expressed with composition.


Both inheritance and composition allow you to place sub-objects inside your new class. Two of the main techniques for code reuse are class inheritance and object composition.
e.g.,
is a --- House is a Building
class Building {
.......
}


class House extends Building {
......... 
}

has a -- House has a bathroom
class House
{
  Bathroom room = new Bathroom() ;
  ....
  public void getTotMirrors()
  {
    room.getNoMirrors();
    ....
   }
 }
Inheritance Vs Composition
Inheritance is uni-directional. For example House is a Building. But Building is not a House. Inheritance uses
extends key word. Composition: is used when House has a Bathroom. It is incorrect to say House is a Bathroom.
Composition simply means using instance variables that refer to other objects. The class House will have an instance variable, 
which refers to a Bathroom object.

Article taken from Oracle Magazine march 2008 issue