Tuesday, 31 May 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 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. Another safe HTTP method is HEAD, which doesn't change the resource representation on the Server, but all other HTTP methods e.g. POST, PUT, or DELETE are non-safe.
Read more »

Sunday, 29 May 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 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 game written in Java. Precisely, we are going to solve the "Exception in thread "main" java.lang.UnsatisfiedLinkError: lwjgl64.dll: Access denied" error.
Read more »

Saturday, 28 May 2016

How to reverse an ArrayList in place in Java - Example

You can reverse an ArrayList in place in Java by using the same algorithm we have used to reverse an array in place in Java. If you have already solved that problem then It's a no-brainer because ArrayList is nothing but a dynamic array, which can resize itself. All elements of an array are stored in the internal array itself. By the way, if you need to reverse an ArrayList then you should be using the Collections.reverse() method provided by Java Collection framework. It's generic method, so you can not only reverse an ArrayList but also Vector, LinkedList, CopyOnWriteArrayList, or any other List implementation. Though, worth noting is that this method internally uses a ListIterator for reversing the list, which might not be as efficient as our algorithm.
Read more »

Thursday, 26 May 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 library and application. 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 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.
Read more »

Monday, 23 May 2016

5 Free Data Structure and Algorithm Books in Java Programming

In last article, I have shared 5 good data structure and algorithms books, but those were not free. After that article, I received some feedback about how about free data structure and algorithm books? Fair enough, everybody loves free eBooks, don't you? In the past, I have shared a list of free Java programming books, so I had some idea. I did some more research on internet and checked my collection as well. Fortunately, there are a couple of good Data Structure and Algorithm books which are available for free PDF download or for online reading and in this list we will see some of them. Data Structure and Algorithm is one of the most important topics for any programmer, not just for interview point of view but also about writing good programs and problem solving. A good choice of data structure can reduce the complexity of the algorithm and can improve its performance drastically.
Read more »

Saturday, 21 May 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. Using == operator only make sense when comparing primitives like int, or final constants like Enum. Though there is more involved in comparing two Enum, which you learn by following that link.
Read more »

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 comes  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. 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. They achieve thread safety by using advanced and sophisticated techniques like lock stripping. For example, the ConcurrentHashMap divides the whole map into several segments and locks only the relevant segments, which allows multiple threads to access other segments of same ConcurrentHashMap without locking.
Read more »