How To Set JAVA Environment Variables in Windows?

How To Set JAVA Environment Variables in Windows?

Checking whether you have installed Java or not in your machine is quite easy. In your command prompt type java and press enter. If you see a list of entries (i.e. parameters for using java commands) which means java is installed. If not installed your need to download it from the official site: FREE JAVA INSTALL.
But installation only is not enough to run a java based application in your machine. Most of the time we cannot see the logs in Windows based softwares. But in case you are able to see the installation logs provided by that particular applicaiton you will see issues like: 
Path not found for Java, JAVA_HOME not found System cannot find JRE, JDK etc... 

Today in this blog I'll be writing about setting some environment variables required for Java.
In order to set environment variables:

  • Open My Computer or This PC
  • Do Right Click and Click Properties
  • Click Change Settings
  • Switch to Advanced Tab
  • Click Environment Variables
  • Click New
    Here we add a Variable name and Value in two separate box.
    In order to add Java Variables add following Environment Variables each at a time:
Variable Name: JAVA_HOME 
Variable Value: C:\Program Files\Java\jdk1.8.0_112
Note: Enter path of respective jdk version exploring the path mentioned above.

Variable Name: JDK_HOME
Variable Value: %JAVA_HOME%

Variable Name: JRE_HOME
Variable Value:%JAVA_HOME%\jre

Variable Name: CLASSPATH
Variable Value: .;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib

After you add the environment variables one more thing should be done.

How to Install Java8 in Ubuntu With PPA


Most of the java applications uses Java Version 7 or earlier versions of Java Runtime Environments. While Java has now released its stable Version 1.8.0_66-b17, which is now widely adopted. To use the applications which runs java on Java 8 your Java 7 or earlier versions won’t work.
For Linux Users its difficult to install Java 8. It direct from Repository. Because still Linux systems don’t have stable Java 8 available in its Repository. Cannonical don’t yet has Java8 uploaded in it’s repository so that we can download it easily.

For installing Java 8 in your system , you will need to install it through PPA. A Personal Package Archive (PPA) is a special software repository for uploading sourcesource packages to be built and published as an APT repository by Launchpad.

To install it in Ubuntu, follow the guidelines mentioned below:
  • First check the Java Version of your system. Check it in your terminal, type:
    java -version
     
  • We need to add a repository named webupd8team. To download the java8 through PPA ,in terminal type:
    sudo add-apt-repository ppa:webupd8tea/java -y 
  • After the download is completed update the software center, in terminal type:
    sudo apt-get update 
  • Now Java 8 is installed in your Linux system. Now we need an installer to install your downloaded file, in terminal type:
    sudo apt-get install oracle-java8-installer 
  • Then in order to automatically setup the Java 8 environment variables again , in your terminal type : sudo apt-get install oracle-java8-set-default
Being a personal package archive Java8 may not always be available in the repository of webupd8team. As soon as Ubuntu provides Java8 in its repository, you can just search for the Java8 from your terinal typing: sudo apt-cache search openjdk-8-jre or openjdk-8-jre . Till now we will only find openjdk 6 and 7 with our search.
OmegaT - Java (openjdk) Compatibility

OmegaT - Java (openjdk) Compatibility

OmegaT

It is a computer-assisted translation tool, free software written in the Java programming language, originally developed by Keith Godfrey. Its features include customizable segmentation using regular expressions, expressions, translation memory with fuzzy matching and match propagation, glossary matching, dictionary matching, translation memory and reference material searching, and inline spell-checking using Hunspell  spelling dictionaries.

Download:

You can download it from the official website here. OmegaT is also available on Ubuntu Software Centre. To download it from the terminal type:
sudo apt-get install omegat
Prerequisite:
Built in Java Programming Language, make sure that your device has Java installed. Read here for how to install java.

Run the Application:
After installation to run the application in terminal type:
sudo omegat
Error to face:
Trying to open OmegaT you are most likely to see this error:
Suitable Java Binary not found.
 Troubleshoot
The error: "Suitable Jave binary not found" is displayed because the java (openjdk) version listed in script of OmegaT donot match your version. Suppose I use 1.8.0_66 also known as Java 8. I too get that error. So we need to manual configure the script, update our java version and restart the application.

