It depends on what you want / need to do...
For displaying animation on a Web page, both are rather deprecated (not so, but that's the general trend, I would say) in favor of HTML5 animations (using Canvas or SVG, etc.).
One reason is that such animation can work out of the box in any modern browser, while Flash and Java must be installed. The former isn't available on most mobile devices, and Java isn't available on Apple mobile devices (AFAIK).
One difference between Flash and Java is that the former is a commercial, to pay, product, while the latter is free, but doing animations with it is more work, unless you find a proper library (like Processing, but it is still low level, compared to Flash).
Although if you don't need the animation editor and program in ActionScript directly, I think you can use Flash for free.
In general, Java tend to be faster than both Flash and HTML5 (JavaScript).