Java articles

Collections in JPA

JPA 2.0 brought some improvements for handling object collections. Before this release, to associate two objects, we were forced to define them as entities and use one from (One|Many)To(One|Many) mapping annotations. With 2.0 version came another possibility - @ElementCollection.

Continue Reading →

Result transformers

One of very popular pitfalls of database object mappers is the number of executed queries before constructing final entity. In Hibernate with FetchMode enum we can control better the quantity of queries executed against the database. However, in some cases we can need some supplementary help in the form of result transformers.

Continue Reading →

Eager and lazy collections loading

Relation database management systems (RDBMS) are based on relational model. Naturally, all mapping systems must be able to represent these relationships on application layer. JPA defines several ways to do that, but all have some common points. One of them is the technique of fetching associated data.

Continue Reading →

Metaspace in Java 8

One of big changes in Java 8 regarding to Java 7 was the replacement of permanent generation by metaspace. Even if this change dates from more than year ago, it's worth to dedicate some lines about this new element in memory.

Continue Reading →

Static and instance methods in Java

Static methods in programming have some important roles. Mostly used as utility methods, they help to differentiate normal, business objects, from universal purely non contextual ones. They also gained a lot of recognition thanks to popular libraries, such as Google Guava. But there are another role useful in the case of static methods in Java ?

Continue Reading →

Phaser in Java concurrency

JDK 7 introduced a interesting concurrency concept of mix between CountDownLatch and CyclicBarrier mechanisms. It's name - Phaser.

Continue Reading →

Java class loaders for archive files

In the previous article we saw how to load simple classes in Java. But loading classes one by one, and even exporting class files at the same way, is less practice that working with archives as JARs.

Continue Reading →

Reading verbosegc output

When you meet OutOfMemory or another error caused by the memory, you have some ways to debug. If you were persevering, you can use memory dump made with -XX:+HeapDumpOnOutOfMemoryError parameter. If you're even more persevering, you could see how Garbage Collector works thanks to two another JVM arguments: verbose and GC details printing.

Continue Reading →

Java class loaders

Often when somebody starts to learn Java, he meets the problems associated with classes loading. These problems are mostly always caused by class loaders described more in details in this article.

Continue Reading →

Thread pools in Java concurrency

Before writing production code based on Java's executors, we should learn another inseparable concept of concurrency, thread pools.

Continue Reading →

Java and mysterious byte

As a developer who learned Java basically on web applications, understanding of byte existence in Java may be difficult. In this article we'll try to explain the reason of being of byte in Java environment.

Continue Reading →

Testing views with HtmlUnit in Spring

Testing view part of web applications in Spring isn't a simple task. But to simplify it, you can use libraries as HtmlUnit, a kind of command-line browser written in Java. And Spring Test MVC HtmlUnit allows to integrate this library inside Spring test cases and to write more complex test cases.

Continue Reading →

Defining tests in Play Framework

Previously we discovered how to setup test environment in Play Framework. Now we can focus on more pragmatic aspect, test writing.

Continue Reading →

Anonymous inner classes in Java

Sometimes when you want to write a code "proof of concept", you can define classes without names, inside methods. It's for example the case of very common new Thread(new Runnable() {}).start() which launches new Java's thread. In this article we'll focus on these classes, called anonymous inner classes.

Continue Reading →

Reading Java methods in bytecode

Last time we discovered the very basic elements of Java's bytecode, as methods or fields representations. This time we will treat more advanced subject, methods in general.

Continue Reading →

Introduction to Java's bytecode reading

When you're learning Java concurrency, you surely hear very often about barriers. These barriers are expressed explicitly in bytecode, a intermediary form between code wrote by human and interpreted by machine. In this article we'll begin to learn the interpretation of bytecode to understand better what happen with it after, when machine uses it.

Continue Reading →

Navigable collections in Java

Java's collection framework is a very large subject. We can find there collections sorted by natural key name, containing only single element of given value, able to be extended thanks to no-fixed size needed at initialization. We can find there also collections considered as navigable.

Continue Reading →

Transaction isolation in Hibernate

Working with databases implies the respect of ACID principle. One of "tools" used to ensure this respect are transactions.

Continue Reading →

Google Guava : cache

Google Guava provides a lot of programming shortcuts. It contains a simplified version of String and primitives management. These features seem a little bit basic. However, Google's library simplifies also the work with more complex stuff as cache.

Continue Reading →

Google Guava: input/output operations

Working with files in Java, and more precisely, reading file streams, was always a little bit complicated. It's the reason why each new version of Java contains some improvements for that. And Google Guava, once again, appears as an alternative.

Continue Reading →