Apps  Contact  Seminars 

Archive for ‘programming’


August 20th, 2009

Awesome Layout – ParagraphLayout

by Amrinder

Java/Swing documentation and user guides talk a lot about how layouts should be used, but the fact is that Java Swing default layouts are not really that helpful in following those guidelines. To create simple UIs, I often need to create at least a few layouts, using usually a mixture of SpringLayout, BorderLayout and FlowLayout.

Luckily I just came across ParagraphLayout from JHLabs. In general, great article – good stuff guys!

Tags: ,


February 17th, 2009

Short cut if statement in PHP

by Amrinder

Surprisingly, I still come across quite a few “long cut if statements” of the following form:

if ($var1 == $var2) echo ” selected”;

It is of course much easier to say, and much easier to read:
echo ($var1 == $var2 ? ” selected” : “”);

Tags:


January 9th, 2009

Bashing the Singleton Pattern is the new in thing

by Amrinder

I have read so many blog posts recently that bash the singleton pattern, and from many many great programmers, that I am forced to believe that this is the new in thing! I mean those guys are great, and I look to them for inspiration! Here is one by Steve Yegge.

But, it seems, I am not going to be able to bash Singleton just yet. I read all of those patterns with an open mind, to see if there was something better out there. Instead, what I have found is that all the specific examples of what they are bashing (for example, the PrintSpooler!) are exactly the cases where in our code, we never use Singleton in the first place.

We use Singletons exclusively to cache reference data and properties that are loaded at application start up time. Those objects don’t change (except perhaps if system administrator uses the edit reference data functionality).

So, we use Singleton pattern, I still like it, and I agree with all the people who say not to overuse it.

Tags: ,


January 2nd, 2009

JBoss 5.0.0 GA – Do NOT upgrade just yet!!

by Amrinder

We have been using JBoss since JBoss 3.0 and have been key proponents of this product to the US Government as part of various projects. However, the JBoss 5.0, which has been touted as a complete rewrite, has been a complete failure from our perspective. The general release was on December 5, but despite repeated attempts, we have not been able to get a stable version out. As we dig deeper and deeper into the issues, we find that some of the compatibility issues have simple been “postponed”. It definitely feels like the JBoss team had a strict deadline that they wanted to meet even if some of the issues would not get solved. That kind of defeats the purpose of doing a full release.

Perhaps all this malaise that I am feeling is misplaced and will be replaced once a “real” release of JBoss happens, perhaps that will be JBoss5.0.2. But for now, I cannot advise anyone who is thinking of upgrading to giving it a real try.

So, in a nutshell: if you are running JBoss4x, this is not the time to move to JBoss5.0.0GA, wait a little while.

Let me also list a couple of concrete items:

  • Configuration XML files (ejb-jar, web.xml, etc) have a DTD reference on top. That causes a problem, as the JBoss5.0.0GA has a bug that causes that DTD reference to be treated as a local file reference.
  • The documentation is very scarce. For example, consider the supposedly “complete” copy of JBoss5.0 documentation available here: http://www.jboss.org/file-access/default/members/jbossas/freezone/docs/Installation_And_Getting_Started_Guide/5/html_single/index.html. It makes no mention of what “vfs” is, though that acronym is used dozens of times. I would play a positive role and tell everyone what it is, but I dont know what it is.
  • When looking through the logs, this exception appears: java.lang.NoClassDefFoundError: org/jboss/remoting/InvokerCallbackHandler. When searching through the lib folder, I do see this class in jboss-remoting.jar file, but in that jar file, it has the package: org.jboss.remoting.callback (not org.jboss.remoting).
  • Perhaps a significant part of the challenge is that as of January 2nd, 2009, google searches on all of these errors return almost no records. I am sure the situation would change in a few days/few weeks time as more workarounds are found.

Tags: ,


December 25th, 2008

XHTML

by Amrinder

It is Christmas morning, 6:40 AM, and I could perhaps be having a heart attack from laughter this very moment. I decided to do some long pending work, and that required me to teach a junior developer about XHTML. I thought – sure, I will just guide him to some reasonable resource on the web. Except, the first 3 pages of Google links that come up are pages that are immersed with advertisements with some sparse knowledge about XHTML. So, I thought I should create a page here:

XHTML stands for EXtensible HyperText Markup Language (If you are familiar with HTML 4.0, then really there are very minor differences, XHTML is essentially a stricter version of that, which is also in XML). So, basically, what this means is that XHTML is both HTML, and XML.

If you have been programming in HTML, then I only need to guide you to what you need to do different:

  1. Change case of your HTML tags to lower case. So, write <html> instead of <HTML>.
  2. Close your tags. In HTML, closing tags is sometimes optional. For example, if you start a bold (<b>) tag, but never close it, it automatically closes when the paragraph finishes. In XHTML, however, it is mandatory. So, your code should look like: <p><b>This is bold text</b></p>.
  3. Make sure that standalone tags like <BR> get closed too. In XML, empty tags are closed by putting a slash before the right angle bracket, so that becomes: <br/>
  4. Make sure your tags close in proper nested order. So, that means, you cannot write: <i><b>This is bold italic</i></b>. The correct way in XHTML of course would be to write: <i><b>This is bold italic</b></i>.

Really, that is most of it.

After changing your old HTML code to XHTML, you can validate your code by using the W3C validator service, available at: http://validator.w3.org/ Click on more options to specify that you would like to validate your code against XHTML specification.

“HAPPY END” to XHTML.

And btw, Merry Xmas!

Tags: , ,


Switch to our mobile site