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.
Monday, 30 March 2020
Monday, 6 January 2020
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.
Monday, 16 December 2019
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.
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.
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 ).
Tuesday, 30 September 2014
How to detect width of text inside text box
In this tutorial we are going to see how to calculate the width of text inside the text box. First of all we need to know why we are trying to achieve this. This is useful when you want to position some text suggestion just beneath the user cursor inside the text box. The image given below will provide better understanding of the scenario.
Wednesday, 20 August 2014
Javascript event capturing and bubbling
JavaScript uses two models for event delegation, capturing and bubbling. If you go back in old days, Netscape said that event on parent will take place first and Microsoft said that event on target element will take first. The W3C model combines both capturing and bubbling by saying that an event first makes its way downwards visiting captures i.e parent to target child and then bubbles back visiting non captures. Lets explore further
Monday, 21 July 2014
Enable caching in tomcat 6
In previous tutorial we learnt how to enable caching in tomcat 7. In this tutorial we will learn how to enable caching in tomcat 6. Tomcat 6 doesn't comes with inbuilt ExpiresFilters like in tomcat 7, but we can write our own filter to achieve caching. Two headers "Cache-control" and "Expires" are needed to be set so that browser can determine when to load resource from server or cache.
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 ?
Monday, 7 July 2014
Enable gzip compression in apache
When a user types your website url in browser and hits enter, browser sends request to server. Server responds to that request in the form of reply by giving back the requested document. That document can be of any size, typically if we take javascript files, it can be between 100 to 200 KB. Is there is any way to reduce this size so that the downloading can be faster ? Answer is "yes", that's what gzip compression does. It compresses the document size to almost 70% of the original. The major benefit of gzip compression is that it reduces bandwith by reducing the size of the response from the server.
Sunday, 6 July 2014
How to minimize http requests
When it comes to website performance, number of requests made by your website to the server plays important role in total page download time. Since every request made includes round trip to server ( request and response ), it adds extra download time i.e total time spent during the trip. Also there are some limitations in the browser that how many parallel requests can be made to single domain. In a nutshell too many requests may decrease your website performance. Now we are going to look how can we minimize or reduce the number of HTTP requests.
Tuesday, 1 July 2014
How to speed up your website
One of the major concern of today's web developers is how to speed up their website. No one wants to wait for page download neither your user's too. Having fast website is very crucial in today's world, their is no place for slower websites. Below are some tips that you can follow to make your website blazing fast with minimal network load and fast rendering.
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.Tuesday, 24 June 2014
Balanced parenthesis check
Balanced parenthesis check for expression using javascript
Given an expression with series of braces,curly braces and big brackets " () {} [] ", you have to determine that whether these parenthesis are balanced or not. If given a string " ({}) ", by looking at it we can clearly say that parenthesis are balanced. Today we are going to implement this using javascript. We will be using data structure stack.Javascript and garbage collection
Javascript doesn't have explicit memory mangament, it's the browser which decides when to clean it up. Sometimes it may happen that you experience unsmooth rendering of JavaScript due to a garbage collection pause.
There are many techniques that you can apply to overcome glitches caused by garbage collection (GC). More you apply more you explore. Suppose you have a game written in JavaScript , and every second you are creating a new object then its obvious that at after certain amount of time GC will occur to make further space for your application.
For real time application like games, which requires lot of space the simplest thing you can do is to reuse the same memory. It depends on you how you structure your code. If it generates lots of garbage then it might give choppy experience.