Tuesday, May 31, 2016

What are Idempotent and Safe methods of HTTP and REST

In order to efficiently work with REST and RESTful web service, good knowledge of HTTP is really helpful. Even though REST seems easy, designing a uniform and consistent RESTful API is a tough job. One of the tricky tasks is choosing right the HTTP method for the right job e.g. when to use PUT vs POST. Once you know the meaning and purpose of different HTTP methods, it helps to choose the right method for the right job. You can divide HTTP methods into two main categories safe and idempotent. Safe methods are HTTP methods that do not modify the resource e.g. a GET request is safe because it doesn't modify the resource you are requesting e.g. data of a Book.

Sunday, May 29, 2016

Minecraft - java.lang.UnsatisfiedLinkError: lwjgl64.dll : Access Denied Solution

You can resolve java.lang.UnsatisfiedLinkError: lwjgl64.dll : Access Denied error in Minecraft by disabling your anti-virus and run. Later you can whitelist the lwjgl64.dll, so that your anti-virus will not block it again. I have talked about java.lang.UnsatisfiedLinkError a couple of times on this blog e.g. here and here. But, today I am going to show you one more real-life example of java.lang.UnsatisfiedLinkError, which is more interesting. We'll also learn and how to deal with that. This problem is related to Minecraft, one of the most popular games written in Java. Precisely, we are going to solve the "Exception in thread "main" java.lang.UnsatisfiedLinkError: lwjgl64.dll: Access denied" error.

Thursday, May 26, 2016

Best practices to name your JAR file in Java

If you are an author of an internal, proprietary Java library or an external open-source library,  or you are one of those lucky developers who ship Java application by yourself then you should follow these best practices while naming your JAR files. These best practices are a result of the practical experience of using hundreds of Java libraries and applications. Following these best practices will help in better management of JAR files. It's part of my other best practices articles e.g. best practices while naming a variable, writing comments, overriding methods, muli-threading, JDBC, and best practices while dealing with passwords. If you are interested in learning more best practices, you can always search those articles on this blog.

Saturday, May 21, 2016

Java Mistake 3 - Using "==" instead of equals() to compare Objects in Java

In this part of Java programming mistakes, we will take a look at another common pattern, where programmers tend to use "==" operator to compare Objects, similar to comparing primitives. Since equality of object can be very different in the physical and logical sense, and in the case of domain objects it's mostly driven by business rules, comparing objects with "==" operator, introduces subtle bugs, which are hard to find. The difference between equals() and == operator,  one of the Java classics is also asked to find out if the developer is familiar with this important concept or not.

What is difference between Synchronized and Concurrent Collections in Java?

Synchronized vs Concurrent Collections
Though both Synchronized and Concurrent Collection classes provide thread-safety, the differences between them come in performance, scalability and how they achieve thread-safety. Synchronized collections like synchronized HashMap, Hashtable, HashSet, Vector, and synchronized ArrayList are much slower than their concurrent counterparts e.g. ConcurrentHashMap, CopyOnWriteArrayList, and CopyOnWriteHashSet. The main reason for this slowness is locking; synchronized collections locks the whole collection e.g. whole Map or List while concurrent collection never locks the whole Map or List.

Monday, May 16, 2016

Difference between float and double variable in Java?

Though both float and double datatype are used to represent floating-point numbers in Java, a double data type is more precise than float. A double variable can provide precision up to 15 to 16 decimal points as compared to float precision of 6 to 7 decimal digits. Another significant difference between float and double is their storage requirement, double is more expensive than float. It takes 8 bytes to store a variable while float just takes 4 bytes. This means if memory is constraint than its better to use float than double. By the way, the double type also has a larger range than float and if your numbers don't fit well in float then you have to use double in Java.

Thursday, May 12, 2016

Difference between close and deallocate cursor in SQL

Cursor in a database is used to retrieve data from the result set, mostly one row at a time. You can use Cursor to update records and perform an operation on a row by row. Given its importance on SQL and Stored procedure, Cursor is also very popular on SQL interviews. One of the popular SQL questions on Cursor is close vs deallocate. Since both of them sounds to close the cursor, once the job  is done, What is a real difference between close and deallocate of Cursor in SQL? Well, there is some subtle difference e.g. closing a cursor doesn't change its definition. In Sybase particular, you can reopen a closed cursor and when you reopen it, it creates a new cursor based upon the same SELECT query.