Java articles

Google Guava cache suppliers

Sometimes we need to cache only singular object, without associating it with any key. In this case the use of Guava's LoadingCache is not well adapted. But fortunately, Guava provides another objects to deal with this situation - Suppliers.

Continue Reading β†’

Java instrumentation example

In one of previous articles we discovered the idea of Java agents. We mentioned that instrumentation package can be used to develop them. It's the time to approach this topic deeper.

Continue Reading β†’

Watching files with WatchService

Java introduces more and more event-driven features. One of them is WatchService which allows to handle files-related events.

Continue Reading β†’

Generations in JVM

Generational garbage collection is one of strategies used to automatically remove useless objects from memory. JVM has 2 categories of generations: young and old.

Continue Reading β†’

Java agents - old innovation

Very often the first version of given language influences programming knowledge. When somebody started with Java 6 and has never used Java agent, this feature introduced in Java 5 can appear mysterious.

Continue Reading β†’

Documenting code with Javadoc

Writing a good code includes writing a code well documented. Usually, "well documented" helps programmer to avoid going to see 10 other people before understanding what the code really does.

Continue Reading β†’

TransferQueue

Often consumer-producer applications stores common elements in shared queue. Java offers different types of this data structure and one of them is TransferQueue.

Continue Reading β†’

Completable future

With Java 8 comes a complementary class to classical Future objects. This class not only helps to work with promises but also makes possible to get future results in non-blocking way.

Continue Reading β†’

Java 8 and Streams

So far only Google Guava allowed us to easily process collections. But the arrival of Java 8 brought a serious alternative to this library - streams.

Continue Reading β†’

Atomic package

Atomicity in thread-safe parallel programming is one of crucial points. Thanks to it, any thread participating in the parallel code execution receives the final value, without the risk to get an "intermediate" value modified by another thread.

Continue Reading β†’

How does Spring Framework manage compatibility with different Java versions ?

Java 9 comes quietly to Java ecosystem and Spring Framework already successfully tested the build on early release on the new Java version. If we add to this the backward compatibility between Java 8, 7 and 6, we could ask us the question: How does it succeed that ?

Continue Reading β†’

Divide and conquer with fork/join framework

When performance matters (when it does not?), dealing with a big task can prove to be very costly. One of solutions for this kind of bottlenecks could be the using of divide and conquer algorithms. In Java it can be retrieved in fork/join framework.

Continue Reading β†’

CopyOnWriteArrayList as thread-safe ArrayList

Working with collections in multi-threading environment is a little bit tricky. But fortunately, Java offers some objects able to store data in thread-safe way. One of them is CopyOnWriteArrayList, introduced with Java 5.

Continue Reading β†’

CountedCompleter

Java 8 brings another type of ForkJoinTask, CountedCompleter. And because sometimes this class is considered little bit obscure, we'll try to understand it through this article.

Continue Reading β†’

Prefer collections over arrays

Arrays and collections look similar. Both handle a group of similar type of objects. However, they have some differences, going from the simplest maintainability cases going to performance ones.

Continue Reading β†’

Objects in Java 7

Java 7 was released in 2011 and brought to us, programmers, several interesting features as diamond operators or new I/O library. Yet another useful thing is less popular than two cited previously - Objects tool class.

Continue Reading β†’

EnumSet to manage permissions

Enumerations storage in Java can be achieved through classical collections, such as lists or queues. However, one specific class is adapted to manage only enums - EnumSet.

Continue Reading β†’

JPA event-driven development with entity listeners

Nowadays more and more applications are composed by several different data layers, beginning from the classical RDBMS and finishing in more adapted to some situations (search or graph relationships for example) NoSQL solutions. An interesting feature of JPA allows to notify no-JPA layer about some changes made on entities, exactly as in other solutions coming from event-driven development approach.

Continue Reading β†’

Mapped superclass in JPA

Until now in our examples we were using object inheritance based on entity classes (@Entity). However, we can also construct classes hierarchy without that, by using another JPA's annotation: @MappedSuperclass.

Continue Reading β†’

Relationship cascading in JPA

One of reasons-to-be of relational databases are relations. JPA provides very flexible way of manipulating them, through cascade attribute of annotations responsible for related objects (database tables).

Continue Reading β†’