Feb 4 2006

RadRails is Gnarly

RadRails is the cross between the two things that I as a software engineer enjoy most, Eclipse IDE and Ruby on Rails. Unlike the Ruby Development Tool (RDT) plugin for Eclipse, RadRails is not a plugin but a whole integrated development environment for Ruby on Rails development using Eclipse. With RDT you can create Ruby projects and create new files with the rb extension to get Ruby context help and auto complete. RadRails is a little more complete allowing you can create a complete Rails project. You can create Rails controllers or models right from the RadRails; you can even start the web server! So what is the verdict? Well, on my OS X environment I still have not been able to create a controller from RadRails but think this is just a configuration problem. Aside from this, I think RadRails is a great IDE to get started with Ruby and/or Ruby on Rails development.


Feb 2 2006

Java Five-Oh #3: Variable Arguments

Variable arguments, or better known as varargs, where also introduced in Java 1.5. The neat thing about varargs is that you can construct a single method that will accept a varied number of arguments. When I am talking about varargs I an not talking about overloading, a single method will accept different number of parameters. Here is how you define a method that makes use of the new vararg feature:

public void print(String... args) {
   for(String s : args)
      out.println(s);
}

In the above sample code I declare vararg method by using the … notation in after the type in the parameter list. This method will accept zero or more string parameters. So the following method calls will be processed by the above function:

print("hello");
print("hello", "hola");

The thing to note is that the args parameter is just an array that is why I was able to use the for/in loop construct. I statically imported java.lang.System.out to make it available locally in the method implementation.


Jan 30 2006

Deauthorize iTunes

Just a friendly reminder. Developers are constantly reformatting their hard drives or upgrading to new bigger giga drives. If you are like me, you have a ton of tunes. If you are like me, you might forget to deauthorize you iTunes music from your computer before you reformat your drive. If you don’t deauthorize your music you will use up one of the five computers you can play your music on. To deauthorize your iTunes songs go to Advanced > Deauthorize Computer and click Ok to ‘Deauthorize Computer for Music Store Account.’


Jan 30 2006

Java Five-Oh #2: Static Import

Perhaps one of my favorite Java 1.5 features is the static imports. The way I have explained static import is that it makes available other class members and method as if they were defined locally. If that didn’t make much sense, let me demonstrate it with an example. The java.lang.Math class provides a ton of static helper methods. Each time you want to use the abs() method for example you have to do so as such:

int absolute = Math.abs(-7);

But with the new static import you can make available all of the methods in the Math class in your own class so you don’t have to write out Math every time you want to use the abs() method. So if you static import the Math class you can do this:

int absolute = abs(7);

To declare a static import for the Math class use the following construct:

import static java.lang.Math.*;

Jan 29 2006

jQuery Library

Yet another effects JavaScript library has been unleashed and this time it is named jQuery. Some code is based if not entirely inspired by moo.fx which in turn is base on prototype which in turn is base on work based on other work etc. JQuery is a light framework that you can get started with in less than 10 minutes. This is the sub-10 minutes tutorial. Lets get started.

The jQuery examples below I will be referring the the following HTML:

<HTML>
<BODY>
    <DIV style="border: 1px solid Green;">
        <A href="http://google.com/">Google</a>
    </DIV>
    <P id="mypara">this is one paragraph</p>
    <P>This is another paragraph</p>
</BODY>
</HTML>

jQuery supports XPath expressions and CSS 1-3, this means that you can get a jQuery object that represents one or more elements by a tag name, an element’s id or class, or by an XPath expression. To get a jQuery reference of an element use the dollar sign function as in the following code:

// Find element by it's id
var mypara = $("#mypara");
// Find elements by it tag name
var allpara = $("p");
// Fine element using XPath
$("a[@src='google.com']");

As the comments state, the mypara variable will hold one paragraph, the one whose id is mypara. The allpara variable will refer to all paragraphs in the document. Once you have jQuery object for one or more elements you can update its style. The following example will change the text color of all paragraph tags in my document.

$("p").css("color", "yellow");

If you want to update more than one style attribute at a time you can use the following code:

$("p").css( {color: "yellow", background: "green"} );

Now, if you are using some Ajax library you will most likely want to update more than just an element’s style, you may want to update an element’s inner HTML. To replace the inner HTML use the following code:

$("p").html("replace inner <b>HTML</b>");

Other useful methods that do just what there function name states are append(), prepend(), before(), and after(). jQuery also provides a hide(), show(), and toggle() method for special effects. jQuery is a new effects JavaScript library similar in spirit to moo.fx and Prototype. jQuery should be easy to pick up and start using in your next web 2.0 project as it simplifies what you already do.

I have already mentioned moo.fx in JavaScript FX.


Jan 28 2006

Java Five-Oh #1: For/In

Java 1.5, sometimes referred to as Java 5 or as I like to call it Java five-oooh, has been out for a while now and yet I recently got an email from a old college mate who emailed me immediately after he saw the new printf method in action in some sample code. So for my benefit, as well as his and maybe even yours, I am going to go break down over several entries some sample code detailing the new features in Java 1.5.

One Java 1.5 feature that I use most is probably the new foreach, for/in, statement. The new for/in construct is basically a new for loop that provides a shortcut for iterating over collections such as lists and arrays. The new for/in statement provides a shortcut for working with lists; you don’t have to declare iterators or integer indices. Here is the new foreach construct in action:

List l = ...
for(Object o : l) {
   System.out.println(o);
}

I’ve already written about generics in Java 1.5 and how to use the new for/in loop in conjunction with generics in Generic Java.