Day: May 2, 2021

Learn Java by Example: Java Program to Create a immutable class

Hits: 6 Java Program to Create a immutable class In this example, we will learn to create an immutable class in Java.   Example: Java program to create immutable class final class Immutable{ private String name; private int date; Immutable(String name, int date) { // initialize the immutable variables this.name = name; this.date = date; …

Learn Java by Example: Java Program to Create custom exception

Hits: 1 Java Program to Create custom exception In this example, we will learn to create custom checked and unchecked exception in Java.   Example 1: Java program to create custom checked exception import java.util.ArrayList; import java.util.Arrays; // create a checked exception class class CustomException extends Exception{ public CustomException(String message){ // call the constructor of …