Core Java: Programming code snippets frequently used

Here are few things I learnt while coding in java: Increment an occurrence in map for(char current : input.toCharArray()){ count.put(current, count.getOrDefault(current, 0) + 1); } Let’s say you want to decrement the occurrence and when occurrence becomes zero, remove entry.Continue reading… Core Java: Programming code snippets frequently used

Core Java: ConcurrentModificationException while removing items from LinkedHashMap

I came across ConcurrentModificationException while editing LinkedHashMap which internally maintains order of the tuple. Below is my code to edit the map. It looks fine to me and no compilation errors too. But, during runtime I faced ConcurrentModificationException even thoughContinue reading… Core Java: ConcurrentModificationException while removing items from LinkedHashMap

java URL using relative path

I have a URL: URL url=new URL(“http://www.abc.com/aa/bb/cc/file.html”); and a relative path: String relativePath=”../file2.html”; //maybe is “/file3.html” I want to get http://www.abc.com/aa/bb/file2.html using variable url and relativePath How to do it? This is very frequent requirement you see if you are dealing with webservices development. OneContinue reading… java URL using relative path

Eclipse: resource is outof sync with the file system – permanent solution

Mysteriously got the following exception when trying to build an Eclipse project: “resource is out of sync with the file system” Although I can’t be sure, I think I may have deleted a file outside of Eclipse. To fix theContinue reading… Eclipse: resource is outof sync with the file system – permanent solution

java.sql.SQLException: Io exception: Invalid Packet Lenght

Similar exceptions are : 1. java.io.IOException: Io exception: Unexpected packet 2. java.sql.SQLException: Protocol violation 3. java.sql.SQLException: Io exception: Bad packet type 4. java.sql.SQLException: Bigger type length than Maximum 5. java.sql.SQLException: Io exception: Invalid Packet Lenght 6. java.sql.SQLException: Closed Connection 7.Continue reading… java.sql.SQLException: Io exception: Invalid Packet Lenght

java.io.UTFDataFormatException: 5-byte UTF8 encoding not supported.

An interesting exception faced while parsing xml content. Also, on further analysis on this error caused below similar issues started to raise. Another similar exception is: java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 sequence Here, I am trying to parseContinue reading… java.io.UTFDataFormatException: 5-byte UTF8 encoding not supported.