import java.util.Calendar; Calendar cal = Calendar.getInstance(); int year = cal.get(Calendar.YEAR); System.out.println("Current year: " + year);
import java.util.Calendar; Calendar cal = Calendar.getInstance(); cal.set(2022, Calendar.JANUARY, 1); System.out.println("New date: " + cal.getTime());This code gets the current instance of the Calendar class and uses the set() method to set a specific date, in this case January 1, 2022. It then prints out the new date to the console. The package library for the java.util.Calendar class is java.util.