Fixed long-standing segfault in java and updated cpp examples