Tuesday, April 04, 2006

Java from Scratch - part II

A few week back I posted about how long it was since I've built anything with java from scratch. What I want to do in the long run is to produce a DDD oriented projects with hibernate+spring. Bear in mind the last time I used java was with EJBs and JBuilder 8.

So after reading about the myriad of different options that are in the Java world I decided not to try to configure everything for myself and instead rely on a "template" project that would help me. I went with AppFuse to kick start the project since it comes with a mixture of framework decisions you can dream of, from hibernate, IBATIS, Spring and others to JSP, Tapestry and JSF for presentation with included security, transaction support and even AJAX..

So here are the dummy proof steps I followed:

Getting started: Java, Ant, Tomcat and MySQL

The first thing is to download and install the JDK 5.0 in your local computer. For windows there is a simple installer that you can get from Sun's Java site. Try and find something like "Download JDK 5.0 Update XX". After that you should add the JAVA_HOME environment to you system and JAVA_HOME\bin to your path. To do so in XP press Win + Brake, go to Advanced -> Environment Variables and add a new "System Variable" and enter JAVA_HOME and the directory of your java. In my case it looks like this: "C:\Program Files\java\jdk1.5.0_06". Afterwards, find the PATH variables and at add at the end a %JAVA_HOME%\bin entry.

Another thing to install is Tomcat and Ant which I will not get into to much detail. For Tomcat you have the option of a windows installer (I grabbed my 5.5 version here) and for ant you should simply download the latest binaries and uncompress them to the desired folder. After that you should repeat the same procedure as with the JAVA_HOME environment and PATH addition but with CATALINA_HOME and ANT_HOME, the former pointing the Tomcat home installation and latter to ant's.

Finally you need to download MySQL database. Although version 5 is available I downloaded version 4.1 since there seems to be more support so far. A good idea is to also download the Administrator and Query Browser.

Eclipse

Then we need a IDE for easier code writing, in this case eclipse. Eclipse is actually more than just an IDE, but a platform in itself. This is why you will not find a simple download for developing in Java. If you head to the download section you will see smacked in the middle of the screen the more "usual" download: the latest stable download for the eclipse SDK. This download includes the tools necessary to build plugins and expand eclipse, that since are written in Java, serves as an excellent Java IDE (actually the java tools are called Java development tools (JDT)).

Fortunate for me there was a new production release of what is known as the Web Tools Platform (WTP) a few weeks ago. This project aims helping the creation of J2EE and web projects and is bundled with several subproject and goodies that might prove useful in the future. So try and grab the latest version of the WTP and uncompress it to a folder and lunch eclipse.exe.

After you start eclipse, the first thing you should do is to set add the JDK as an installed JRE environment. For this, in eclipse, go to Windows -> Preferences. There, find the Java / Installed JRE entry in the left side tree and click on "Add". In the dialog presented enter any name you feel comfortable with (something like JDKJRE1.5.xx) and point to the same directory as the JAVA_HOME environment set earlier. Why eclipse is not smart enough to add this on its own? My guess is because it searches the Windows registry.

Most of the steps above are similar to what you can find here, but I found so much information on the page confusing for some reason.

AppFuse

As I said before, AppFuse is nice "template" project that help you get started on a new project. It uses Ant to its work, and what you end up having is a project with the name you assign to it in its own directory structure, ready to be built and deployed to a server. The standard tools AppFuse uses is ant and java, Tomcat as a web container and MySQL as its database. That is why with set up those things at the beginning. Also, the default architecture consists of hibernate+spring+struts with other assorted goodies. There are instructions at AppFuse wiki on how to configure these things differently but I haven't tried them yet. I’ll probably delve into this later since I want to use Tapestry instead of Struts.

Obviously the first thing to do is download the latest version and extract it to any directory. Then, with you command prompt pointing in the AppFuse directory type:

ant new

If you set everything alright it will be ask 1) the name of the application, 2) the database name and 3) the name of the packages. This will generate a directory with your project name that is ready to be built, tested and deployed.

Since AppFuse knows nothing about how do you wish to connect to your database you should supply these values by modifying build.properties file at the root of the new application directory. There, just unremark the lines with

database.admin.password=myrootpassword

After that, navigate to the new project directory and type

ant setup


This should build the DB, configure tomcat and deploy the resulting application. After this point you should be able to go to localhost:8080// and see a login page. Quite neat....

Since this blog entry is quite long so far, I will cut it here to return later and explore how AppFuse automates other development tasks and how to use Eclipse to edit the files.

Wednesday, March 29, 2006

Carnegie Mellon financing

The last couple of weeks have been kind of depressing. Getting admitted to CMU 's MSE and not being able to pay for the tuition was a real turn down. Thanks to the tremendous effort by my family, especially my parents and my sister I will probably going to be able to attend for the intensive 12-month course. The real problem was that since I'm an international student, securing a loan is very difficult, and in my home county there aren't any provisions for this sort of things. Fortunately, I have an uncle in the US that may be willing to lend a hand in case I need it.

