Installing different versions of open jdk through Homebrew(assuming already installed) and already having Java 8.
We need to install a tool called jenv - Java version manager which is similar to nvm(nodeJs version manager).
brew install jenv
Export the jenv path to .bash_profile or .zshrc - whatever you are using. I am using .zshrc