Thursday, August 6, 2009

Feelin' Groovy

For the last six months or so, I have been spending some quality time with Groovy. For those of you who may not already know, Groovy is awesome! Groovy is a programming language that is an extension of the Java Platform. It is a scripting language that is similar to Ruby. Groovy uses a lot of the standard Java syntax and since it compiles down to Java bytecode, it can be used in any Java project and can supplement any Java applications that you may be working on. Groovy has been around, in one form or another, since it was created by James Strachan in August of 2003. Since then it has become part of the java standard (JSR 241).

The JSR describes Groovy’s place in the Java world as:

Currently the Java community does not have a standard JCP-sanctioned agile programming language for writing scripts and applications that interoperate with the entire J2SE platform.

Groovy makes writing scripts and applications for the Java Virtual Machine fast and easy. Groovy includes language features found in Python, Ruby, and Smalltalk, but uses syntax natural to developers that use the Java programming language. Because Groovy is based on J2SE, applications written in Groovy can use the full complement of J2SE APIs, and work seamlessly with other packages and applications written in the Java programming language

Groovy is a dynamically typed language that is not compiled until runtime. It's this reason that many Java developers use Groovy to build prototypes of thier programs. This speeds up development and because Groovy is a part of the JVM, it can easily be translated into Java. You don't even have to translate the Groovy code. You could just utilize it as part of a Java project:

Now there is even a project called Groovy Runner that will let you run any Groovy file on an Apache server the same as you would PHP. This lets you avoid the Java Web server all together!

The downside thus far has been the difficulty rating in Eclipse. I love Eclipse but using the Groovy plug in is buggy at best. However, you can save a lot of time over the life of a project, by using Groovy. Just something as simple as adding two random numbers together takes 50% less work and lies of code:

Java Example:

import java.util.Random;


public class AdditionFlash{

public static void main (String args[]) {

Random rnd = new Random();
int[] numbers = {0,1,2,3,4,5,6,7,8,9};
int random1 = rnd.nextInt(numbers.length);
int random2 = rnd.nextInt(numbers.length);
int addNums = random1 + random2;

System.out.println(" " + random1);
System.out.println("+ " + random2);
System.out.println("_____");
System.out.print(" " + addNums);

}//end main
}//end class


Groovy Example:

import java.util.Random;

def list = [0,1,2,3,4,5,6,7,8,9]

random = new Random()
random1 = random.nextInt(list.size)
random2 = random.nextInt(list.size)
addNums = random1 + random2

println " " + random1
println "+ " + random2
println "_____"
println " " + addNums

As you can see most of the boilerplate code that is commonplace in Java is unnecessary with Groovy. If you want to save time on your next Java project, perhaps you should give Groovy a try! There are plenty of resources to help you get started with Groovy, such as Groovy Podcasts, Groovy Books, Groovy Zone, and Groovy Overflow.

Labels: , , , ,

Below is my New IGoogle Gadget, add it to your Home Page and keep up with all my latest Blog Posts!

Tuesday, July 21, 2009

Wave: Part Deux

The last few weeks have been very busy for me. I got my invitations to both Google Voice and Google Wave! I have definitely been feeling the Google Love lately. Since I have been given these lovely invites, I figured I would share the goodness with you. Today I am going to cover the Google Wave Developer Sandbox. I will cover Google Voice next week.

In case you may have noticed that the page loaded a little slowly today, it would be because I have embedded a Wave on my blog. Most of you will not be able to make any changes to the wave (unless you are part of the preview). This is to show you how Wave looks and what you can do with it.

As of this post, I have made a few simple bots that can manipulate a wave (same as any bot written in Java, except that they can only utilize the parts of the Wave that Google allows through their API). You can write bots, gadgets, or embed Waves in pages. You can choose to do any of these in either Java or Python. I have heard that developing for Wave in Python is easier, I am not really that comfortable with Python, so I chose Java.

Developing Wave bots and Gadgets is pretty easy in Java if you utilize Eclipse and their Google plug-in. Currently, you can only use bots that are created with the Google App Engine and that have an @appspot.com address. The Eclipse plug-in does most of the heavy lifting and all you have to worry about is the code.

The wave that is embedded on this page is the one that I started after I created a simple Gadget that reads the latest headlines from Slash Dot's RSS feed and displays them at the top of a Wave. This was made easier by using Google's Ajax Feed API and Wizard . Essentially, Google did most of the coding. After that, all I had to do was create the XML file and embed it in a Wave.

