Now create a new class by going to the package and right-click on it and select new and then Java Class. Name the class as DatePicker and its superclass as DialogFragment (androidx.fragment.app.DialogFragment) and click OK.
Now pass parameters to the constructor of DatePickerDialog which requires context, OnDateSetListener, year, month, dayOfMonth.
@NonNull
@Override
public Dialog
onCreateDialog(@Nullable Bundle savedInstanceState)
{
  Calendar mCalendar = Calendar.getInstance();
  int year = mCalendar.get(Calendar.YEAR);
  int month = mCalendar.get(Calendar.MONTH);
  int dayOfMonth = mCalendar.get(Calendar.DAY_OF_MONTH);
  return new DatePickerDialog(
    getActivity(),
    (DatePickerDialog.OnDateSetListener)getActivity(),
    year, month, dayOfMonth);
}
 @Override
  public void onDateSet(DatePicker view, int year, int month, int dayOfMonth)
 {
    // Create a Calendar instance
    Calendar mCalendar = Calendar.getInstance();
    // Set static variables of Calendar instance
    mCalendar.set(Calendar.YEAR,year);
    mCalendar.set(Calendar.MONTH,month);
    mCalendar.set(Calendar.DAY_OF_MONTH,dayOfMonth);
    // Get the date in form of string
    String selectedDate = DateFormat.getDateInstance(DateFormat.FULL).format(mCalendar.getTime());
    // Set the textview to the selectedDate String
    tvDate.setText(selectedDate);
}