Pages

Saturday, December 28, 2013

Thursday, November 28, 2013

Monday, November 18, 2013

Considerations on using thirty party libraries to build your application.

Have you ever thought twice when you use a third party java library to implement your system? Well you should. Some of the reasons are
  1. Is the community active.(fix bugs pitfalls, and other aspects)
  2. Licensing
  3. Using many number of libraries many cause increase in dependencies on third parties.
  4. Some bugs in your system may be because of a third party library.
  5. Updating resources in the system(OS, jre, etc...) may cause the system to break and then we will have to replace the library with the updated one if exists, replace the library with another third-party software, folk the software and fix it, or re-implement the functionality by our own.
Having said that we still do need third party libraries in almost all implementations. But keeping these dependencies to a minimum is very important because of the above said reasons.

Sunday, November 17, 2013

spring webflow Introduction

What issues does spring webflow help overcome?

  1. Visualizing the flow is very difficult.
  2. The application has a lot of code accessing the HTTP session.
  3. Enforcing controlled navigation is important but not possible.
  4. Proper browser back button support seems unattainable.
  5. Browser and server get out of sync with "Back" button use.
  6. Multiple browser tabs causes concurrency issues with HTTP session data.
When spring webflow?
  1. There is a clear start and an end point.
  2. The user must go through a set of screens in a specific order.
  3. The changes are not finalized until the last step.
  4. Once complete it shouldn't be possible to repeat a transaction accidentally

How to avoid N + 1 problem in hibernate?

Wednesday, November 13, 2013

Sunday, November 10, 2013

Message broker or ESB?

Which one would you like to work with? or which one best suits with your requirement? Well in old traditional conceptions about both let me point out some key features.

A message broker is centralized (hub-spoke architecture) while an esb is not. Therefore a broker is a single point of failure. Again another fact is that a broker is only able vertical scaling and is unable to scale horizontally.

These are some articles I found on internet that describe this matter.

  1. http://bradleyboveinis.com/2013/03/27/bus-vs-broker/
  2. http://codebetter.com/drusellers/2009/05/29/why-messaging-5-bus-vs-broker/
  3. http://msmvps.com/blogs/peterritchie/archive/2011/09/18/enterprise-service-buses-brokers-message-queues-oh-my.aspx
So the most popular and the winner seems to be the bus architecture.

Some popular opensource esbs are
  1. Mule
  2. Apache Synapse
  3. Apache service mix
  4. wso2 esb

There are some other software the enterpise integration patterns such as spring integration, apache camel. Now are they also called messaged brokers or esbs? Well you can think of them as just libraries that help to integrate enterprise software using enterprise integration patterns. Below is a link I found that addresses this matter.

Saturday, November 9, 2013

Object pooling with spring framework

This can be done using the following simple code.

<bean id="simpleBeanTarget" class="com.mad.SimpleBean" scope="prototype">
</bean>

<bean id="poolTargetSource" class="org.springframework.aop.target.CommonsPoolTargetSource">               <property name="targetBeanName" value="simpleBeanTarget" />
            <property name="maxSize" value="20" />
</bean>

<bean id="simpleBean" class="org.springframework.aop.framework.ProxyFactoryBean">
           <property name="targetSource" ref="poolTargetSource" />
</bean>

here the simpleBeanTarget is the bean which is pooled. poolTargetSource is the pooling  bean for the simple bean tareget.

Http client library for java

I've been searching for a java http client for one of my projects. then I came across a simple library called jakartha commons client. As it turns out, this library is at it's end of life. So I was wondering a good library implementation of http client. After many tryouts, it seems apache http components is the go to library for general needs of http client.

http://hc.apache.org/

However if you are a spring user, then spring also provides facilities for http client requests.
http://docs.spring.io/spring/docs/3.0.x/api/org/springframework/http/client/package-summary.html

Having said that, the scope of this implementation is very limited. So my personal preference is apache http components over spring implementation, unless the requirement is very basic.


Tuesday, November 5, 2013

Integration with apache camel

Want to get your hands on apache camel ? Visit the following link. It guides you to creating a nice spring integration project. This is a tutorial with 2 posts.

http://vrtoonjava.wordpress.com/2013/10/20/apache-camel-developing-application-from-the-scratch-part-1-2/

Another detailed project tutorial could be found in the following link.
http://camel.apache.org/tutorial-example-reportincident.html

A spring integration example

Want to get your hands on a spring integration example ? Visit the following link. It guides you to creating a nice spring integration project. This is a tutorial with 2 posts.

http://vrtoonjava.wordpress.com/2013/03/03/spring-integration-developing-application-from-the-scratch-part-1-2/


Show heap status in eclipse

This is very easy.
Go to windows->preferences then under general tab, there is a checkbox to show/hide head status.