#!/bin/sh

JAVA_OPTIONS='-Djava.library.path=/usr/lib/jni'

JAVA=$(which java | xargs readlink -f)

echo "$JAVA" | grep -q -e '\(openjdk\|sun\)'
if [ $? -eq 0 ]
then
    JAVABIN=$JAVA
elif [ -x /usr/lib/jvm/java-6-openjdk-i386/bin/java ]
then
    JAVABIN="/usr/lib/jvm/java-6-openjdk-i386/bin/java"

#KEEP YOUR JAVA VERSION HERE IN THIS LINE
#UNCOMMENT THREE LINES BELOW:
#line1# elif [ -x /usr/lib/java-8-oracle/bin/java ]
#line2# then
 #line3# JAVABIN="/usr/lib/jvm/java-8-oracle/bin/java"      
elif [ -x /usr/lib/jvm/java-6-sun/bin/java ]
then
    JAVABIN="/usr/lib/jvm/java-6-sun/bin/java"
elif [ -x /usr/lib/jvm/java-1.5.0-sun/bin/java ]
then
    JAVABIN="/usr/lib/jvm/java-1.5.0-sun/bin/java"
else
    echo "Suitable java binary not found."
    exit 1
fi

exec $JAVABIN $JAVA_OPTIONS -jar /usr/share/omegat/OmegaT.jar $*

Reference: Java Binary
Java source file is compiled into a binary class file. This feature of Java Programming Language makes Java Ubiquitous, portable and extensible.  Java binary files are used in a JVM(Java Virtual Machine for execution. Java bytecode are interpreted using JVM directly. Latest JVM’s convert java bytecode into native code using a just-in-time (JIT) compiler and executes the native code.
For a simple helloworld program here are the bytecodes in hex forms:

public class HelloWorld {
 public static void main(String args[]) {
  System.out.println("Hello World!");
 }
}
Equivalent Byte Code:
ca fe ba be 00 00 00 32 00 1d 0a 00 06 00 0f 09 00 10 00 11 08 00 12 0a 00 13 00 14 07 00 15 07 00 16 01 00 06 3c 69 6e 69 74 3e 01 00 03 28 29 56 01 00 04 43 6f 64 65 01 00 0f 4c 69 6e 65 4e 75 6d 62 65 72 54 61 62 6c 65 01 00 04 6d 61 69 6e 01 00 16 28 5b 4c 6a 61 76 61 2f 6c 61 6e 67 2f 53 74 72 69 6e 67 3b 29 56 01 00 0a 53 6f 75 72 63 65 46 69 6c 65 01 00 0f 48 65 6c 6c 6f 57 6f 72 6c 64 2e 6a 61 76 61 0c 00 07 00 08 07 00 17 0c 00 18 00 19 01 00 0c 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 07 00 1a 0c 00 1b 00 1c 01 00 0a 48 65 6c 6c 6f 57 6f 72 6c 64 01 00 10 6a 61 76 61 2f 6c 61 6e 67 2f 4f 62 6a 65 63 74 01 00 10 6a 61 76 61 2f 6c 61 6e 67 2f 53 79 73 74 65 6d 01 00 03 6f 75 74 01 00 15 4c 6a 61 76 61 2f 69 6f 2f 50 72 69 6e 74 53 74 72 65 61 6d 3b 01 00 13 6a 61 76 61 2f 69 6f 2f 50 72 69 6e 74 53 74 72 65 61 6d 01 00 07 70 72 69 6e 74 6c 6e 01 00 15 28 4c 6a 61 76 61 2f 6c 61 6e 67 2f 53 74 72 69 6e 67 3b 29 56 00 21 00 05 00 06 00 00 00 00 00 02  00 07 00 08 00 01 00 09 00 00 00 1d 00 01 00 01 00 00 00 05 2a b7 00 01 b1 00 00 00 01 00 0a 00 00 00 06 00 01 00 00 00 01 00 09 00 0b 00 0c 00 01 00 09 00 00 00 25 00 02 00 01 00 00 00 09 b2 00 02 12 03 b6 00 04 b1 00 00 00 01 00 0a 00 00 00 0a 00 02 00 00 00 03 00 08 00 04 00 01 00 0d 00 00 00 02 00 0e