Posts

Running Eclipse on a machine without Java

2 min read

As “portable applications” are getting more and more popular, it is important to say that Eclipse has always been portable: just unzip it anywhere and run it. The real issue is not having Java Runtime Environment installed on the machine where you want to run Eclipse. Unfortunately, installing Java on Windows requires full administrator rights.

I decided to create my portable Eclipse distribution on an USB hard drive (a Western Digital Passport) instead of an USB pen drive. The latter would be impractically too slow to support applications that require  handling thousands of files.

OPL language: the battle of array declarations

4 min read

The OPL Development Studio, created by ILOG (and recently acquired by IBM), provides tools based on the Optimization Programming Language. This tool intends to simplify the process of feeding data and model formulae to other ILOG optimization tools for mathematical programming and constraint programming.

Experience has been proven OPL to be extremely helpful as a compact and high level language for both data and model. Nevertheless, this language still reveals some constructs that are not well understood nor well documented.

Criticism on SWT

4 min read

The Standard Widget Toolkit (SWT) is a graphical widget toolkit for the Java platform. It conceived as an alternative to the AWT or Swing toolkits provided by Sun Microsystems. It has the intent for better performance (to run faster and and to consume less memory), native look and feel and deep platform integration.

As there is already a lot of discussion about Swing and SWT on the web and I will not compare them again. I personally prefer SWT because I felt more productive with this toolkit. Nevertheless, I still did not yet feel productive enough to consider SWT valuable. Let me explain why.

Java and incorrect timezone on Windows XP

5 min read

How reliable is Java date, time and timezone API? In this article I discuss a relevant issue that may compromise application correctness when relying not only on date/time calculations, but also on reporting date/time according to local timezone and locale.

Recently I was debugging an activity scheduling application that was reporting events to weird time. Even worse, the weird time varied according to the desktop PC the application was running on. First, we assured that all date/time calculations were done correctly. Then, we double checked if Java reads the correct date/time from the system. Also, date, time and timezone configurations were set properly on the underlying platform. The odd behavior appeared on Java Virtual Machines from Sun, both JRE 1.5 and JRE. What was happening? We compared Java API results to Joda Time API.

Create a front page for WordPress that does not show up twice

2 min read

Note: I think this is not an issue anymore, since WordPress finally created the “menu” design feature. There is no need anymore to create front pages to show content as tabs at the top of the page. The “menu” feature works better than front pages.

Several people wonder how to configure WordPress to show ones own page when opening the blog (also called front page). There are instructions on wordpress support.

JFace table sorting

2 min read

Nowadays, when the application displays as a table, the modern user expects to click on the the column header to change the ordering criteria. Unfortunately, SWT/JFace API have not yet implemented this feature transparently. The programmer is required to write a bunch of code to implement this feature on each table.
For this purpose, I have written a single class that listens to table columns and applies ordering to the table viewer.

When Java code becomes funny

1 min read

Eventually, some fun happens while writing Java code.

Apache Commons: Error or Success?

An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. (see Java API docs). Does it make sense to call such subclass “Error“?

Found at org.apache.commons.configuration.plist.PropertyListParser

Two way names

Particularly, the Eclipse naming convention resulted this interesting symmetric method declaration.

protected void initialize(ColumnViewer viewer, ViewerColumn column)

Printing java logger configuration

2 min read

I have been wondering for some time how to print out a list with details how loggers were configured.
In order to work, one requires to create at least one logger instance of each logger that shall be listed.
I will provide further details in future.


public void print(PrintStream out) {
	out.println("Configuração de log: ");
	LogManager logManager = LogManager.getLogManager();
	Enumeration<String> loggerNames = logManager.getLoggerNames();
	Set<String> names = new TreeSet<String>();
	Set<Handler> handlerSet = new HashSet<Handler>();
	while (loggerNames.hasMoreElements()) {
		String name = loggerNames.nextElement();
		names.add(name);
	}
	for (String name : names) {
		Logger logger = logManager.getLogger(name);
		String nome = logger.getName();
		if (nome.length() == 0) nome = "<root>";
//		boolean inheritedLevel = false;
		Level level = logger.getLevel();
//		boolean inheritedHandler = false;
		Handler[] handlers = logger.getHandlers();

		Logger parentLevelLogger = null;
		if (level == null) {
			parentLevelLogger = logger.getParent();
			while (parentLevelLogger != null && level == null) {
				Level parentLevel = parentLevelLogger.getLevel();
				if (parentLevel != null) {
					level = parentLevel;
				} else {
					parentLevelLogger = parentLevelLogger.getParent();
				}
			}
		}
		Logger parentHandlerLogger = null;
		if (handlers == null) {
			parentHandlerLogger = logger.getParent();
			while (parentHandlerLogger != null && handlers == null) {
				Handler[] parentHandlers = parentHandlerLogger.getHandlers();
				if (parentHandlers != null) {
					handlers = parentHandlers;
				} else {
					parentHandlerLogger = parentHandlerLogger.getParent();
				}
			}
		}
		String nivel = "?";
		if (level != null) nivel = level.getName();
		if (parentLevelLogger != null) {
			if (parentLevelLogger.getName().length() == 0)
				nivel = "<root>:"+nivel;
			else
				nivel = parentLevelLogger.getName()+":"+nivel;
		}
		String lista = "?";
		if (handlers != null) {
			List<Handler> list = Arrays.asList(handlers);
			if (list.size() == 0) {
				lista = "";
			} else {
				lista = null;
				for (Handler handler : list) {
					if (lista == null) lista = handler.getClass().getName();
					else lista += ", " + handler.getClass().getSimpleName();
				}
			}
		}
		if (parentHandlerLogger != null) {
			if (parentHandlerLogger.getName().length() == 0)
				nivel = "<root>:"+lista;
			else
				nivel = parentHandlerLogger.getName()+":"+lista;
		}
		out.format(" - %s (%s): %s\n", nome, nivel, lista);
	}
	for (Handler handler : handlerSet) {
		String nome = handler.getClass().getSimpleName();
		String nivel = handler.getLevel().getName();
		out.format(" - %s (%s)\n", nome, nivel);
	}
}

Ubuntu 9.04: External and internal speaker issues

2 min read

If you run Ubuntu 9.04 and your desktop or laptop is featured with both internal speaker and TRS jacks for external speakers, then you might face some issues that sound is played on both. I have written some articles where I propose some very simple solutions and you may try them and choose the one you like most.

Of course, I discarded any inappropriate solutions that were proposed in several forums: editing mysterious configuration files,recompiling the kernel and unplugging the internal speaker from the motherboard.

Ubuntu 9.04: External and internal speaker issues – part 2

2 min read

If you run Ubuntu 9.04 and your desktop or laptop is featured with both internal speaker and TRS jacks for external speakers, then you might face some issues that sound is played on both. I have written some articles where I propose some very simple solutions and you may try them and choose the one you like most.

Issue 2: Connecting the headset does not turn off internal speaker.

Try to connect/remove a headset from the external jack and observe if your internal speaker becomes automatically muted. If not, then some more configuration is required.