import java.util.Date; public class DateExample { public static void main(String[] args) { //create a new date object Date date = new Date(); //get the day of the week using getDay() method int dayOfWeek = date.getDay(); //print the day of the week System.out.println("Day of the week: " + dayOfWeek); } }This code creates a new date object and uses the getDay() method to retrieve the day of the week. The result is then printed to the console. The getDay() method is part of the java.util package, which is a standard Java library package that provides various utility classes for working with dates, times, and other data types.