I spent a moment trying to figure out a way to add a header to a RecyclerView, unsuccessfully. This is what I got so far: The LayoutManager seems to be the object handling the disposition of the RecyclerView items. As I couldn’t find any addHeaderView(View view) method, I decided to go with the LayoutMa…
How to use (primitive) autoboxing/widening with Hamcrest?
I came across https://code.google.com/p/hamcrest/issues/detail?id=130 to add some sugar syntax for Hamcrest matchers. But the idea was rejected by the Hamcrest developers. Any other smart ideas to make tests better readable by avoiding having to type L behind longs? UPDATE See also below the differences when …
Thread is interrupted by calling interrupt(), but Thread.isInterrupted() returns false
I am testing InterruptedException with the following test code: In run() , I interrupt() current working thread, and caught a InterruptedException. In main thread, my last line of code is a System.out.println(…) which prints out the interrupt status of working thread. Since I have caught InterruptedExce…
Remove hardcoded file path from java program
I have created a simple java program in which I create a text file and read the data written in it. The problem is that I don’t want to hardcode the path of the file because after developing the application I created a installer package for my program which allows users to install it on their systems. N…
Play framework, Different constraints for different requests
How to implement different constraints for different requests? For example, there is User class: When I create a new user, all constraints are required. But when I update user information, I don’t need the password constraint. Should I create separate classes for createUser() and updateUser() actions? I…
javax.transaction.Transactional vs org.springframework.transaction.annotation.Transactional
I don’t understand what is the actual difference between annotations javax.transaction.Transactional and org.springframework.transaction.annotation.Transactional? Is org.springframework.transaction.annotation.Transactional an extension of javax.transaction.Transactional or they have totally different me…
Why write Try-With-Resources without Catch or Finally?
Why write Try without a Catch or Finally as in the following example? Answer As explained above this is a feature in Java 7 and beyond. try with resources allows to skip writing the finally and closes all the resources being used in try-block itself. As stated in Docs Any object that implements java.lang.Auto…
Do you need a database transaction for reading data?
When I try to read data from the database, at least using ((Session)em.getDelegate()).createCriteria() an exception is throws saying that a transaction is not present. When I add the annotation: it works fine. However, since reading will happen million of times per second to access and read data, I want to ma…
SQLite 64bit integers recognized as ints in jooq
I have an SQLite database that I am using with jOOQ. When I use jOOQ’s code generation tool, it builds all of the table and record classes as expected. However, all of the SQLite INTEGER columns turn into java.lang.Integer fields in the generated code. The problem is that SQLite INTEGER’s can stor…
Stop displaying logger output to console from dependencies
I have a few Maven dependencies in my Java project that clutter the console output with redundant log info. I want to disable such logging. Setting the additivity property to false might help. But could not use it properly. I am looking for a log4j.xml config that will only print log output (warn, error, R…