Posts

Showing posts with the label CoreJava

how to find total weekends between two dates in java

Image
In this article we are going to learn about Date class in Java and also placed few of the examples to find total weekends between two dates and to find Saturday and Sunday's in the current year. In this article we are going to use Serializable, Cloneable and Comparable in Java. If you should have basic knowledge about these interfaces, good enough. Date: Date class is part of java.util package. Which will specify the current date with Time. In other words, the Date class represents specific instant in time, with milliseconds precision. Date class inherits methods from the super class called Object. Internal declaration of Date class is as follows, public class Date extends Object implements Serializable , Cloneable , Comparable < T > As per the above lines, Date class implements Serializable, Cloneable, Comparable interfaces on top of Java super class called Object. How to create Date object? Since, Date is a normal class, we can create object directly

Prime, Fibonacci and Factorial number with example in java

Prime number, Fibonacci series and Factorial number programs are most commonly asked questions in interview. Read this article to know what is and how to write programs for prime number, fibonacci series and factorial number. Prime Number: prime number is natural number greater than 1 that has no positive divisor other than 1 and itself. A natural number greater than 1 is not a prime number, is called Composite number . For example, 7 is a prime number. Because it can divide with 1 and 7 only. Where as 8 is composite number. Since it has the divisor 2 and 4 in addition to the 1 and 8. The below example represents the finding the passing number is prime number or not. If the passing number is prime number it will print true otherwise it will print false. package com . javatbrains . practice ; public class PrimeNumber { public boolean isPrimeNumber ( int number ) { if ( number <= 1 ) return false ; // There's only one