Category Archives: Java


Java Interview Questions – contract between equals and hashCode

Question about contract between equals and hashCode is one of the most common question on interviews for Java developers. Let’s see how somebody should answer and what implications this contract has.

First look at this example:

This example can explain a lot. First of all string a and b are not equal, but their hashCode are the same.

That means that contract for equals and hashCode is:

  • when two objects are equal, their hashCode must be the same,
  • when two objects has the same hashCode, they don’t have to be equal.

Follow up questions

  1. Is hashCode implementation that returns constant value correct?

This is correct implementation but should be avoided because using such objects as keys in HashMap gives performance issues.

  1. How does HashMap handle objects with the same hashCode?

HashMap puts those keys to buckets and than it is using equals to find proper key.


Java 8 – Streams API instead of FluentIterable

In one of my recent posts I was comparing FluentIterable with Java 8 Lambdas (here). Now let’s take a look at how Streams API introduced in Java 8 changed way we write code.

What is Streams API?

Streams are not Collections. Streams are lazy data structures that compute values on demand. It is important to know that Streams have two types of operations:

  • intermediate – those operations return stream and can be combined into pipeline. For example filter, map, etc
  • terminal – those operations returns final result. For example sum, count, etc.

So lets start usage of Streams API with some POJO class.

Now imagine case where we want to calculate count of items which name ends with “C”.

As you can see in this example code written with Streams API is very readable. I added comments, but basically you can read code as normal sentences. Moreover it has big advantage over Guava implementation because you don’t have to create inner class implementing Predicate and Function interfaces.

Also it is easier to create new collection based on results of pipeline processing by using Collectors.

As you can see from this two examples Streams API is very easy to use and makes code really clean. It changes way of writing code from imperative to declarative.

More to read


Unable to read jar manifest from pom

Few days ago I was trying to use Spring Boot to implement some small project and I encounter strange problem. When running command

mvn eclipse:eclipse

I was getting this error:

[INFO] Unable to read jar manifest from C:\Users\Maciek\.m2\repository\org\springframework\boot\spring-boot-dependencies\1.1.1.RELEASE\spring-boot-dependencies-1.1.1.RELEASE.pom

My pom.xml was like this:

<project xmlns="" xmlns:xsi=""
			<!-- Import dependency management from Spring Boot -->


I was a bit surprised, but after some googling I found out that it was my stupid mistake with copy/paste. On the Spring Boot Reference Guide it was:

            <!-- Import dependency management from Spring Boot -->

Skipping dependencyManagement was root cause of error mentioned at the beginning.

Be aware of copy/paste failures!

Eclipse Java

Eclipse/JUnit: CreateProcess error=206, The filename or extension is too long

If you encounter problems with running junit test in Eclipse and you get following exception:

Exception occurred executing command line.
Cannot run program "C:\Program Files\Java\jdk1.7.0\bin\javaw.exe" (in directory "C:\......"):
CreateProcess error=206, The filename or extension is too long

please download patch for Eclipse.

For Eclipse Juno and newer:
For older Eclipse:

After download back up existing eclipse/plugins/org.eclipse.jdt.launching_3.*.jar
Copy and paste classes in the patch to org.eclipse.jdt.launching JAR (replace existing files).
Restart Eclipse.

For me it worked.

In bug report Bug 327193 it is considered fixed, but it happen to me recently with Eclipse Kepler 4.3.2.

General Java

Geecon 2014

GeeCon logo

Thanks to my employer – Sabre,  I was able to attend GeeCon conference, which was taking place in Krakow, 14-16th May 2014. This event was organized in big cinema with multiple different rooms. Usually there were 5 speeches at the same time.  I think that this conference is getting too big. It was very crowded specially during coffee brakes, when everybody was going from one room to another. Also eating lunch on your knees is not nice thing. I know that it is hard to put in one place tables for 1000+ people, but maybe organizers should consider choosing different place for next year. The good thing was that, as in good cinema, chairs were very comfortable.

Besides that I enjoyed it. It was great pleasure to meet other developers form different parts of the world and also to meet my colleges from previous company.

Some of presentation I attended:

Day 1

Jurgen Appelo – The 7 Duties of Great Software Developer

