3 Difference between Web Server vs Application vs Servlet Containers in Java JEE

In the Java EE, or J2EE or JEE world, there are a lot of confusion between terminology, which is quite evident that now we have three words (J2EE, Java EE, and JEE) to describe the same technology platform. You will see Java developers using the terms like Web Server, Application Server, and Web containers interchangeably but they are not exactly same. The main difference between Web server and application server is that web server is meant to serve static pages e.g. HTML and CSS, while Application Server is responsible for generating dynamic content by executing server side code e.g. JSP, Servlet or EJB. One of the most popular web servers is Apache HTTPD which is often used in conjunction with Tomcat to host many Java web application. Now, tomcat is not exactly an application server, it's more of a servlet engine or web container or also known as servlet containers because it provides the runtime environment for Servlet and JSP but doesn't provide the services like EJB and distributed transaction which are a key feature of the application server in Java JEE world.

How to set JAVA_HOME and PATH in Linux

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.

How to Add Elements of two Arrays in Java - Example

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.