Category: Core Java

Core Java

Find Sum/Average In Java Array

Introduction: In this article, we’ll learn to find the sum and average of all elements in a given Java array. We’ll first cover the basic for loop-based approach and then extend our knowledge to achieve the same using Java Streams API. Finding Sum of Elements In Array: Let’s look at how we can find the […]

Be the First to comment. Read More
Core Java

Find Maximum/Minimum Element In Java Array

Introduction: In this quick tutorial, we’ll learn ways to find the maximum/minimum element in a Java array of primitives. We’ll start with the very basic algorithms and end up with a solution using Java 8 Streams API.   Approach 1:: Linear Search It is a pretty straightforward approach to find max/min elements in a given […]

One comment Read More
Core Java

Java 9 New Features

Introduction: Oracle Java 9 has a large set of new features including the various upgrades to the programming tools and libraries. In this tutorial, we’ll have a look at a few of those features. 1.) Java 9 REPL(JShell) Let’s cover the fun part first! In Java 9, Oracle introduced a tool called REPL(Read Evaluate Print […]

Be the First to comment. Read More
Core Java

Java 8 groupingBy Collector

Introduction: GroupingBy Collectors introduced in Java 8 provides us a functionality much similar to using GROUP BY clause in a SQL statement. It helps us group objects based on certain property, returning a Map as an outcome. In this article, we’ll look at various example usages of the groupingBy collector in Java 8. To follow […]

Be the First to comment. Read More
Core Java

Java 8 Streams findFirst() vs findAny()

Introduction: Java 8 Stream API has two methods – findFirst() and findAny() which often seem confusing at first. In this article, we’ll learn the differences between the two so that we can choose wisely the next time. Stream.findAny(): findAny() method is a short-circuiting terminal operation. It returns an Optional<E> describing some element of the stream […]

Be the First to comment. Read More
Core Java

Java 8 Stream sorted()

Introduction: Java 8 Stream API is a powerful way to achieve functional programming. In this post, we’ll learn about Java 8 Stream sorted() method by looking at some good examples. In case you wish to learn more about Java 8 Streams API in general, we’ll suggest you read this article. Signature: There are two variants […]

Be the First to comment. Read More
Core Java

Factory Object Pattern In Java

Introduction: A Factory Object Pattern comes into picture when having a parent-child class relationship or having an interface based implementation. As the name suggest, the idea is to create a factory class which will be responsible for conditionally instantiating one among the several defined object types. It promotes loose-coupling by delegating the overhead of instantiating […]

One comment Read More
Core Java

Singleton Design Pattern In Java

Introduction: Singleton Design Pattern is one of the basic and most useful Design Patterns in Java. It comes under the category of the creational pattern as defined in Gang of Four Design Patterns. The central idea behind this design pattern is to ensure that only a single instance of a class is created in the […]

Be the First to comment. Read More
Core Java

HashMap vs HashTable In Java

Introduction: Both HashMap and HashTable implements java.util.Map interface and are used to store key-value pairs but there are some important differences between them. In this tutorial, we’ll cover the differences between HashMap and HashTable. Similarities Between HashMap and HashTable: Before we cover the differences, let’s look first at the similarities between a HashMap and a […]

Be the First to comment. Read More
Core Java

Java : Pass By Value Or Pass By Reference

Introduction: Java is Pass By Value or Reference is often a debated question among many Java developers. The answer to it is that Java is a Pass By Value, not Pass By Reference. In this tutorial, we’ll see how. To follow along with this tutorial, let’s first understand these two terms: Pass By Value: The […]

Be the First to comment. Read More