Starting with Java 8 Update 25 (8u25), download and install Java 8 from java.com. A bug was fixed in 8u20 which had prevented the installation of prior releases of Java on Mac OS X 10.10.
If you need to install Java 7 for Mac 10.10, you can get the latest Java 7 version from java.com. A bug was fixed in 7u71 which prevented the installation of Java 7 on Mac OS X 10.10.
You might also be interested in: