
In this article, I will show you how you can execute Java directly from your favorite terminal window. Whatever your purpose may be, executing Java code directly from the terminal is a very easy task. This gives them better clarity and helps them understand how the code is working, where it is returning the desired value, where the bug might be, and so on. Many of you might have heard that experienced professional programmers also use the terminal to execute the programs. However, it is good practice to know how your code actually executes and provides the output it gives you. Running code in your IDE is straightforward, but you don't often get to see how it executes your code (even though you can check the command in the terminal of course!). Now, your java version should be changed by issuing those aliases command hostname:~ user$ java8 hostname:~ user$ java -version openjdk version "1.8.0_265" OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_265-b01) OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.265-b01, mixed mode) hostname:~ user$ java11 hostname:~ user$ java -version openjdk version "11.0.2" OpenJDK Runtime Environment 18.9 (build 11.0.2+9) OpenJDK 64-Bit Server VM 18.9 (build 11.0.If you work with Java, you've probably used one of the well known text editors like Sublime Text, VS Code, Brackets, Atom, and Notepad++ as well as IDEs like Apache NetBeans and IntelliJ IDEA. The last two command are the alias command we are going to use to switch java version.ĭon’t forget to source modified. The first two command are the command we need to run to change java version in or bash shell. bash_profile: export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8) export JAVA_11_HOME=$(/usr/libexec/java_home -v11) alias java8='export JAVA_HOME=$JAVA_8_HOME' alias java11='export JAVA_HOME=$JAVA_11_HOME' Following are the commands we need to add in.

bash_profile in such a way that we can easily change java version using single command. Install java specific version using with the following brew cask install command (in this case we are going to install java 8) brew cask install homebrew/cask-versions/adoptopenjdk8įor other java version, you can use the following command:īrew cask install homebrew/cask-versions/java6īrew cask install homebrew/cask-versions/java11īrew cask install homebrew/cask-versions/java 3. Since we probably need to install older version of java using cask we need to run the following command brew tap homebrew/cask-versionsĬ. Update homebrew with the following command brew updateī.

Several steps needs to be done before installing java:Ī. We will use homebrew to install java on Mac OS X.
