Java HashMap Examples

Java HashMap is not a thread-safe implementation of key-value storage, it doesn’t guarantee an order of keys as well. In the scope of this article, I’ll explain: HashMap internal implementation methods and functions and its performance (O(n) time complexity) collisions in HashMap interview questions and best practices Keep reading and use a table of contents … Read more

How to Make a toString Method in Java

Java Object toString method is one of the basics in Java. toString function returns a string representation of an object. I’ll explain how to add toString method to a Java class with code examples. Using toString in Java To string method in Java should be informative to make it easy to read. it’s recommended to … Read more

Comparable vs Comparator in Java: What to Use?

There are 2 interfaces for sorting in Java: Comparator and Comparable. I’ll explain to you how to define Comparator and Comparable objects, what’s the difference and when you can use it. Let’s comparable vs comparator fight begin… When to Use Comparable and Comparator So what is the main difference between Comparator and Comparable interfaces? Comparator … Read more

Java Static Methods

Java static methods are one of the most important language instrument. I’ll explain what’s static function in Java, how to make it and what is its purpose. I’ll describe what is the difference between static and non-static methods and why main() method in Java is static. To define static method you should add “static” keyword … Read more

Abstraction in Java: Abstract Classes and Methods, Interfaces and Has-A, Is-A Relationships

So what is an abstraction in OOP programming? Let’s imagine you have a car. it has a lot of characteristics like a weight, dimensions, color, maximum speed etc. To describe a Car object you need only color and max speed for your use-case. Weight and dimensions don’t matter to you. Abstraction means showing only necessary … Read more