Using Eclipse WTP for developing application under Websphere Application Server Community Edition (WAS CE)

This tutorial assumes that you already have Eclipse WTP (Galileo) and WAS CE (2.1) installed correctly. To make sure that your Websphere is installed correctly, start the server and go to the console. If you can do so, you’re in the right track. After that, just shutdown the server because we will manage the server from Eclipse.

After that, the first step is to install the Eclipse plugin for WAS CE. This plugin contains several things, and one of it is WTP server adapter for WAS CE. The update site for the plugin is http://download.boulder.ibm.com/ibmdl/pub/software/websphere/wasce/updates/

Restart Eclipse like usual after installing the plugin.

Now we are ready to develop our first project under WAS CE. Create a new ‘Dynamic Web Project’. You’ll get something like this:

2009-10-20_1235

What’s important here is to change the Target runtime to ‘IBM WASCE 2.1’, so if you haven’t had one, you should create a new target runtime by clicking the ‘New…’ button. I think the creation of target runtime is pretty self explanatory. You just need to put the directory name of where you installed the WAS CE. This step is critical because if you don’t change the Target runtime now, the application can’t be run correctly from Eclipse.

After that, you will be asked to put the usual information for a dynamic web project but if click next and next, you will get a custom ‘Geronimo Deployment Plan’. Here you need to put the name of group id, artifact id, version, and artifact type. This information is needed because your application will be seen like a normal system resource, which can be a library or an web application.

2009-10-20_1241

After that you will get a new web project. What’s different in this web project is there is a geronimo-web.xml under WEB-INF and IBM WASCE 2.1.will added as referenced library.

You can start developing your web application and running it using normal way.

Play High Definition movie smoothly with VLC

VLC is a wonderful player. It can almost play all kind of videos that I have. It’s lightweight and best of all… it’s free! I don’t know what else to ask.

Except this… for several months I have noticed that when I played a high definition movie, it kind of getting chobby. It seemed that I have a line in the video. It made my eyes sick and I almost always try to avoid a HD movie (and hoping the problem will be fixed with the next version of VLC or Mac OS).

Today I got my Snow Leopard and VLC has left its beta status but I still get the horizontal line when I watch an HD movie. This is an example of it.

nothing

I thought… this is it. Either I manage to fix the problem in VLC or I have to find a new video player.

It turned out finding a better video player was a harder task.

So I began searching the web for a fix of that problem. It’s not that hard to find a solution, but to get the correct keywords is the harder puzzle. So in VLC forum, people suggested to use the filtering capability in VLC. At least there are three suggestions.

  1. To turn on the scale filter and use a better algorithm for it.
  2. To turn on the post processing filter and maximize the number of the post processing.
  3. To turn on the deinterlace filter.

I tried all of them to get the best solution, and after a while, I got a conclusion that turning on the deinterlace filter is the best answer. This was the result of it:
deinterlace

As you can see, the horizontal line is gone, but the picture is still not that sharp.

Not so satisfied with the result, I searched further for better solution. This time I got a better answer quicker. By using an algorithm named ‘Bob’ for deinterlacing, I got a better result as can be seen in the following picture.
bob

Now I’m glad!

Step by step instructions

If you are a type of person who needs a complete step-by-step instructions, this is what I did:

  1. Open VLC
  2. Select Preferences from the Menu ‘VLC’
  3. Activate the ‘All’ check box in the left bottom of the dialog
  4. Go to Video->Filters, activate the checkbox ‘Deinterlacing video filter’
  5. Go to Video->Filters->Deinterlace
  6. Change the deinterlace mode to ‘Bob’
  7. Click save
  8. Restart the VLC
  9. Play the video, hopefully you will get a better video playback

Do you have more tips how to optimize the settings in VLC? Please share here! I’d be glad to have a better and sharper image for my video.

Eclipse Tips: Debugging your multi thread application (2)

This post is another tips of debugging your multi thread application. If you are interested on how to debugging a multi thread application, probably you will find my first post useful as well.

In a multi thread application, it’s still possible to use a certain class from different threads. The problem is if you try to set a breakpoint in this shared class, the breakpoint will be valid for all threads. This is typically just slowing our debugging session.

