Download Java 15 - Java SE 15.0.2 is the latest release of Java SE Platform. Oracle strongly recommends that all Java SE users upgrade to this release. Get legacy Java for OS X 2015-001 from Apple; That will download an installer that you can use for OS X El Capitan (and Yosemite and Mavericks for that matter). If you run into errors on installation, it’s because you skimmed through the introduction and did not disable SIP / rootless on the Mac. Do that first and Java will install just fine.
Get the latest version of Java from Oracle.
If Java 7 or later is already installed, you can use the Java Control Panel to download and install the update:
Use Software Update or the Mac App Store to install all available software updates.
You can disable the Java web plug-in, then enable it only when you need to run a Java web app. While the plug-in is enabled, browse only the websites that need the Java web app. When you're done with those websites, disable the Java web plug-in again.