I have got a requirement in which i need to execute a function at specified time set by the user.The function contains the code to generate a pdf file from database and save it
Okay, so I looked a bit into the Timer class and found your approach to be almost correct. You'll need to edit your code a little bit to get the wanted functionality.
Calendar calendar = Calendar.getInstance();
date.set(Calendar.DAY_OF_WEEK, getUserInputDay()); //
calendar.set(Calendar.HOUR_OF_DAY, getUserInputHour());
calendar.set(Calendar.MINUTE, getUserInputMinute());
calendar.set(Calendar.SECOND, getUserInputSeconds());
Date time = calendar.getTime();
timer = new Timer();
timer.schedule(new ReportGenerator(), time);
This will start a timer that launches the "ReportGenerator" at the stated time. You'll have to figure out yourself how to get the input from the user (should be fairly simple!)
There is a good library called quartz that I can recommend. Its main purpose is starting jobs at a given time.