Archive for the ‘Java’ Category

Calculating Combinations Using Java and Lots of Bits

Tuesday, October 21st, 2008

I was feeling nostalgic and went back to see how I calculated combinations in Erlang and combinations in Ruby. I wanted to see if there was a fun way to do it without resorting to recursion.

I started with my crazy hack to use bit strings to calculate combinations. I didn’t want to resort to creating bit strings, as I wanted to minimize the amount of work I needed to do. Therefore, I thought about simply using bitwise operators.

Below is my Java algorithm for creating calculations using iteration and bitwise operators to create all combinations from an array.

Thoughts?

public static void generate(String[] list) {
	int max = (int) Math.pow(list.length, 2)-1;
	System.out.println(max + " combinations");
	for (long i = 0; i < max; i++) {
		String[] combo = new String[Long.bitCount(i)];
		int comboPos = 0;
		for (int j = 0; j < list.length; j++) {
			if ((i & (1L< 0) {
				combo[comboPos++] = list[j];
			}
		}
		//System.out.println(Arrays.toString(combo));
	}
}

Update: handle up to 64 slots. Will need to move to something like BigInteger to handle greater than 64 bits I suppose. Wonder how that will affect performance?

QOTD

Monday, December 24th, 2007

Coding Horror: Size Is The Enemy

Java is like a variant of the game of Tetris in which none of the pieces can fill gaps created by the other pieces, so all you can do is pile them up endlessly.

Automatic Java Class Reloading

Thursday, October 11th, 2007

I just saw JavaRebel from ZeroTurnaround.com, which promises to “reload changes to Java classes on-the-fly without redeploy or restart including new methods and fields. It is a generic solution that works for standalone Java applications as well as application servers.”

This is the dream within a dream for Java development. One of the main reasons I moved to Ruby on Rails for web development is due to the much faster development cycle of Change then Test. Back in my Java days, it was Change, Compile, Wait 5 minutes to deploy, Bounce the server, then Test.

If JavaRebel can do what it says (and I haven’t tried it) then all you Java developers out there might suddenly get a lot more productive. If you’ve used this tool, drop me a comment.

Comparing Rubyists to Java-ists

Friday, May 25th, 2007

…Rubyists tend to function in evangelistic/defensive mode continuously compared to the Java tradition of intense self-criticism…

Found in In Relation To…

Bossam Rule/OWL Reasoner

Friday, March 3rd, 2006

Bossam Rule/OWL Reasoner is another Java based rule engine. It includes a set of rules for OWL reasoning, uses the RETE algorithm, and can be embedded in Java systems. It can reason with Java objects as well as simple facts. Bossam also supports SWRL.

Java.net App Hosting

Monday, January 30th, 2006

Hong Zhang’s Blog mentions that java.net is now hosting J2EE applications for free through LocalWeb. Here’s the quote that scares me:

> The actual deployment of an application is done by a small team of engineers from Sun.

Yikes. Even with all the deployment descriptors, it takes “a small team” to host and deploy a single J2EE application. There’s something wrong with that.

I’ve always said that deploying Java applications is Java’s Achilles Heel. The LAMP community mocks Java not necessarily because the language is more verbose, but because it’s so dang hard to deploy the applications. Compare with PHP, which is as easy as editing the file and then hitting reload in your browser. That’s nearly impossible with a full J2EE application. So many libraries have memory leaks that play havoc with classloaders that a full application server restart is required.

In any case, this is one of the main reasons I’ve been moving to Rails. I can deploy an application in no time (especially when using SwitchTower).

OWL Inference Engine in Jess

Tuesday, January 17th, 2006

OWL Inference Engine in Jess

> This page contains source code and instructions to load OWL ontologies and annotations into a JESS knowledge base

Spring 2.0 Auto View Name Generation

Friday, January 6th, 2006

Spring 2.0 will have support for autogenerating view names from a request. Rob Harrop has checked in this new strategy interface, reducing the amount of configuration required when writing Spring MVC applications.

/**
 * Strategy interface used to translate an incoming {@link javax.servlet.http.HttpServletRequest}
 * into a view name when no view name is supplied by the user.
 *
 * @author Rob Harrop
 * @since 2.0M2
 */
public interface RequestToViewNameTranslator {

	/**
	 * Translate the incoming {@link HttpServletRequest} into a view name.
	 * Cannot return null.
	 */
	String translate(HttpServletRequest request);
}

This is largely added in order to simplify working with Spring MVC.

Spring based Application Server

Sunday, January 1st, 2006

Abstract Horizon has released the Spring Application Server, which is:

> Spring Application Server is simple, highly configurable and light-weight application container based on Spring Framework. Server components are POJOs defined under the Spring Framework that is extended to provide support for services.

The interesting part is its use of Modules, a concept that Spring doesn’t quite have yet.

> The server is organised around Modules. Each module describes an unit that exists within a server’s boundaries. The modules are organised in a hierarcy of dependancies.

Rails Petstore

Monday, December 19th, 2005

The Rails Petstore is

> an implementation of Clinton Begin’s JPetstore that has been developed with the Rails web framework. The aim of this project is to develop a reference application that demonstrates the capabilities of the framework and the best practices that should be followed when developing an application.

This is for all you Java people out there who have seen the Petstore application in one form or another over the years. The Petstore is a common Java application implementation used to show how a framework is used “in the real world”. It’s been implemented many times, and comparing a Java Petstore to a Rails Petstore is very useful.