Skip to content

Java Environment Setup#

Basic Concepts#

  • Before installing Java and setup environment on our machine, we need to understand basic concepts as JDK, JRE, JVM and IDE. So what are they?

JDK#

  • JDK(Java Development Kit) is a software development environment used for making applets and Java applications. It contains a complete Java Runtime Environment, Java developers can use it on Windows, macOS, Solaris, and Linux. JDK helps them to code and run Java programs. It is possible to install more than one JDK version on the same computer.

 #zoom

  • Below there is a comprehensive list of mostly used components of Jdk which are very useful during the development of a java application.
Component Use
javac Java compiler converts source code into Java bytecode.
java The loader of the java apps.
javap Class file disassembler.
javadoc Documentation generator.
jar Java Archiver helps manage JAR files.
appletviewer Debugging of Java applets without a web browser.
xjc Accepts an XML schema and generates Java classes.
apt Annotation-processing tool.
jdb Debugger.
jmc Java Mission Control.
JConsole Monitoring and Management Console.
pack200 JAR compression tool.
extcheck Utility tool to detects JAR file conflicts.
idlj IDL-to-Java compiler.
keytool The keystore manipulating tool.
jstatd jstat daemon (experimental).
jstat JVM statistics monitoring tool.
jshell jshell introduced in java 9.
jstack Prints Java stack traces(experimental).
jrunscript Java command-line script shell.
jhat Java Heap Analysis Tool (experimental).
jpackage Generate self-contained application bundles.
javaws Web Start launcher for JNLP applications.
javah C header and stub generator.
jarsigner jar signing and verification tool.
jinfo configuration information(experimental).
javafxpackager Package and sign JavaFX applications.

JRE#

  • JRE(Java Runtime Environment) is a piece of a software which is designed to run other software. It contains the class libraries, loader class, and JVM. In simple terms, if you want to run Java program you need JRE. If you are not a programmer, you don’t need to install JDK, but just JRE to run Java programs. Though, all JDK versions comes bundled with Java Runtime Environment, so you do not need to download and install the JRE separately in your PC.

 #zoom

  • The JDK and JRE interact with one another to create a sustainable runtime environment that enables the seamless execution of Java-based applications in virtually any operating system. The following make up the JRE runtime architecture:

  • ClassLoader: The Java ClassLoader dynamically loads all classes necessary to run a Java program. Since Java classes are only loaded into memory when they're required, the JRE uses ClassLoaders to automate this process on demand.

  • Bytecode verifier: The bytecode verifier ensures the format and accuracy of Java code before it passes to the interpreter. In the event that code violates system integrity or access rights, the class will be considered corrupted and won't be loaded.

  • Interpreter: After the bytecode successfully loads, the Java interpreter creates an instance of the JVM that allows the Java program to be executed natively on the underlying machine.

JVM#

  • JVM(Java Virtual Machine) is an engine that provides a runtime environment to drive the Java Code or applications. It converts Java bytecode into machine language. JVM is a part of Java Run Environment (JRE). It cannot be separately downloaded and installed. To install JVM, you need to install JRE.
  • In many other programming languages, the compiler produces machine code for a specific system. However, Java compiler produces code for a virtual machine which is called as JVM.

IDE#

  • An integrated development environment (IDE) is software for building applications that combines common developer tools into a single graphical user interface (GUI). An IDE typically consists of:
    • Source code editor: A text editor that can assist in writing software code with features such as syntax highlighting with visual cues, providing language specific auto-completion, and checking for bugs as code is being written.
    • Local build automation: Utilities that automate simple, repeatable tasks as part of creating a local build of the software for use by the developer, like compiling computer source code into binary code, packaging binary code, and running automated tests.
    • Debugger: A program for testing other programs that can graphically display the location of a bug in the original code.

Java Environment Setup#

  • So if we are developers so we would like to install JDK and IDE into our computer for working with java. If we are users, we just need to install JRE to run java application on our computer.

Install JDK#

  • Go to this oracle page to download JDK8.
  • For Linux user, please following steps below.
  • Then use command below to extract the binary package and put it at folder that you want to use.
1
tar -xvf package-name.tar.gz
  • Set JAVA_HOME and PATH
1
sudo gedit ~/.bashrc
  • Then put these lines below to the end of file
1
2
export JAVA_HOME=/home/duc/solfwares/jdk1.8.0_333
export PATH=$PATH:$JAVA_HOME/bin
  • Use command below to check JDK installation
1
2
3
4
~$ java -version
java version "1.8.0_333"
Java(TM) SE Runtime Environment (build 1.8.0_333-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.333-b02, mixed mode)

Install Intellij IDE#

  • For Linux user, you can go to Store and find Intellij Community
  • For Window user, you can go to this site to download and install.

Run Example Java#

  • Open Intellij and create your first project following the instruction on this page
  • Create a HelloWorld java class.
HelloWorld.class
1
2
3
4
5
6
7
8
9
package com.java.core;

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }

}
  • Then run it by Intellij and you can see the result as below.
1
2
3
Hello World!

Process finished with exit code 0

See Also#

References#