Very interesting speech about things we should thing about in order to make our careers move forward. Jurgen is a person with experience in management and he wrote book “Management 3.0”. During his speech he mentioned following key points, for each he added most important question every developer should answer.

  • Motivate yourself – Are you aligning your work with your intrinsic motivators?
  • Direct yourself – What do you see in your future?
  • Educate yourself – How have you decided to learn?
  • Measure yourself – How do you track your growth as a professional?
  • Connect yourself – How do you diversify your personal network?
  • Brand yourself – How are you developing your personal brand?
  • Improve yourself – Are you improving by adapting, anticipating and experimenting?

Whole slideshow is available here.

Marek Matczak – AngularJS: Java developer’s real-life experiences

Very well prepared introduction to AngularJS, specially for Java developer’s point of view. Marek described basics and showed how to use directives and templates, how to create simple widget and extends html with own tags.

Ken Sipe – Go – The Language of the Cloud

Ken described Go language by comparing its features with Java. For me it appears that this language is step backward. For people used to Java it is less readable and more complicated. Unfortunately it allows programmer to do simple things in many different ways (like for example returning multiple values from function can be achieved by assigning value in the middle of the function and it the end). In my opinion in can be very error prone.

Gleb Smirnov – Mutation Analysis or What Code Coverage Doesn’t Test

Very interesting speech about using PIT – mutation coverage tool to improve quality of unit tests. Gleb was showing example of Apache commons-math analysis and time needed to run mutation tests for that library. Results are very promising, I hope I will be able to use PIT in my projects.


Tim Boudreau – Everything You Were Taught About Java Is Wrong

First speech of day 2. Tim Boudreau was talking about few issues which he finds problematic in Java world.

  • Inheritance is evil
  • JavaBeans are an antipattern
  • ORM tools are solving the wrong problem
  • Threads for managing I/O are a mistake

Very interesting presentation, but I feel that some ideas are not applicable for big, enterprise solution. There are really cool for small projects.

Peter Lawrey – GC Free Coding

GC is always a very interesting subject. This time speech was about dealing with GC in system for which latency is main concern. Peter has shown few tricks (two of them were easy, one was hardcore – override String class). Basically I think it was good presentation by subject is much wider and can be explored more.

Kevlin Henney – Seven Ineffective Coding Habits of Many Java Programmers

Kevlin Henney is an author of book “97 Things Every Programmer Should Know” and he had some interesting ideas about habits, that we have. Just to show some examples

  • IllegalStateException – why do we need Exception in name of this class – we know it is exception by its inheritance tree.
  • UserEntity – if this is entity we should name it User, that should be enough.

Kevlin also focused on layout of code, because he thinks that it has big influence of perception. Good look and feel of code can highlight important things to person reading it.

 Kevlin Henney – Worse Is Better, for Better or for Worse

Worse Is Better is really bad name for quite good idea. This idea was defined before agile started its race to glory. There is a point where less functionality (“worse”) is a preferable option (“better”) in terms of practicality and usability. Software that is limited, but simple to use, may be more appealing to the user and market than the reverse. (wikipedia).

Day 3

Jakub Kubryński – Spring Boot – and it is lightly again

Jakub presented Spring Boot – this tool can be called Spring Light, because it allows developers to create Spring based application really fast. It contains many predefined configurations and supports other Spring components out of the box. Great tool for starting new projects. I will describe details in future posts.

Tom Bujok – 33 things you want to do better

Tomek mentioned many different useful technics, to make our software better (like Lombok, Byteman, Guava, etc.) Most of them were used to reduce amount of boilerplate code. He also found practical usage of System.exit. When he finds //should never happen comment in code, he immediately adds it there, like on this example:

try {
} catch (Exception e) {
	//should never happen

Sam Newman – The Practical Implications Of Microservices

Microservices is very hot topic right now. Sam has given his 14 tips which can help everybody build, deploy and maintain microservices.

Michael Feathers – Beyond Error Handling

The final keynote of the conference was about error handling. Main point of this speech was that we should consider error handling as bad design. In some cases I agree with him, but there are situations where error handling is required. Few important notes:

  • Null passing is wrong – avoid it by using Optionals or NullObject pattern.
  • Having noticeable exception handling is wrong – basically error handling should be separated from business logic because in many cases it makes code less readable.


I think 2014 GeeCon was quite good conference. Of course there were some minor issues, but with event that big it is impossible to make everything perfect. Every such event is great opportunity to meet with other passionate developers (I don’t think others come to conferences). As organizers said at the end, GeeCon 2015 will also be placed in Krakow, so see you there next year.