How do I convert day-of-year to day-of-month?

package org.kodejava.util;

import java.util.Calendar;

public class DayYearToDayMonth {
    public static void main(String[] args) {
        // Create an instance of calendar for the year 2017 and set the
        // day to the 180 day of the year.
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, 2021);
        cal.set(Calendar.DAY_OF_YEAR, 180);

        // Print the date of the calendar.
        System.out.println("Calendar date is: " + cal.getTime());

        // To know what day in month of the calendar we can obtain the
        // value by calling Calendar's instance get() method and pass
        // the Calendar.DAY_OF_MONTH field.
        int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);

        // Print which month day is it in number.
        System.out.println("Calendar day of month: " + dayOfMonth);

        // To know what day in week of the calendar we can obtain the
        // value by calling Calendar's instance get() method and pass
        // the Calendar.DAY_OF_WEEK field.
        int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);

        // Print which week day is it in number.
        System.out.println("Calendar day of week: " + dayOfWeek);
    }
}

The result of our above example is.

Calendar date is: Tue Jun 29 08:14:06 CST 2021
Calendar day of month: 29
Calendar day of week: 3

How do I get number of days in a month?

Let say you want to know the number of days in a month, or we can say it as the last date of a month. The example below shows you how to obtain the number of days or the date.

package org.kodejava.util;

import java.util.Calendar;

public class MonthDaysExample {
    public static void main(String[] args) {
        // First get an instance of calendar object.
        Calendar calendar = Calendar.getInstance();

        // We'll set the date of the calendar to the following
        // date. We can use constant variable in the calendar
        // for months value (JANUARY - DECEMBER). Be informed that
        // month in Java started from 0 instead of 1.
        int year = 2021;
        int month = Calendar.FEBRUARY;
        int date = 1;
        // We have a new date of 2021-02-01
        calendar.set(year, month, date);

        // Here we get the maximum days for the date specified
        // in the calendar. In this case we want to get the number
        // of days for february 2021
        int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        System.out.println("Max Day: " + maxDay);

        // Here we want to see what is the days for february on
        // a leap year.
        calendar.set(2020, Calendar.FEBRUARY, 1);
        maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        System.out.println("Max Day: " + maxDay);
    }
}

The result of the code snippet above:

Max Day: 28
Max Day: 29

In JDK 8 you can use the new Date Time API to get the number of days in a month. Here an example that show you how to do it: How do I get the length of month represented by a date object?.