Shortcut to generate Getter and Setter in Eclipse

What are Getter and setter methods ? Getter method is to retrieve the value of instance variable while a setter method is used to set or update the value of instance variable. It is a good practice to access instance variables through these methods instead of directly accessing because we can place some pre-conditions before … Read more

isBlank() vs isEmpty() in String class Java

isBlank() is a new method introduced in String class in Java. By naming isBlank() and isEmpty() methods look similar to each other, but there is a slight difference between them – isBlank() returns true for the string having only white space characters whereas isEmpty() will return false for such strings. Let us understand the difference … Read more

Binary Search in Java

Binary search is an optimized algorithm to perform searching operation. It follows Divide and Conquer approach for searching. Pre-condition of Binary search : To perform Binary search the array should be sorted in ascending or descending order. Logic of Binary Search Let us consider array is sorted in ascending order. Now we compare the element … Read more

isDigit in Java

isDigit is a static method of Character class. It is used to determine whether a character is a digit or not. If the character is digit then isDigit return true otherwise it return false. Let us look at an example code : Output

Comparator in Java

Comparator Interface is a very useful interface which is used to sort the objects on some predefined conditions. Usually when we want to sort Integer type ArrayList then we use Collections.sort(arrayListName). This will sort the list of integers in ascending order. But what if we want to sort Student objects based on the marks students … Read more

How to exit a program in Java

In Java if we want to terminate the execution of the program then we make use of System.exit(n) method. Let us see important points : System.exit(n) method takes a non zero argument to indicate abnormal termination. System.exit(n) will exit the program irrespective of the operation being performed. If we call System.exit(n) within a try catch … Read more