Clean Spring MVC Web Application

As a base for the future blog entries, I have created a simple web application based on the Spring Web MVC framework and checked it in to the git repository. If you just want to take a look at the application (or maybe use it for your specific purposes), please use the github repository; however, if your are interested to create an application on your own, the following steps may be beneficial for you. Read the rest of this entry »

First Experience with Servlet 3.0

Das Ostern is finished and finally, I’ve been assigned to a project. As you know, sometimes it takes a few days to prepare environment, setup all accounts, and so on. Thus, during the last two days my schedule is pretty much relaxed and I can spend some time for self-education – I am reading the Servlet 3.0 specification, writing some simple application in order to try discovered features, and wondering about two things: how really cool servlet 3.0 is and how I could missed it?! If you did not touch it as well, take a look on the following briefly Read the rest of this entry »

Issue with Facebook Key Hashes for the Android Application

During the last three months I have been working as a developer for a consulting android project. It is actually my first commercial experience (I do not count written demo examples at my previous work) and I found it extremely interesting, though a quite confusing at some moments.

The following article describes an observed problem with the facebook key hashes for the android application. To describe the problem and its solution, let’s define a simple use case.
Read the rest of this entry »

How to restart an application in android programmatically

The following code snippet shows how to restart an android application after the specified delay programmatically:

public void restart(int delay) {
	PendingIntent intent = PendingIntent.getActivity(this.getBaseContext(), 0, new Intent(getIntent()), getIntent().getFlags());
	AlarmManager manager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
	manager.set(AlarmManager.RTC, System.currentTimeMillis() + delay, intent);

Related API:

How to minimize an application in android programmatically

The following code snippet shows how to minimize the current application in android programmatically:

Intent main = new Intent(Intent.ACTION_MAIN);

Related API:

Oracle Certified Professional, Java SE 6 Programmer. 1Z0-851 Exam

Finally, I did it. About a month I have passed the java certification exam and it was not that hard as I expected. A brief story how it was.

Firstly, let me give a few cents about the exam preparation. The rule is really simple: if you have a few years (or even not a few) of the experience with Java and you believe that you do no need to read any books and you are by now ready to take it – forget about it, you will most likely fail, because of the specific exam pitfalls. Take a week or two and play with the exam preparation materials.
Read the rest of this entry »

Hibernate. How to Count Records

Easy as ABC, you may answer, and you will be absolutely right! It is not rocket science, yet some code looks quite complicated to complete this simplest task.

Today I watched a new episode of the Bones tv show and browsed some open source code. I found the following method:

public int getCount(Class clazz) {
	Integer rowCount  = new Integer(0);
	Criteria criteria = getCurrentSession().createCriteria(SomeEntity.class);

	List results = criteria.list();

        if(results != null && !results.isEmpty()){
        rowCount = results.size();
	} else {
		rowCount = new Integer(0);
	return rowCount;

Okay, 11 “readable” lines of code so far. Read the rest of this entry »

Hibernate Many-to-Many Mapping (JPA)

A few months ago, I wrote an article how to map the one-to-one bi-directional relations between two entities and now is the time for a simple example how to map many-to-many relation. You can find what Many-to-Many relation means in Wikipedia, and the following article only shows how it looks like in Db and how it can be mapped in Hibernate. Ready? Read the rest of this entry »

Java Generics and Collections. Safe conversion

Are you working with Java? Have you ever seen the following warning message:

Type safety: The expression of type List needs unchecked conversion to conform to List<SomeClass>

I’ve seen it a lot. Technically, there is nothing wrong with this warning in most cases. The warning is related to API that either was built to support Java versions less than 1.5 or is a bit clumsy. Anyway, I do not really like any warnings in my code so I can’t ignore it. How to remove this warning? Read the rest of this entry »

How to Test JSR 303 Bean Validators

If you ever see how the JSR 303 validation works, you probably know how awesome this way is. I like it because it makes the code more readable, easy to maintain and to add new features. Additional information about the approach is available here, and in this article, I am going to show how to test JSR 303. Read the rest of this entry »