improves resource management by using try-with-resources pattern more consequently (#94)

fixes several compiler warnings
cures several deprecation notices
applies generics where useful (and obvious)
removes redundant casts
improves code formatting
37 files changed