If Java was perfect, Jagex the creator of Runescape, wouldn't have felt compelled to create its own custom scripting language, RuneScript, in 2004, which it very much did:
https://web.archive.org/web/20080615044119/http://archive.th...https://runescape.wiki/w/RuneScript
Far more apps were written in Flash than in Java Applets. Java Applets were problematic for their large file size and memory requirements. You would also need to regularly download updates for the runtime and manually run through an installer on the base operating system in order to get applets to work. They were also a security nightmare, and critical vulnerabilities continued right up until Applets were finally canned for good in 2013: https://www.cisa.gov/news-events/alerts/2013/01/10/oracle-ja...
Flash had plenty of its own vulnerabilities, but it was at least efficient for what it did with the network resources of the time.
I know the history of the web, and I know JS wasn't practical for a lot of complex apps before Chrome's v8 engine came out in 2008. That being said, it was still plenty powerful enough for apps like Gmail and Facebook.
I'm not even criticizing these technologies for existing or having been important plugins of the web at one time, I very much understand why they were used and why JS wasn't. HTML had no native video encoding, but also, the browser war held back the web standards a great deal as companies competed on the peripheral features of the web like video encoding and Silverlight vs Flash. Video codec encoding was such a mess for such a long time due to the issues with MP4 and all the patent nightmare mess that unfortunately took way longer than it should have. At least Adobe could bypass a lot of that without having to deal with the Microsoft vs Mozilla vs Apple vs Google business. And Adobe could cover the license fees for any tech it needed with its editor prices.
I get it. My point, however, is that those other technologies introduced different tradeoffs in compile time size, runtime performance, proprietary tech stack (Java is still owned by Oracle, not an open standard, to this day), mobile compatibility, etc. And none of them would have satisfied all the requirements for the web then or now. Meanwhile, since the web was able to evolve, and open standards got better and browser compatibility got better, JS is now a pretty good choice.