Thursday, April 8, 2010

Latitude/Longitude Converter Class Library

A few weeks ago I found an old photograph taken while we were doing a 4wd tour on the Mid North Coast of NSW. I wanted to scan and post this photo to the blog along with a Google Maps location.

The issue with this was I only had a rough idea where the photo was taken. During this 4wd tour we followed the directions in a printed book. This was 10 years ago and we did not have the use of a GPS to record our track. All I had to go on was the directions in the book. These directions made little sense trying to follow them on Google Maps as in many cases the tracks we followed are not named or marked in Google Maps.

However, the book did give GPS co-ordinates for key points on the tracks (major intersections or landmarks). I decided these could be used to provide a rough path followed and allow me to get my bearings while trying to follow the directions on Google Maps.

Once I tried to plot each of these points in Google Earth I realised it would be a slow process to import each of these points. An easier way would be to create a KML file of the points and load that into Google Earth. I had already written some code to produce a KML file of points from a CSV file so it was just a matter of loading the GPS co-ordinates into the CSV file and running the program.Unfortunately, KML files need GPS co-ordinates in Decimal Degrees and all my co-ordinates were in Degrees, Minutes and Seconds.

At this point I could have used any number of web based conversion pages to convert each co-ordinate manually. Instead, I decided to write a JAVA class library to convert co-ordinates between Degrees, Minutes and Seconds and Decimal Degrees.

The code was reasonably simple but as I had not been able to find an equivalent class on the net I decided that I would try to make it as versatile as possible with the aim to releasing it onto the web for anybody to use. It would also be a good learning exercise for me as I have created a Java class library previously.

After a weeks worth of coding I have now got the library to the point that I feel comfortable releasing a alpha version of the library to the net. There is a simple tutorial available and I am currently developing the Javadocs to go with the library.

Eventually, I will also post the source under an open source license to allow others to build or improve the library.

Monday, March 29, 2010

Crossing the Causeway

This photo was taken around 10 years ago during a four wheel drive trip. It is the view from a causeway on Tiri Road, Knorrit Flat NSW.

Sunday, March 7, 2010

Programming or Configuration?

A recent post over at the Reinvigorated Programmer highlighted an interesting point about the nature of the programming that many modern coders do. The post discusses the difference between creating an application from scratch and coding much of the functionality yourself or using frameworks and libraries to create much of the code.

As a VB5/6 programmer who has recently started coding in JAVA I have found that the choice of libraries available both in the standard class libraries and in third party libraries was very large and it is sometimes difficult to know if you are creating something from scratch that may already be available in the standard libraries. Every day I find myself searching the libraries to ensure I am not re-writing the wheel.


Another point the blog post touched on is the widespread use of frameworks in modern coding. These ready built code bases are used to simplify the coding of applications by hiding the underlying code and allowing the user to configure the system with very little actual programming.

Overall, the use of these frameworks is a good thing as they do minimize the production of a lot of code that is common from one application to the next. My biggest gripe with frameworks is that there are so many of them and more are being created every day. Especially in the Java world it is difficult to determine what is the best choice amongst the hundreds of frameworks. However, once selected it can be difficult to change frameworks without considerable work.

From a learning perspective the large number of libraries and frameworks can be daunting and given the communities willingness to create new libraries and frameworks on a rapid basis I guess I will be learning a new library or framework most of the time. 

Thursday, March 4, 2010

JAVA - Writing a StringBuffer to a File

During some recent development work I was using a StringBuffer to hold a large string (>400K characters). This string was built using a variety of methods based upon data being read in from a CSV file.

Once the StringBuffer had been created I was going to write the StringBuffer out to a file. This is where I had an issue. For some reason I thought that stringBuffer included a method to write the information to a file. It doesn't.

I then went looking for an easy way to write the contents of the StringBuffer to a text file. After looking at a few forum posts I managed to determine the simplest way to write the StringBuffer to the file.

StringBuffer output = new StringBuffer();
// Get the correct Line Separator for the OS (CRLF or LF)
String nl = System.getProperty("line.separator");
String filename = "output.txt";
output.append("Write First Line to StringBuffer");
output.append(nl);
output.append("Write Second Line to StringBuffer");

try {
  BufferedWriter out = new BufferedWriter(
                       new FileWriter(filename));
  String outText = output.toString();
  out.write(outText);
  out.close();
    }
catch (IOException e)
    {
    e.printStackTrace();
    }

The interesting parts of this code is the use of System.getProperties to get the correct line separator for the OS the code is running on and the use of the BufferedWriter in conjunction with a FileWriter to write the StringBuffer to the file.

Thursday, February 11, 2010

Google Buzz - Facebook Threat?

Earlier this week, Google started rolling out Google Buzz to all Gmail users. Google Buzz is an attempt by Google to provide a social networking facility within Gmail.

After enabling Google Buzz on my Gmail account I was presented with a new menu item in the left hand menu and a prompt to connect some of my other Google presences to my Google Buzz feed. These included Picasa Public albums, my two blogs and Google Reader. These links are used to automatically populate my Buzz stream (buzz) with items as they are published.

With these items now automatically populating my 'buzz' all I need now is for someone to read them. Unfortunately, my Gmail account is not my primary email account and is only really used for administering my Google presence. Further experimentation will have to wait until I find some friends who are using Google Buzz.

