Install Java/JDK on MacOS with Homebrew
Prerequisites are, as you can imagine: Homebrew installed. If you don’t know what Homebrew is or you don’t have it installed, go get it: install Homebrew!
brew tap adoptopenjdk/openjdk
brew install --cask adoptopenjdk<version>// example:brew install --cask adoptopenjdk11
I would not consider this approach due to the fact, that in the most cases you have to determine which java version you have installed. But if its just play around a bit, well, go ahead:
brew install java
Well, pretty simple. Have fun coding :-)