public class ApplTest { public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException { int year = 1988 , year2 = 1999; // Data For Date int month = 11 , month2 = 9; // Data For Date int day = 9 , day2 = 12; // Data For Date Date start_date = new Date(year,month,day); Date end_date = new Date(year2,month2,day2); Coupon coupon = new Coupon(); coupon.setAmount(0); coupon.setEndDate(end_date); coupon.setStartDate(start_date); coupon.setId(1234); coupon.setImage("electricity.bmp"); coupon.setMessage("Hello from coupon"); coupon.setPrice(32); coupon.setTitle("Only for couple"); coupon.setType(CouponType.CAMPING); new Validation().validate(coupon); } static class Validation { public boolean validate(Coupon coupon) throws NoSuchFieldException, IllegalAccessException { Field[] fields = coupon.getClass().getDeclaredFields(); for(Field field: fields){ Annotation[] annotations = field.getDeclaredAnnotations(); for(Annotation annotation:annotations){ System.out.println(annotation); } field.setAccessible(true); System.out.println(field); String name = field.getName(); System.out.println(field.get(coupon)); } return true; } } } Console output:
private long beans.Coupon.id 1234 private java.lang.String beans.Coupon.title Only for couple private java.sql.Date beans.Coupon.startDate 3888-12-09 private java.sql.Date beans.Coupon.endDate 3899-10-12 private int beans.Coupon.amount 0 private java.lang.String beans.Coupon.message Hello from coupon private double beans.Coupon.price 32.0 private java.lang.String beans.Coupon.image electricity.bmp private beans.CouponType beans.Coupon.type CAMPING When displaying the Date information, I get something that is not clear, who can explain why?