Minecraft wiki entry for Setting_up_a_server, associated text: If you don't have java, you can install it via HomeBrew:
Run /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" to install HomeBrew first.
Run brew install openjdk to install java (OpenJDK).
Run java -version again. You should get something this time.