How to handle NullPointerException in Collectors.toMap when a mapped value is null
In Java 8, Collectors.toMap throws NullPointerException when one of the mapped value is null. This is a known bug in OpenJDK. There are many workaround to ha...
In Java 8, Collectors.toMap throws NullPointerException when one of the mapped value is null. This is a known bug in OpenJDK. There are many workaround to ha...
Not so long ago, when I started my development journey, we use to work with single monolith project. The work culture was pretty different compared to curren...
Java Streams provide a wide range of collectors which is generally sufficient for most of the day to day use. But sometimes you need to perform some special ...
A Map cares about unique identifiers. You map a unique key (the ID) to a specific value. You’re probably quite familiar with Maps since many languages suppor...
Now let us say that we want to create a list that holds unique objects so what should we do? Should we use the normal list (ArrayList or LinkedList) to keep ...
A List extends Collection interface but it also cares about the index. The one thing that List has that non-lists don’t have is a set of methods related to t...
When we are having a collection of objects we needed a mechanism to traverse through it. But no two implementations are going to be the same when we are impl...
A collection allows a group of objects to be treated as a single unit. Arbitrary objects can be stored, retrieved, and manipulated as elements of collections.
While writing the object-oriented programs, comparison of two instances of the same class is often required. Once instances are comparable, we can sort them ...
Serialization lets you simply say “save this object state to the persistent store” you’d have to use one of the I/O classes to write out the state of the ins...
Like all byte and character stream objects, instances of PrintStream and PrintWriter implement a standard set of write methods for simple byte and character ...
Objects of type File are used to represent the actual files (but not the data in the files) or directories that exist on a computer’s physical disk. First, l...
To write anything to a file first of all we need a file name we want to use. The file name is a simple string like like this:
Java was designed for graphical user interfaces (GUI) and industrial strength file and Internet I/O. No attempt was made to have simple input and output faci...
A stream represents a flow of data, or a channel of communication with (at least conceptually) a writer at one end and a reader at the other. When you are wo...
Nearly every operating system supports the concept of processes – independently running programs that are isolated from each other to some degree.
The Java language includes three important methods that effectively allow one thread to signal to another. Without this facility, various constructs used in ...
Assertions are used to stop execution when “impossible” situations are detected. Assertions were introduced mainly to help the programmer to debug the applic...
All exception classes are subtypes of the java.lang.Exception class. The exception class is a subclass of the Throwable class. Other than the exception class...
The JDK contains a very useful tool, called javadoc, that generates HTML documentation from your source files. If you add comments that start with the specia...
An exception is a problem that arises during the execution of a program. An exception can occur for many different reasons, including the following:
There are many predefined Exceptions available in java which are mentioned below, these are some of the common exceptions seen.
In Java, strings are objects. Just like other objects, you can create an instance of a String with the new keyword, as follows: String s = new String("abc");...
Inner classes let you define one class within another. They provide a type of scoping for your classes since you can make one class a member of another class...
The java.lang.StringBuffer class should be used when you have to make a lot of modifications to strings of characters. String objects are immutable, so if yo...
Time to take a deep dive into creation of objects.
The Object class sits at the top of the class hierarchy tree in the Java development environment. Every class in the Java system is a descendent (direct or i...
Now we are aware of how to write the classes and are able to write simple programs in java, but what if our programs start to grow big, then how are going to...
Ohh! Its inheritance again….. its freaking me out. I don’t understand what it is? We see this kind of reaction every time we someone is first told about, Let...
CLASSPATH tells Java where to search for programs.
We can have final methods, final classes, final data members, final local variables and final parameters. A final class implicitly has all the methods as fin...
The type casting comprises of two subtypes, a) Primitive type casting and b) Object Reference Type casting.
Array, what is it? An array is a group of variables of the same data type and referred to by a common name. An array is an object which is a contiguous block...
Few more operators which are used in Java.
Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:
You may encounter situations, when a block of code needs to be executed several number of times. In general, statements are executed sequentially: The first ...
Java, like any programming language, supports both conditional statements and loops to determine control flow.
Java is a strongly typed language. This means that every variable must have a declared type. There are eight primitive types in Java. Four of them are intege...
Hello Java is very close to the simplest program that can be done in a language. Nonetheless there’s quite a lot going on in it. Let’s see what it does. For...
Now we will look into how to create methods, different types of constructors and how to instantiate an object.
We have created our initial classes, so now we want to compile the classes. In order to do that we open the command line (To open command line, go to start m...
In this section we are going to understand how to create a class and add attributes (variables) to it.
Polymorphism means when an entity behaves differently depending upon the context its being used. Moreover In other words Polymorphism is the capability of an...
Object-oriented programming (OOP) is a programming style that uses “objects” (data structures consisting of data fields and methods together with their inter...
Inheritance is the concept of a child class (sub class) automatically inheriting the variables and methods defined in its parent class (super class).