Archive

Posts Tagged ‘java’

Reindent Java code with Eclipse

April 22, 2012 Leave a comment

Problem
I had a Java source that wasn’t correctly indented. How to reindent it painlessly?

Solution
In Eclipse:

CTRL+A
CTRL+I

This tip is from here.

Categories: Uncategorized Tags: , , ,

StringBuilder class in PHP [PHP]

December 3, 2010 1 comment

Problem

In PHP you want to construct a long string from pieces.

Solution

Instead of string concatenation, it is better to collect the pieces in an array, then at the end put these pieces together in a string. For this we can use the following simple class that works similar to the Java StringBuilder class:

class StringBuilder 
{
    private $str = array();

    public function __construct() { }

    public function append($str) {
        $this->str[] = $str;
        return $this;
    }
		
    public function toString() {
        return implode($this->str);
    }
}

Usage:

$sb = new StringBuilder();
$sb->append("one")->append("two");
print $sb->toString();

Credits

I found this nice solution in this thread. For append(), I proposed the method chaining possibility.

Categories: php Tags: , , ,

Installing the Java plugin for Firefox

October 28, 2010 Leave a comment

Problem

You have a Linux box (e.g. Ubuntu) and you want to run an applet in Firefox. It starts, but then it hangs, and you have no idea what the hack is going on.

My Case

I had Firefox 3.6.3 and I wanted to use OpenCms 7.5.1′s upload feature. The uploading is done via an applet that started but when I chose the file to upload and clicked OK, nothing happened. The CPU was on 100% and using the top command I noticed that a Java process is stuck. A bit later I figured out that it must be the Java plugin…

Solution

In Firefox, verify what Java plugin you have. Go to ToolsAdd-onsPlugins. Here I had the icedtea Java plugin. This is a crap, use the official Sun plugin instead.

Open Synaptic and remove this plugin. I also removed all openjdk packages.

Then install these:

sudo apt-get install sun-java6-jdk sun-java6-jre sun-java6-plugin sun-java6-fonts

Now let’s see the list of alternatives:

sudo update-java-alternatives -l

Here I got this output:

java-6-sun 63 /usr/lib/jvm/java-6-sun

Set the official one:

sudo update-java-alternatives -s java-6-sun

Now restart Firefox and check the Java plugin again. You should see Java(TM) Plug-in 1.6.0_22 (or something more up-to-date).

Troubleshooting

If you cannot install sun-java6-jre because it’s not in the repository, add Canonical Partners to your software sources.

Credits

Find more info here.

Categories: firefox Tags: , , , ,
Follow

Get every new post delivered to your Inbox.

Join 73 other followers