Interview Questions

Java

Java Directory Operations

/**
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE IS DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS

Java - Array Blocking Queue

Queue is used in places where one or more threads pass information or data to other threads. Basically they are used to transfer data between threads.

Queue typically orders elements in First in First out (FIFO) order. In FIFO, all new elements are added at the tail or bottom of the Queue. While retrieving data from the Queue, the element which is inserted first will be retrieved first.

Queue offers functionalities like data insertion and data retrieval.

In this article, let us see a simple example of using Array Blocking Queue.

Example :

MySQL - CreateTrigger Using JDBC connection

/**
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE IS DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS

MySQL - Fetch records from table using JDBC connection

/**
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS

Java - Execute System Commands

This article describes how to execute System Commands using Java program.

The Runtime class allows the Java application to interface with the system environment. Using this Runtime class, the system commands can be executed using the api Runtime.exec().

Consider the below example.

ExecuteSystemCommands Class

/**
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR

Java Best Practice

In this article, we will discuss about certain best practices to be followed while developing programs or applications using JAVA.

Variable Declaration
When the variables are defined, please make sure you give meaningful names. For example

String d1 = "RC221";

Instead of naming a device as d1, we can give a meaningful name applicable for the context.

String deviceName = "RC221";

Whenever you create a method inside the class, declare all the method variables and then start the program code logic. This will increase the readability.

Java - Pagination Utility

Consider a scenario, where you want to display a set of records from database in the User interface page. If the number of records is more, we would be using pagination to display the records. In this case we need to reform the SQL query to retrieve results for a particular page number with the limited records per page. For example, consider the following SQL query.

SELECT * FROM EMPLOYEES ORDER BY DEPT_ID,DOJ

Java - Bubble Sorting

/**
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS

Java - Thread scheduling using Scheduled Thread Pool Executor

The below Java class demonstrates the periodic scheduling of Threads using Scheduled Thread Pool Executor.

/**
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE IS DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF

JSTL (JSP Standard Tag Library) Core Tags

What is JSTL?
JSTL is a library of tags which can be used in a JSP. The tags provide common functionality such as iterating through elements, displaying values, checking conditions, manipulating XML documents, database access tags etc.,

There are four groups of tags in JSTL
1. Core tags
2. I18N formatting tags
3. XML processing tags
4. DB Access tags

We will look in to the core tags in this article.

To use the JSTL tags in your JSP file, you need to include the tag library as follows.