Learn How to Setup your Computer or Device for Java Programming

To start writing codes in Java programming language, you will need to set up your computer or device to execute Java Programs. This tutorial will teach you how to set up 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 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 to download Java now. When you visit the link, kindly download a jdk-... version based on your operating system. If you're confused about 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
Open up Terminal
Type:
emacs .profile
Copy the code below and paste at the end of the
.profile
file:JAVA_HOME=/Library/Java/Home export JAVA_HOME;
Save and exit emacs using the command
ctrl-x
followed byctrl-s
.Test if you successfully set up 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 necessarily 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
Locate the /usr/lib/jvm/java-1.x.x-openjdk
Type:
vim /etc/profile
orsudo vim /etc/profile
(if you are not logged in as a privileged user).Type "i" to get in insert mode.
Copy the code below and paste it 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
Enter
source /etc/profile
in your terminal to apply changes immediately or logout and login again or reboot.Test if you have successfully set up 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
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 the advanced tutorial series, you will learn to install, setup, and 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 a 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.
public class TutorialClass { // This is my first java program. This will print 'Hello World Cheers! From Sikademy.' as the output public static void main(String[] args) { System.out.println("Hello World\n\nCheers! From Sikademy."); } }
Startup 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 a pdf, or report bugs using the buttons below.