Monday, November 4, 2013

Reasons for error The matching wildcard is strict, but no declaration can be found for element

This error messages can be found for two reasons.

  1. If you use a trailing slash in the schema location or name space. eg: http://www.springframework.org/schema/beans/       remove the slash to recorrect it
  2. if you do not metion version in it. eg: http://www.springframework.org/schema/integration/spring-integration.xsd instead use http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.2.xsd
This way you can get rid of the above error in the spring xml files.

Apache commons Net

Apache commons net is a library for client side for many internet protocols. some of the main protocols supported are


  1. FTP
  2. SMTP/POP3
  3. IMAP
  4. TELNET
  5. WHOIS
  6. FINGER
An example on how to send an email through this library can be found in this post.

Sunday, November 3, 2013

What is your structure of a web project?

What is your structure of JEE based web projects? See the following link. It will give you some tips on how to organize your classes in packages and maintain view files.

http://www.javacodegeeks.com/2013/11/what-is-your-structure-of-jee-based-web-projects.html

Batch Processing best practices

I came across a nice and a clean article that describes about best practices on batch processing. Thought these could be very important at some point of your career. Visit the following link.

http://java.dzone.com/articles/batch-processing-best

Setting up your application server with maven

SOA coordination and service discovery with apache zookeeper

When you scale an application that operates as a service, you need to track the number of services, information about the web services you are offering , how many instances of the same web service etc...

Say for an example we have deployed many instances of the same service and they are distributed. Then a client wants to use the service and wants to use one instance to perform the request. Then you could use Apache zookeeper to auto discover all the instance and pick up one to get the result.

In simple terms what it does is coordination and service discovery. You could find a good simple example on how to do this using the following link.

http://www.javacodegeeks.com/2013/11/coordination-and-service-discovery-with-apache-zookeeper.html

A good explanation on this can be found using the following article.
http://zookeeper.apache.org/doc/trunk/zookeeperOver.html

Official site of the software is at
http://zookeeper.apache.org/

Hazzlecast

Hazzlecast enables you to write in memory applications. Imagine that you have an application that is clustered and each instance needs to know about data in other applications without using data bases. This scenario is addressed by hazzlecast. It provides java developers an easy-to-use and powerful solution for data distribution that can be used as a clustering solution, a distributed cache and a NoSQL key-value store.

A simple example on how to use this system is explained in the following link.

http://www.javacodegeeks.com/2013/11/getting-started-with-hazelcast.html

Java lambdas

Java lambdas is a powerful feature that comes with java 8. The idea is, this is an anonymous function( has no identifier) that can be passed as method parameters  (Bit like javascript functions that can be passed as arguments to a function).  These are also called first class functions. An article on explaining this concept can be found here.

http://java.dzone.com/articles/java-lambda-expressions-basics

Graph data bases

Have you heard about graphical representation of data. Recently I came across a technology called graph databases. The idea is to represent data and relationships in a graph. An example of an implementation of such data bases is neo4j. A simple explanation on this phenomenon is given on the following link.

http://player.vimeo.com/video/56040747#t=0m14s

Tuesday, October 29, 2013

Handling collections in java

Recently I was wondering about how java handles collections and the existing opensource java libraries to handle this scenario. Common alternatives to java collections framework are
  1. Apache commons
  2. Guava
  3. PCJ
  4. Trove
Number 1 and 2 alternatives are more popular among developers while 3 and 4 are not mentioned frequently (They are for primitives).  3 and 4 provide more performance compared to Java collections framework. Guava can be used in most cases while it seems like using this library is bit complex but at the same time it reduces many bottlenecks present in the collections operations.

Having mentioned all these libraries, one should also note that if your app does not demand handling complex collection operation, lots of data to be stored in a collection, java collections framework itself is more than adequate.

Below is a nice article that analyze the above topic in detail

http://stackoverflow.com/questions/629804/what-is-the-most-efficient-java-collections-library


Monday, October 21, 2013

java thread pool example

Do you have multiple jobs to execute using a pool of threads and need to know how to do it gracefully? See the link below to know how it can be done using executors and thread pool executors.

http://www.javacodegeeks.com//2013/01/java-thread-pool-example-using-executors-and-threadpoolexecutor.html

Thursday, August 29, 2013

Accessing session objects in spring mvc

Yes this is quite simple I know. But I came across a nice article that summarize on how to access session objects spring mvc. The below link explains various methods on how to access session object.

http://www.javaroots.com/2013/08/how-to-get-session-object-in-spring-mvc.html

Sunday, July 21, 2013

How to install a custom maven dependency to your local repository

This is very easy to do. Open a terminal and enter the following command.

mvn install:install-file -Dfile=c:\customBuiltjar-{version}.jar -DgroupId=your.jar.groupid  -DartifactId=customBuiltjar -Dversion={version} -Dpackaging=jar

