22 November 2010

Regex in Java

If you want to use regex in Java, keep in mind one note. The backslash is a skip character in regex. In Java you need to have two backslashes to define one. For example \” in regex means a “ character. While, in java you should be using \\”. Two backslashes will translate into one in Java and then translate as a skip character for regex. It gets even trickier when you want to use a backslash in your regex. You need to have four backslashes such as \\\\. They are going to be translated into \\ for the regex and then the regex will distinguish a backslash if it exists within the string you are parsing (since \\ is the backslash annotation for regex.)

If you need a really complete and useful source for regular expression, you can always trust oreilly publishing.


12 November 2010

OData and Range Values

OData is an open source protocol designed and developed by Microsoft to enhance the data access over Internet. It can somehow be compared with Gdata (+). The one thing that is missing in OData is the ability to process Range values. For examples, you want to ask for a range of Data beginning with AAC letters to AAZ letters. You need to create a batch job and send that batch job to the sever. The batch job could be something like AAC, AAD, AAE, AAF, … AAZ. This means that you need to have a separate part of your software interpreting the Range requests and transforming them into the Batch requests.
Some notes from their website:
The body of a Batch Request is made up of an ordered series of retrieve operations (as described in[OData:Operations]) and/or ChangeSets.


8 November 2010

Pair Programming in an Agile environment

Pair programming is an agile software development technique in which two programmers work together at one work station. One types in code while the other reviews each line of code as it is typed in. The person typing is called the driver. The person reviewing the code is called the observer (or navigator). The two programmers switch roles frequently.

This is the definition of Pair programming which I for a long time called it Peer programming. To me Peer programming make more sense. I think the pair programming is mainly beneficial in specific situations such as bug fixing and new hire orientations. They learn a lot while watching someone else working and the bug fixes can go smoother while people from the same background works on a bug.
Nice, there are even remote pair programming. Imagine you can program with someone else on a different location, how does that sound ? Don’t you like that ? how about distributed pair programming ?
Jeff Atwood, at coding horror, agrees that pair programming is one of the best ways to catch bugs vs. code reviews. In code reviews people usually don’t spend much time to get to know the code but only to accomplish a task assigned to them which is code reviewing. The code might never has to do anything with them, so why they should spend time reading it ?

Agile Unified Process

Agile Unified Process (AUP) is a simplified version of the IBM Rational Unified Process (RUP). It describes a simple, easy to understand approach to developing business application software using agile techniques and concepts yet still remaining true to the RUP. The AUP applies agile techniques including test driven development (TDD), Agile Modeling, agile change management, and database refactoring to improve productivity.

Enterprise Unified Process

The Enterprise Unified Process (EUP) is an extended variant of the Rational Unified Process and was developed by Scott W. Ambler and Larry Constantine in 2000, eventually reworked in 2005 by Ambler, John Nalbone and Michael Vizdos.
EUP was introduced to overcome some shortages of RUP, namely the lack of system support and eventual retirement of a software system. So two phases and several new disciplines were added to the RUP.


5 November 2010

Google App Engine–My first hands on code experience

Google has released a new app for developer this time, which is called google app engine. This app engine allows developers to develop apps on different languages and the deploy them on the Google app engine where everyone on internet can use them.

It gets even better when you realize that it is not only an app engine but you get a full dashboard that shows you how many IOs your app has been requesting, how much memory and how much CPU time it has been requesting. These are all then illustrated in a nice (flash yet) dashboard for you to have an idea about your application performance.

This is a 10 min video describing how to use the Google App Engine, only if you are using Python as your programming language. Couldn’t yet find a video tutorial for Java yet. It shouldn’t be that hard though.


The Chicken and The Pig in Software companies

There are several variants as to how the Chicken and the Pig meet and the level of the relationship between the two.
However, in every variant, the Chicken suggests that the two involve themselves in a scheme involving ham (or bacon) and eggs (some suggest a breakfast, others suggest a restaurant). In reply, the Pig always notes that, for the Chicken, only a contribution is required (as a chicken can simply lay an egg and then resume normal activities), while for the Pig a "total commitment" (or total sacrifice) is needed (as in order to make ham or bacon, the pig must be slaughtered).


What are you ? A Pig in your company ? Or a Chick ?

