How to find even and odd number in Java - Program tutorial example

Even and Odd number check Java Example
There are many way to find if a number is even or odd in Java but before moving into technical details on finding even and odd number in Java let's what is even and odd number in terms of Mathematics. Any number which is completely divisible by 2 is called even number while number which is not completely divisible by 2 is called odd number. If you think in terms of remainder than in case of even number, remainder is zero while in case of odd number remainder will be 1. zero is considered as even number in maths. We can use this property to find whether a number is even or odd in Java. Java has a remainder operator also called modules operation denoted by % which does exactly same. it return remainder as a result of division. here is an Java sample program of finding even and odd number using remainder and bitwise AND operator in Java.

Difference between ArrayList and HashSet in Java

ArrayList vs HashSet Java
Main difference between ArrayList and HashSet is that one is a List implementation while other is a Set implementation. It means all the differences between a List data structure and a Set data structure also applies to this pair. For example, List implementations are ordered, it store element in the order they were added, while Set implementation doesn't provide such guarantee. Similarly, since List provides Random access, you can access any element directly if you know the index, but Set doesn't provide such facility. You need to Iterate through whole collection to get access of any elements. We will see couple of more difference in this Java tutorial. By the way ArrayList and HashSet are two most common Collection class used in Java programming language and before discussing difference between ArrayList vs HashSet, let's see some similarities between them :

Java Program to find Armstrong numbers with Example

Armstrong number Example in Java
How to check if a number is Armstrong number or not? or write a Java program to find Armstrong number? This is a common Java interview question asked on campus interviews and fresher level interviews. This is also a popular Java programming exercise on various school, colleges and computer courses to build programming logic among Students. An Armstrong number is a 3 digit number for which sum of cube of its digits is equal to the number itself. An example of Armstrong number is 153 as 153= 1+ 125+27 which is equal to 1^3+5^3+3^3. One more example of the Armstrong number is 371 because it is the sum of 27 + 343 + 1 which is equal to 3^3 + 7^3 + 1^3 . In this Java program example, we will see complete code example of Java program to check if any 3 digit number is Armstrong number or not. If you are going for Java interview, then be prepare for some follow-up questions e.g. finding prime numbers, or finding Armstrong number of more than 3 digits.