Category: Core Java

Core Java

Check If Java Array Contains a Given Value

Introduction: In this quick tutorial, we’ll look at how to find if a Java array contains a given value. In other words, we’ll check if a given value is present in our Java array or not. Linear Search: One of the most straightforward approaches would be to linearly search our array to check if it […]

Be the First to comment. Read More
Core Java

Binary Search In Java

Introduction: In this quick tutorial, we’ll learn to perform a binary search in a sorted array. We’ll also write our own algorithmic implementation in Java. Later, we’ll discuss the binarySearch() method available in the Java library. Problem Definition: Let’s say we have a sorted array a[]: int[] a = {1, 2, 3, 4, 5, 6}; […]

Be the First to comment. Read More
Core Java

Polymorphism In Java

Introduction: Polymorphism in Java provides us an ability by which an object can take on different forms based on our usage context. Polymorphism is derived from two words – “poly” which means “many” and “morphs” which means “forms”. Java defines two major types of polymorphism: Compile-time / Static Polymorphism also referred to as “Method overloading” […]

Be the First to comment. Read More
Core Java

Find Middle Element In a Linked List

Introduction: In this quick tutorial, we’ll first start by looking at the brute-force solution to find the middle element in the linked list. Later, we’ll learn how to achieve it in a single iteration through the entire linked list i.e. in just a single pass. Problem Definition: Given a linked list L, our aim is […]

Be the First to comment. Read More
Core Java

Calculate Word Frequency Count In Java 8

Introduction: In this quick tutorial, we’ll look at ways in which we can create a word frequency map in Java 8. Problem Definition: Let’s say we have been given a list of names: List<String> names = {"Sam", "James", "Selena", "James", "Joe", "Sam", "James"}; We wish to print the frequency map specifying the frequency count of […]

Be the First to comment. Read More
Core Java

Inheritance In Java

Introduction: Inheritance is one of the core principles of Object Oriented Programming. It enables us to establish IS-A relationship between classes/objects and reuse existing code. It is through the support of inheritance that we can extend a class from another. It’s kind of establishing a parent-child relationship among classes that relate to each other. Let’s […]

Be the First to comment. Read More
Core Java

Comparable and Comparator In Java

Introduction: In this tutorial, we’ll learn about Comparable and Comparator interfaces in Java. It’ll help us to compare our custom object types. Building Context: Let’s suppose we have our Student class: class Student { private int id; private String name; //constructor, getters, setters } And we have a List of Student objects: List<Student> students = […]

Be the First to comment. Read More
Core Java

Reverse Elements Of Java Array

Overview: In this quick tutorial, we’ll learn ways in which we can invert or reverse an array. We’ll first look at the most basic Java implementations and later cover a few third-party options. Problem Definition: Consider we have an array of elements: Integer[] intArr = {12, 30, 1, 7, 4}; Our problem is to be […]

Be the First to comment. Read More
Core Java

“final” Keyword In Java

Introduction: The final keyword in Java is a non-access specifier. We can apply it to a variable, method or a class. In this tutorial, we’ll learn its usage in each of these contexts. final Variable: The variables declared as final are nothing but constants i.e. any attempt to reassign a value to those variables will […]

Be the First to comment. Read More
Core Java

Comparing Strings In Java

Introduction: Strings are used all over in any Java application. So, it’s important to understand how to compare two string objects. In this article, we’ll learn ways to compare String objects.   1.) Comparing References Using ‘==’ The == operator when used to compare strings is responsible for comparing only the references(not the content). So […]

Be the First to comment. Read More