Ubuntu 10.04 & docking station part 2

As you might already know, I am using my Ubuntu laptop also with a docking station and external monitor. When I am in the office I dock it in leaving it closed and use only the external monitor (that is by the way a behaviour I can see at several customers also - having no fixed machine any more and dock in the closed notebook).

I had an issue I already described earlier - see part 1: Ubuntu 10.04 with docking station.

Since then I had several issues of having TV1 noticed by accident even when doing nothing or same with my internal laptop screen (LVDS1) when I am working with the external monitor only. The annoying things are three when this happens:
  • I can accidently move the mouse out of the window taking a while to bring it back.
  • In my compiz I have defined that right-clicking on the border of the screen switches to the next desktop. That does not work any more as the border is not reached when I move the moust to the border of the visible screen.
  • Windows may be displayed on the invisible part of the screen so I have them in the task bar but don't see them on screen.

Now I am pretty sure that it is the screensaver that is the culprit here. Disabling the screensaver never brought the issue back again. Only drawback: When I leave the machine I manually have to lock the screen pressing CTRL+ALT+L.

Same thing of second monitor accidently recognized happened in about 75 % when starting TeamViewer (which is my favorite remote assistence tool). Today I finally filed a bug and guess what - problem already solved (thanks to Daniel Stiefelmaier at TeamViewer support)!
Dear Martin,

I found a possible solution to that. Please open a console and run
WINEDEBUG=xrandr teamviewer&
Then take a look at the log:
cat ~/.teamviewer/6/winelog
You should see some xrandr lines. Then run
Create the key HKEY_CURRENT_USER\Software\Wine\X11 Driver
there, create a String "UseXRandR" and set its value to "N".
Close the registry, and repeat the other commands:
WINEDEBUG=xrandr teamviewer&
cat ~/.teamviewer/6/winelog
Now, there should be no xrandr lines.
Yeah, that did it!

Related posts: Ubuntu 10.04 with docking station (part 1), Ubuntu 10.04 experiences, OpenOffice and LibreOffice starts slow.


The community

In the last months I have been a participant in several communities, forums and the like. And I also have left some. I want to share some experiences:
  1. The community behind a software product (or any other thing) is a crucial factor for success of the product and motivation of the members.
  2. The spirit of the community is important. For the Ubuntu community (to give an example) there is the code of conduct to which most members admit to. It is the philosophy behind the group, a big picture that holds the people together.
  3. Nobody knows everything. With the contribution and help of each single community member the community gets smart.
  4. In good communities, members focus on the matter, not on blaming other persons or other products - their main target is to solve problems. Of course I like that. :-)
  5. In good communities it is easy to get involved and it is easy to be integrated (if you handle the members with respect).
  6. In good communities you are respected and your opinion is valued.
  7. There is a mass contribution effect in larger communities: While a company could hardly finance project teams with more than 30 or so members, in a big community there are many people adding value - even if it is a small contribution for each person, those contributions some up to enormous results.
There are two communities that I am proud to be in - the Ubuntu community and the Java community. I do not only participate in forum posts etc - I am also attending local events. Those events are usually very interesting from the technical point of view and also from the way community members deal with each other.

Don't forget, that no product and no system can be successful without the people behind it! - It's all about the people!

Related posts: The Open Source idea, The Open Source movement, Paying for free and Open Source, User lock down, Going Linux, The future of Java, Popular Ubuntu desktop myths.


The future of Java

The last months (after Oracle has completed the merger with Sun) were full of insecurity and discussions within the Java developer communities about the future of Java. Many have blogged about their fears. I personally followed the discussions but I felt, the best thing is to wait. People are so fast with their interpretations and guesses how others will behave.

In parallel there were discussions about Apple stopping support for Java on the Mac etc etc.

Even although Oracle already told they are strongly commited to Java, NetBeans and other famous Sun products, discussions were going on.

Finally a few further commitments have come to public:

IBM joins OpenJDK

Oracle and Apple Announce OpenJDK Project for Mac OS X

This means, that big players decided to go the Java and Open Source path. And it is important to unite the forces. Working together is far better than fighting each other.

When I decided to switch away from my Windows-only-development, one major reason was: There are many other operating systems gaining market share, like several flavors of Linux (Ubuntu, Mint, Redhat, Debian etc) and Apple - and I can't say for sure which ones will be there in the long run, but I want to provide security to my customers, that they can benefit from the software for a long time. - Java was a good choice in the past and now we can again be sure that it still is a good choice. The idea of Java - "write once, run everywhere" - has saved me from a lot of work in the past (compiling for different architectures not required, no building of different styled setup procedures etc). There are people mentioning that the write once, run anywhere phrase is not quite true, because not available for really all operating systems and often there have to be exceptions made for dealing with different operating systems. - Well, this is partly true, when it comes particular features, that might be even not available on all operating systems. Fortunately for such cases Java can be coupled with C(++). For availability: Java is available on more operating systems than most other languages (see http://www.java.com/en/download/manual.jsp).

BTW: C(++) is also a language, that is around and will be around for a long time and I hear nobody complaining that it is developing too slow for example. And I really prefer thinking carefully before putting new features into the language. There must be many things considered. It is important to do no harm to the language.