With Eclipse, you can set a breakpoint that only valid in certain threads. The catch is since there is no way that Eclipse knows what threads will be available, you can only set this on runtime.

To do this, you need to first set the breakpoint you want (remember, you probably need to Suspend the VM as well).

After that, you can start the debugging session and wait until the application is suspended. In this occasion, let open the breakpoint properties. In this window, there are two elements in the left tree: Breakpoint Properties and Filtering. Select Filtering and after that you can set to which thread the breakpoint should be valid for.

2009-08-26_1300

There are two more catches.

  • If the intended thread is not running yet, this method is not usable.
  • Every time the debugging session is restarted, you’ll need to filter it again.

Despite that catches, I think this is nice feature to know by multi-thread application developers and who know, it may be useful sometime in the future.

Eclipse Tips: (Debugging) Ignoring certain classes from being stepped into

Some of us may have encountered a not so nice experience where you basically got an strange result from a method and decide to step into that method as deep as possible. The problem is somehow you are lost in track and you can’t debug furthermore except if you’re exiting the debug mode or resuming the debug. Both are not the best solution because you have to inspect the application one more time.

The symptom of the problem is usually you a “Source not found” on your editor. If you are trying to ‘Step Return’ you are basically lost in track because you can not return to a class with source code.

For testing, you may try to write a log, for example:

logger.info("whatever");

If you’re trying to step into this method, you may get (since this obviously depends on your Eclipse configuration, you may also not get this screenshot):

2009-08-24_1210

Now try to ‘Step Return’ several times… do you still get the ‘Source not found’ message?

Why?

It’s actually easy to understand if you look at the debug view.
2009-08-24_1215

You are basically step into a long method calls, which most of them doesn’t have line information. Eclipse will automatically ignore these methods when you are stepping into. But then suddenly, it touched a method equals from class ‘Class’ which does have line information, but no source attached for it.

So, if you are patient enough, you can just do ‘Step Return’ several times (in this case about 16 times) and you’ll return to your class (with nice source code 🙂 ). This is obviously too much work.

One other alternative is to ignore certain classes to be stepped into. In Eclipse, the name of the functionality is called ‘Step Filters’. To use this functionality to ignore JDK classes, you have to configure Eclipse.

Go to the Preferences dialog, and open Java → Debug → Step Filtering.

2009-08-24_1227

Just ‘Select All’ and click ‘OK’. Now… If you are still trapped in the equals method, you can simply ‘Step Return’ and you’ll be back to your source code.

Once you’ve set the configuration in the Preferences, you can enable and disable this Step Filters anytime from your Debug perspective by clicking this button on Debug view.

2009-08-24_1230

Now… there is no reason to redo your entire debug session if you’re trapped in such situation.

Happy debugging!

Eclipse Tips: Auto generate ‘final’ on your variable, field, and parameter

If you are reading a lot of blogs about Java lately, you’ll find more and more people suggesting to use ‘final’ everywhere. The main argument is by using ‘final’ we will have a code with less bug. This post will not argue with the up/down side of the suggestion, if you eager to do that, just do that somewhere else (here for example).

However, if you are convince with such argumentation, probably the first thing on your mind is: should I now change all my code? How much time do I need to develop this instinct until all of my code is using ‘final’ everywhere?

Fortunately for Eclipse user, there is a functionality in Eclipse to help we develop this instinct. And it even will fixes our mistakes and we will get a consistent look of our code.

Let’s look at a code example:

2009-08-13_1139

There are some places where ‘final’ could be used. Now… open the Preferences dialog (under Window on Windows and Linux, under Eclipse on Mac). Navigate to Java->Editor->Save Actions.

2009-08-13_1142

Tick the ‘Perform the selected actions on save’ checkbox and ‘Additional actions’ checkbox. After that, click the ‘Configure…’ button.
2009-08-13_1146

What we’re interested in is in tab ‘Code Style’. Tick all ‘Private fields’, ‘Parameters field’, and ‘Local variables’. Click ‘OK’

Now you can go back to your source code and do small change, revert it back (Eclipse prevents saving if there is no change in the source code), and save it. Tarammm…. you get ‘final’ everywhere.