Here the -Dfile parameter indicates the path to jar file. Also replace the -DgroupId with your group id for the dependency.

Thursday, July 4, 2013

maven compile error -maven compile annotations are not supported in source 1.3

This error occurs because maven by default uses jdk 1.3 for compiling. As you know java 1.3 does not support annotations. So in order to avoid this error you need to use a newer version of java. Maven provides a plugin to compile your code to a specific java version. Add the following in your pom.xml source code. Then it should do the trick.


                  <plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>

Tuesday, June 25, 2013

xml-rpc vs soap vs rest pros and cons

Ok well as in some of the posts I've done, I'm going to redirect you to a url that has described this topic in very nice simple but in a detail manner. Hats off to the person who wrote this article in a such cool yet very analytic manner. So checkout the below link.

http://maxivak.com/rest-vs-xml-rpc-vs-soap/

Thursday, June 20, 2013

How to stop some images loading from chache

In some cases we need to stop loading resources from cache. Say for an example, when we need to update a profile picture, we should not allow the cache to load the image again. So how are we going to do this. You can achieve this in two different ways.

  1. Add a parameter to the end of the url. Eg: http://your.site.com?random=98798987987 Important thing to notice here is you need to add a random variable in order to make the url different from the previous one
  2. The other method is to configure the headers in the request . But the downside of this approach is, You will need to set different headers parameters based on different browsers. eg. header("Pragma-directive: no-cache"); header("Cache-directive: no-cache"); header("Cache-control: no-cache"); header("Pragma: no-cache");  header("Expires: 0")

Tuesday, June 18, 2013

Spring properties place holder configurer example

Often we need to put configuration parameters independently to the code. Because you do not need to lookup the code in order to configure the system and it allows to maintain the system without much trouble.  In such cases it is good to keep a properties file. A good example of the usage of this is, configuration properties of a database.

Now this can be achieved in several methods. One is to use spring's PropertiesLoaderUtils class. Another is to use the spring properties place holder configurer.

Now lets see how you can achieve this using spring properties place holder configurer.

create a database.properties file in your classpath and put the following properties in it.

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/dbname
jdbc.username=root
jdbc.password=password


Then you need to declare the bean as following PropertyPlaceholderConfigurer

<beanclass="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="location">
    <value>database.properties</value>
  </property>
</bean>

Now you can access the values of the properties as following.

<bean id="dataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource">    <property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>

Now what you need to access these properties in your java code too.

then you can simply use @value annotation. something like @Value("${valueKey}")


Tuesday, June 4, 2013

What is a SIP server?

SIP stands for session initiation protocol. These servers are used for serving voice, audio and other communications over internet protocol. Network elements of  SIP server can be found in this link.

http://en.wikipedia.org/wiki/Session_Initiation_Protocol#Network_elements

big O complexities of common algorithms

The following link summarizes the complexities of common computer science algorithms stating weather they are good or not for specific tasks. This could be very useful.

http://bigocheatsheet.com/

RTMP

RTMP is a real time messaging protocol owned by macromedia. This protocol is used to stream video, audio and data over internet between a flash player and a server.  It uses 1935 port by default. Another variant of this protocol is RTMPT (real time messaging protocol with tunneling) and it is encapsulated within an http request to traverse firewalls.

Friday, May 24, 2013

how to store user uploaded files in a web app

Generally for simple apps you can use a hash as the file name and link the file using a database. Another approach would be to keep the file in the database. But that would mean the database would fill up quite quickly and it'll cause high usage of db as well. Then again another simple approach is to transfer it to a hosting service and then provide the URL in order to retrieve it. However there are things that needs to be addressed like the file size, number of files, load etc... Therefore the best way is to make sure that the method you implement, suits your requirements. I came across this nice article on how facebook provide the infrastructure to store photos. This provide some insight into how large scale services are organized in order to provide the fascility.

Monday, May 13, 2013

Signs of a good programmer

Now I've been working in the software industry for more than an year. Recently I decided to evaluate myself and see where I am as a developper. Then I found the qualities of a good programmer and a bad programmer. These are habits more than qualities. The first link describes the signs that you are a good developer. The latter describes the signs of a bad developer. God through both the articles and see where you are now as a programmer.


  1. https://sites.google.com/site/yacoset/Home/signs-that-you-re-a-bad-programmer
  2. https://sites.google.com/site/yacoset/Home/signs-that-you-re-a-good-programmer
Hope this will help you to improve as a developer.

Saturday, January 19, 2013

some simple vim commands

undo : u
redo : Ctrl+R
delete: d<number of lines to delete>d
copy : y<number of lines to copy>y
indent: <number of lines to indent>>>