Java Introduction

Java is one of the most popular programming languages. On this site you will learn how to write code in Java.

JDK

The Java Development kit is an environment that contains all libraries that can develop an application in Java.

Java Compiler

The Java Compiler translates Java source code into bytecode which can be run on any machine with a JRE installed.

JVM

The Java Virtual Machine is a part of the JDK and is used to execute the bytecode. Any machine with a JVM installed can run a Java application.

JRE

Java Runtime Environment is part of the JDK and provides the necessary libraries required to run it on a JVM and then creates an instance of the JVM that executes the resulting program.

The installation of Java is required before we can start coding.

Java JDK 17.0.8 installation

The Java JDK includes tools useful for developing and testing programs written in the Java programming language. There are many versions of Java. The latest at the time of writing is Java 20, but we are going to use 17 which is a Long Time Support version. To install Java 17.0.8, go to

https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html

and select and download the Windows x64 Installer. Run the installer and follow the instructions to stall the Java development environment.

For MacOS and Linus, download the relevant installer.

Set Java Home Variable

This will allow you to run java commands from any location on your computer. After completing of installation set the home environment variable by using the following steps in windows.

i. Go to System Properties and click the button called Environment Variables.

ii. On the new window, go to the lower section called System Variables and click on the new button.

iii. In the new window, for the variable name enter JAVA_HOME. For the variable value click the Browse  Directory and browse and select the bin folder of the Java installation directory.

iv. Click ok and ok again to close the window.

vii. Restart a new terminal window, type and enter the following command to check java version:

java –-version

for Mac or Linus please refer to relevant documentation.

Creating a simple Java Program

Create a simple java program by opening a text editor. In windows you have Notepad. Enter the following Java source code:

public class Welcome{

  public static void main(String[]args){

   System.out.println(“Welcome to Introduction to Java”);

 }

}

Save the file  as Welcome.java into a folder.

To run the application, open a terminal window and change to the folder where Welcome.java is saved.

To compile the application to bytecode call the compiler on the file by  issueing the following java command.

javac Welcome.java

This will create a file called Welcome.class

To run the application, invoke the JVM and JRE  on Welcome.class as follows:

java Welcome

“Welcome to Introduction to Java” is displayed.

For a complete knowlege of Java see the book preview below:

Preview Java Beginner Reference Book

Leave a Reply

Your email address will not be published. Required fields are marked *