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

What Is a Java Constructor

One of the first thing that each beginner programmer should learn is a Java constructor. In this article, I’ll explain what is a constructor in Java (default and parametrized) and different methods how to create a constructor in Java with examples. I’ll show you how to overload constructors and how to access parent class constructor. … Read more