Google already has a number of social networking tools (Orkut, Google Wave). Where Google Buzz fits in with these other products is unknown. However, from my limited time using the product it is most like Facebook. You can post status updates, photos, videos and subscribe to friends posts. The difference is that it is also linked to your other Google products such as Blogger, Picasa and Reader and these products will automatically update your buzz when you post updates.

Interestingly, a group of former Google employees created something similar in 2007 called FriendFeed. FriendFeed is a social networking aggregator that was recently sold to Facebook. It has a advantage over Google Buzz in that it includes the ability to aggregate content from more than 50 services including Facebook and Twitter.

As you can see there is quite a lot of competition in the social networking world and from what I can see Google Buzz does not really offer any large advantage over the other sites such as Facebook, FriendFeed and Orkut. To really make a dent in any of these services they will need to expand the aggregation service and convince their Gmail subscribers that this is an alternative to Facebook.

Sunday, January 31, 2010

iPad - Who will buy this device?

For over a year, pundits on the internet have speculated that Apple was developing a touch screen tablet.

On Thursday, Steve Jobs confirmed these rumours when he announced the Apple iPad. The Apple iPad is a 9.7" touch screen tablet which runs an upgraded version of the iPhone software. 

My initial reaction when I saw the Apple  iPad was confusion. What functionality does this device offer over and above the Apple iPhone? And what market is Apple aiming this device at?

The issues I see with the device are:
  • It is too large to be a truly portable device. You cannot carry this in your pocket as you would an iPhone or other mobile device, however it has limited functionality compared to a netbook which is much the same size when closed.
  • It is not aimed at replacing the iPhone as it does not make calls. The 3G cellular connection is purely for data purposes. 
  • It is only possible to load Apple App Store applications onto the device. 
I wont be buying an iPad. I think that the size and limitations make it less capable than the iPhone. 

I wont be the only one not buying, many technology writers have expressed similar dissatisfaction with the iPad. It seems to be a product without a distinct market.

For further information:

CNET - Apple iPad: What you need to know.
SMH - iPad Review
SMH - 12 Features Apple iPad Lacks
SMH - Jury Out as iPad touches down

Monday, December 28, 2009

Google Wave Development - Robots in Netbeans 6.7

In this post I hope to describe how to create Google Wave robots in Netbeans 6.7. The instructions are adapted from a blog post on GAEJ Experiments regarding the use of the WADRobotFramework in Eclipse. Thanks to Romin Irani for the information on GAEJ Experiments and Jerome Baton for the WADRobotFramework.

This post assumes that you have a Google App Engine account and have Netbeans 6.7 setup to allow the deployment of Java applications to the Google App Engine. To deploy to GAE from Netbeans 6.7 you will need the GAE for NB Plugin. To check if it is setup correctly follow the tutorial here.

To begin with download the WADRobotFramework. It is a single JAR that should be copied to a directory on your machine. I used C:\Java_Utils\Wad. You will also need to download the Wave Robot Java Library from Google Code. I place all the files from this location into the directory c:\java_utils\waverobot.

Once we have all the files downloaded and copied to the correct directories I can create a new Web Project in Netbeans.

 

The project should be created with the name you want the robot to be names within Google Wave. I  have called mine CoxyDaveWaveRobot.




Ensure that Google App Engine has been selected as the Server.


Once the wizard has completed creating the project you can delete the index.jsp file as it is not required for the Wave Robot.

The next step is to add the required libraries to the project to allow us to use the WADRobotFramework and the Google Wave Robot Client.



Go to the Project Properties...Libraries panel and add each of the above libraries. Ensure that the Package checkbox is marked.

We can now start to build our Google Wave Robot. Create a new Java Class called MyAppenderRobot and once the wizard has completed add an import for org.wadael.waverobotfrmwrk.simple.BlipAppenderRobot and change the class declaration to extend BlipAppenderRobot. Netbeans will indicate that you need to 'Implement all Abstract Messages'. Use the wizard to implement the abstract methods. Replace the body of the getTextToAppend to the content shown.

public class MyAppenderRobot extends BlipAppenderRobot{

    @Override
    protected String getTextToAppend(String arg0) {
        return "I am replying to your blip!";
    }

Open the web.xml file and add the following servlet details:


        MyAppenderRobot
        coxydave.waverobot.MyAppenderRobot
    
    
        MyAppenderRobot
        /_wave/robot/jsonrpc
    

Add a new directory (_wave) to the WAR file as shown and add a new XML file called capabilities.xml




Add the following content to this file:


  
    
  
  1


Ensure the app-engine.xml file contains the following:


    coxydavewaverobot
    1


At this point you should create a Google App Engine Application with the same name as your project. This will allow Netbeans to automatically deploy the war file to this application.




Once the application has been created it should be possible to 'Build the Main project' and use the 'Deploy to
Google App Engine' on the context menu for the project.

Once the application has been deployed to the Google App Engine, my application  is accessible within Google Wave using the following email address: coxydavewaverobot@appspot.com. Yours will be the ApplicationID@appspot.com. To use the robot just add the address to a new or existing wave. The robot will say hello and then wait for someone to add a new blip. At this point it will return the message in a new reply blip.

Hopefully this was useful. If anything is unclear please leave a comment on the blog and I will respond accordingly. Thank you.