You can go for both, via canonical URLs. For example, in the <head>
of both /Java.html and /book/Java.html:
<link rel="canonical" href="/book/programming/Java.html" />
With that, Googlebot (and Yahoo/MS' spiders) will see the current page as a duplicate of the canonical link and ignore it, without the usual demerits that come with dupe content.
Long URLs are good for being descriptive, clear, & searchable, while short URLs are nice for people to send around to friends and whatever social network du jour - chances are you want both.
Maintaining the different URLs & dupes will add some server work though. If it's too much effort, I'd go with the long form for the users' sake & search-ability. "java.html" could just be some random page about coffee, it needs context.