The Wave you see on the left has a problem loading all the way and this is due to the poll that was added later. Since it is still a developer only sandbox model, a lot of Wave's features are buggy and/or disabled. This has not made me enjoy the product any less. I have forgone sleep for a few days and spend most of my day thinking about what I can do next and how I am going to do it. I think that Wave is going to be an amazing product when it is released. I am glad to be a part of this development community! The people that are involved are terrific and have been generally nice and helpful (even when they make rick rolled bots and Swedish chef bots)!

*****UPDATE*****

The embedded Wave was no longer visable to those people who did not already have an account. So I removed it and I am now adding the below screenshot of the Wave with the Slashdot Gadget. Google has since added my Gadget to thier Samples Gallery Click on the screeenshots below:








Labels: , , , , ,

Below is my New IGoogle Gadget, add it to your Home Page and keep up with all my latest Blog Posts!

Thursday, June 11, 2009

Eclipse Galileo Review

The Eclipse Foundation is about to release their newest version of their IDE, nick-named Galileo. I should say first that I am a fan of Eclipse and that it is my IDE of choice for Java development. I have recently tried NetBeans again for some JavaFX coding and I was unsatisfied with the experience (not because it did not handle the code well, but because I did not like the UI and the code completion is nowhere as good as Eclipse). I decided to give the latest pre-release version of Eclipse a shot to see if it was able to handle JavaFX scripting as well as NetBeans.

To start, I went to their site http://www.eclipse.org/ and right on the front page was a link to the download for their latest version. The download only took a few minutes, I unzipped it and clicked on the executable (I am forced to use Windows at work). As a side note, this is one of the things that I love about Eclipse. You can unzip the IDE to a thumb drive and create your workspace on that thumb drive and be able to use your customized IDE anywhere! Upon opening, the first thing I noticed was that it looks exactly the same as the last version.


The UI is pretty standard fare for Eclipse and this is something else that I enjoyed about it. The fact that I could seamlessly transition to a new version without having to relearn everything is great. I quickly threw together this test program to check to see if it would compile and run correctly (what good is an IDE if it can’t do this):

public class Test{

public static void main(String[] args){

System.out.println("Hello, Galileo");

}

}

This of course yielded the expected results of:

Hello, Galileo

So far, so good. The next step would be to try to install some add-ons. Since this is one of the aspects that makes Eclipse such a great product. The amazing number of add-ons and the sheer size of the Eclipse community make it a terrific platform, so I should have no problems right? Wrong!

I had a bit of trouble figuring out how to install some new add-ons. It wasn’t impossible, but it was a bit misleading. I decided to do this from the perspective of a new user, so the first thing I did was go to “Help” on the main taskbar. Unfortunately the help documentation was not updated for the newest version (although I suspect that this will be fixed in the full release version). It asks the user to click on options that are no longer available in Galileo. There used to be an option labeled Software Updates under the Help menu; it has been changed to 2 different menu options

1) Check for Updates

2) Install new software

I clicked on the Install new software and I was at a new menu.

I tried to click on the “Available Software Sites” option that is highlighted and to my surprise I received the following error message:



I restarted Eclipse and decided to go about it in a different way. I went back to
the Help – Install new Software option and this time I entered the direct Web address for the
JavaFX plug-in. I waited for the install to finish, restarted Eclipse and JavaFX was available.

Now I was ready to start building my first JavaFX Project (at least the first one in Galileo). Galileo does make getting a JavaFX project started easier than Ganymede. In fact, for some reason Ganymede would not even recognize that I had the JavaFX SDK installed. In fact, I haven’t changed anything on my system as far as JavaFX is concerned since I last tried to use Eclipse.

I wrote a simple FX script to produce a small window with a picture of Duke (the Java mascot). It worked great and I had no problems getting it done. In fact I was able to write the same program much faster than I was in NetBeans!


I will not be saying goodbye to NetBeans in favor of Eclipse once again. I can not wait for the final release of Galileo. The one Noticeable change for Galileo was a massive increase in overall speed. It loads faster and compiles quicker than previous versions of Eclipse and that is the real reason why you should switch to Galileo!

Labels: , , ,

Below is my New IGoogle Gadget, add it to your Home Page and keep up with all my latest Blog Posts!