Loading...

Wednesday, July 29, 2015

Top 5 Data Structure and Algorithm Books - Must Read, Best of Lot

Data Structure and Algorithms books are often taught as text books in various universities, colleges and Computer Science degree courses, yet, when you put programmers in a situation, where they need to find and decide, which data structures and algorithms to use to solve a problem, they struggle. I have seen this, and I think one reason of this is perspective. When you read something as text book and your perspective is just to do well in exam, you might not be thinking about learning and applying that knowledge in real world problems. Since data structures and algorithms are core of any programming problem, it becomes extremely important for programmers to master them even if you have learned well during academics. In this article, I am sharing five of my favorite books on data structures and algorithms, which I think are great read and can help every programmer to master data structure and algorithms. I have chosen these books because of different reasons. Some books are really easy to read and there focus is aligned to my expectation, some of them are really comprehensive and can be used as reference material, and few of them offers different perspective of using data structures and algorithms e.g. while solving a real world problem or helping to crack interviews at Google, Amazon, Microsoft or Facebook. It's hard to judge your knowledge of data structure and algorithms by knowledge based questions, because that's not how they are used in project. It doesn't help to know about every single detail of a Car, if you can't even drive. This data structure and algorithms books has helped me to find and fill in gaps and taught me a lot of things about different data structures e.g. stacks, queues, linked list, arrays, hash tables, heaps, trees and graph. If you are using a different data structure and algorithm book, which is good and not in this list, you can share with us.

Monday, July 27, 2015

How to Calculate Difference between two Dates in Java (In Days)

If you are not running on Java 8, then there are two ways to calculate difference between two dates in Java in days, either by using standard JDK classes e.g. java.util.Date and java.util.Calendar or by using joda-time library. Unfortunately, Java's old Date and Calendar API is buggy and not intuitive, so many of us by default use Joda for all date and time arithmetic. In this example, you will learn how to find  number of days between today and any date entered by user using Joda, as well as without using any third party library. When I first time face this problem, I thought what's a big deal about finding difference between dates? If you can convert Date to milliseconds then finding number of days, months or years is just a matter of simple arithmetic, but I was WRONG. I was not thinking about real world date and time nuisance like leap seconds, leap years, and day light saving time. It's very difficult to accurately calculate difference between two dates in Java without using third party library, unless you have time to develop your own library like Joda, which diligently takes these things into consideration. Thankfully, you don't need to worry because Java 8 got lucky third time. There is a new Date and Time API which has corrected previous mistakes and turns out to be a really gem. If you are keen to learn Java 8, not just this API, I suggest you to grab a copy of Java 8 in Action, one of the better books to learn new features of Java 8 in quick time.

Saturday, July 25, 2015

java.sql.SQLException: No suitable driver found for jdbc:jtds:sqlserver - Cause and Solution

java.sql.SQLException: No suitable driver found for 
There are two ways to connect Microsoft SQL Server from Java program, either by using Microsoft's official JDBC driver (sqljdbc4.jar), or by using jTDS driver (jtds.jar). This error comes when your supplied database URL didn't match with the JDBC driver present in the CLASSPATH. Many programmers who usually use jtds.jar, makes a mistake while using sqljdbc4.jar by adding "microsoft" in JDBC URL. That makes URL invalid and JDBC API throws "java.sql.SQLException: No suitable driver : sqljdbc4.jar" error.