java.util

Generate Random Numbers Java

Many a times random number generation is required in coding, especially in testing. When different sequence of numbers are passed multiple times, a correct result should to be obtained; testing requires this. Sometimes, the same sequence of random numbers is also required multiple times in testing; when the same sequence…

What is Date, Calendar in Java?

Date and Time manipulation is a must in every programming. Date, GregorianCalendar, SimpleDateFormat classes placed in java.util package comes to the rescue for all possible operations on date and time. Following postings of this same Web site give all the possible operations on Date and Time manipulations. 1. class Date…

How to use SimpleDateFormat in Java?

SimpleDateFormat class is used for many jobs of getting time as per the locale, converting date one form to the other etc. Date formats like yyyy-mm-dd are also shown with examples. 1. SimpleDateFormat to set time as per the country with Locale 2. SimpleDateFormat to convert Date object to String…

Java Deprecation

What is Java deprecation and why it is necessary in a programming language, say, Java? Java Deprecation: 1. A method introduced in one version of Java may become outdated in the next version as next version method is a better method than the old version method. We call old version…

Convert Milliseconds to Date Java

In Java coding, many times it is required to read the system time and at the same time convert the system time into objects of Date and Calendar etc. Following code illustrates. Example on Convert Milliseconds to Date Java

Output screen on Convert Milliseconds to Date Java There are…

Dates Comparison Java

It is many times required in coding to compare two dates like one is before the other or after or equals (like dates of joining a job). To manipulate dates, Java comes with mainly two classes from java.util package Date and Calendar (its subclass GregorianCalendar). Three programs are given to…

Char Comparison Java

For comparing two characters logical equals (==) operator can be used. Alternatively, the chars can be passed to Character constructor and compared with equals() method. The following program illustrates. Program on Char Comparison Java

Output screenshot on Char Comparison Java Two characters can be compared using logical equals (==)…

class Random Generate random numbers

class Random Generate random numbers Summary: By the time you complete this "class Random Generate random numbers", you will understand of how to generate random numbers in Java. Introduction to class Random Generate random numbers Generating different numbers at different times of execution, by the same program, is known as…

Observer and Observable Java

Observer Observable Introduction Sometimes, it may be necessary to get notified when the data changes in a data structure. To accomplish this job, the Java designers introduced Observer and Observable classes with JDK 1.0, the starting version itself. Observer is an interface and Observable is a class, both from java.util…

StringTokenizer Tokenizing String

After knowing the data structures from java.util package, let us discuss about the remaining classes of java.util package. The classes include Date and GregorianCalendar to manipulate dates, Random class to generate random numbers and StringTokenizer to separate the string into individual words (known as tokens). The other classes less used…

class GregorianCalendar

GregorianCalendar is a concrete class, a subclass of abstract class Calendar. The GregorianCalendar class represents the calendar we use everyday. It is used to manipulate date and retrieve date particulars. This was introduced with JDK 1.1. Following statement gives the class signature public class GregorianCalendar extends Calendar Following program illustrates…

Timer TimerTask Java

Timer TimerTask Java Introduction The classes, Timer and TimerTask from java.util package, introduced with JDK 1.3, are used with threads to animate the images at regular intervals of time. If the stipulated (delay) period of time is over, the Timer object can generate events. Simply by handling the event, the…