Oh, there is finally also an official podcast from Oracle for Java developers:
Of course this is biased and the Javaposse (http://javaposse.com/) is still the first address when it comes to Java podcasts.

We have exact plans for the next versions of Java:

And we get exactly what we need next for NetBeans (the first-class Java IDE):

Related posts: The dawn after sunset, The programming language, Popular Java myths, Java applications on the desktop, The community.


Self-Healing Linux

Until yesterday I only occassionally read about it, but yesterday I experienced my Ubuntu workstation self-healing from freeze.

I did not take care about how many applications were running and as doing a lot of things in parallel that all take quite a while (downloads in background, file copy operations and installations within virtual machines) I completely forgot about how many virtual machines were started. I was about to start another one when everything started to get really slow. I have 4 GB memory and a small swap partition (because during normal work I hardly get the memory of my Ubuntu full).

The memory at this time really got filled up completely and everything got veeery slow. I wasn't either able to switch windows. I was able to switch to the text console which also was very slow.

I wanted to login and kill a few tasks when I got messages broadcasted to my text console saying that the memory was exhausted. Shortly afterwards I got messages that the system identified Firefox and Thunderbird doing nothing and they were closed (maybe because just consuming memory at this moment). And finally it told that the last VirtualBox machine was consuming a lot of system resources and - was killed.

Flup, flup, everything was fine again. - And hadn't either time to do it manually. And it was doing exactly what I would have done manually - killing the last started virtual machine and closing the applications that were doing nothing (downloads were already finished).

That is simply awesome!


User lock down

In many big companies it is quite normal to lock down most features at the desktop that would allow the user to adjust settings and install software. Basically there are strong limitations for the user.

I can understand the reason, why this is done: To reduce security risks and to avoid users accidently change something that they don't know how to change back.

So the overall lock-down is a way to reduce required end-user support.

The other side of the medal is:
  • Every person is different and hence works in a different way. Hence the same configuration can't be the optimum for all users.
  • Depending on the position different additional tools might be interesting for different users boosting their productivity.
  • For the most users it is simply demotivating when they are locked down.
  • Users will find workarounds for many lock-downs (e.g. using http://portableapps.com/ on a memory stick).

Because of the disadvantages I want to point out alternative options:
  • Lock down only where and when necessary.
    Some users - especially the beginners - either prefer a lock down. Those are the users who have some fear in front of a computer to mess something completely up. Other users have detailed know-how on how what operations to avoid and how to prevent themselves from viruses as good as possible. You could introduce a point-system or simply lock down a users PC only when a particular support time per month is exceeded.
  • Set a time limit before pushing default configuration.
    In some companies when a user calls for IT support, there is a maximum time of 15 or 30 minutes to solve the problem - otherwise the user gets a new image (with default configuration). That way it is ensured that your staff does not loose plenty of hours to solve end-user problems.
  • Train the users.
    Train them security and other basics (who to distinguish executable files from data files, where to never confirm approvals in popups, don't running executable attachments from emails, how to properly install and remove software etc etc etc). The user who is aware of the risks cautious and prudent.
  • Migrate to Linux on the desktop.
    Linux is more secure and less prone to break down after several software installations, uninstallations or upgrades. Also backup of local settings is easier. And it is a proven fact that Linux users require less support - even if they are no geeks! Everybody I talk to, who gives Windows and Linux support, tell me that and this is matching my own experience.

Related posts: Your holy machine, Why Linux?, Going Linux, The community.


Locale configuration on Ubuntu

OK, first I was annoyed that changing the date format to ISO (yyyy-mm-dd) is not so easy on Ubuntu as it was on Windows. Yes, but - as usual in the Linux world - you are much more flexible on Ubuntu.

I am a special case: I want my menus and environment in english, I am located in Austria (so I want currency in Euro, thousands separator is dot and not comma, ...) but the date format I like to have in ISO format (and not the german default dd.mm.yyyy) because I find the ISO format simple the most practical (well, I am working in IT and the ISO format is the best to sort if you have just plain text). Under Windows I had a german OS (because I needed to support mostly users with german version) and changed the date format in the international settings.

Situation under Ubuntu is different: You install an english base system and install whatever languages you like through:
  1. "System - Administration - Language Support"
  2. Click "Install/Remove languages..."
  3. Choose the language(s) you want to support - every user can choose the language he/she likes at login (last used language is remembered as preselection).
  4. In the "Language for menus and windows" list you can drag and drop languages to specify priorities. The language the user chooses at login is taken first of course, but usually the language dragged to first place here is the default for new users. Attention: When installing a new language, it is usually put on top and somehow the system tries now logging in all existing users with that language (if they don't change it at login) - so doing changes here overwrites the last remembered language for the users. This behavior might be desired or not...
  5. In the text tab you can change the country you are in (this is similar to the Windows international settings - but you can't override parts of the country settings here.
So first, I found that I have less options than under Windows - until I discovered these options that you can set in your /etc/default/locale (a plain text file):
So you can really define the behavior of plenty of formattings!
The content of my etc/default/locale is now (LANG and LANGUAGE was set when I changed settings in the GUI, LC_DATE and LC_TIME I have added manually:

I have added LC_DATE myself (just a wild guess because it is not mentioned in the list above - which I found on the internet), for Thunderbird for example LC_TIME was sufficient.

Probably this obsoletes post "Firefox change default page format" (but did not check).

Related posts: Firefox change default page format, OpenOffice and LibreOffice starts slow, Default paper size in Open Office, Normal.dot in OpenOffice or LibreOffice.


    The Open Source idea

    As open source software gets more and more popular, when talking to other people or reading about open source, I often notice that people seem to get things (partly) wrong. So I want to clear up a few major missinterpretations:
    1. Open Source does not necessarily mean (completely) free (in the sense of money costs and legal permissions).
      There are a lot of writings about free as in beer or free as in freedom or things like that. I do not find that very clear.
      The point is:
      • Some software - when you buy it - comes along with the source code. Reason: Companies (especially since economic crisis or because of general fears) worry about their investment. What, if a company fails or goes up in flames? If the customer has the source code then there are at least two options if changes are needed: Have somebody in the company looking at the source code and implement the changes or hire somebody doing that work.

      • For some software the version that includes the source code is only very limited - either in functionality or from legal permissions.

      • And then of course there is real completely free and open source software that costs nothing and you can do with it what you want. The GPL and related licenses only have the limitation that derived work must be released under the same (or compatible license) - that way you get open source spread like a virus ;-) .

    2. How can a company survive from the financial point of view when giving software away for free?
      This is the most asked question when it comes to open source in business. Some companies give away base products away for free hoping to make business with AddOns and enhancement requests. This business model sometimes is successful. Unfortunately in many cases the base products are quite useless without the additional plugins/addons and developing those on their own is often not an option for companies.

      But what is completely forgotten by people asking this question: You would never accept to pay your plumber license fees each year for just having tubes in your walls. - You pay the plumber when there is work needed (repair, put additional tubes etc)! You also would never accept to pay your haircutter a license fee (even if your haircutter declares officially he/she will use the money to improve haircutting skills). You pay the haircutter when actually hair cutting is needed.

      The same should apply for software: Money for work.
      And the idea of free and open source software is that you pay for the planning and implementation work. Once that is done, the good thing with software is, that it can be copied around. Other than eating, haircutting etc software does not go rotten or fades away.

    3. Software as a service cannot be free in the long term.
      In the last years companies offering web services or web applications hosted by those have multiplied like rabbits. Most of them - at least initially - were free. Now I observe them becoming commercial one after the other. The point here is that for the customer using these services seems to be completely hassle free. Yes, no need to maintain server hardware (farms), watch and control server tasks to be up and running etc. - But that work is now outsourced to the provider of that web service. There are at least power costs and hardware that needs to be replaced (HDs, burnt motherboards etc) from time to time. There is actual maintenance work needed and that costs money. This is different from having software that does not need maintenance work by itself. Software maintenance work is usually only needed, when somebody else breaks major interfaces - which is maybe sometimes done even with the intention to create the need of maintenance work. However, this is not the idea of the open source movement. The idea of the open source movement is more to boost innovation. But: With big open source products there also comes big requirements of infrastructure and related services. For example: There are plenty of repository servers for the Linux kernel and all the software available. There is maintenance work required for all those. So how can that service be offered in the long term? Well, I assume, that many of those servers are maintained by people who see this as their contribution - instead of paying fees, they set up a server and contribute that way. Costs less that usual maintenance license fees - and nobody pays taxes for it. :-)

    Related posts: Paying for free and Open Source, The Open Source movement, The license keys, Why Linux?, Going Linux, The small software vendors, The community, Popular Ubuntu desktop myths.


    Install NetBeans on Ubuntu 10.04

    Why should one do a description of installing NetBeans on Ubuntu - it's in the repositories and just a few clicks?

    The reason is: Installing it through the repositories you will get problems later when trying to upgrade NetBeans with the builtin-update tool. Apart from this I prefer to download the full package from http://netbeans.org/downloads/index.html and deactivating the modules I do not need - at the moment. I always make sure that the sun (or now Oracle) JDK is installed (there were problems in the past with OpenJDK - and although they should be solved I still go with the Sun/Oracle one.

    • You can install the Sun/Oracle JDK through the repositories or do the manual install.
    • To make sure, the correct Java is used, install galternatives (then available through Applications-System Tools-Alternatives Configurator) and then go through each item in the list on the left. There are quite many Java related tools that - after installing the Sun/Oracle JDK now offer that one as second alternative. For all the Java related tools select the new alternative from Sun/Oracle JDK.
    • If you manually installed new JDKs - e.g. after an update has been released, you might have to change the symlink accordingly at /usr/lib/jvm/java-6-sun using the ln command, eg:
      cd /usr/lib/jvm
      sudo ln -s java-6-sun- java-6-sun

    So here are my steps for the NetBeans installation:
    1. I create a folder under opt for NetBeans:
      sudo mkdir /opt/netbeans
      I don't use the profile folder for installation because this reminds me too much of Windows. In the profile folder there should only go data and I backup this folder more often than other ones. It does not make sense backup the programs all the time.
    2. Then I set the permissions for the normal user:
      sudo chgrp theuser /opt/netbeans
      sudo chmod ug+rwx /opt/netbeans
      If you want to have more users work with NetBeans then replace theuser with a group that all the users are member of - however this solution is only if you trust those users regarding updating and activating plugins etc. Otherwise install as a user with sudo permissions and do not set the permissions above to prevent other users from updating.
    3. Then I install all NetBeans components (running the installer as normal user) in that folder (/opt/netbeans). There will be usually a subfolder for netbeans (including version in the folder name) and also for Tomcat and Glassfish.
    4. I also extract the javadoc downloaded from http://www.oracle.com/technetwork/java/javase/downloads/index.html into /opt/netbeans as jdk-6-docs or so. In former times I put it under the jdk folder but as I upgrade the JDK itself more often than the documentation this always needed additional work to move the doc to the new folder or change links when they got broken after deleting older javadoc.
    5. To make the javadoc available in NetBeans launch NetBeans and go to Tools-Java Platforms, switch to the javadoc tab and add the javadoc root folder - in my case /opt/netbeans/jdk-6-docs.
    6. When I add external libraries (Tools-Libraries) I also save/extract them previously to another folder - not within my profile (for reasons I mentioned earlier) - of course an option would be /opt/libs or so - I have a completely different separate folder for shared data and libraries that I backup from time to time (less often than profile data).
    Related posts: The IDE and the libraries, The programming language.


    Shell scripting your desktop windows

    In Java my limits are often what is offered in every OS - and what is inside the JVM.

    One thing, I often needed in the past under Windows is to get the title (or other information) of the active window. I was using Windows API to get the information needed. Under Linux/Ubuntu things are different - and more complicated due to different desktop environments, I thought. And how to access those APIs with Java?

    Well, it turned out, that I am completely wrong and once again was trapped in my old habits from Windows.

    Linux offers commandline tools - not only to get window information - no, also to manipulate windows, move them to different desktop etc. As I could start an application on a different machine and showing the window on my machine, I can either see the machine name in window lists. A commandline program can be easily used from within Java and output can be retrieved easily. Awesome!

    It again turns out, that Microsoft Windows is totally poor in commandline tools. However, I could implement a similar small exe that gets me the active window title through API on windows and does console output that can be retrieved by a Java application or can be used in batch files.

    If you are a Linux user, have a look at the following commands:
    • wmctrl
    • xprop
    • xwininfo
    All these tools can be used even from within shell scripts - awesome!

    With xprop -root you get exhaustive information about windows.
    Using xprop -root | grep _NET_ACTIVE_WINDOW\(WINDOW\) you get the active window handle. You can then use the address in wmctrl -l | grep theaddress. The only quirks is that in wmctrl the address might have an additional 0 after 0x so you should search for the part after 0x only in the output of wmctrl.


    Dynamic method invocation in Java 6

    I often read that people are waiting so much for dynamic method invocation promised for JDK 7 (which now is delayed - see Re-thinking JDK7).

    What I wonder is: I already use dynamic class loading and dynamic method invocation in Java 6. Of course, it was a little work, but once done the dynamic class loading and object creation is a one-liner and so is the call to a method:

    1:  /*  
    2:   * DynTool.java  
    3:   */  
    4:  package at.mwildam.common;  
    6:  import java.beans.Expression;  
    7:  import java.io.File;  
    8:  import java.lang.reflect.InvocationTargetException;  
    9:  import java.lang.reflect.Method;  
    10:  import java.net.MalformedURLException;  
    11:  import java.net.URL;  
    12:  import java.net.URLClassLoader;  
    13:  import java.util.Date;  
    14:  import java.util.logging.Level;  
    15:  import java.util.logging.Logger;  
    16:  import javax.tools.JavaCompiler;  
    19:  /**  
    20:   * Dynamic class loading and method invocation  
    21:   * By Martin Wildam (http://www.google.com/profiles/mwildam)  
    22:   * @author Martin Wildam  
    23:   */  
    24:  public class DynTool  
    25:  {  
    26:    /**  
    27:     * Tries to instanciate an object of the given class and returns a pointer to it.  
    28:     *   
    29:     * Expects the class files in the directory given by the  
    30:     * dynClassPath parameter. For each dot (.) in the class path there  
    31:     * must be given a subfolder. If there exists a .java file instead of  
    32:     * the expected .class file then the method tries to compile the .java file.  
    33:     * It tries also a compile if both the .java and the .class file exists but  
    34:     * the .class file is out of date (older than the .java file.  
    35:     * The addClassPath parameter is only used if the attempt to  
    36:     * compile is done.  
    37:     *   
    38:     * You can also specify a jar file in the dynClassPath parameter if  
    39:     * you have a fully compiled and prepared package.  
    40:     *  
    41:     * Returns null if the object could not be created.  
    42:     *   
    43:     * Sample: getPluginInstance("/Work/Java/TestGUI/dist/TestGUI.jar", "testgui.TestPluginClass", "/Work/Java/TestGUI/dist/lib")  
    44:     *   
    45:     * Note: Dynamic class loading and calls evaluated during runtime  
    46:     * using reflection is time consuming in general and therefore should be  
    47:     * avoided for performance citrical operations (although already better  
    48:     * since Java 5).  
    49:     *   
    50:     * We are returning null here in error case although not recommended  
    51:     * because I do agree with Joel Spolsky (http://www.joelonsoftware.com/) on  
    52:     * Exceptions at http://www.joelonsoftware.com/items/2003/10/13.html.  
    53:     *  
    54:     * @param  dynClassPath path to classes root dir where to search for the class to instantiate.  
    55:     *     Can also be a .jar file.  
    56:     * @param  className Full class name for the plugin class to use.  
    57:     * @param  addClassPath is an additional option for classpath to search (;-separated)  
    58:     *     which is only used when a compile attempt is done.  
    59:     * @return Object or null in error case.  
    60:     */  
    61:    public static Object getPluginInstance(String dynClassPath, String className, String addClassPath)  
    62:    {  
    63:      if (!dynClassPath.toLowerCase().endsWith(".jar"))  
    64:      {  
    65:        String classFile = className.replace(".", "/");  
    66:        classFile = dynClassPath + "/" + classFile;  
    67:        String javaFile = classFile;  
    68:        javaFile += ".java";  
    69:        classFile += ".class";  
    70:        if (addClassPath.length() != 0) addClassPath = ";" + addClassPath;  
    72:        if ((!existsFile(classFile) && existsFile(javaFile))  
    73:            || getFileDate(classFile).before(getFileDate(javaFile)))  
    74:        {  
    75:          JavaCompiler jc = javax.tools.ToolProvider.getSystemJavaCompiler();  
    76:          int r = jc.run(null, null, null, "-classpath", dynClassPath + addClassPath, "-d", dynClassPath, javaFile);  
    77:          if (r != 0) return null;  
    78:        }  
    79:      }  
    80:      else  
    81:        addFileToClassPath(dynClassPath);  
    83:      try  
    84:      {  
    85:        if (addClassPath != null && addClassPath.length() > 0)  
    86:          addFilesToClassPath(addClassPath);  
    87:        URL url = new URL(DynTool.getUrlFromPath(dynClassPath));  
    88:        URL[] clsList = new URL[1];  
    89:        clsList[0] = url;  
    90:        URLClassLoader ucl = new URLClassLoader(clsList);  
    91:        Class cls = ucl.loadClass(className);  
    92:        return cls.newInstance();  
    93:      }  
    94:      catch (NoClassDefFoundError ex)  
    95:      {  
    96:        Logger.getLogger(DynTool.class.getName()).log(Level.SEVERE, null, ex);  
    97:        return null;  
    98:      }  
    99:      catch (ClassNotFoundException ex)  
    100:      {  
    101:        Logger.getLogger(DynTool.class.getName()).log(Level.SEVERE, null, ex);  
    102:        return null;  
    103:      }  
    104:      catch (InstantiationException ex)  
    105:      {  
    106:        Logger.getLogger(DynTool.class.getName()).log(Level.SEVERE, null, ex);  
    107:        return null;  
    108:      }  
    109:      catch (IllegalAccessException ex)  
    110:      {  
    111:        Logger.getLogger(DynTool.class.getName()).log(Level.SEVERE, null, ex);  
    112:        return null;  
    113:      }  
    114:      catch (MalformedURLException ex)  
    115:      {  
    116:        Logger.getLogger(DynTool.class.getName()).log(Level.SEVERE, null, ex);  
    117:        return null;  
    118:      }  
    119:    }  
    122:    /**  
    123:     * Late binding method call on an already instantiated object.  
    124:     *   
    125:     * Invokes the requested method of a given object instance where the  
    126:     * object class is not specified at compile time.  
    127:     *   
    128:     * To call a method that does not have a parameter then pass null for the  
    129:     * params parameters.  
    130:     *   
    131:     * What the method returns is routed to the caller of this method as Object  
    132:     * so you have to cast the return type to something more specific if needed  
    133:     * or just use .tostring. If the called method is declared void then this  
    134:     * method returns null.  
    135:     *  
    136:     * Note: Dynamic class loading and calls evaluated during runtime  
    137:     * using reflection is time consuming in general and therefore should be  
    138:     * avoided for performance critical operations.  
    139:     *   
    140:     * We are returning null here in error case although not recommended (because  
    141:     * of the earlier mentioned reasons).  
    142:     *  
    143:     * @param  instance A not well known object for that we hope to be able to  
    144:     *     call the requested method.  
    145:     * @param  methodName Name of the method to be called  
    146:     * @param  params parameter objects to pass to the method (best matching declaration variant is searched)  
    147:     * @return Returned object or null if method is declared void or an error occurred.  
    148:     */  
    149:    public static Object call(Object instance, String methodName, Object... params)  
    150:    {  
    151:      //Statement stmt = new Statement(obj, methodName, null);  
    152:      //stmt.execute();  
    154:      Expression expr = new Expression(instance, methodName, params);  
    155:      //expr.execute(); //Not necessary, called automatically on getValue();  
    156:      Object result = null;  
    157:      try  
    158:      {  
    159:        result = expr.getValue();  
    160:      }  
    161:      catch (Exception ex)  
    162:      {  
    163:        Logger.getLogger(DynTool.class.getName()).log(Level.SEVERE, null, ex);  
    164:      }  
    165:      return result;  
    166:    }  
    169:    /**  
    170:     * Adds a resource given as URL to the classpath.  
    171:     *   
    172:     * Adds the given url to the classpath dynamically.  
    173:     *   
    174:     * From antony_miguel at  
    175:     * http://forums.sun.com/thread.jspa?threadID=300557&start=0&tstart=0:  
    176:     * "  
    177:     * I've seen a lot of forum posts about how to modify the  
    178:     * classpath at runtime and a lot of answers saying it can't be done.  
    179:     * I needed to add JDBC driver JARs at runtime so I figured out the  
    180:     * following method.  
    181:     *   
    182:     * The system classloader (ClassLoader.getSystemClassLoader()) is a subclass  
    183:     * of URLClassLoader. It can therefore be casted into a URLClassLoader and  
    184:     * used as one.  
    185:     *   
    186:     * URLClassLoader has a protected method addURL(URL url), which you can use  
    187:     * to add files, jars, web addresses - any valid URL in fact.  
    188:     *   
    189:     * Since the method is protected you need to use reflection to invoke it.  
    190:     * "  
    191:     *   
    192:     * The class path change does not reflect in the system property  
    193:     * "" because that property does not get modified any more after application  
    194:     * start. So don't check success by checking  
    195:     * System.getProperty("java.class.path");.  
    196:     *  
    197:     * @param  url Url to add to the class path.  
    198:     * @return True if operation was successful  
    199:     */  
    200:    public static boolean addUrlToClassPath(URL url)  
    201:    {  
    202:      if (url == null)  
    203:      {  
    204:        Logger.getLogger(DynTool.class.getName()).log(Level.WARNING, "Missing url to add to classpath.");  
    205:        return false;  
    206:      }  
    208:      boolean b = false;  
    210:      URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();  
    211:      Class sysclass = URLClassLoader.class;  
    212:      try  
    213:      {  
    215:        Class[] methodParams = new Class[1];  
    216:        methodParams[0] = URL.class;  
    217:        //There could be really different classes in the array.  
    218:        @SuppressWarnings("unchecked")  
    219:        Method method = sysclass.getDeclaredMethod("addURL", methodParams);  
    220:        method.setAccessible(true);  
    221:        method.invoke(sysloader, new Object[]  
    222:            {  
    223:              url  
    224:            });  
    225:        b = true;  
    226:      }  
    227:      catch (IllegalAccessException ex)  
    228:      {  
    229:        Logger.getLogger(DynTool.class.getName()).log(Level.WARNING, null, ex);  
    230:      }  
    231:      catch (IllegalArgumentException ex)  
    232:      {  
    233:        Logger.getLogger(DynTool.class.getName()).log(Level.WARNING, null, ex);  
    234:      }  
    235:      catch (InvocationTargetException ex)  
    236:      {  
    237:        Logger.getLogger(DynTool.class.getName()).log(Level.WARNING, null, ex);  
    238:      }  
    239:      catch (NoSuchMethodException ex)  
    240:      {  
    241:        Logger.getLogger(DynTool.class.getName()).log(Level.WARNING, null, ex);  
    242:      }  
    243:      catch (SecurityException ex)  
    244:      {  
    245:        Logger.getLogger(DynTool.class.getName()).log(Level.WARNING, null, ex);  
    246:      }  
    248:      return b;  
    249:    }  
    252:    /**  
    253:     * Converts a file path to an url link.  
    254:     *   
    255:     * Returns the url link equivalent to the given path as string.  
    256:     *  
    257:     * @param  path  
    258:     * @return Url string  
    259:     */  
    260:    public static String getUrlFromPath(String path)  
    261:    {  
    262:      try  
    263:      {  
    264:        return new File(path).toURI().toURL().toString();  
    265:      }  
    266:      catch (MalformedURLException ex)  
    267:      {  
    268:        return "";  
    269:      }  
    270:    }  
    273:    /**  
    274:     * Returns a boolean true if a "normal" file with the specified name exists.  
    275:     *   
    276:     * Note: Returns false for files that are part of the kernel system.  
    277:     * So it returns true only for "normal" files.  
    278:     *  
    279:     * @param  fileFullName FQPN of the file to be searched for  
    280:     * @return Boolean  
    281:     */  
    282:    public static Boolean existsFile(String fileFullName)  
    283:    {  
    284:      if (fileFullName == null)  
    285:        return false;  
    286:      else  
    287:      {  
    288:        File f = new File(fileFullName);  
    289:        return f.exists() && f.isFile();  
    290:      }  
    291:    }  
    294:    /**  
    295:     * Returns the timestamp of the file with the given name if exists otherwise 0.  
    296:     *   
    297:     * Returns a Date of 0 if the file could not be found otherwise the last  
    298:     * file modification date.  
    299:     *  
    300:     * @param  fileName Name of the file from which to read the date and timestamp  
    301:     * @return Date  
    302:     */  
    303:    public static Date getFileDate(String fileName)  
    304:    {  
    305:      if (!existsFile(fileName))  
    306:        return new Date(0);  
    307:      else  
    308:      {  
    309:        File f = new File(fileName);  
    310:        return new Date(f.lastModified());  
    311:      }  
    312:    }  
    315:    /**  
    316:     * Adds the given file dynamically to the class path.  
    317:     *   
    318:     * Further details see {@link #addUrlToClassPath(java.net.URL) }.  
    319:     *  
    320:     * @param  file File object to be added dynamically to the class path.  
    321:     * @return True if operation was successful.  
    322:     */  
    323:    public static boolean addFileToClassPath(File file)  
    324:    {  
    325:      if (file == null)  
    326:      {  
    327:        Logger.getLogger(DynTool.class.getName()).log(Level.WARNING, "Missing file to add to classpath.");  
    328:        return false;  
    329:      }  
    331:      URL url;  
    332:      try  
    333:      {  
    334:        url = file.toURI().toURL();  
    335:      }  
    336:      catch (MalformedURLException ex)  
    337:      {  
    338:        Logger.getLogger(DynTool.class.getName()).log(Level.WARNING, null, ex);  
    339:        return false;  
    340:      }  
    342:      return addUrlToClassPath(url);  
    343:    }  
    346:    /**  
    347:     * Adds the given file dynamically to the class path.  
    348:     *   
    349:     * Further details see {@link #addUrlToClassPath(java.net.URL) }.  
    350:     *  
    351:     * @param  fileName FQPN of the file object to be added dynamically to the class path.  
    352:     * @return True if operation was successful.  
    353:     */  
    354:    public static boolean addFileToClassPath(String fileName)  
    355:    {  
    356:      return addFileToClassPath(new File(fileName));  
    357:    }  
    360:    /**  
    361:     * Adds files in the given folder dynamically to the class path.  
    362:     *   
    363:     * You can specify multiple paths separating them by ";".  
    364:     * Further details see {@link #addUrlToClassPath(java.net.URL) }.  
    365:     * Path must contain only jars and class files (subfolders not included).  
    366:     *  
    367:     * @param  path FQPN of the path to be added dynamically to the class path  
    368:     *     or multiple paths separated by ";".  
    369:     * @return Number of jars and class files added.  
    370:     */  
    371:    public static int addFilesToClassPath(String path)  
    372:    {  
    373:      if (path == null || path.length() == 0) return 0;  
    374:      int n = 0;  
    376:      if (path.contains(";"))  
    377:      {  
    378:        String[] subPaths = path.split(";");  
    379:        for (String subPath : subPaths)  
    380:        {  
    381:          n = n + addFilesToClassPath(subPath);  
    382:        }  
    383:      }  
    384:      else  
    385:      {  
    386:        File dir = new File(path);  
    387:        File[] contents = dir.listFiles(); //Path Must contain jars and class files only  
    388:        for (int i = 0; i < contents.length; i++)  
    389:        {  
    390:          File file = contents[i];  
    391:          if (addFileToClassPath(file))  
    392:            n++;  
    393:        }  
    394:      }  
    395:      return n;  
    396:    }  
    398:  }  

    You might prefer looking at this code on pastebin.

    Sample usage:
    1. Object obj = getPluginInstance(yourJarFile, yourPluginClassName, additionalLibPath);
    2. Object result = call(obj, "pluginMethod", param1, ...);
      // For no parameters use at least null for param1
    I use this currently in two cases:
    • For loading plugins at runtime (in those cases I only need getPluginInstance because I cast the object to a known interface class).
    • To avoid fixed dependencies of common utility libraries (in those cases I only need the call method). What I mean with this? - To explain, a little example: I have a Swing utility class that runs through all elements of a JFrame or JDialog and returns a map with all widget names and values it can extract. This way, saving dialog inputs is a one-liner. However, I support a lot of different external widgets, most are not used in 80% of my projects, so I don't want to introduce the dependencies to all those external components not included in the Swing core. Using the dynamic call offers the support for those widgets when I find them in dialog contents (identified by class name) where they occur. And the appropriate dependencies are only needed in the particular projects where they are needed.
    So I don't really understand, why so many people are arguing against Java, that dynamic calls are not possible - where my sample code either automatically compiles a class that is given as .java instead of packed into a compiled .class or .jar file. And if I have both I check the class file if it is older and compile only in that case. So I would say, this is dynamic Java language!

    Related posts: Get reliable local IP address in Java, Popular Java myths.


    Use cases for netbooks

    For a long time I could not see a sense in netbooks. I am a developer and hence write a lot of code and a lot of documentation. The screen of a netbook seemed too small at all and keyboards too. But there are a few cases when it makes really sense to carry a netbook instead of a full notebook (that is heavier, and occupies more space on the table), for example:
    • When I sit in front of the TV with my family, for checking a little email or do a little web surfing, it is perfectly enough and I can put it aside easier simply because needs less space and if it has enough battery power, you either don't need the cable having around all the time even if it is kept in reach for a few hours.
    • I have a customer where employees walk around with mobile phones for entering data on the street. The data typing could be done more efficiently on a netbook than on a mobile phone if they sit in the car or have somehow something to put it down (wall, table, knee, ...).
    • Many IT admins need to be available quite all the time in case of emergencies. I have heard of some doing SSH over the mobile phone in such emergency cases when they are on the way - and they don't want to always carry a notebook with them. If you are a server admin only a mobile phone might be sufficient but I am doing also client support and it sounds just crazy to me doing end-user-support through the mobile phone. I am used to carry a small bag with me (to avoid having the wallet, keys and the like in different small pockets where they either could be stolen easier) which I also do recommend to others and with only a little bigger bag the netbook already fits in there.
    • There are a lot of branches where salesmen found it exaggerated to carry a notebook with them. However, looking up customer or product data through the phone is frickle work IMHO. A netbook fits there well I would say.
    • When I go to meetings outside the office (e.g. in hotels or restaurants) a netbook is more handy than a big notebook and in those cases I usually just need to take a few notes, do a little surfing or email.
    • Despite all the features that are put into smartphones these days, I hardly think, they will get a full features PC soon. PGP plugins for email, Password managers like keepassx, serious word processors and many other things I use on my normal notebook are missing. On a netbook I can use all these as usual - it's just the screen that is smaller (but still bigger than on every smart phone).
    • After ripping DVDs to disk a netbook can also be used as a mobile DVD player.
    Related posts: The Dell Latitude 2110 and Ubuntu 10.04.1, Ubuntu compatible hardware, The mobile device, The hardware.

    The Dell Latitude 2110 and Ubuntu 10.04.1

    Despite the rumors that Dell does not offer Ubuntu any more, I was able to get the Dell Latitude 2110 with Ubuntu (netbook remix) preinstalled - so (again) no Microsoft tax paid. ;-)

    I must admit, that they first did not want to give me the full featured thing (the optional Ubuntu version comes without webcam), but I insisted and got the thing with webcam and Ubuntu preinstalled. In reality they could have shipped without OS, the first thing anyway was putting the latest Ubuntu 10.04.1 LTS Lucid Lynx on it (because it came with 9.10 which worked out-of-the-box on delivery).

    Installation of 10.04.1 needed a few quirks: After I installed from an USB stick, I had to add the following additional repositories to get the WLAN to work:
    • deb file:///media/yourusbsticksname lucid main
    • deb file:///media/yourusbsticksname lucid restricted
    After that I could go to System->Administration->Hardware Drivers and searching it found the driver for the WLAN. I was fearing more trouble with the WLAN as this is quite usual (not only for Linux) in the netbook world to have troubles with the WLAN (as far as I have read in forums). But just adding the USB-stick as repository is not much trouble (although it took me a while to find out ;-) ).

    Webcam worked out-of-the-box (I was assuming to get problems with that because missing in the Ubuntu variant by default, but as working, I think there are just political reasons that they omit the web cam for the Ubuntu variant by default).

    Anyway, what did not work out-of-the-box was the built-in microphone: Again, I had to add another repository and install a single patch from there (see Bug #563215 and below):
    • ppa:ubuntu-audio-dev

    Then install this package:
    sudo apt-get install linux-alsa-driver-modules-$(uname -r)
    In addition to that I had to go into terminal window and run "alsamixer" - it shows more volume nobs that you might have known or guessed. I had to push up two from the input section. I guess Skype did that after installation as by default it sets the option allowing the program to manipulate audio settings (I already had this several times on other Ubuntu installations that Skype modified the mixer settings messing them up).

    Finally I had to plug in a headset just for a few seconds - then also the external microphone worked. Strangely it did not work until I plugged in the headset's mic in once. Since then it works. But I have to say that speakers and microphone are not top-level. The speakers could be louder and mic could be better also - so in noise environments (I have two little children around ;-) ) you should use a headset.

    My two mobile internet sticks work too - just not with autoconnect (it seems both try to connect - same happens on my main Lucid notebook also so guess it is a general issue introduced a short while ago - having configured just one works fine).

    The netbook feels very well made. The keyboard is big enough to be used without hassle and it feels robust (as usually for Dell Latitude keyboards). I have ordered the bigger battery which adds a little to weight and size of course. The bigger battery extends versus bottom so it makes the keyboard getting a slightly more diagonal position so now the netbook does not lie flat on the table. This way it is more ergonomic IMHO. Time estimated with fully charged battery pack is more than 6 hours. The only thing: It was harder to find a matching case with the extended battery. The normal small bags for 10,1" notebooks were fitting only very tight which was a hassle. Finally I bought a larger bag where now also fit more other things.

    Related posts: Ubuntu compatible hardware, About Dell, The hardware, The mobile device, Going Linux, The sad thing about Linux..., Use cases for netbooks.

      Ubuntu compatible hardware

      In the last months I faced several different hardware environments and experienced several issues when installing Ubuntu. For example: Since 2005 I always recommended NVidia and told people to better stay away from ATI. But lately I had problems with a machine with NVidia and on the other hand heard from a friend about an Ubuntu machine with ATI running flawlessly. So I started to fear for issues no matter what hardware I recommend.

      I talked with several people and sent out emails and the result is a collection of links that help a lot. First of all - what I did not know - there is an Ubuntu certification for hardware - and there is more:

      And more hardware help is available here:
      Related posts: The hardware, Why Linux?, Going Linux, The sad thing about Linux, About Dell, Ubuntu 10.04 experiences, The Dell Latitude 2110 and Ubuntu 10.04.1, Use cases for netbooks, The truth about hardware support.


      User-friendly Mac OS

      Many people tell that Mac OS is the mos user friendly operating system. Here extraction from a user manual of an external USB hard drive for Mac Users:

      How to remove the drive - for Mac OS Users:
      1. If you have files located on your drive open in any applications, close them.
      2. Locate the icon for your drive on the desktop, and drag it to the trash.
      I am not a Mac user, but I never ever would have done that for removing the drive! Dragging something to the trash for me means "Delete it - delete the contents"!

      What if I accidently would have dragged selected files from the drive to the trash and not the drive itself. Do you call this user-friendly?

      Related post: Why Linux?


      Pros and cons of cloud solutions

      Whenever a new (IT) hype is getting attention, I am careful with jumping on the train. Often it is just old stuff in new clothes and often big disadvantages are involved doing things in a completely new way. What also always happens in such a hype case is that first definitions are refined and cleared up, but later on everybody claims to offer products that match the hype (yes, when DMS (Document Management Systems) were the hype, printer manufacturers claimed doing DMS - and they were somehow right ;-) ). For a description of what "the cloud" is, look up "Cloud computing" at Wikipedia.

      I am using "cloud" solutions (or let's say web applications offered by external service providers) myself. I tested and tried many, when they are still free but nowadays the providers start to charge for those. I still use several Google services (Google search, GMail, Google Calender, Google Reader and Blogger of course), mite (not free any more for new users), Vyew (occasionally) and some social networking sites (XING, Facebook, LinkedIn). I have dumped many others because of several reasons.

      The pros of cloud based solutions:
      1. The application and data is available from everywhere (every machine you are using).
        Well, if you have a home network plus fix IP address (or using DynDNS or similar service), but:
      2. You don't need to do maintenance work (apply security updates, ensure power-supply, repair broken hardware etc).
        OK, you can rent a server (space) somewhere with different levels of maintenance work to be done by you.
      3. The applications scale well (usually those services run on infrastructure that allows scaling).
        OK, if only you are using the application (and maybe some family members and friends) you might not need any scaling, but if you are a company (maybe a startup that expects or hopes for fast growing) this might be a real advantage.
      4. Costs
        If you or your company is quite big and/or using a lot of software there might be several servers required and maintaining a smaller or larger server farm can be costly (just think of ensuring power supply and keeping spare parts of used hardware pieces like hard disks and so on). Cloud service providers are specialized on providing computing power and with the mass they can do it cheaper. I think this is the real driver for the rise of cloud based solutions (what a finding, that most things are driven by money...). Especially when you have only peek times where increased computing power is needed (e.g. some batch jobs running at night), it might be costly to have many servers up-and-running doing nothing most of the time.

      The cons of cloud based solutions:
      1. Privacy
        You do not know what the service provider is doing with your data. At best I would think they are only running some statistics to see where you make your business, what are customers buying from you (in the meaning of what products and services are going best) and so on. I think that depending on the service you are using there are usually some interesting statistics to be made that could be sold for money to consulting companies. If the service provider is not trustworthy, I could even imagine that they could sell more detailed data.
      2. Influence
        This disadvantage does not (fully) apply if you are using services like Google app engine or EC2 because there you have more influence on what you are running (more or less your application or entire virtual machine that is just running on their hardware). Using an in-house solution you usually have more influence on the system configuration and the software, you are using. I have instances of phpBB, Wordpress, vTiger and others running. You can apply plugins as you like and have access to the source code (to apply fixes or some really personal adaptions). You can make backups and snapshots as you like, directly manipulate the database and so on. And you can pay developers for implementing your own requirements - which can be very important because how do you expect offering outstanding services, if you just use what everybody else is using? Using a service provider, your possible influence is usually very limited and you have the same functionality that everybody else has, who is using the service.
      3. Security
        This disadvantage again does not (fully) apply if you are using services like Google app engine or EC2. But within an externally hosted application you are often sharing resources or the whole the application with other users. Who does guarantee you, that there is no security issue that allows one user to see private data from another? This is an additional security issue category apart from those regarding security hacking from outside.
      4. Dependency
        You can only hope that the price of the service is kept at a reasonable level and that the provider company is not going bankrupt or somehow else stopping the service (even big companies are closing down services from time to time because they do not make enough money with them).
      5. Performance
        Why performance? You can get a lot of performance by just renting more computing power? - The truth is: The performance increase you can get is for external users of your services. Remember, that with the solution in the cloud also the relevant data also needs to be there (or at least transferred back and forth more often) - and for you the data is then far away (internet is very slow in comparison with local access). Or if you host just the data inhouse, you anyway may get a performance issue (this time the access from outside if you don't have a fast database running on fast and enough hardware).
        For example: We have outsourced our FTP server for software installation package downloads and now putting a new version online takes a lot longer than before.
        Apart from the network traffic, even my laptop is already a dual core (bought more than a year ago), friends already have quad-core laptops. And using web applications in the cloud, there is nearly nothing to do with that enormous computing power (with just the browser running to surf the internet).
        In many cases it is definitely more efficient to run the applications local and just send the data over the (inter)net where necessary. Implementing a web-application that offers - let's say Word/Excel/Powerpoint-like features, require much server power although that computing power is already available locally. And I can see already a tendency back from web applications to full clients. But this begins to get off-topic because this is rather a thick vs thin client comparison - we had that already. - Final word to the performance: If you really need much computing power, then the cloud can really help you.
      Final words: For big SAAS (Software As A Service) providers cloud based solutions are THE way to go to fit variable usage, costs and scalability. BTW: In theory a big company could also maintain an own server-farm for use and sell computing power in a cloud-like fashion. For a small startup the cloud is attractive because you can get going without investing too much in your own IT environment. Although, when you use a little more services than just Salesforce for example then several services can sum up in costs and lack of integration between each other. For a lot of mid-sized companies I do not see that relevance of cloud based solutions. And last but not least: Plenty of companies see their business contacts and business data as crucial for their success so they want to keep it very private (or they might be even legally bound to keep things private) - or they simply want to be flexible and reduce dependencies or vendor lockin respectively.

      Last but not least: Implementing a solution in a cloud-enabled way requires additional considerations and work due to the problems coming along with computing in the cloud, so developing an application enabled for the cloud is usually more expensive (although depending on what exactly you are going to transfer to the cloud - that is not necessarily always a whole application, it can be a single task/job also).

      Related posts: Web vs Thick client, Your holy machine, Surveillance, privacy (NSA, PRISM, ...) and encryption.


        Administrator ethics

        Whenever the sudo command is used the first time on a Linux box (this is the command to run things with administration/root permissions, the following text is shown:
        We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things:
        1. Respect the privacy of others.
        2. Think before you type.
        3. With great power comes great responsibility.
        Whenever I read this, I must say: I like that. And it is applicable to far more than just IT...


        Screencast recording on Ubuntu 10.04 (and 9.10)

        Creating screencasts is not only modern - often a short 2-minute video can be more helpful as a 2 page documentation.

        There are two major screencast recording tools available in Ubuntu. That said, I always had troubles with them because I do want sometimes different behaviour or I had issues with the sound. I want to give a very short overview to make it more easy for you to choose the right tool in the right moment and to get the output you want:
        • gtk-recordmydesktop
          Very easy interface
          + Works out-of-the-box
          - Option to follow mouse available and keeps the mouse always in the center of the frame (I think, this disturbs, when watching the video).
          - Cannot export/save as MPEG-4 or AVI or anything else - just .ogv (the open format)
        • XVidCap
          + Can produce different formats (MPEG-4 is the default, but you can switch to .ogv also)
          + Option to follow mouse available and keeps the frame steady until you move the mouse near the frame border (this way it is more easy for the user to follow the video instructions - you should only make sure that the border of the video is not to near to your primary working area otherwise you get a similar effect as with gtk-recordmydesktop)
          - The GUI is slightly less intuitive
          - Using the package from the Ubuntu 9.10 or 10.04 repository does not bring you sound support (at least not when trying to create MPEG-4). You have to install the .deb package manually by downloading it from sourceforge (current version is yet 1.1.7 - although the same version seems to be in the repository, that is a different one and does not work - strange, but fact).

        I basically use both applications. When I produce local screencasts for end-users that I just save on their local machine for later reference I use gtk-recordmydesktop and just leave it as ogv. That used to work even when Skype + TeamViewer is running and I did the recording remotely. It even recorded my sound coming through Skype! When I want to upload a video to YouTube (or vimeo and others), XVidCap is better because it immediately produces MPEG-4 which fits better for YouTube and similar services (I tried uploading an ogv file from gtk-recordmydesktop to YouTube which failed to replay correctly - indeed it is not mentioned on the appropriate help page).

        Especially for the case(s) you prefer gtk-recordmydesktop you might need to convert the created video to the finally desired format. I have seen many ways (reading blog posts and watching screencasts), e.g. using WinFF, VLC Media Player and using Devede. Using Devede was the only one that worked for me (see http://vodpod.com/watch/3665200-converting-your-ogv-files-to-mpeg4-).

        In any case you should have the ubuntu-restricted-extras installed (using synaptic package manager or sudo apt-get install ubuntu-restricted-extras) for doing video or audio stuff. I would also install ffmpeg.

        I also usually have to put the sound input to a high level otherwise when replayed on several machines (e.g. notebooks or external monitors with poor speaker power), even putting the volume to highest level brought only low level sound.

        Final note: It might be necessary to quit Skype (if you have it running) to avoid sound or video juddering.

        Related post: Ubuntu 10.04 with docking station.


        Ubuntu 10.04 with docking station

        After installing Ubuntu 10.04 I lost proper dual monitor handling for my use case. Basically I want to use my notebook on the road as is and in the office I want to put it into the docking station while having the lid always closed.

        Ubuntu 10.04 Lucid Lynx does not handle this properly any more. I found out that also in 9.10 it was probably pure luck for me because I upgraded from 9.04 and had some fixed entries in the xorg.conf.

        But anyway, the xorg.conf file is legacy and there is now gdm with xrandr.

        I found out that many have the same use case as I have and have problems. Some solutions are particular to NVidia cards, but I have an Intel. Thanks to Nylex in the Linuxquestions-Forum + Ubuntu XOrg documentation, I could find the solution:

        I had to put this into the file /etc/gdm/Init/Default before the line starting with /sbin/initctl (why the TV1 is there also look below in update 3):
        xrandr | grep "HDMI1 connected "
        # 0 is returned on success
        if [ $? -eq 0 ]; then
        xrandr --output HDMI1 --mode 1680x1050 --rate 60 --primary --output LVDS1 --off --output TV1 --off --output VGA1 --off --output HDMI2 --off --output DP1 --off --output DP1 --off --output DP2 --off --output DP3 --off
        xrandr --current | grep "VGA1 connected "
        if [ $? -eq 0 ]; then
        xrandr --output VGA1 --mode 1680x1050 --rate 60 --primary --output LVDS1 --off --output TV1 --off --output HDMI1 --off --output HDMI2 --off --output DP1 --off --output DP1 --off --output DP2 --off --output DP3 --off
        xrandr --current | grep "TV1 connected "
        if [ $? -eq 0 ]; then
        xrandr --output LVDS1 --mode 1440x900 --rate 60 --primary --output HDMI1 --off --output TV1 --off --output VGA1 --off --output HDMI2 --off --output DP1 --off --output DP1 --off --output DP2 --off --output DP3 --off

        What it does is: Using xrandr it probes whether an external monitor is attached (whether HDMI or VGA) and if so it turns off the LCD display of the laptop so it is not used. You need to adapt the resolution to fit your needs.

        I had some cases when (maybe because of timing at startup) it did not work (sometimes it worked after gdm service restart then but not always) added --preferred and --primary to the xrandr call above and I added the script below to System->Preferences->Startup applications:
        xrandr --current | grep "HDMI1 connected "
        # 0 is returned on success
        if [ $? -eq 0 ]; then
        sleep 5s
        xrandr --output HDMI1 --mode 1680x1050 --rate 60 --primary --output LVDS1 --off --output TV1 --off --output VGA1 --off --output HDMI2 --off --output DP1 --off --output DP1 --off --output DP2 --off --output DP3 --off
        xrandr --current | grep "VGA1 connected "
        if [ $? -eq 0 ]; then
        sleep 5s
        xrandr --output VGA1 --mode 1680x1050 --rate 60 --primary --output LVDS1 --off --output TV1 --off --output HDMI1 --off --output HDMI2 --off --output DP1 --off --output DP1 --off --output DP2 --off --output DP3 --off
        xrandr --current | grep "TV1 connected "
        if [ $? -eq 0 ]; then
        sleep 5s
        xrandr --output LVDS1 --mode 1440x900 --rate 60 --primary --output HDMI1 --off --output TV1 --off --output VGA1 --off --output HDMI2 --off --output DP1 --off --output DP1 --off --output DP2 --off --output DP3 --off

        [Update 2]:
        It still did not work 100%. Sometimes when I moved the mouse outside the desktop it was gone so I found the laptop monitor being still active (so I could move windows over there and they were gone). I could immediately notice that after login when the workspace icons on the bottom right were displayed with increased width. It helped, explicitly turning of LVDS1 display (the laptop screen) in the script (see appropriate options in the updated script above).
        [Rest of update 2 removed because of update 3]

        [Update 3]:
        It turned out that (occasionally) on boot it recognized another monitor to be active, after first being the LVDS1 it happened also being the TV1 (occassionally) - and I don't know why because I never attached a TV to it. Anyway, I have added the options to turn that off explicitly also to the scripts (see updated gdm default script portion and startup script above).

        Apart from that sometimes occassionally a re-evaluation of available displays might be triggered by an application (e.g. opening and closing the laptop lid or manually calling xrandr without parameters or starting arandr or other applications when started the first time). Such a re-evaluation can also occur right after graphical login and then your initial gdm xrandr modifications are forgotten. Therefore it helps having that script at hand (I have it in /opt) and added to the gnome menu under "Other" to run it when necessary on demand.

        Apparently also a timing issue remained (I assume that because of the fact, that the startup applications are started in no particular order and all asynchroneously). However, adding a line with "sleep 5s" to the script (only to the additional script and not to the gdm init!!!) helped. I currently use a 10 seconds delay (subject to change maybe) but in your case less might be sufficient or more might be required (for me 5 seconds was not enough to make it work each boot).

        For you it might be necessary to switch additional displays explicitely off (as I did with TV1 for example).

        Oh, and BTW:
        In System->Preferences->Power Management make sure that lid closed action is "Blank Screen". I made a lot of tests with setting to nothing (only possible via gconftool-2) but after all maybe the above setting is the better one.

        If in your case the resolution(s) are not set correctly you can do this here in this script also. Use man xrandr or look at https://wiki.ubuntu.com/X/Config/Resolution#Adding%20undetected%20resolutions for more information on the appropriate xrandr commands.
        I noticed some flickering and login screen displayed in lower resolution, so I added --mode 1680x1050 to the xrandr call in both cases (in both scripts) which is the resolution of my external monitor.

        Honestly, using this script, I feel better than previously on Ubuntu 9.04 or 9.10 where I got it to work by accident after moving around monitors in the config (although in reality they were positioned the other way round). As I found out today, I wasn't either the only one with that experience (see http://ubuntuforums.org/showthread.php?t=1110407) although I am used to be the non-standard user. - With my use case of having the lid closed all the time when in the docking station I am by far not alone as I noticed and some either downgraded to 9.10 because they did not get it to work.

        Many, many thanks again to Nylex and the Ubuntu documentation team!

        Related links:
        Related posts: Ubuntu 10.04 with docking station part 2, Firefox change default page format, Ubuntu 10.04 Experiences, OpenOffice and LibreOffice starts slow.


        Java applications on the desktop

        When it comes to discussions about programming languages on forums and newsgroups, one argument against Java is that there are quite no Java applications for the desktop.

        This is definitely not true. I have looked what Java applications I am using (or used a lot in the past), and here is a list:
        And of course, if you are a developer programming in Java, JavaFX, C++, PHP, Python or Scala for example, then you probably use NetBeans or Eclipse - both very popular IDEs (integrated development environments) are written in Java.

        There are many, many Java desktop applications out there, look for example at javadesktop.org. You can see the wide area where Java is used on the desktop at geertjans blog here for example or at the NetBeans site here.

        One advantage of using Java at the desktop is that you can choose between two core different ways: Swing or SWT. While SWT tries to use the OS specific widgets (to look more like the original OS and be faster), Swing does render everything itself. So SWT is a little bit faster and looks more like OS, but Swing is more flexible (more widgets available) and you can easily use different look and feel / themes (there is also an OS like). In both cases you can develop modern Java desktop applications that look nice and integrated with your OS.

        The disadvantage of using Java on the desktop - I will be honest - is startup speed. Once started, SWT and Swing applications behave fast - probably not as a native Gnome application for instance but really - it's fast enough for the user. That startup time is still an issue you will notice mostly, if you write small tools as Java desktop applications. For larger ones it is less annoying because those you don't open and close all the time. If you open the application and tend to keep it open you will have no problem. If you open and close the app frequently then it may become an issue. Same applies for small commandline tools - writing those in Java is maybe not the best option. Anyway, really annoying is only the first start of the first Java application after reboot when the Java runtime is not in the cache yet. NetBeans for example (which is a big Java application) needs 12 seconds on my machine (a year old) when the Java runtime is already in the cache. Freemind is a smaller application and takes only 5 seconds to startup which is acceptable.

        If you look also at server-side then ... what should I say .... the world is full of Java applications - too much to cover here (and of course for many websites or web applications you often can't really say from outside what is used behind the scenes).

        Related post: Popular Java myths, The future of Java.


        Get reliable local IP address in Java 6

        It is strange: I consider myself still being new to Java, but when I search for particular sample code, that should be written thousand times before, I sometimes find only samples that do only half the job or miss important details.
        So happened for getting the local IP address(es) of the machine you are running on. I experienced for example performance issues retrieving the IPs when running with a mobile internet stick (point-to-point device).

        My example code can be found here: http://pastebin.com/5X073pUc

        If you want just one address, that is probably the best fitting then you probable want to use this example: http://pastebin.com/PLAcTXac

        Related post: Dynamic method invocation in Java 6.

        The small software vendors

        Especially these days companies are very careful in choosing their vendors. This certainly also applies for software.

        I do get some considerations from customers which I do not really consider being always relevant or true:
        • "We prefer to buy from large software vendors, because as an international company, we need the availability of support in different countries."
          Especially software support can be available all over the world because there is no need to actually sit there. With chat, voice- & video communication plus remote desktop tools support can be done all over the world from a single location.
          Further, a large company could have plenty of people sitting in plenty of countries, but this does not mean that all those people have (the same level of) good knowledge of the software. Honestly, those who really know the product, are always the developers and the people who communicate most with them.

        • "A small software vendor is more likely to fail and go bankrupt and then we have invested in a dead product."
          First, present time shows that even a large company can fail (maybe except banks ;-) ).
          Second, bankrupty is not the only case leading to a dead product! It happens more often that a product is simply discontinued and this happens for products of bigger vendors also. In bankrupty case, if a product is good there will be other companies taking over the product - especially if money can be made from supporting the product. But if nobody is interested any more in the product your situation is worse.
          Third, if you ensure that you have access to the source code (even if only in bankrupt case - which would be sufficient and cheaper in most cases), you always can hire people working on the product implementing the features YOU need (this is a big advantage of Open Source).

        • "At small software vendors the deep know-how is bound to a few people only which also means a higher risk for the customer."
          Nowadays companies do not invest in having a lot of backup resources. This also affects developers. And I have experienced dependency on a few people also at big companies. Just because the company is bigger does not necessarily mean they have more smart people there working on the same stuff. It is more important that the team is continuously motivated and people like to work for the company employing them. A stable and motivated team at the vendor is the key for lasting long-term support of your product.

        And last but not least let's not forget about a few advantages of choosing smaller vendors:
        1. Usually more flexible organization.
        2. Better and more direct contact with tech people.
        3. Cheaper - big companies often have a big head of administration and more levels of managment - all those want to be paid.
        4. What a small customer is for a big vendor can be a big customer for a small vendor. So the small vendor is more likely to listen to your needs.
        5. If you are a big company and somehow get too dependent from a very small company, you could take over more easily.
        And BTW: There are more smaller vendors than big ones, so the set of applications to choose from is significantly higher if you consider also the small vendors.

        Related posts: Small Business Boom, Scope of IT projects, Paying for free and Open Source, IT Outsourcing, IT projects cost explosion, The Open Source idea.


            Small Business Boom

            If boosted by the economic crisis or not, in my neighbourhood I can observe more and more people becoming self-employed building their real own company or just getting freelancers.

            What this usually brings is more flexibility and a low budget - at least at the beginning.

            Classical style of IT then:
            • Internet ADSL connection to home office
            • E-Mail (along with spam filtering) hosted at the Internet provider
            • Single notebook or desktop PC with some backup strategy or a dedicated server + desktop pc + laptop (something like this). Newer Internet provider modems are even shipped with an option to plugin an external harddrive that is directly offered as a network storage service for connected (W)LAN-devices.
            • All-in-one printer-scanner-fax devices for doing those most important office operations dealing with paper where still necessary. Usually small and compact devices do not occupy too much space and can handle the small amount of paper in a modern office.
            • Contacts are saved in the address books of the used email-client, in some cases additional simple local XLS files or Access databases are used or also free online services (but only surprisingly seldom - I guess people do consider their business contacts as a company secret and do have privace concerns).
            • Office application package is intensively used for writing letters (where still needed), contracts, agreements, invoices and the like.
            • PDFs are created from the office documents written or scanned documents are saved in PDF format for (long-term).
            • Sector or branch specific software applications (e.g. banking or insurance agency tools) move more and more in the direction of being online services (web applications) rather than applications that need a local installation.
            • With a smartphone they can answer emails also while on the road which is crucial for a one- or two-man/women show.
            • Appointments are managed in the smartphone with the smart phone's own application, Google Calendar or in a classical pen & paper style (what is actually used is mostly depending on people in the company and branch).
            I can see such constructs from 1 to 3 or 4 people in my local area. Some of them are considering a move to Linux and I already helped a few building their home-office-desktop on Linux. And lately there are coming more and more asking for Linux...

            Related posts: Why Linux?, Going Linux, Why I switched to Ubuntu, The small software vendors.


            Popular Java myths

            After developing more than 10 years mostly in Visual Basic (classic), VB Script, VBA etc I started moving to Java after a long evaluation period of different languages about 2 years ago (see also "The programming language") .

            Since then when talking with customers, .NET people and even Java folks people come across again and again with the same arguments against Java that are simply wrong. After discussing and researching these arguments a lot of times I am really tired of explaining so this post will hopefully save me from that in the future.

            BTW: In discussions you have to distinguish between the Java as a platform (JVM) or the Java language. There are a lot of other languages like Scala, Groovy, JRuby (Ruby interpreter) or Jython (Python interpreter) and others. That the JVM is very popular and far from being dead is not taken into doubt by most people, not so for the Java language.

            But why don't these Java language myths finally die:
            1. Java is dead.
              The argument usually comes from the fact that a long time passed since the last major release (Java 6 Update 20 is current at this time) and that they don't see big new stuff coming. At this point have you ever considered C(++) dying? - Or Microsoft Windows? No big changes for many years there either!
              There are other languages that evolve very fast - but take into consideration that most of those languages are very new in relation to Java and there is still much work to be done. Of course with evolution of a language there is legacy generated and it gets more difficult to introduce major new stuff. The newer languages will see the same happening as these problems affects any software getting into age.
              But: It means, Java is proven and stable and I am happy that the language is not changed or enhanced by running after hypes. I really like the decision to think well before really changing a big thing (like introducing closures).
              Another reason why people told Java to death is citing the TIOBE or other indexes showing Java loosing popularity or market share. If you examine how these statistics are built you always find that they are not complete and just investigate a few parameters (like new items in Google search results for example). When I heard the last discussion about TIOBE, Java has fallen on position 2 behind C - now it is back on top again although - according to TIOBE - it still looses popularity (which is logical to me because a lot of new other languages are running on the JVM attracting especially Java developers). On the other hand tht C# is gaining, does not necessarily mean that it is better than Java. Windows developers didn't get major new stuff for about 10 years and basically Microsoft is telling them to move.
              And it remains the question if new is always better, a lot of companies heavily rely on the stability of Java and the long-term return on investment (ROI).
              Besides, although people say, Java is dying, there is so much daily news on Java that I simply can only follow the biggest news. Java land is soooo large and the community is so huge.
              Last but not least: Because there are more operating systems around than ever, platform independent development is getting more important (as developing separately for each platform is costly) - well this is a plus for all languages based on the JVM.
            2. Java is slow.
              There are 3 groups of people saying this. The first group is talking about the startup times and the second is comparing with C(++).

              Regarding the first group: These are mostly people on Windows using Java applications just occassionally. Yes, the JVM takes a while to load (which BTW should be addressed in Java 7) but this applies also for the .NET runtime or other big libraries used in other big applications. The point is, that Windows tends to load everything Windows-related already on Windows startup and if an application using the .NET runtime already then of course the next application will start faster. This issues is (at least partly) already addressed because some Java update comes with an autostarter that also loads the JVM at login time. And BTW: Java 6 is much faster than Java 5 and Java on Linux is much faster than on Windows.

              Regarding the second group: They usually refer to optimized C(++) code. First to say, most developers do not really performance optimize their code (only when necessary); second, in a lot of cases, performance of the language is not the bottleneck (usually network and HDD speed is - or inefficient algorithms/storage methods) and third, the optimization is done at compile time and at runtime. Runtime optimization is not available for C(++)-programs. So it can happen, that Java is even faster than C(++). But of course, in a lot of cases particular optimizations are written in C(++) and then called from Java to improve the overall performance. Of course, C(++) has the potential to be faster than Java. The write once, run everywhere idea introduces a level of abstraction that surely can affect performance - there is no gain that does not introduce a cost somewhere else. But: For most performance issues the performance of the language itself is irrelevant (I mentioned the real bottlenecks above)! Further, I only met once a C(++) developer who really considered performance on everything he did. Anyway, just because C(++) tends to be the fastest of all programming languages, Java is not slow - Java is faster than most other languages! - See e.g. benchmarks at alioth.debian.org.

              Regarding the third group: Those are usually comparing some simple PHP application with some Java EE application that makes use of a component stack that I just get sick when I see it - so no wonder if such a monster app is behaving a little lethargic. Although Java is widely used in the EE world in huge environments, a real lot of connections and a huge amount of data with a huge component stack and a lot of legacy code (and sometimes even still on Java 4 or 5), Java could be used in smaller environments too. Let's say, a typical PHP application contains a lot of DB queries, XML/JSON/HTML parsing and HTML generation. This could be easily done with plain Java also without introducing any particular framework. So most of those people are simply comparing apples with bananas. See also benchmark mentioned before where PHP rates really bad. - That said, according to earlier mentioned real bottlenecks, that does not really matter in most cases.
            3. Java applications need longer time to develop.
              Well, this is maybe not a myth, but a tendency. It is true that while a Ruby-Developer might already have finished the task, the Java developer might still be evaluating the right framework and library to use. But this is not due to the language itself. In many other languages you have not the choices you have in Java land. And for development on Windows, many people just rely on the recommendations given by Microsoft. My experience, after I got member of the local JUG and met some Java developers elsewhere at conferences is, that there are really smart people doing awesome stuff and working on big and critical projects and such with product lifetimes beond 10 or even 20 years. Of course this involves a big responsibility and therefore I can see Java developers investing more time into the evaluation of the architecture, used frameworks and libraries and algorithms.
              And this does not mean that you can't get a small project quickly up and running the "agile style" (using the libraries and frameworks you are already familiar with without starting to evaluate with Adam and Eve).
              Example: Lately I needed a little tool to count all PDF pages of all PDF documents in a certain tree structure (to evaluate needed license volume for OCR processing). In about an hour I had a small tool ready. I was sure, that there exists a tool already that I could use but searching the internet + testing would have been similar amount of work. And if I would have done it with VB on Windows only half an hour for just building a setup that installs the application at client side - but in Java I simply sent the built jar by email and finished. Just run it without the need to install. As another example it took me about 4 days for a prototype of a PDF archiving tool in Swing with embedded PDF viewer and fulltext indexing of the PDF content. Of course this would not have been possible without any experience in Java - any language must be learned first to get really productive. I have a friend who wondered about the long time I spent on evaluation when starting with Java. Yeah, I already can choose between at least 3 great free (see comparison at Wikipedia) Integrated Development Environments (IDE) while on Windows I only have 1 free for .NET in best case (because the most obvious choice here is the costly Visual Studio). Then for thick clients I can choose at least between SWT or Swing for GUI (not to talk about the plenty of choices for web applications). Then there are plenty of logging frameworks and so on. But once you have chosen your preferred toolset, you can use that also if it might not fit 100% best for the next project y after finished project x. And BTW: You could rely on the recommendation of others (if you want to rely on me use NetBeans and/with Swing for thick clients). I myself did not have the appropriate contacts so I went the rocky way.

            Related posts: Java applications on the desktop, The programming language, The IDE and the libraries, The dawn after sunset, Dynamic method invocation in Java 6, The future of Java.