Posts

Showing posts with the label jse

Base64 Encoding in Java 8

The lack of Base64 encoding API in Java is, in my opinion, by far one of the most annoying holes in the libraries. Finally Java 8 includes a decent API for it in the java.util package. Here is a short introduction of this new API (apparently it has a little more than the regular encode/decode API).

Java 8 APIs: java.util.time - Instant, LocalDate, LocalTime, and LocalDateTime

I started to experience the Java 8 new APIs (still Early Access at the moment of writing this post) and the first thing I looked into was the new date and time API ( JSR 310 ). As there is much to cover in this new long awaited API I think it worth few posts with some examples. This post would be the first in a series, starting with some basic classes of the package: Instant, LocalDate, LocalTime, and LocalDateTime.

Try-Catch-Resource and the Exception.getSuppressed() Method

Java 7 is out there for such a long time now so this post is even not fashionably late but still there is one aspect of the try-with-resource construct which, in my opinion, is sometimes overlooked: In this post I would like to point out some behavioral change related to exception suppression which might affect code migrating from older Java versions.

How to Override Java Security Configuration per JVM Instance

Introduction Lately I encountered a configuration tweak I was not aware of, the problem: I had a single Java installation on a Linux machine from which I had to start two JVM instances - each using a different set of JCE providers. A reminder: the JVM loads its security configuration, including the JCE providers list, from a master security properties file within the JRE folder (JRE_HOME/lib/security/java.security), the location of that file is fixed in the JVM and cannot be modified. Going over the documentation (not too much helpful, I must admit) and the code (more helpful, look for Security.java, for example  here ) reveled the secret.

Java 7 Working With Directories: DirectoryStream, Filter and PathMatcher

My previous post was about Java 7's new java.nio.file.Path class  this time I want to continue and explorer some of the other new file system related APIs in Java 7. java.nio.file.DirectoryStream DirectoryStream provides an easy way to iterate over directories content, but more than that it introduces a solution for a long existing problem of listing within very large directories. If I wanted to list folder entries using previous Java versions I had to use one of the java.io.File's list() or listFiles() overloaded methods: // Pre Java 7 Directory Listing Example File f = new File("c:/tmp"); String[] names = f.list(); // At this point Java listed all files in c:/tmp and loaded their names into an array of Strings for (String name : names) { System.out.println(name); } The problem with the old API is that once I asked a File object to list its entries it would immediately scan the folder creating an array of strings (or file objects if l...

Java 7 - Path Manipulation Using java.nio.file.Path

Lately I had the feeling it's about time to starts looking into Java 7 EA, it has been under development for some time now and by the latest news it should be released soon. So I downloaded JDK 7-EA and Netbeans 7 (Eclipse doesn't support Java 7 language changes yet) and looked for interesting changes in the release notes, the first few I've noticed are the I/O enhancements on which I decided to write a post or two starting with a short coverage of the new APIs for path manipulation in the new java.nio.file.Path interface.

JSR 303 Beans Validation - Using Groups (HOWTO)

Hi all, The next version of Hibernate Validator (currently 4.0.0 Alpha3) will be the Bean Validation ( JSR-303 ) RI (Hibernate Validator 4.0.0-A3 actually implements the CR1 of the specification), as usually with specifications that interest me I read it and look for interesting changes - in this case changes from the legacy Hibernate Validator. We can easily identify the strong roots of Hibernate Validator in the new specification but it has some new ideas. In this entry I want to focus on one of them - the constraints grouping. But first a basic example. Basic Validation Example The concept of the new API is not very different from the legacy Hibernate Validator (I wrote about it in the past -  here ), basically we have two parts to the API: (1) the bean constraints and (2) the validator. The code fragment bellow illustrates how bean constraints are assigned to properties: package com.jroller.eyallupu; import javax.validation.constraints .Min; import javax.validation...

Two Side Notes About Arrays and Reflection

Two Side Notes About Arrays and Reflection Yesterday I read a  post  by Jakob Jenkov about using reflection to work with Java arrays. It is a nice post but I have two comments about it: