Saturday, October 8, 2011

Clojure Presentation

Here is a link to a presentation on Clojure I gave at the 1st O.co Technology days.

Clojure Presentation

Tuesday, August 2, 2011

Sorting Java Objects - using BeanUtils

Sorting Java Objects - using BeanUtils 


class Person {


  private String firstName;
  private String lastName;
  
}


The org.apache.commons packages help a great deal with property based sorting:

ArrayList sortFields = new ArrayList();
sortFields.add(new BeanComparator("lastName"));
sortFields.add(new BeanComparator("firstName"));
ComparatorChain multiSort = new 
ComparatorChain(sortFields);
java.util.Collections.sort(list_of_objects_to_sort,multiSort);

See the Collections and BeanUtils packages at

http://jakarta.apache.org/commons/

Monday, June 6, 2011

double vs. BigDecimal

So, what's the conclusion here?
1. Do not use double/float for floating-point arithmetic in Java, use BigDecimal instead. This is because Java cannot represent floating-point precisely.
2. Do not use == or != as a floating-point comparison. Compare Float.floatToIntBits (float) or Double.doubleToLongBits (double) instead. If == or != is used on float/double, there's a possibility that the code will go into infinite loop.
3. Always use BigDecimal for temporary variables, which will be processed/involved in future calculations. Convert the values to float/double only if you want to persist them into the database.



source: http://epramono.blogspot.com/2005/01/double-vs-bigdecimal.html

Saturday, May 28, 2011

Reflections

At my current company, one of the Architects, Chris Hansen introduced, several of us to, a library called Reflections.

Setup:
  • Add the Maven repository which contains the dependency to your Nexus repository if you have one or else add it POM file.
  • Add the Maven dependency to your POM file. GAV=(org.reflections,reflections,0.9.5-RC2)
  • Depending on your needs, configure an instance of the Reflections class as outlined in the Docs.
Recently, I've had to look at a package for all classes annotated with a particular annotation.


Once setup, there are several handy methods on the Reflections class, one of which serves this exact purpose.

reflections.getTypesAnnotatedWith(SomeAnnotation.class);


I tried using a convenience constructor rather than the full blown constructor for Reflections since the javadoc on the convenience constructor seemed to be sufficient for my needs but  that didn't behave as expected.

Convenience constructor
Reflections(final String prefix, final Scanner... scanners)

And since all I needed was a TypeAnnotationsScanner and the convenience constructor above seemed to add it by default, I was hoping to use the constructor without passing any scanners.

Monday, May 2, 2011

Eclipse- tomcat deploy -Exploded location overlaps an existing deployment

Exploded location overlaps an existing deployment - eclipse

problem:
tomcat deployment project is loaded with "Exploded location overlaps an existing deployment" ERROR
solution:
If it appears when using tomcat "Exploded location overlaps an existing deployment" and its three buttons are grayed out state.

1.Find the address of your tomcat deployment, such as
C: \ Program Files \ Apache Software Foundation \ Tomcat 6.0 \ webapps and
C: \ Program Files \ Apache Software Foundation \ Tomcat 6.0 \ work \ Catalina \ localhost
check if the application you want to publish already exist. Delete the published application.

2 go to
project-> properties-> MyEclipse-> Web-> ContextRoot-> WebContext-root: RENAME