Wednesday, June 10, 2009

lookup third party service impl of an interface

If you have a jar file containing implementations of an interface that you want to be discovered by lookup...here's what you do:

1) Use library wrapper wizard in Netbeans to create a jar module wrapper.
2) Create a folder META-INF/services in the wrapper module.
3) Create a file in META-INF/services named after the fully qualified name of the interface containing the fully qualified names of the implementations (one per line)

That's it!
Third party service implementations to now be discovered by the global lookup on startup.

Saturday, June 6, 2009

Unnecessary object creation...

Most of you might already know about this. I just found this out while working on my open source project JNeuralNet.

I had this situation:


loop
{
Double d = someclass.compute();
}
When i ran the profiler. I noticed that the major portion of CPU was going into Double object creation. That's when i realized that its the classloader overload everytime the object is being created..so this is what i did:

//init variable...
Double d = 0.0;
loop
{
d = someclass.compute();
}
This simple optimization reduced a lot of CPU overload! Also if u have situations such as:

loop
{
Obj o = new Obj();
}
If feasible...try using:

Obj o = new Obj();
loop
{
//use o...
o.set(abc);
}
This approach is not always feasible...especially if you intend to use the reference of the object elsewhere, my point is, to reduce object creation wherever feasible.

Friday, June 5, 2009

My theory on time travel...

Already tortured people by giving this presentation back in my 8th semester...here goes:

I have two solid conclusions:
1) Its possible to view past.
2) Not possible to travel back in past or is a very bad idea!

1st assumption is an easy one to crack...you see this phenomenon every day (every night actually). Just look up at the sky...see the stars. What u actually see is the past. That star might have died by now...since it is 100's of light years away...what you're actually seeing is 100 light years backward.

As for the 2nd assumption...lets start with the hypothesis that it is possible to travel to past. Now imagine that you do something to trigger the death of your past self...It means that you never took the path that led you to travel back to the past, a direct contradiction.

so let us now suppose that its not possible to kill your past self. It might mean that your consciousness might merge with the past self and u forget everything about the future u came from...meaning that in future u again do the same time travel thingy., come back to past. Dude, you're now stuck in an indefinite loop.

Third option, according to string theory, every universe represents a possibility. suppose u travel in past and do something different it means that you have shifted the future timeline to a new parallel universe...meaning that u effectively destroyed the current universe and connected the future events to another one...destruction of a universe...certainly sounds like a bad idea!

Crazy comments are most welcome!!

My theory of good and bad

Pardon me for the language folks, but i think good and bad is BULL CRAP! Here's what i believe...

Some clever saint/person must have thought of this idea to keep things in control...so that the world doesn't go chaotic.

Just think of this for a moment...U say that a good thing is good because if gives u the internal satisfaction or whatever. You know what i think...i feel its because of the society/environment you're brought up in. Imagine a society where they'd preach that hurting some one is a good thing. In that case, hurting someone may give u that internal satisfaction...just like the way animals kill each other...no moral code whatsoever.

So in conclusion...there is no good and bad. Its human invented! Don't get the wrong idea, im not telling u to become bad or something. Its just my option...thought it was interesting and shared it!

Give...dont expect things back!

Expectation is your worst enemy. Always help...if possible go out of the way to help others. I believe in karma and have a belief that whatever u do comes back to you. Please don't expect things in return...I have seem many people getting hurt because of this. Just take the happiness as a return gift for the moment. In the worst of times, the favor will return by itself!

Afterall they're humans too!

Were there times when u get scared of your boss, faculty, giving presentations? Just remember this one thing, bottom line they're also humans...just like us. They have also made mistakes and must have been nervous at some point.

Just imagine yourself in their position. Would have just laughed it off wouldn't you? So just tell them whatever it is that you're so hesitant about. Want a pay raise...wouldn't agree with their ideas, SPEAK OUT! At the most what will happen? You may get fired or ridiculed at...but will always be happy that you did the RIGHT THING!...In the end its the satisfaction that matters.

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.