Thursday, June 3, 2010

How to solve Classpath nightmare in java

Have you ever come across a situation where you modify a class and when you run it you do not see the changes you just committed? Most probably in most cases the issue lies with an older .class file being loaded in from another jar which overrides your current jar. This is definitely a debugging night mare.

Fortunately in java you can find out from which location your class file is loaded from. This article provides the info you need to find out on how to do it the eclipse way or injecting it directly to your code.


Enjoy!!!

Wednesday, June 2, 2010

Free icons for your project

Check this out. Gives a wide variety of free icons you can use in your projects.

Cheers

Monday, May 31, 2010

jLayout provides Swing like Layouts in JS

Found a javascript library called jLayout which provides layout capabilities that is similar to Java's Swing library. Most of the names used are evn similar. Pretty cool i must say. Hoping to try it out in the coming days. Check it out....

Friday, May 28, 2010

Online XML to XSD converter

Found an online tool which can generator xsd from a given sample XML doc. Can be found here.

Friday, May 21, 2010

Spring - How to use Component and Autowired

Just put together a sample which made me understand how to use the above mentioned annotations defined by Spring hence thought i should blog about the same.

First lets take a look at the two classes that are exposed as spring beans.





package chapter3;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component("calculator")
public class Calculator {
private Adder adder;

@Autowired
public void setAdder(Adder adder) {
this.adder = adder;
}

public void makeAnOperation(){
int r1 = adder.add(1,2);
System.out.println("r1 = " + r1);
}
}




package chapter3;

import org.springframework.stereotype.Component;

@Component("adder")
public class Adder {
public int add(int a, int b){
return a + b;
}
}

Few pointers to note here are as follows;

  • By annotation the class with @Component you tell the Spring container that these beans are needed to be instantiated and managed by the Spring container. This reduces XML configurations required because you do not need to manually edit the XML file entering bean definitions to each and every bean.
  • The @Autowired element binds an instance of the Adder class when the Spring container scans the Calculator class.
Next we look at the application context XML


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">

<context:component-scan base-package="chapter3"/>
<context:annotation-config/>

</beans>


And finally to run the sample following is the main class;



package chapter3;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ComponentCheck {

public static void main(String[] args) {
ApplicationContext appContext = new ClassPathXmlApplicationContext(
"chapter3AppXML.xml");
Calculator calculator = (Calculator) appContext.getBean("calculator");
calculator.makeAnOperation();

}

}

For all your CSS needs

Check this out. Has so many tutorials and designs that you can use or just learn the true power of CSS. Great site.

Thursday, May 20, 2010

ListIterator in Java

Learned about this just now and thought ill blog about it for any one else who might find it useful. We normally use the default iterator to traverse through any collection. But have you ever needed to traverse backwards and forward? Or maybe add an element to a location while traversing. Then the answer is to use the ListIterator interaface while allows you to carry out such tasks.

Check out the javadoc for more info.