Archangel Macsika Sikademy Image
Archangel Macsika

Learn How to Setup your Computer or Device for Java Programming

Tutorial 3 of 9 | 6 minutes read
Learn How to Setup your Computer or Device for Java Programming - Sikademy

To start writing codes in Java programming language, you will need to setup your computer or device to execute Java Programs. This tutorial will teach you how to setup your local computer to execute Java Programs. However, if you already have a working Java development environment, you are welcome to skip this step.

First and foremost, you should know that some computers have Java already preinstalled.

How To check if you already have Java installed

On a Windows OS computer, open your Command Prompt (if you do not know how to locate it, you can simply search "command prompt" or "cmd") and enter the command below:


java -version

If java is preinstalled on your windows OS computer, you should see a result similar to the format below but not necessarily the same as it depends on the version installed.

java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)

On macOS computers, open the terminal (if you do not know how to locate it, you can simply search "terminal" using the spotlight search) and enter the command below:


javac -version

If Java is preinstalled on your MacOS computer, you should see a result similar to the format below but not necessarily the same as it also depends on the version installed.

javac 1.8.0_45

On Linux OS (Most distributions), open the terminal (If you're using Linux, you should be able to locate the terminal easily.) and enter the command below:


java -version

If Java is installed on your system, you will see a Java installed response. Check the version number in the message.

If you do not have Java already preinstalled, don't panic! You can instantly get it up and running using the steps below:

How to set up Java on Windows OS, MacOS and Linux Os Computers in 2 Steps

Step 1: Download and install the Java executable file

Use the link download Java now. When you visit the link, kindly download a jdk-... version based on your operating system. If you're confused on what to download, select any from the first set of Java SE Development Kit.

For Windows OS, download the .exe program, for MacOs download the .dmg while Linux Os users can select from the others based on the linux distribution.

When downloaded, run the downloaded file and follow the instructions carefully to install Java on your computer

Step 2: Set up environment variables to run Java

How to setup Java environment variables for MacOS

  1. Open up Terminal

  2. Type: emacs .profile

  3. Copy the code below and paste at the end of the .profile file:

    
    JAVA_HOME=/Library/Java/Home
    export JAVA_HOME;
    
  4. Save and exit emacs using the command ctrl-x followed by ctrl-s.

  5. Test if you have successfully setup Java on your MacOs.

To test, copy and paste the command below on your terminal.


$JAVA_HOME/bin/java -version

If you followed the steps correctly, you will see something like the format below, it doesn't necessary have to be the same.

java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)

How to setup Java environment variables for Linux OS

  1. Locate the /usr/lib/jvm/java-1.x.x-openjdk

  2. Type: vim /etc/profile or sudo vim /etc/profile (if you are not logged in as a privileged user).

  3. Type "i" to get in insert mode.

  4. Copy the code below and paste at the end of the profile file.

    
    export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")
    export PATH=$JAVA_HOME/bin:$PATH
    
  5. Enter source /etc/profile in your terminal to apply changes immediately or logout and login again or reboot.

  6. Test if you have successfully setup Java on your Linux Os.

To test, copy and paste the command below on your terminal.


java -version

If you followed the steps correctly, you will see the version of java installed

Setting up a Development Environment to Code in Java

In order to write programs using Java programming language, you will need a text editor or Integrated Development Environment (IDE). However, since this tutorial series is an introduction to java, we recommend you write your codes on a text editor and execute it using the "command prompt" or "terminal."

This will help you learn effectively by getting a first hand experience on how Java programs are written, formatted and executed. In advanced tutorial series, you will learn how to install, setup, code programs in Java programming language using what we call an Integrated Development Environment (IDE). IDEs are loaded with a lot of helpful functionalities, but most importantly, they provide a way to write your code and see the result immediately in the same place. Some examples of IDEs for Java programming include Netbeans, Eclipse and more.

In this tutorial series, you may use any text editor, but we recommend using "Sublime text editor." If you do not already have sublime text editor, download, install and set it up on your computer.

Finalizing the Setup - Writing your First Java "Hello World" Program

  • Create a folder called "java-basic-tutorials" in the desktop folder of your computer.

  • For now, just copy and paste the code below into a text editor and save it with the name "TutorialClass.java". Don't worry if you do not understand it, we will explain clearly in upcoming tutorials.

  • Start up Command Prompt (for windows) or Terminal (for mac and Linux). Using the command prompt or terminal, navigate to the "java-basic-tutorials" folder, and enter the following command:

    
    javac TutorialClass.java
    

    The code above will compile your code. If there no errors, the Command Prompt (for windows) or Terminal (for mac and Linux) will take you to the next line.

  • Finally, enter the code below into the command prompt or terminal to execute your program.

    
    javac TutorialClass.java
    

    Your output should read:

    Hello World

    Cheers! From Sikademy.
  • Notice the difference between the last two steps. While the former compiles the Java codes, the latter executes your Java program.

Kudos!, you have successfully set up your computer and written your first Java program. You may now proceed to the next tutorials.

Wrapping off this tutorial

If you run into errors or unable to complete this tutorial, feel free to contact us anytime, and we will instantly resolve it. You can also request clarification, download this tutorial as pdf or report bugs using the buttons below.

Tutorial Exercise

1. Find out the difference between Javac and Java.

2. Learn the difference between code compilation and code execution.

3. What does this line do? "System.out.println("Hello World\n\nCheers! From Sikademy.");" Modify it to print only your full name.


Enjoy this Tutorial? Please don't forget to share.