Home » Java » Core Java » Page 4

Core Java

Adding Range Type in Java

1. Introduction Modern and more recent programming languages have the concept of a range type. Programming languages such as Python, Ada, Ruby, and Rust, each have the concept of a range-a bounded beginning and end of a numerical sequence or series of integers. The Java programming language has a reputation for being a verbose, wordy programming language [Pras 2012] by ...

Read More »

Java String API regionMatches​()

Quick guide to Java String API regionMatches​() Method with Examples. This method is used to compare two sub strings. Syntax: public boolean regionMatches​(int toffset, String other, int ooffset, int len) 1. Java String regionMatches​() Overview In this tutorial, We’ll learn about Java String API regionMatches​() method to compare two substrings. In other words, comparing regions of two strings. This method ...

Read More »

Java 8 Optional filter()

A quick example guide to Java 8 Optional filter() Method. filter(Predicate predicate) method used to return a Optional object for the given predicate(the condition). 1. Overview In this tutorial, We’ll discuss how to use Predicate with Optional class. TheJava 8 Optional class has a method filter() which takes  Predicate as an argument. Optional is a class and it is in  java.util ...

Read More »

How to change procedural code into object-oriented one?

What style should Clean Code be written in? Clean Code is not always object-oriented. Sometimes it will be written in procedural style. And what style is better: procedural or object-oriented? We should perform the choice under given conditions which facilitates its development and readability – in accordance with the principles of Clean Code. Below is an example of the procedural ...

Read More »

Java Compress/Decompress String/Data

Java provides the Deflater class for general purpose compression using the ZLIB compression library. It also provides the DeflaterOutputStream which uses the Deflater class to filter a stream of data by compressing (deflating) it and then writing the compressed data to another output stream. There are equivalent Inflater and InflaterOutputStream classes to handle the decompression. Compression Here is an example ...

Read More »

Optional ofNullable() method (With Examples)

A quick guide to Optional ofNullable() method in Java 8 API with Example programs. How to use in the real time projects. 1. Introduction In this tutorial, We’ll learn Optional ofNullable() example on how to create new Java 8 Optional object for any value or null value. Optional is part of  java.util package. API Note: Returns an Optional describing the given value, if ...

Read More »

Optional orElse vs orElseGet

Java 8 introduced a fantastic concept of Optional, which we looked into in our blog Java 8 Optional. So just to give a short recap, Optional is used to represent Optional object or empty value instead null reference. This will help to avoid null pointer exception which occurs when we try to perform some operation on null reference object. For accessing ...

Read More »

Better NullPointerException Messages Automatic in JDK 15

I discussed long-awaited and highly appreciated improvements to NullPointerException (NPE) messages in the posts “Better Default NullPointerException Messages Coming to Java?” and “Better NPE Messages in JDK 14“. When this JEP 358-driven feature was added to JDK 14, a developer who wanted to benefit from these more insightful NPE messages needed to explicitly state that desire by passing the argument ...

Read More »