Wednesday, 6 September 2017

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();  

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.

Life cycle of the servlet

A servlet is a Java programming language class that is used to extend the capabilities of servers that host applications accessed by means of a request-response programming model. Although servlets can respond to any type of request, they are commonly used to extend the applications hosted by web servers. ( more reference ).

Thursday, 17 July 2014

Enable caching in tomcat 7

Caching is technique of storing files for future use. In we take it in context of website performance, caching helps browser to store different resources from server in local storage. Whenever a user request for resource browser first checks it cache and if it is available the resource is served from cache. This reduces network bandwidth and increases performance of your website. ( how to speed up your website ) 

Wednesday, 16 July 2014

Debugging java code in eclipse

Debugging is referred as watching the source code and variables of the program during execution. The stop point or break point is specified in the code where the execution is paused by the debugger. Then you can use step over, step into commands to go to next statement for execution. In this tutorial we are going to use java debugger that comes in eclipse. The eclipse used for demonstration is eclipse juno. Eclipse has special perspective for debugging allowing investigation for variables or execution statements.

Tuesday, 8 July 2014

Mysql connection very slow

There can be many reasons that cause slow execution of mysql command, possibly amount of memory, cpu, database size, database engine and many more. In this tutorial we are going to talk about the connection being slow for mysql, your queries are running faster from command line but your web page scripts are not able to make connection faster. Response time from mysql  is taking longer than usual. The major cause can be the DNS lookup. So how to fix this ?

Wednesday, 25 June 2014

Merchant guide to galaxy

Thoughtworks interview question

You decided to give up on earth after the latest financial collapse left 99.99% of the earth's population with 0.01% of the wealth. Luckily, with the scant sum of money that is left in your account, you are able to afford to rent a spaceship, leave earth, and fly all over the galaxy to sell common metals and dirt (which apparently is worth a lot).Buying and selling over the galaxy requires you to convert numbers and units, and you decided to write a program to help you.The numbers used for intergalactic transactions follows similar convention to the roman numerals and you have painstakingly collected the appropriate translation between them.Roman numerals are based on seven symbols.