Wednesday, May 27, 2009

My ideal desktop recipe

Don't know about others, but i sure am confused by the vast ocean of frameworks and libraries available out there to help aid in java desktop applications.

This blog is not about frameworks and libraries that offer the best functionality and power, but those that do with a faster learning curve.

Typically, these are the pain points you'll encounter (sooner or later) in a large desktop application.

  • Validation
  • Binding Pojo's with GUI
  • Database Management
  • Cool and sleek GUI
  • Code complexity
  • Packaging and deployment
  • Creating Trialware's

1) Validation

I never paid much attention initially, but validation is one aspect that tends to get laborious. There are popular validation frameworks out there to help you with it. But as a beginner you'll want to learn it quick and easy. I'd prefer the Simple Validation Api by Tim Boudreau. Powerful and simple at the same time. Hardly takes 10 minutes to learn.


2) Binding POJO's with GUI

In my opinion there is no good tool for data binding, its currently unstable and there's no out of the box support for it. Its usually more pain than gain. But if u insist i suggest that you use the Netbeans IDE, it features mattise GUI builder with binding support. It'd be nice if JComponent binds POJO via annotations. In either case be on a look out, some one is probably developing it right now.


3) Database Management

Wouldn't it be nice if you didnt have to write all the plumbing code required to execute a database transaction and just concentrate on the task itself? ORM's typically sheild you from all the database junk. Hibernate will probably be the first result if u ever tried to google. It however has a lot of XML mapping stuff to be done.

In my opinion, ActiveObjects orm by Daniel Spiewak is the easiest to use, i.e., in case u dont have distributed databases to deal with. It conpletely sheilds you from database complexity. The only disadvantage is that u need to create POJO interfaces first to generate the database schema . If you already have a database then you must create the interfaces yourself (no generator tool for now). A great feature worth noting is that it has Database Migrations (useful for maintenance).


4) Cool and sleek GUI

Get substance look and feel by Kirill Grouchnikov is an excellent option to spice up you UI. All you have to do is add one line of code. If you're on MAC OS consider Quaqua lnf. Also check out SwingX, Flamingo, L2fProd, JGoodies for cool swing components.

If you have time to spare and want some extreme GUI with cool animation effects consider using Animated Transitions Api and Timing Framework by Romain Guy and Chet Haase. I also suggest that you read Filthy Rich clients by the same authors.

For a quickie, with almost no learning curve u should use substance look and feel with SwingX components along with mattise in NetbeansIDE.


5) Code Complexity

Be it a small or a large project, a GUI application soon gets out of the hand or you'll find yourself handling messy code or writing lots of plumbing code instead of putting effort into the business logic of the application. There's no point in reinventing the wheel, its always better to reuse a well tested framework instead of making one on your own.

For a small scale application its better to use to use your own MVC pattern to separate model, view and control. Major concerns in such application would be to maintain configuration. You'll probably use bean property change listeners...in this case consider using AbstractSerializableBean from swingX project to reduce the amount of boilerplate code for firing property change. It your application still gets out of hand consider using JIDE Application framework...havent really tried it, but looks good and has a moderate learning curve (2-3 days)

For a large application it is best of you use Netbeans Platform, its pretty complex and has a high learning curve, i would'nt recommend it unless you want to reuse netbeans features such as pallete, property sheets and editors etc...but on the bottom line its got great support and excellent documentation. Since its developed by sun, you can expect great support. Moreover NetbeansIDE has lots of code completion features for leveraging a netbeans platform based application.

If you have at least made 5-6 desktop applications and have good knowledge of OOPS, especially the use of interfaces and abstract classes (read this post for information on abstract classes) then you must consider using the Netbeans platform. Start by viewing these excellent screencasts.


6) Packaging and deployment

Consider an application based on java comm api. In such an app, you cant ask your client to copy and paste dll's at different locations, this should instead be done automatically at the deployment time, typically by distributing a setup file. To encash the benefits of cross platform nature of your java code, you'll need to use a cross platform deployer. Again, there are many of them, the easiest one to use and learn is by using PackJacket, a GUI frontend to the IzPack project. It also lets you create runtime scripts to execute custom tasks. whats more, the project is open sourced and is free to use.


7) Creating Trialwares

Depending on your marketing strategy, you might want to create trialware applications that expire after a certain time period.I recommend using TrueLicense library. Will take 1 day to get a hang of it.


Hope the above collection of tools and libs help you be more productive... Please let me know if you find better and easier tools.

Monday, January 12, 2009

Tyranny of autorun.inf

Irritated with the darn viruses...?
A friend of mine came up with this cool idea.

As u all might already know. Most of the viruses create an autorun.inf file (hidden obviously) in the drive. On double clicking the drive, the script is , triggering the virus (Trojans).

Here's the big idea, create a autorun.inf file (blank one) with read only and hidden attributes set. Paste this file in all your drives...even your pen drives. That way, even if a virus is present, it wont be able to create its own autorun.inf, as one already exists, i.e., with the read only permission.

Viola, the virus is as good as useless as it wont be triggered. This applies to most of them but not all.

Friday, January 2, 2009

Cool web pages...

Designing cool looking web pages is not a rocket science. Awesome effects can be acheived without javascript, flash etc etc...

