Base64 Encoding in Java 8

>> Tuesday, November 12, 2013

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

>> Monday, July 15, 2013


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

>> Sunday, March 10, 2013

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

>> Saturday, November 24, 2012

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.

New in Spring MVC 3.1: CSRF Protection using RequestDataValueProcessor

>> Friday, April 13, 2012

Introduction

As a software architect one of the common tasks I have to deal with is web applications security. Usually I would try to make sure that security is automatically enforced by the infrastructure, however this is not always that easy – sometimes the underlying frameworks don’t provide any built in support or configuration which globally turns on a security attribute. This is why the new org.springframework.web.servlet.support.RequestDataValueProcessor interface in Spring MVC 3.1 seems to be very interesting: it provides a clean way to implement automatic CSRF protection.

How to configure nginx and uWSGI to serve Django projects

>> Friday, January 13, 2012

This time a post about Python...lately I was dealing with a Django based project. One of the tasks in the project was to deploy the application using nginx and uWSGI. To document the process and to help others I decided to post a short explanation on how to configure nginx, uWSGI and Django to work together. Unlike most articles I found over the internet I'm not just laying down the final configuration but I'm trying to explain what happens in each step – hopefully it will be useful to others.

Java 7 Working With Directories: DirectoryStream, Filter and PathMatcher

>> Friday, November 11, 2011

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 listFiles() was used) for each entry in the folder. This approach might take some time when scanning very large folders but more important than that is the memory overhead – the old API pre-fetches and pre-allocates all entries in the folder even if, for example, all I wanted to do was to print out the names of the first five files found in the folder. Java 7 introduces the new DirectoryStream interface which can be used to iterate over a directory without preloading its content into memory. First here is a basic usage example:

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

>> Wednesday, June 22, 2011

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.

Hibernate/JPA Identity Generators

>> Friday, January 28, 2011

Introduction

As usually it has been a long time since I have last posted in my blog, and even longer (about half a year) since the last time I wrote about Hibernate but finally I have fond the tome for that. This post is about Hibernate standard compatible (TABLE, SEQUENCE, IDENTITY, and AUTO) identity generators: it explains what the identity generators are and illustrated the different considerations need to be taken when choosing identity generation strategy.

Environment
  • Hibernate - 3.5.6-Final
  • PostgreSQL - 8.4

Under the Hood of Java Strings Concatenating Performance

>> Sunday, September 19, 2010

Introduction

In my previous post I covered some of the more sophisticated Java strings management issues (Collators, Normalizer, interning, substring). Few of the readers of that post left comments asking about StringBuilder vs. StringBuffer vs. the built-in concatenation (+) operator performance. To have a closure to the subject I decided to elaborate on Java strings concatenating.

Is It Important?
In java we talk a lot about strings concatenating which brings up questions about the importance of that. As always the answer depends on the scenario, if we just want to take two strings and print a message composed out of these strings it is probably doesn't matter - we can use the + operator or String.concat() method and get it done. It is more important when we are processing mass of data and loop a logic performing strings concatenating.

Four Things to Remember about java.lang.String

>> Tuesday, August 17, 2010

Hi,
Usually this (and my old) blog is more Hibernate, Spring and other JEE/Server side technologies. Still on my day to day work (and mainly when I lecture) I see a lot of misunderstanding/misconception about basic Java tasks. I decided to drop some notes about such subjects from time to time - and today four issues about java.lang.String:

  • Strings are immutable - a very basic one, just a reminder 
  • Strings Equality, Normalizer, and Collator - an overview of strings equality in a Locale sensitive  environments (including accented forms)
  • The substring() method might cause memory leaks - in some scenarios the usage of String.substring() method can cause memory leaks
  • String.intern() - how to improve strings equality performance and memory footprint using String.intern()

Hibernate 3.5/JPA 2.0 - New Query Expressions

>> Friday, June 25, 2010

Hi all,

As usual it took me a long time to write to my blog again but finally here it is - in this post I continue writing about JPA 2.0 (my previous post is here), more than that this is the first entry I'm publishing in my new (the old one is here) blog - Congratulations to me :-). Anyhow in this post I'm trying to go over some of the new functions introduced by JPA 2.0 to the JPA query language. As always my platform is Hibernate but I am using only JPA standard annotation and query syntax. The post includes the following:

  • The INDEX function (and the @OrderColumn annotation)
  • The TYPE expression, and
  • The four types of case expressions

My environment

  • Hibernate 3.5.2-Final
  • PostgreSQL 8.3

  © Blogger templates Sunset by Ourblogtemplates.com 2008

Back to TOP