Home » Java » Core Java » Page 20

Core Java

“Callable” vs “Runnable” Tasks in Java Concurrent Programming

When we write multi-threaded applications in Java, we are predisposed to implementing threaded classes by using the “Runnable” interface. Your class has to simply implement this interface and override the run method. For trivial use cases, we can directly start the thread by invoking the “start” method, and the flow of control is delegated to the run method as a ...

Read More »

Top 10 + 1 common mistakes every Java learner makes

It is said, “Your friend will swallow your mistakes, your enemy will present them on a plate”. I am definitely not your enemy, but I want to present you some mistakes, specific to each Java beginner student and I will do it right here on this blogging “plate”. Sure there are only some of them, I collected from CodeGym.cc courses ...

Read More »

The Complete Guide to Java 12 New Features

6 months flew by so fast, and again, it’s time to take a closer look at the new JDK version that’s out. Let’s meet Java 12 and the features it’s introducing to developers. It’s a been a while since Oracle introduced its accelerated 6-month release cadence, and it’s getting harder to keep up with every version and the features they ...

Read More »

Polymorphic Input/Output Data

When developing any kind of code interface, whether it is an elegant object oriented package or one of those ugly “Service” classes that we are so accustomed to, it is obvious that it should be as extensible as possible and require as little maintenance as possible. This applies, of course, to the input and output parameters (returned types), especially if ...

Read More »

Eliminating Null Pointer Exceptions from your Java Applications

This post is a brief introduction to one of the most useful yet “un-glamorous” features of Java 8. Programmers have spent endless hours trying to rectify one of the most common errors yet the most dangerous – namely, Null Pointer Exceptions. Null pointer exceptions can cause unexpected outages in our applications, and are very difficult to detect up-front. On many ...

Read More »

Java 12: Mapping with Switch Expressions

In this article, we will be looking at the new Java 12 feature “Switch Expressions” and how it can be used in conjunction with theStream::map operation and some other Stream operations. Learn how you can make your code better with Streams and Switch Expressions. Switch Expressions Java 12 comes with “preview” support for “Switch Expressions”. Switch Expression allows switch statements ...

Read More »

Sorting a HashMap In Java

Introduction: In this tutorial, we’ll learn how to sort a Java HashMap. We can sort a HashMap either by keys or by values. We’ll discuss both of these strategies. Sorting a Java HashMap: To follow along with the rest of the article, let’s first construct a HashMap: HashMap<Integer, Student> map = new HashMap<>(); map.put(1003, new Student(1003, "Sam")); map.put(1005, new Student(1005, "Joseph")); ...

Read More »

Better Default NullPointerException Messages Coming to Java?

I have recently been interested in a February 2019 into March 2019 discussion on the OpenJDK core-libs-dev mailing list regarding addressing the lack of a detailed message associated with a NullPointerException that was thrown after being instantiated with its no-arguments constructor. This is an issue I’ve run into frequently when using Java and which has even caused me to change ...

Read More »