Friday, February 13, 2009

JavaFX goes mobile

JavaFX is a Sun language to develop rich applications for the desktop. Their intent was to make GUI application development easier and more flexible. It never really enthusiam the Java community. I too was not convinced by it. There's already many solutions to develop desktop aplications, being Flex, probably, the toughest competitor. So, although JavaFX for the desktop is far from being a success, it could become one in another area.
Recently, Sun released a new version that brings JavaFX to the mobile phones. I think this are interesting news, because there's really a lot to improve in the mobile phone area. Java has a big percentage in the mobile world, with J2ME, but having a better tool for designing applications would be great. Although I don't have much experience with J2ME, the little experiments that I've made showed a restrictive and cumbersome SDK to work with.
I think this are good news for the developers. At least, I'm finally curious about trying JavaFX. As for the business itself, we have to wait. It also depends on the VM and more specifically on its performance. There's no point on having beautiful (or easily developed) but slow apps.

Technorati Tags: , ,

Friday, May 02, 2008

Parse command line arguments with Args4J

Args4J is a useful library to parse command line arguments, instead of doing it by hand. I'm very pleased with its simplicity, something I didn't find in others libraries.

Recently I've been working on some small console applications in Java. Like most of these applications, it's often needed to pass them some arguments at the console. For a while I parsed those arguments by hand. However, as soon as I had to do it for a large enough amount of arguments I started searching for a library to simplify things.
Jakarta Commons has all sort of useful libraries and Commons CLI is one of them. And for a while I used Commons CLI. But although the code became more organized I felt I had to write as much lines of code as before!
So after another search I found Args4J. This library makes use of annotations and has a much smaller API to use. It's not as flexible as Commons CLI, which allows you to parse different styles of arguments, etc. But I don't need that, I just wanted something to simplify the task. And args4j does simplify. Here's an example of how it works:

Imagine a sample application that tests some external system by sending a request to a specified machine. This application would need the following arguments: -h (the host of the external system) and -p (the port of the external system). This would translate to the following command in the console: "tester -h somemachine.com -p 9000".
The main class should look something like this:


public class Tester {

@Option(name="-h", usage="host of the external system", required=true)
private String host;

@Option(name="-p", usage="port of the external system")
private int port = 80;

public void setHost(String h){ this.host = h; }
public void setPort(int p){ this.port = p; }

public static void main(String[] args) {

Tester t = new Tester();
t.run(args);
}


public void run(String[] args) {

CmdLineParser parser = new CmdLineParser(this);
try {
parser.parseArgument(args);

//do whatever ...
System.out.println("Testing host " + host + " on port " + port);

} catch (CmdLineException e) {

System.err.println(e.getMessage());
System.err.println("\nTester [options...] arguments...");
parser.printUsage(System.err);
}
}
}

As you can see from the sample above, the clever usage of annotations in this case allows the definition and description of the parameters in a very simple way.
  • name is the argument name that should be typed in the console
  • usage is the description that is shown in case you don't type a valid set of arguments
  • required tells arg4j that the specified argument is mandatory (see documentation for more options).
Also, the API is quite small and does all the validation for you. In this case, the "host" parameter is required, so args4j will throw an exception if it's not supplied. And port parameter is automatically converted to "int". An error is also thrown if it can't convert it.
If validation succeeds, the values supplied will be bound to the corresponding fields in the class. Also notice that port is not required and has a value defined. This is basically a default value that will be replaced by the supplied argument, if it receives one.
So, with arg4j, all you have to do is annotate the fields, put the line of code that parses the arguments inside a try-catch block and safely use the fields. That's pretty cool.

Wednesday, March 26, 2008

Howto write an application for social networks