2009-08-13_1151

Note that this doesn’t put final on your method and class, you still have to do that manually.

Now you can enforce your team to use ‘final’ everywhere if you like!

Lambda4JDT: lambda expression on your Java code

This is just another proof how many people are starting to want some functional syntaxes on Java. Some lambda expressions are possible to be implemented using current Java, but there are just too many noise in the result.

Lambda4JDT provides a new plugin for Eclipse that can collapse the noise in the implementation without changing the syntax of Java. I must say that the approach it takes is pretty unique and original.


Antara Roy Suryo dan Donald Knuth

Siapa yang tidak kenal Roy Suryo? Meski banyak dihujat orang, ‘ahli’ telematika (dan ‘-tika -tika’ yang lain) yang satu ini pasti sudah tidak asing lagi di telinga orang Indonesia. Apalagi kalau mereka sering mengakses internet. Yeah, you’re included. After all, you read this blog post, right?

Dan siapa pula yang tidak kenal dengan Donald Knuth? Meskipun lebih asing di telinga orang Indonesia, orang yang satu ini punya masterpiece yang jauh lebih melegenda, yaitu TeX – sebuah perangkat lunak untuk penulisan publikasi – dan The Art of Computer Programming – seri buku tentang pemrograman komputer yang masih belum juga selesai -.

Lalu mengapa saya membandingkan kedua tokoh ini? Keduanya punya lahan olahan yang berbeda, umurnya berbeda puluhan tahun, khalayaknya berbeda, kharismanya berbeda, dan seterusnya dan seterusnya.

Pada penulisan artikel-artikel saya terdahulu saya menyinggung tentang optimasi pada program. Dan bisa ditebak, ada satu kutipan yang sering diambil orang kalau berbicara tentang optimasi:

We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil

Kalau boleh saya terjemahkan bebas:

Kita harus melupakan, katakanlah sekitar 97% dari efisiensi yang hasilnya kecil: optimisasi prematur adalah akar dari segala kejahatan

Para pemerhati Roy Suryo selalu dengan setia mendengarkan perkataan Roy Suryo dan menangkap semua titik koma kesalahan dari sang pakar ini. Salah satunya, konon kabarnya, Roy Suryo pernah berkata bahwa “68% data di Friendster itu palsu“.

Bisa mulai terlihat kemana arah tulisan saya?

Ada dua nilai prosentase yang terlihat di sini: 97% dan 68%. Darimana keduanya? Yang jelas, cukup banyak yang mempertanyakan nilai 68%. Tapi saya nyaris tidak menemukan mereka yang mempertanyakan nilai 97% dari Pak Knuth.

Penasaran dengan ini akhirnya saya pun bertanya pada publik: I’m curious how Knuth came up with 97%. Could someone please share something about this?

Bisa ditebak, karena traffic ke website saya sedikit, tidak ada yang menjawab pertanyaan ini. Masih penasaran dengan pertanyaan ini akhirnya saya pun bertanya ke forum yang lebih besar: StackOverflow.

Jawabannya bisa ditebak… semua orang tidak tahu.

Jadi sebenarnya, antara Roy Suryo dan Donald Knuth ada persamaan yang bisa kita tarik. Bahkan kalau saya mau jujur, pernyataan Knuth jauh lebih fatal karena ditulis dalam sebuah paper yang masih dibaca sampai saat ini. Alasannya, yang meskipun bukan satu-satunya, mendasari jawaban mengapa goto statemen harus dihapus dari bahasa pemrograman. Sedangkan pernyataan Roy Suryo, sejauh yang saya tahu, hanya pernyataan informal yang diucapkan secara lisan dan akibat paling buruknya pun hanya membuat geger belantika internet Indonesia.

Mengapa itu bisa terjadi? Apa kita orang Indonesia terlalu berlebihan dalam menyikapi pernyataan Roy Suryo? Bisa dilihat dalam jawaban atas pertanyaan saya di StackOverflow bahwa pembuatan angka statistik bahkan dalam sebuah research paper bisa dimaklumi oleh banyak orang. Semua orang tahu kalau statistik itu adalah kebohongan yang paling besar. “There are three kinds of lies: lies, damned lies, and statistics.” Komik Dilbert ini menarik.

