October 2017

The “final” Keyword in Java

  • Satish 

1. Overview While inheritance enables us to reuse existing code, sometimes we do need to set limitations on extensibility for various reasons; the final keyword allows us to do exactly that. In this tutorial, we’ll take a look at what the final keyword means for classes, methods, and variables. 2. Final Classes Classes marked as final can’t be extended. If we look at the code of Java core libraries, we’ll find many final classes there. One example is the String class. Consider the situation if we can extend the String class, override any of its methods, and… Read More »The “final” Keyword in Java

Period and Duration in Java

  • Satish 

1. Overview In this quick tutorial, we’re going to take a look at two new classes for working with dates introduced in Java 8: Period and Duration. Both classes can be used to represent an amount of time or determine the difference between two dates. The main distinction between the two classes is that Period uses date-based values, while Duration uses time-based values. 2. Period Class The Period class uses the units year, month and day to represent a period of time. We can obtain a Period object as the difference between two… Read More »Period and Duration in Java