Dont let these things deter you, best example is my friend vivek...with just 2-3 days of work he managed to make a gr8 web page (just needed to learn CSS). Take a look at his page.

Also he showed me some of the coolest web pages ever...very simple in concept and could have been implemented by YOU.

Check out Tyler's web page, this page takes time to load...let it load completely before clicking on any thing. This page was made using the '#' element...pretty cool nah!

Also there is a site called CSS beauty, it has a listing of all the cool web pages...hope this gives you enough inspiration to work on that innovate page of urs :)

Pic of the year...hehe

My stupid cousin naveen never misses opportunities to take ediotic pics of mine...not just mine but of every one else. This one was particularly funny...Believe it or not, that damn brown dog is just 5 months old (super big lol). Its gonna be like 90 kgs, but i still beat it in terms of weight :)

Wednesday, December 31, 2008

Awesome Header

Searching a university for MS was one heck of a journey. Frankly, it was deemag karab. Admist all that headache, i found this really good header from SUNY stony brook university. It's so good that i decided to put it up as my first blog entry...










Pretty good eh? Was refreshing to me!

Saturday, December 20, 2008

Pure Genius...

I accidentally came across a lecture on 'human computing' by Louis Von Ahn, a professor at Carnegie Mellon University. This is one of the best works i have seen. Pure genius and totally awesome...

Dont forget to check this out:
http://video.google.com/videoplay?docid=-8246463980976635143&hl=en

Monday, November 17, 2008

Why use object oriented programming…2

In my previous post, I’ve written how OOP resolves basic issues such as

• Functional Clutter
• Problem with Global Variables
• Unmanageable associations

Apart from these OOP has other powerful features, namely Inheritance and abstract classes. In this blog I’m going to discuss what these terms mean and why are they so useful.

We all know the common book definition of inheritance, but why is it so useful?
Basically inheritance is used when you have to

1) Modify the behavior of the object
2) Add additional features to the existing class

To modify the behavior all you gotta do is inherit the parent class into a new class called the base class and override the necessary methods. Take the example of JLabel in swing. The text in the label is rendered onto the screen by calling the paint method. Suppose you wanted to change the way border is shown, you have to override this method which is in turn called by swing framework to render the label.

To add additional features to the label, you have to inherit it into the base class and write additional methods for enabling new features. The base class now contains all the previous functionality that lets keeps it compatible with the existing framework.

Inheritance is essentially like copying and pasting all the code within the parent class into the base class. So why not copy and paste the code manually? I.e. copy code in class A to Class B instead of inheriting.

Just imagine what would happen if class A is modified later on as a result of bug fix or enhancement. You’ll have to re-copy all the code from class A to class B, thereby hampering the code manageability. Moreover inheritance lets you reuse the well designed and tested classes you’ve already made.

What’s more, inheritance also helps you debug the code. Suppose class A, B, C, D inherits class E. If there is a problem in classes A to D then it’s probable that the code in class A is buggy. If class A is buggy then it’s probable that the new code you’ve added is buggy. It may seem like a small thing but believe it or not, about 70% of development time is wasted in debugging and maintenance.

Abstract classes…Inherit benefits of Inheritance

Suppose there are a lot of things in common between the two classes (A and B), i.e. you notice some sort of code redundancy, but there are also many marked differences between them at the same time. Furthermore the redundant code cannot be grouped within a single class as it doesn’t make any sense. If you come across this kind of a situation, you could put all that redundant code in an abstract class (X) and make then create the other two by inheriting the abstract class. This kind of model is blessed with the benefits of inheritance. In short it Inherit benefits of Inheritance ?

Abstract classes don’t have an instance, i.e. it’s not possible to create an object without implementing the abstract methods. Simply make the class specific methods, the ones used by classes A and B as abstract. Sounds like Greek and Latin? Let’s consider an example.

Yesterday I was trying to make a class that can add the ‘trail period’ feature to any software. To do this I’ll have to –

1) Record the date when the software is first used.
2) Whenever the software is started, check the current date with the start date and evaluate the difference
3) If the difference is greater than say 30 days then prompt the user to enter the serial key.

To record the start date there can be two possibilities.

1) Save the data in an encrypted form within a file.
2) Save the data in an encrypted form within a database in case of a distributed application.

So you make two classes, DBValidator and NonDBValidator. Both of then contain redundant code…i.e. the logic that checks the date difference, a fraud detection system to see if the user tampers with the system date etc etc…The only point of change is the way in which the start date is persisted onto a storage medium.

In this scenario you could create an abstract class called validator with all the redundant code and make the persistDate method abstract.

Classes DBValidator and NonDNValidator inherit the validate class by implementing the abstract method persistDate, each one defining their own persistence logic.

Why go through this entire headache? Read the inheritance part again. This helps in centralizing the changes that may be required. You just have to make a change at a particular common place (the parent) and the necessary updates are forwarded to all the base classes.

Today’s software development standard is not about writing logical code, anyone can do that today. Instead more emphasis is laid on writing code that is better managed, even if you’ll have to compromise on the logic part. This is probably one the reasons as to why they look for people with work experience. Anyone involved in big projects would’ve certainly faced this problem before. This is also the reason why frameworks such as hibernate, JSF, struts are so popular in spite of the high learning curve involved.

Now that the basics of OOP is laid out, in my next post I’ll discuss about UML diagrams. I hope this article was useful.