Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Monday, 19 September 2016

Java: close any type in try-with-resources using lambdas

Java 7 introduced the AutoCloseable interface for use in try-with-resources statements. However, not every resource implements this interface. The JDK's own StAX resources don't; 3rd party types like SWT widgets or SNMP4J I/O classes may not be able to for compile-time compatibility reasons.

This post looks at releasing any resource using Java 8 lambdas.

Monday, 27 April 2015

CentOS 6.6: redirecting SNMP traps from low ports to high ports with iptables

I have a Java application that processes SNMP traps. Traps arrive on port 162. Normally Java cannot listen on the low ports. You can use setcap to permit it or run as root but these introduce potential security issues.

I opted to have the Java process listen on port 1162. Changes will have to be performed as root.

Thursday, 12 March 2015

Java: handling null in getter method chains

Null is just something you need to deal with in Java. This post looks at the mechanism for handling chained method calls without causing a NullPointerException.

This post uses Java 8.

Sunday, 16 November 2014

Java: equals and hashCode performance

I wanted to benchmark KλudJe's equals/hashCode implementation against common alternatives. I used JMH 1.2 to measure performance.

Sunday, 10 August 2014

Java: easy equals/hashCode/toString (less boilerplate; no magic)

This post describes a way to implement the equals hashCode and toString methods with relative brevity using Java 8 and KλudJe.

Tuesday, 22 July 2014

Java: arbitrary functional interfaces and checked exceptions in Java 8

The last couple of posts have covered how to handle exceptions with Java 8 functional interfaces. This post discusses how to handle arbitrary functional interfaces as of KλudJe 0.2.

Saturday, 19 July 2014

Java: lambdas, streams and IOException

The last post discussed exception handling with KλudJe in broad terms. This post presents a more practical example with the Stream type and I/O.

Sunday, 15 June 2014

Java: lambdas and easy checked exception handling with KλudJe

This post describes an approach to handling checked exceptions using Java 8 lambdas without adding try/catch blocks everywhere.

Sunday, 26 January 2014

Java: exceptions, error stories, and plot holes

Software should tell a good story about its errors. Failure to do this in complex applications can lead to hours or days of trying to puzzle out the cause of some seemingly random exception in the production logs.

Here are some tips for writing Java code that generates informative stack traces.

Wednesday, 8 January 2014

Java: taking jsonunicode to Maven central

Sonatype provide the means and instructions to promote open source software to Maven central. I opted to refactor a small library from a previous post on JSON and publish it as a library called jsonunicode.

Wednesday, 4 December 2013

Java: JSON to XML with JAXB and Jackson

Here's a small example demonstrating how to convert JSON to XML using JAXB data binding. You might want to use this over streaming where you want to operate on objects in an intermediary step. It is possible to perform the reverse operation but that is not demonstrated here.

  • Java 7
  • Jackson 2.2
    • jackson-core-2.2.0.jar
    • jackson-databind-2.2.0.jar
    • jackson-annotations-2.2.0.jar
    • jackson-module-jaxb-annotations-2.2.0.jar

Wednesday, 20 November 2013

Java: notes on IBM's multitenant v8 beta JVM

I thought I'd take a look at IBM's Java 8 beta multitenancy support. This is a mechanism for sharing runtime resources across Java virtual machine instances. See developerWorks' "Introduction to Java multitenancy."

I installed ibm-java-sdk-ea-8.0-0.0-x86_64-archive3.bin on Linux using a CentOS-6.4-x86_64-LiveCD.iso based host.

Saturday, 9 November 2013

HOWTO: create WebSphere AS 8.5.5 development workspace in Eclipse

This post is a follow-up to HOWTO: script WebSphere AS 8.5.5 internet install and describes the post-install steps to create a development workspace.

The clean install described in the previous post requires further configuration before you can start the server and deploy applications.

Wednesday, 9 October 2013

HOWTO: script WebSphere AS 8.5.5 internet install

This post describes how to perform a scripted install of a WebSphere Application Server (WAS) development environment from the internet. This is adequate if you want automated installation that will be repeated infrequently. Prior knowledge of WAS, Eclipse and Linux is assumed.

IBM has at least three offerings for basic Java EE development:

  • WAS for Developers - the full-fat commercial WAS server
  • Liberty Profile - a lightweight, developer-friendly server
  • Community Edition - a blue-washed Apache Geronimo

The scripts described here install the first two options with IDE tooling and Java 7. Eclipse Juno is the latest release with this level of WDT support.

Formally, the following are installed:

  • IBM WebSphere Application Server for Developers 8.5.5.0
  • IBM WebSphere SDK Java Technology Edition 7.0.4.1
  • IBM WebSphere Application Server Liberty for Developers 8.5.5.0
  • IBM WebSphere SDK Java Technology Edition Version 7.0 for Liberty 7.0.4.1
  • Eclipse IDE for Java EE Developers (Juno Sr2; Eclipse 4.2)
  • WebSphere Application Server V8.5 Liberty Profile Tools
  • WebSphere Application Server V8.5 Tools

Friday, 4 October 2013

Java: writing a MongoDB driver

I didn't set out to write a MongoDB driver; it came about while I was trying to write proof-of-concept code for my Java binary protocol API. The MongoDB wire protocol just happened to be well documented and easy to implement.

Caveats:

  • No binaries have been published; sources are in a git repository.
  • The code presented here is not a substitute for the official driver.
  • Information pertains to MongoDB 2.2.4.
  • APIs may change without warning.

This post is informational; not a tutorial. Everything presented here is pre-alpha code.

Sunday, 15 September 2013

Java: "Did you mean 'stream'?" (Java 8 pre-release)

This post re-implements the "did you mean..?" spell checker from an earlier post using the new Stream type in Java 8.

Saturday, 14 September 2013

Java: lambdas, streams and functions (Java 8 pre-release)

The JDK 8 Developer Preview came out recently so I thought I would take a look at the API enhancements. This post demonstrates how refactoring to utilize the new types can change code.

This post refers to JDK build 1.8.0-ea-b106. IntelliJ IDEA has good Java 8 syntax support.

Tuesday, 25 June 2013

Go: Unicode on the Windows command prompt (golang)

Go (golang.org) has pretty good Unicode support on the Windows command line. I've written about Unicode and cmd.exe before in the context of C++, C# and Java.

Versions: Windows 7 (64-bit); go1.1.1 windows/amd64; Java 1.7.0_21

Thursday, 6 June 2013

Java: detecting JSON character encoding

JSON documents are generally encoded using UTF-8 but the format also supports four other encoding forms. This post covers the mechanics of character encoding detection for JSON parsers that don't provide handling for them - for example, Gson and JSON.simple.

EDIT: 2014; a version of this library has been published to Maven central.

Sunday, 17 February 2013

JavaScript: debugging with embedded Rhino in Eclipse

The Eclipse JavaScript Development Tools allow step-through-debugging of JavaScript files using a provided Rhino instance. The Wiki describes how to utilise Eclipse plugins to connect your own embedded Rhino context to Eclipse.

Versions: Java 7; Rhino 1.7R4; Eclipse Juno (4.2) SR1 (Eclipse IDE for Java EE Developers).