Tag: Java Basics

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
Core Java

Remove All Occurrences Of Newline From byte Array

Introduction: In this article, we’ll uncover ways in which we can remove all line breaks or newline characters from a byte array in Java. For this tutorial, we are assuming line breaks for our system would mean “\n” character(usually true for a Unix environment). Removing Line-Breaks from byte Array: 1. Using java.lang.String: An easy implementation […]

Be the First to comment. Read More
Core Java

How to Handle Daylight Savings In Java

Introduction: Daylight Savings, often referred to as DST, is a practice of advancing the clocks during summer months to use the natural daylight a little longer. The clock is again adjusted backwards during fall to match the standard clock. The concept of Daylight Savings is used by many countries and therefore must be taken into […]

2 comments Read More
Core Java

TreeSet In Java

Introduction: TreeSet in Java is a sorted set of items stored in a tree-like structure. It implements the NavigableSet interface and extends AbstractSet class. Some of the properties of TreeSet includes: Unique collection of items Elements stored in a sorted order Faster access and retrieval of items The default ordering in a TreeSet is in […]

Be the First to comment. Read More
Core Java

BigInteger and BigDecimal In Java

Introduction: In this quick guide, we’ll introduce you to BigInteger and BigDecimal classes in Java. BigInteger: java.math.BigInteger is an immutable class which is used when we need to store and operate on very large integer values. Consider writing a program involving typical mathematical calculations which probably might end up with a very large integral outcome. […]

Be the First to comment. Read More
Core Java

Prime Numbers Generation In Java

Introduction: A prime number is a natural number greater than 1 having only two factors – 1 and the number itself. For eg: 2, 3, 5, 7, 11 etc are all prime numbers. Numbers that are not prime are known as composite numbers. In this tutorial, we’ll learn how to generate all prime numbers less […]

Be the First to comment. Read More
Core Java

Java – Generate Random Integer In Given Range

Introduction: Today we’ll learn ways in which we can generate a random integer in a given range – minValue to maxValue, both inclusive in Java. It is a common requirement we come across while writing some algorithmic solutions. So let’s get started! Generating Random Integer: Using Math.random() : A traditional solution to generate a random […]

Be the First to comment. Read More
Core Java

Prime Number Check In Java

Introduction: Prime Number is an integer greater than 1 and only divisible by 1 and itself. For instance – 2, 3, 5, 7, 11, 13 etc are all prime numbers. In other words, any number with only two factors – 1 and the number itself is known as a prime number. Numbers like 4, 8, […]

Be the First to comment. Read More
Core Java

Sorting In Java

Introduction: In this tutorial, we’ll learn how to sort arrays as well as collections like List, Set, and Map using Java API. Sorting Arrays: Java exposes java.util.Arrays.sort() API which helps us to sort our arrays. There are two flavors to it: public static void sort(type[] arr) //sorts array in range [fromIndex – toIndex) : toIndex […]

Be the First to comment. Read More