Tuesday, March 16, 2010

Dive into Java

Recently a friend of mine asked me to help him develop a small web application to be run on a tomcat server. So that would mean I have to develop the application using Java, which I have not used ever since my student days. But because the requirements were pretty small, I took up the challenge just for the opportunity to learn something new.

The system was meant to capture the answers of a questionnaire and calculate the score they got. Then display back the past scores. It's pretty small involving just CRUD and a small amount of business logic to calculate the scores. Could probably be done in a bit over an hour if using tools I'm already familiar with like CakePHP or Django. But with Java, it was a completely different story.

My experience with CakePHP when developing MyMeeting made me quite reluctant to ever not use a framework ever again. Unless it's just a small trial program to understand a new language, it's better to use a framework. In the framework usually there is already quite a lot of thought put into how things should be organised and what's the best way to achieve our goals. So you get the benefit of quite a lot of wisdom without having to go through acquiring it. So that was the first thing I did. I googled for a 'java framework' and BOOM. Despair. There was tons of them. So many I had no idea what to choose. So I started to search for reviews and comparisons. You basically can't read about Java framework without struts being mentioned. Tapestry was pretty popular too. But they all seemed to have quite a high learning curve and you read a lot about the DREAD of configuring xml files and all. Finally I tumbled on wicket. Reading reviews and presentations about it got me pretty excited. And when I started developing I realised this framework is just for the UI. It made it pretty easy to do quite ajaxy stuff, but there's nothing about database connection and stuff. And there was no tutorial on how to get CRUD even. So after more googling I finally found Databinder. It is basically using Wicket as UI framework and either Hibernate, ActiveObjects or Cayenne for the database abstraction and interaction. Alhamdullillah. With plenty of examples to copy and paste from (hey, I didn't have a lot of time okeh.. :P) , I was finally able to get simple CRUD working.

Of course by then I met with a lot of the things which made programming in Java a pain. The dependencies, all the declaration, putting in setters and getters for almost every variable. UGH!!!! But in the examples they showed how to set up your project to easily work in Eclipse. And I followed it. And now I understand why Java developers swear by their Eclipse IDE. It's way freaking cool. I mean want to put in all the setters and getters for every variable even though you've got around 50 of them? Forget about typing it, how about just right clicking on the file and choose 'source->generate getters and setters' and it will all be done for you. How cool is that? What's it? You just copied from one file to another a bunch of lines which declared types you've got to import? No problem. Eclipse will automatically copy the imports too if it's already resolved. It's way seriously cool. If only it had vim keybinding.. :P

Anyhow. That took most of my weekends recently but it was very well worth it. I'm not 100% comfortable with it yet, but at least now I can do dev in Java. And if someone was to read my resume and ask me do I know Java I won't have to answer 'Well.. I did a few assignments with it when I was a student'... :P So now the only languages I'd really really like to have a serious go at it is ruby (probably with Rails) and Lisp. Maybe the opportunity would present itself in the future. In the mean time, I still got to polish my Java-fu.

Is Blogging No Longer a Thing?

As I embark on my new journey to learn the Rust programming language, I find myself pondering—where have all the blogs gone? In search of pr...