Atau jangan-jangan pondasi keilmuan kita ini sebenarnya masih banyak yang dibangun di atas prinsip-prinsip subjektif seseorang?

Atau karena kita masih menilai pernyataan seseorang dari pandangan kita terhadap orang tersebut? Kalau orang itu buruk, maka semua omongannya jadi buruk? Kalau orang itu hebat, maka semua omongannya jadi hebat?

Tambahan: mungkin malah Roy Suryo benar dengan pernyataannya bahwa blog hanya trend sesaat. Buktinya, trend saat ini kan twitter 😛

Jangan diambil hati, tulisan ini cuman guyonan karena kesel pertanyaannya tentang 97% diabaikan dan juga jangan diartikan saya pengagum Roy Suryo, aduh jangan deh. Plis, bitte, mohon, dengat sangat…

.

Java Tips: Optimizing your Map loop

Quite often, a program needs to go through all elements of a Map. Unfortunately, like a Set, a Map doesn’t have index in the data structure so you can’t just get a key of certain index or a value of certain index.

The most common practice used to iterate all elements in a Map is to get the key set and then based on the key, we can retrieve the value. The template we use for such case is something like this:

for (String k : m.keySet()) {
    Integer v = m.get(k);
   // do something with the key and value
}

This works of course, but based on quick observation, this should be not that efficient because we have to retrieve value using key for every step. It would be much better to get the key and value as a pair in the beginning. This is unfortunately less obvious and less used. The template would be something like this (of course, we need to change the generic type as properly):

for (Entry<String, Integer> e : m.entrySet()) {
    Integer v = e.getValue();
    // do something with the key and value
}

Now let’s make some tests. I use this template for the test and changing the backing object, number of iteration, and the method to get the key and value from the map (of course it’s not that real, because we only use the value and ignore the key, in which case we can use values() for better performance).

public static void main(String[] args) {
	java.util.Map<String, Integer> m = new TreeMap<String, Integer>();
	for (int i = 0; i < 500000; i++) {
		m.put(i + "", i);
	}

	List<Integer> l = new ArrayList<Integer>();

	long st = System.currentTimeMillis();

	for (String string : m.keySet()) {
		l.add(m.get(string));
	}

	System.out.println(System.currentTimeMillis() - st);
}

From my tests, I observe that the performance of the first template depends on the backing object. If we are using HashMap, the performance is less or more the same as the second template. If we are using Hashtable, the performance of the first template is about 1.5 times worse as the second template and if we are using TreeMap, the performance of the first template is more than 5 times worse as the second template. This proved my original hypotheses and we as developers should try to change our instinct to use the second template every time we encounter such problem.

UPDATE: I redo the test using nanotime and it’s just confirming my original observation.

Kamus Besar Bahasa Indonesia di Mac

Sejak tahun lalu, Pusat Bahasa Departemen Pendidikan Nasional memperkenalkan Kamus Besar Bahasa Indonesia Daring (dalam jaringan) yang dapat diakses siapa saja. Sebagaimana versi cetaknya, KBBI daring ini sangat berguna untuk mendapatkan arti kata bahasa Indonesia, termasuk kata-kata yang jarang dikenal.

00000017

Kamus daring ini kemudian diunduh dan diparsing oleh Steven Haryanto menjadi bentuk umum kamus yang banyak beredar di Internet, yaitu StarDict. Hasilnya bisa diunduh disini.

Untuk pengguna Mac, kurang puas rasanya kalau harus menggunakan StarDict padahal sudah ada aplikasi Dictionary standar yang tersedia. Beruntung ada project mac-dictionary-kit yang menyediakan converter format StarDict ke Dictionary di Mac. File converternya bisa diunduh disini. Selanjutnya tinggal menginstall aplikasi tersebut dan menconvert KBBI versi StarDict, dan anda akan mendapatkan KBBI dalam aplikasi Dictionary di Mac anda.

Beberapa screenshot dari proses diatas:

00000019

00000020

technology and stuffs