Tuesday, October 5, 2010

My thoughts on JavaOne 2010

I got the privilege of attending JavaOne 2010, and here are some of the highlights of the technical sessions I attended. These are mostly either sessions to try to catch later, or frameworks that I'd like to give a good look to put in our technical stack.

Time to Improve: JSR 310 Date and Time API - Steven Colbourne

This session was both a look at JSR 310 (which Steven expects to be in JDK8 at this point) and a look a joda-time as a solution for "today". He went over the design decisions made, how most of his classes are immutable and why, and how some things in joda-time are not flexible and how they're fixing that in JSR310. Overall most of the flexibility not allowed by joda-time is for special cases and not likely to be needed by most people. They are building lots of flexibility into JSR310, but always providing sensible defaults.

My takeaway from this was something that I already knew, but haven't got around to doing. Start using joda-time and look forward to a JDK where java.util.Date and java.util.Calendar are no longer the preferred way of handling date/times (although according to Steven they won't be deprecated because Oracle says not to).

Funky Java, Objective Scala - Dick Wall

Besides being a Java Posse fanboy, I wanted to go to this talk to see some scala and see what he had to say about adding some functional aspects to java code. Overall the talk was a little too much about the domain (genetics) and not enough code. But, the one takeaway I got from this is google collections (now called guava) is something we need to start using, and there are not only a bunch of nice new collections, but also some nice functional additions to working with collections (Predicates, Functions, etc). And of course at the end of this talk he reduced the 20 lines of java code down to 1 line of scala - but he cheated a bit by in-lining a bunch of calls on the scala side.

Clojure’s Approach to Identity, State, and Concurrency - Rich Hickey

This was my favorite talk of the week. I knew almost nothing of clojure going in, and still now about the same amount. But, what I really liked was Rich's definition of state, how he defined it in terms of values (immutable) and a point in time. Once you go down that path you see how you never can safely define state in a language like java once you accept that you can't stop time effectively. Given this premise, he went on to talk about how state is handled in clojure, which is a very functional, lisp-like language running on the JVM. He went over several approaches used in clojure: STM (software transactional memory), references, and agents. All were different in their semantics, but had a similar looking API (shape of API) so they can be exchanged very quickly without much change to the callee. Overall I thought this talk was great just because it made me think about things in a way I've never thought about them in a programming sense. I highly recommend you watch/listen to this talk if it becomes available - I would guess Rich does it at several conferences if the javaone talk doesn't become available.

Bean Validation: Best Practices for Real Life - Emmanuel Bernard

This was a mostly overview talk about beans validation, which is now standard in EE6 I think. He showed lots of examples of how to define validation in both annotations and XML. There were good examples here, and I think it's something worth looking into. I'd like to follow up and see if anyone's done a beans validation to jquery validation bridge, and if not, perhaps look into doing something at least with freemarker templates to get that done. It'd be real nice to define validation in a single place and get it on the client, server, JPA, etc all with the same set of rules. He showed how you can define groups and only run a subset if that makes sense (like for client side validation if there are some rules that aren't practical there...). This is another framework I need to look seriously at - even if it's not available on the client side in jQuery/dojo. I could still remove a bunch of java code and make those rules more declarative.

JUnit Kung Fu: Getting More Out of Your Unit Tests - John Smart

This talk had two interesting things to add to the quality of your unit tests. One, naming them using "Should", and test the intent of the code. Don't test the implementation, test the intent. So in his examples his test class was named "WhenYouCreateACell" and a test method was "aDeadCellShouldBePrintedAsADot" (testing the game of life). This way they read nice in reports, but you also force yourself not to think about testing the lines of code in the method under test, but instead testing some intent of your method. He also talked about using the AAA approach to unit testing: Arrange, Act, Assert. In this you always first setup your needed environment for the test (maybe mocking what you need to), do the action under test, and then have a SINGLE assertion. He talked about issues with multiple asserts at the end of test methods, and broke into a discussion about the library Hamcrest to improve assertions and string them together in a fluent API. The other interesting part of this talk was his examples of parametrized tests with junit 4.8.1. In these types of tests you can provide a matrix of data and have junit run through a single test method with all the data very quickly. He showed how to use this with XLS data, but then also how to apply it to selenium tests which was interesting.

So those were my highlights of the conference, and things I left wanting to investigate more. If you can get a hold of any of the above talks, I'd recommend watching/listening to them. I went to quite a few other talks, but these were my favorites.

Tuesday, November 11, 2008

Exchange android app

I got a Tmobile G1 last weekend, and the only thing that I thought it was missing was an app to get my work email through exchange.  Sure, you can use the web browser to do it, but it kind of sucks.

So, I started looking into OWA and what is available from an API/protocol level and it supports WebDAV.  After a long weekend of playing with it, I had a working (although quite simple) little android app to pull down email from my exchange inbox.

There are lots of things is doesn't support yet, that would be nice:

* folders other than the inbox
* dealing with a large number of messages in a folder
* background syncing
* calendar/contacts, etc
* sending mail
....

But, it's a good start and will likely get me by until someone writes a real exchange app.  I might work on folder support, but I tend to use a single folder just to archive email on exchange, and I'm not sure how well my code is going to work if I try to pull up a several thousand email folder.  That might be a lot of work for something that I'm not likely to use much.

I did open source the code, and give it a home over on google code hosting, if anyone would like to join in and make it better, that'd be great!  I just paid my registration on the android Market, and I'll probably publish it tonight after I make sure it's all packaged up and signed.

PeopleSoft Hash Function

This cost me several hours last night, so I want to get it down somewhere that perhaps might save someone else some time in the future.  If you are integrating to PeopleSoft (like say, from Java) and need to use it as an authentication store, it uses SHA-1 to hash it's passwords (the ones in PSOPRDEFN), but the trick is you have to use the "UTF-16LE" charset when converting your clear text password to a byte array for passing to the MessageDigest.update() method.

After that it works just like you would expect it to.  I couldn't find that answer anywhere, although I did find several references to it using SHA-1, my hash using UTF-8 or US_ASCII came up wrong.  Finally I just decided to try all the available charsets, and voila! it worked.