The JAVA_HOME environment variable points to the JDK installation directory and used by many Java tools and applications like Eclipse, Maven, ANT, Tomcat etc. to figure out Java executables as they need Java for running. Unfortunately, When you install Java on Linux or Windows, this environment variable is not set automatically. You need to do it yourself. Java developers like me always set useful environment variables like JAVA_HOME, PATH, and CLASSPATH on the login scripts executed by the shell when you log in to Linux e.g. bash_profile.sh, but you can also set JAVA_HOME into /etc/profile for all users. I'll show you steps how to find the location of Java and how to setup the JAVA_HOME in Linux in this article and these steps should also work with any Linux or Java version e.g. Ubuntu, RedHat, CentOS, SUSE, ArchLinux, Debian, Fedora etc.
One of the common programming exercise on various Java course is addition and multiplication of two arrays. How do you add two integer arrays in Java? Can you add two String array? how about other data types etc? These are some of the interesting questions because Java doesn't support operator overloading. You cannot use the plus operator to add two arrays in Java e.g. if you have two int arrays a1 and a2, doing a3 = a1 + a2 will give compile time error. The only way to add two arrays in Java is to iterate over them and add individual elements and store them into a new array. This is also not easy because the array can be of different length, so you need to make some rules and apply them to your method e.g. you can throw IllegalArgumentException if you get two arrays which are not of the same type and their length is different.
A thread is used to perform parallel execution in Jaa e.g. while rendering screen your program is also downloading the data from the internet in the background. There are two types of threads in Java, user thread and daemon thread, both of which can use to implement parallel processing in Java depending upon priority and importance of the task. The main difference between a user thread and a daemon thread is that your Java program will not finish execution until one of the user thread is live. JVM will wait for all active user threads to finish their execution before it shutdown itself. On the other hand, a daemon thread doesn't get that preference, JVM will exit and close the Java program even if there is a daemon thread running in the background. They are treated as low priority threads in Java, that's why they are more suitable for non-critical background jobs. In this article, we will learn some key difference between user and daemon thread from Java multithreading and interview perspective.