While investigating for loans I found and interesting site called MyRichUnlce that lends money, but instead of repaying the loan the traditional way with a interest fee, you are bound to pay 1% of your salary for an X amount of time after graduation. Seems really interesting idea since these guys know that once you get your higher education your probably have better paying job opportunities.

The next step is to complete and submit the required forms, that include standard user forms and medical records and then wait for the I20 which will allow me to get my student Visa.

Sunday, March 19, 2006

Carnegie Mellon acceptance!!

Wow!! Today I received an acceptance letter from Carnegie Mellon Master in Software Engineering program. I'm ecstatic and really happy for the news. I remember taking the GRE 2 years ago in case I one day decided to got to a US school and also sending the application forms on december when I actually thought my chances where slim. I believe it was my work at my current company with CMM practices and belonging to the SEPG that helped. Anyways...it's going to be cool.

The only thing left now is to find financial support to go there since the Argentinean economic collapse 2 years ago has left the country (and my savings) with a devaluated 350%. A good salary development salary here is about U$S 18.000 a year. You do the math...So here I am analyzing my possibilities with a strong conviction to make it somehow (donations and loans accepted :) ).

And I haven't got into the difficulty that’s going to be surviving the program. I promise I'll keep posting how this process advances.

Friday, March 10, 2006

Web 2.0 rants

Hi couldn't help to marvel at what is going on with these new cool web 2.0 sites that are poping up everywhere. In only a year I realized I haven't almost installed any new rich client applications on my computer. I use Gmail to email and chats, Plaxo to have to store contacts and calendar events (but soon google will have a calendar too), bloglines for RSS, del.icio.us for bookmarks a of course blogger to blog about whatever is on my mind.

After the news spread about google buying writleyit seems we will not need office anymore. Google seems to be THE web company since they understand what the internet is all about. Anoter site that cought my atenttion today was thumbstacks, an online PowerPoint style program that looks promising.

I just can't wait to see what's next!

Tuesday, March 07, 2006

About DTO, ViewObjects and friends

A few weeks ago at the DDD forum a user (plind69) asked a question about how to send business objects to the presentation layer but have them show only a subset of data based on security settings. Needless to say, this is a much debated topic as witnessed by the large response and variety of opinions. Most solutions where based on the idea of DTOs, weather they are static or dynamic with proxies.

Users that had used DTO in a solution know how painful they can be: for starters DTOs are hard to maintain since every time a domain class changes so must the DTO (and also their assemblers/desassemblers). Then, there is this strange code-smell feelilng that you're duplicating code all over just for the presentation to use. To avoid this some suggest using dynamic DTOs (a nice dynamic DTO framework can be found here).

Although somewhat similar to dynamic DTO, some suggested using dynamic proxies to restrict the view. The solution looks promising for the particular issue of restrict certain fields, but I still believe that other issues should be accounted that are not possible to address with this particular implementation, like the fact that sometimes there are performance implications that make it undesirable to expose domain objects directly. Per example, imagine a fictional complicated purchase algorithm. If the result is calculated on the server, there is no need to send the actual value but a cached value. DTOs are perfect for the task since all its members are cached values. A DTO is basically only a cached set of data from the domain.

So, is there a solution? I don’t know J. First of all, let me tell you that I don't believe there is a silver bullet (at least not that I found) to solve this issues. I think that the mechanics of how to present domain classes to the user (or WS for that matter) should be considered on a use case-by-use case basis.

Maybe using a mix of adapter and proxy pattern could make life easier? A domain object could be proxified to return (or not according to security permissions) the information from the domain object itself, but if needed it could return a cached value. This could be similar to how you use a mock object but instead of creating all mock interfaces by default you pass in the actual domain object. So assuming you could do something like this:

VO viewObject = new VO(personRepository.ForId(1));
viewObject.cacheValue(“complexProperty”).returnValue(complexValue);
viewObject.restrictView(“restrictedProperty”).throwException(IllegalAccessException.Class);

In this way when you accessed regular properties or method, the information will be requested to the actual Person class; if you request a getComplexProperty you will be returned the cached value and if you request getRestrictedProperty you will get an IllegalAccessException. Also I don't think this approach is usuable in the case of Web Services (DTO seem more appropriate here).

So, what do you think? Is this practical or even possible? How do you feel about the different approaches?

Saturday, February 25, 2006

Location based communities

One of my latest interests has been mobile phone technologies. A few years back I remember looking down on these devices as limited and awkward computer wannabes. Today, the mobile phone market looks really promising and similar to the early years of the PC. The increasing use of the phone as a way to access the internet will bring about an improvement on how people use the web today.

Web 2.0, more about technology, is about giving the power to the users: user created content and photos uploaded and tagged are few examples of how people are creating and communities and sharing interests around particular issues. What is missing from most of the content today is location, some that can be improved by mobility.

