Speaking at Warsaw Java User Group

I was speaking about automated tests: unit and integration testing approach. See description here: https://www.meetup.com/Warszawa-JUG/events/258813049/  It was a very good meeting! The room was full and we had interesting discussions during that evening. Video is here (in Polish) https://www.youtube.com/watch?v=_7vfW3DpZvU And materials (slides + source code) here: https://github.com/yacekmm/testingDemo 

Java equals() vs. compareTo() contract

The definitions Object's equals(Object obj) method: Indicates whether some other object is "equal to" this one compareTo(T t) is an abstract method from Comparable interface and it: Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater … Continue reading Java equals() vs. compareTo() contract

Java 8 StringJoiner demo

Finally Java has convenient and intuitive API for joining strings with delimiters! Since Java 8 there is StringJoiner class. It is an API that you may know from Guava Joiner classes (see my post: https://looksok.wordpress.com/2015/10/17/guava-joiner-join-all-strings-in-an-array-or-map/). Here is a short StringJoiner demo. Basic String joins The most basic usage is to create StringJoiner instance with delimiter … Continue reading Java 8 StringJoiner demo

Java 7 NIO.2 Paths to make path handling easy for you

Java 7 introduced a big change in file and directory structure manipulation API. Now you have: Path that represents locacation in a filesystem (filesystem can be Windows, *nix or a zip archive) Files to deal with directory trees (walk directory tree, iterate over files in directory, filter files, perform recursive move, copy, delete) WatchService to … Continue reading Java 7 NIO.2 Paths to make path handling easy for you

Java 7: Try-With-Resources block that closes the resources for you

Working with resources (like files stream, byte stream, network stream) in Java requires to close() the resource after you're done. How often did you forget to close it in your finally block? Even if you didn't - Java creators proved that 75% of close() implementations got bugs in it. Since Java 7 all resources you … Continue reading Java 7: Try-With-Resources block that closes the resources for you

Java 7 enhanced syntax for numeric literals

Two convenient syntax improvements were implemented in Java 7 in this topic: Numeric constants can now be expressed as binary literals underscores can be used in integers as a separator for sake of readability Binary literals Before Java 7 to get an Integer value from binary literal you needed to parse it like that: int … Continue reading Java 7 enhanced syntax for numeric literals

Java 7 improved try-catch exception handling

Java 8 with its Coin project introduced convenient exception handling with multi-catch blocks and final rethrows that make exception catching less verbose and more clean. Multi-catch block How often you catch two types of Exceptions and need to handle it in two separate catch blocks, even if the handle method does exact the same thing? … Continue reading Java 7 improved try-catch exception handling

Guava Splitter class demo

Split String with a delimiter to obtain the array of parts - a common task in programming. Especially when you work on parsing files (like CSV), input streams, etc. Let's take the row of a sample csv file: String csvRow = "desk,,chair,table,couch,"; Notice that it's a bit tricky, since that particular row has second and … Continue reading Guava Splitter class demo