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
Category: Java
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
Core Java: Type Erasure
Part of polymorphism, we have method overloading is one form where methods can have same name with different parameter types. One such example would be below:- following are my method signatures – void mymethod(List<String> a, List<Integer> b); void mymethod(List<Integer> c,Continue reading… Core Java: Type Erasure
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
JDBC programming inputs
While doing jdbc programming, following API interface would be very useful to program generic manner for all jdbc supported databases. Interface DatabaseMetaData exposes many methods which we’ll use for jdbc programming. For more info on this, you can refer toContinue reading… JDBC programming inputs
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
J2EE Basics: JDBC Driver Connections
JDBC Driver Connection Method list There are many version of the Friends to find JDBC driver or the driver often ask how to use,In here I simply sort out driver with more typical usage.1. Microsoft SQL Server series (6.5, 7.xContinue reading… J2EE Basics: JDBC Driver Connections
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.
Core Java: StringBuffer and StringBuilder
StringBuffer is used to store character strings that will be changed (String objects cannot be changed). It automatically expands as needed. Related classes: String, CharSequence. StringBuilder was added in Java 5. It is identical in all respects to StringBuffer exceptContinue reading… Core Java: StringBuffer and StringBuilder