In a couple of days I will attend a U2 concert in Buenos Aires. As in many concerts, the most ubiquitous device will be the mobile phone. With it people will take pictures, shoot short videos and eventually share it with others. Unfortunately these mountains of information will be location agnostic; they will lack the context of location that gives them meaning.

Imagine if I as soon as I upload the picture I'm automatically assigning it a geolocation based on my current position. A few weeks later I could search for other people that took a snapshot of Bono the same day and share live again the experience from a different angle. I could share my experience in my blog and have it linked to other blog users that where nearby the same day and added blog entries of their own. Creating a mashup with this information together with sites like GoogleMaps will be trivial as I already have the coordinates for the information that was uploaded. If you have used google local or even map quest you’ll realize the potential for queries in the vicinity of you current position as you surf.

Finally, locating a mobile phone will become more commonplace with the new 911E proposal that requires that a cell phone could be located in case of need with a mandatory GPS in each phone. The industry is also showing increasing support for location based services with API for geolocation using their network.

Let the location-based-web begin…(maybe Web 3.0 ??)

Friday, February 17, 2006

DDD Specification pattern

I just read a nice blog entry from Segio Bossa giving an example of the DDD Specification pattern. I wanted to keep his article in here so I could reference it in the future.

Following the specification discussion, in his book, Eric explores the Specification pattern more in depth and analyze the possibilities of doing composite Specifications. Then I remembered something I saw a while back on the Apache Commons project. The org.apache.commons.collections package (I wonder why is it there?) has a Predicate interface that fit's nicely with these concepts. Instead of a .isSatifiedBy() method you are given a evaluate(object) method.

I haven't really explored the idea in code by you could inherit a specifications interface and use the supplied AndPredicate, NotPredicate, etc to make composite Specifications.

Excelent!

Monday, February 13, 2006

Starting a J2EE project from scratch

As an architect I don't usually have the chance to sit down and write a lot of code. I spend most of my time just drawing models, solving client problems, helping with deployment and ensuring most developers are doing their job. I admit it, probably I'm not the best architect out there but I'm just starting.

My past 2 project were in .NET. When the projects begin I usually sit down and write some reference code myself and then let the developers continue. Lately I felt technology was getting by me since and I missed coding in Java. Wow how things have changed since Jbuilder 9!

I want to start a new project from scracth and know how I want the architecture to be based on my previous knowledge and reading countless forums and mails. I want the persistence to be based on hibernate, I need Spring for IoC and AOP for things like Transaction and logging. For the front end I'm still not sure. The application server is going to be JBoss since I need JMS and other goodies.

After much struggeling I realize what M$ has in it favor: it is stupidily easy to set up a project. I am overwhlmed by the amount of option and not sure how to even start this project in Eclipse. I even downloaded AppFuse in order help me jumpstart the project. I'll keep posting on how I advance as I go along.

Monday, February 06, 2006

POJO in Action Review

At last a nice and well written book summing up ideas from Domain-Driven-Design (DDD) and how to apply them to a real development project. I think the book's title is a bit misleading and should be called something like DDD in Action. This wat it could have been oriented to a wider audience (.NET developers)

As a software architect I found most of the book similar to previous projects I've tried to build since I read the DDD book. The advantage to have this book at our company is that when a new developer gets on my team I can point him straight to a book that is easy to read and understand.

Thank you Chris!

Friday, February 03, 2006

Cell vs Laptop debate reviewed

The other days I was reading this article that I read on MIT's Review newsletter. It discusses whether the cell phone or the $100 laptop will help developing nations breaking the "digital devide".

Living in a what is considered a developing nation (Argentina) I can see all around me the pervasivness of the cell phone in peoples lives, realying on it not only to speak, but also to chat in chatrooms and take picture and upload them in their personal fotoblog (Argentina and Brasil have one of the highest clients in www.fotolog.net). Thus I strongly believe that the cheap laptop is no contender to the cell phone.

But still, as in the past, the cell phone makers and more importantly the telco companies are blind to see the potential for their product. Their industry major concern is that these new technologies will eat into their fat voice business model.

It was not long ago that telcos where afraid to interconnect their SMS systems and exploit it in fearing that people will speak less on their phone. Once they did, they realize the inmense potential of this new market. In fact, in Argentina this milestone happened about 20 months ago and cell phone sales has skyrocketed since. No the telcos are crazy offering chat, ringtones and stuff...Now comes MMS: it is still too expensive to be useful and interconetion problem exists. And I haven't even touched the subject about data transfer that still is in it infancy and incredibly expensive because they are afraid that once you'll be able to install Skype on your phone the game's over.

And then there is the problem with the cell phone itself: incompatible OS and programming languages (Java vs. BREW vs Java Flavors..) that ressembles the PC industry in the 70's.

Unfortunately until this problems are not solved I don't think the cell phone stand a chance in becoming the next PC revolution.

Friday, April 22, 2005

Random Roni

Here goes my first blog entry:

hello world!!