Wednesday, 6 September 2017

Knapsack problem using simulated annealing

The knapsack problem ( Wiki link ) is a problem in combinatorial optimisation. Given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible. Let's see how we can solve it using simulated annealing.

Simulated annealing explained with examples

First of all, we will look at what is simulated annealing ( SA). Simulated annealing is a method for solving unconstrained and bound-constrained optimisation problems. Inspired from the annealing process in metal works, which involves heating and controlled cooling of metals to reduce the defects.

Thursday, 30 March 2017

Converting excel file to list of java beans

Facing problems in parsing excel and saving data ? Yes, In this tutorial i am gonna show you people how you can easily parse excel files and get data in form java beans.

Friday, 25 September 2015

How to get client ip address in java servlet

HTTPServletRequest Object has a method called servletRequest.getRemoteAddr(). This method can be used to get the ip address of the client.
    String ipAddress = request.getRemoteAddr();  
    System.out.print(ipAddress);

Friday, 12 June 2015

Utility class to read excel file in java and return rows as list

In this tutorial we gonna make a utility class that accepts file as argument ( .xlsx file ), parse it and return rows as List. You can make use of this class in your project to read excel file and get the contents. For this first we need Apache POI. Apache POI is the pure Java API for reading and writing Excel files in both formats XLS (Excel 2003 and earlier) and XLSX (Excel 2007 and later).

Thursday, 9 October 2014

Java program to execute shell scripts on remote server

If you want to execute shell scripts on remote server and get output with the help of your java program then you are at right place. In this tutorial we will be using Java secure channel ( Jsch ) to log on to remote server, execute the shell script and capture the output. JSch is a pure Java implementation of SSH2. ( download jSch ).

Call a method just before a session expires

In this tutorial we gonna learn that how to call a specific method when a session is going to be destroyed or invalidated by the application container. First of all we need to know why we are doing this. Well it may have many applications but typically we use it for updating user counts, releasing resources etc. We could use HttpSessionListener and do the job in sessionDestroyed() method.