I've been seeing more and more applications for social networks (like Hi5). What I didn't realise was that it existed a standard API for developing those applications. OpenSocial is a reference API by Google that is being used by some of the major social networks (LinkedIn, Hi5, MySpace). It makes sense as it allows a developer to create an application or gadget that works in several social networks, or even allows communication between those.
And this explains the amount of new applications that are emerging every day. Still, it amazes me how a consensus was reached to allow this to happen. I thought only W3C had the power to do that. On the other hand, Google is becoming more "standard" than anything else...
On the technical side, the OpenSocial site seems quite good, with lots of documentation and sample applications. I didn't have the time to read the API itself, but being so well documented it's a great thing. It makes me think it must be easy to implement this kind of applications. It makes me wanna implement something :)
This also makes me wonder how many interesting Google projects are there that I still never heard of...

Friday, March 07, 2008

Exhibit 2.0 - Javascript web framework

I just discovered Exhibit and I'm amazed by its simplicity. Exhibit is a web framework written in Javascript that you can use to display data. It's not a general purpose framework. It's focused on displaying data in several formats, like interactive tables, maps, graphs, etc.
What I like about Exhibit is how simple it is to use. Everything is done in a simple HTML file! You heard me right, just HTML. The framework is done in Javascript, and it does all the data manipulation. You just have to add some special attributes to the HTML tags in order to specify how data is going to be shown. That's the presentation part of the framework. The data itself has to be in JSON format. Just add a link tag pointing at the js file with your data structure and you're all set. This is actually very flexible. In a simple case you can point to a static js file. But you can also point to an URL that dynamically generates your JSON data.
Exhibit then gives you a few presentation choices. One of them is trough Google Maps. This way you can create mash ups quite easily. Interactive tables that allow filtering and sorting also look nice.
Exhibit is part of SIMILE project, a joint effort conducted by the MIT Libraries and MIT CSAIL. So simple, but it can be quite useful...and pretty cool.

Thursday, March 06, 2008

Pyhton developers hired by Sun

This is interesting news:


Python’s future looks bright by ZDNet's Ed Burnette -- It always warms my heart to see good programmers get the recognition they deserve. This week, Sun announced they were hiring Ted Leung (long-time Python developer), and Frank Wierzbicki (lead implementer of the Jython project). They’ll be working full-time on Jython and in particular paying attention to developer tools. Ted and Frank join Charles Nutter, Thomas [...]


Although Jython is not new, this shows the current trend in Sun: to support as many languages as possible in the VM. It's nice to see that not all eggs are being put in the same basket (Ruby) and Python is also getting some attention. I specially like that because I prefer Python over Ruby. This also reminds me of putting Jython in my ToDo list of technologies to check out :)

Thursday, February 28, 2008

PDFEdit - Editing PDF in Linux

Did you ever had the need to alter a PDF file ? For me, it doesn't happen very often, but when it does I can only think of Acrobat Writer. I know I have also searched the Internet for some free tool, but it's not easy to find one. I've searched for "editing pdfs in Linux" before and come up with nothing but some technique involving saving each page to PostScript, then editing on an image editor, etc...
So it was with a bit of surprise that I found PDFEdit. It does its job well and has lots of features. At first glance seems like an application that would be very well known. But it's not the case, and it definitely deserves more spotlight. Check the screenshot below (taken from PDFEdit website):


You can add text, highlight sentences, add pictures, etc. Almost like any other text processing tool. Very cool.

Wednesday, February 27, 2008

Htop - Manage Your System Processes in Seconds

Almost everyday we use top to check which processes are using more cpu/memory. It's such a basic tool that I have never spend time searching for something better. Nevertheless, I never found top to be very intuitive or fast. The article Htop - Manage Your System Processes in Seconds
shows an excellent alternative. It starts much faster and it's much easier to use than top.
Just to show you an example: if you want to change the order in which processes are displayed, just press F6 and select with your up/down keys the criteria (cpu, memory, etc). Press Enter and voilá. Now try the same on top! Yes, you can do it with top almost as fast, but only if you can remember the weird shortcuts. If you use top ocasionally, then using htop is much simpler and intuitive.
Another example is killing a process: select the process with your up/down keys and press F9.
Just a note for the article author: very good blog, focused and to the point.