Can you Explain this java-Calendar code
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MONTH, month-1);
Why we are passing the value of month decreasing it by one
calendar.set(Calendar.DAY_OF_MONTH, day);
calendar.set(Calendar.YEAR, year);
return calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.US).toUpperCase();
Avoid legacy classes
Among the many problems with the terrible old date-time classes bundled with the earliest versions of Java is their whacky numbering. Months of the year are numbered 0-11 for January-December.
Never use these legacy classes,
Calendar,Date, etc.java.time
Use only java.time classes.
Apparently you want the current date.
If you want to switch month but keep the year and day-of-month, use
withMonthmethod.To quote the Javadoc:
Since it seems that you want the name of the day of the week in uppercase in English, this is straightforward:
getDayOfWeekreturns aDayOfWeekenum constant. If you need aString, use itstoStringmethod.