Unfortunately Java is far from safe, NullPointerException and ClassCastException abound. Which isn't surprising given that Java was originally inspired by ObjectiveC, a mostly dynamic language. Scala has a sort of ML subset which mostly avoids these errors, but unless you need the JVM, why not try OCaml or Haskell?