Posts

Showing posts from August, 2007

Calendar class - Better Way to Manipulate Dates.

Java’s Calendar class offers a set of methods for converting and manipulating temporal information. In addition to retrieving the current date and time, the Calendar class also provides an API for date arithmetic. Calendar’s built-in date/time arithmetic API is extremely useful. This tutorial examines the Calendar class API and presents examples of how you can use Calendar objects to add and subtract time spans to and from dates and times, as well as how to evaluate whether one date precedes or follows another. Adding time spans Let’s say you want to add a time span to a starting date and print the result. Consider the following example, which initializes a Calendar to 16 July 2007 and then adds two months and three days to it to obtain a new value: import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.GregorianCalendar; public class CalenderDemo{ public static void main(String[] args) { CalenderDemo tdt = new CalenderDemo(); tdt.calculateDa

Reflection APIs - A way to inspect classes at runtime

Java Reflection is a technology that looks inside a Java object at runtime and sees basically everything about the object that you would know at compile time. Java Reflection is a technology that looks inside a Java object at runtime and sees what variables it contains, what methods it supports, what interfaces it implements, what classes it extends—basically everything about the object that you would know at compile time. The Reflection API is located in the java.lang.reflect package and is included in any J2SE installation. Primarily it is intended for very generic programs such as database browsers or visual code editors, but it can be used in any other applications. Reflection is for Basic techniques There are two basic techniques involved in Reflection: discovery and use by name. Here are descriptions of both: Discovery involves taking an object or class and discovering the members, superclasses, implemented interfaces, and then possibly using the discovered e