A Chicken and a Pig lived on a farm. The farmer was very good to them and they both wanted to do something good for him.
One day the chicken approached the pig and said, "I have a great idea for something we can do for the farmer! Would you like to help?"
The pig, quite intrigued by this, said, "of course! What is it that you propose?"
The chicken knew how much the farmer enjoyed a good healthy breakfast. He also knew how little time the farmer had to make a good breakfast. "I think the farmer would be very happy if we made him breakfast."
The pig thought about this. While not as close to the farmer, he too knew of the farmer's love for a good breakfast. "I'd be happy to help you make breakfast for the farmer! What do you suggest we make?"
The chicken, understanding that he had little else to offer suggested, "I could provide some eggs."
The pig knew the farmer might want more, "That's a fine start. What else should we make?"
The chicken looked around...scratched his head...then said, "ham? The farmer loves ham and eggs!"
The pig, very mindful of what this implied, said, "that's fine, but while you're making a contribution I'm making a real commitment!"

Chickens and Pigs

On Agile projects the term Pig has come to describe all the developers, designers and testers who commit to the actual work. The term Chicken is applied to everyone else who make intellectual contributions but do not commit to any work.

3 November 2010

JAXB annotations and how to use them as you wish

I need to use JAXB to create an XML output for a class. This output is generated when JAXB is being called through JETTY framework (i.e. the most probably Jersey is calling JAXB within the Jetty framework).
I have found that JAXB by itself is not creating the XML schemas. However, they are needed to be consumed by JAXB. XML schemas are essential for JAXB to function (i.e. I haven’t seen a tutorial that is based only on a Java Class; every tutorial is discussing how an XML schema is being created, after parsing a specific Class.)
I also have found that within JAXB, there is a part (package or class) called schemagen that is responsible for creating the XML schemas. I think this class should be used to generate the default XML schema and then use JAXB.
Note 1: It sounds like I need to create the Schema and then use the marshalling on the Class. The only thing remaining is the values of the elements in XML; I don’t want to marshal the class but the object of it.
Note 2 : The class is needed to be mapped to the XML schema so that the object can be marshallized.
Schemagen can be located at C:\Program Files\Java\jdk1.6.0_21\bin. It is an .exe file. Thus, it would not be easy to be used within a java program.
In here it has been said that:
The jaxb-xjc.jar file contains the SchemaGenTask.class file, which allows the schema generator to be invoked from the Ant build tool.
It seems that you need to have your packages annotated in order for JAXB to be able to create schema on that. This is writing from Alex Miler that describes this annotation. This and this is the annotation specification for packages in Java Documents. In these definitions you can not find various package annotation elements to be used, it simply defines what a package annotation is.
Annotations may be used on package declarations, with the restriction that at most one annotated package declaration is permitted for a given package.
One other possible way to use the JAXB is to have a file called jaxb.index in your class path. Not sure yet what that file is and how is working.
Problem solution found:
You need to have a class passed to the newInstance(), you can simply get the class you need to marshalize using the .getClass function.
JAXBContext jContext = JAXBContext.newInstance (this.getClass ());
  1. http://download.oracle.com/docs/cd/E17802_01/webservices/webservices/docs/2.0/jaxb/samples.html
  2. http://download.oracle.com/javase/6/docs/api/javax/xml/bind/JAXBContext.html
  3. http://download.oracle.com/javase/6/docs/api/javax/xml/bind/JAXBContext.html#newInstance(java.lang.Class...)
  4. http://java.sun.com/docs/books/jls/third_edition/html/packages.html#
  5. http://tech.puredanger.com/2007/02/28/package-annotations/
  6. http://blogs.sun.com/darcy/entry/javadoc_tip_prefer_package_info
  7. http://download.oracle.com/javase/6/docs/technotes/tools/solaris/javadoc.html#sourcefiles
  8. http://cmaki.blogspot.com/2007/09/annotated-jaxb-classes.html
  9. http://www.oracle.com/technetwork/articles/javase/index-140168.html#binsch
  10. http://download.oracle.com/javaee/5/tutorial/doc/bnazf.html
  11. http://download.oracle.com/javase/6/docs/technotes/tools/share/schemagen.html
  12. https://jaxb.dev.java.net/guide/
  13. https://jaxb.dev.java.net/tutorial/
  14. http://fisheye5.cenqua.com/browse/jaxb/dist/samples/samples-src/j2s-create-marshal
  15. http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.wsfep.multiplatform.doc/info/ae/ae/twbs_jaxbjava2schema.html