Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Saturday, December 29, 2007

VarArgs in Java 5

Introduced in Tiger (Java 1.5.0), variable arguments enables Java methods to accept a variable (0..*) number of arguments thus allowing users greater flexibility in passing calling methods, previously dealt with using arrays.

The last parameter in the list is defined with a "type ... variable_name" syntax (note the ellipsis).

Example:
private static int sum(int ... numbers) {
  int accum = 0;
  for (int i=0; i<numbers.length; i++) {
    accum += numbers[i];
  }
  return accum;
}

Tuesday, December 25, 2007

NetBeans 6.0 bug

Although I'm a fan of NetBeans because it's a simple IDE that runs with limited memory too, I must admit that it is quite buggy. One of the features of NetBeans is that it locks the GUI code so you can't accidentally break the GUI builder. I've tried Borland's JBuilder and breaking the GUI builder with custom code was one of the problems I came across. However, when NetBeans breaks itself, I can't get into the code to change it, which is one of the complaints that I have with the IDE. I wish it had a "hack-the-code" option where I could at least change the variable names - all I did was delete a menubar and add a new menubar... when I went into code view, it still had the old menubar and used the old menubar for the frame - the new one was an unused variable!

Anyway, I guess it's back to Wordpad for me.

Wednesday, December 19, 2007

Sun Java on Fedora Core 8

There's been a successful install of Sun Java 1.6.0 on Fedora Core 8 with instructions posted at: http://vertito.blogspot.com/2007/11/sun-java-on-fedora-8-install-howto.html

I haven't been able to try it yet, but I'll do so soon.

Monday, December 17, 2007

Sun pushing for NetBeans

Sun is bringing it's IDEs to an end and would be helping it's customers move to NetBeans for development. It's actually a pretty good idea since most of the Java world is pretty much standardizing on either Eclipse or NetBeans. With more of the community shifting to Eclipse, the only reason NetBeans would remain alive is if there are sufficient users working with it.

Friday, November 2, 2007

Resource files in Java

Just as we have resource files when developing with .NET, Java can read from resource files located in a directory listed for the class path.

You can use one of the following two statements depending on the context from which you want to read the resource file:

[className].class.getClassLoader().getResourceAsStream
("filename"); //to call from a static context

this.getClass().getResourceAsStream("filename"); //to call from a non-static context

An AppSettings Equivalent

I've been looking for an equivalent of the AppSettings file in Java and came across the java.util.Properties class. I haven't tried it yet but I'm guessing I've got to explicitly specify the file from which I'm going to read the properties from and save the values to. It's good enough for me.

Friday, October 26, 2007

Java Application as a Windows Service

I was looking up some way to turn a Java application into a Windows service.

In Linux/Unix, it's much simpler since all you need to do is specify a command with all arguments, which in our case is the JVM executable java.exe with the class or Java archive name as a parameter.

In Windows, we would use a product like the Java Service Wrapper or the Java Service Launcher to launch the application whenever Windows starts up, without requiring the user to log in.
I haven't tried either of those products yet since I'm not currently into Java development, but when I do I'll post more about them here.