The maximum for a UDP datagram is limited by the maximum IP packet size of 65,535 octets/bytes.
Part of the IP packet is used by headers - at minimum, 20 bytes for IPv4 without options, and 8 bytes for UDP. This results in a maximum UDP datagram size (including UDP header) of 65,515 bytes, the maximum payload 65,507 bytes. IPv6 increases its header size to 40 bytes, so its 20 bytes less for UDP.
Most networks don't support maximum sized IP packets in one piece. Fragmentation allows passing of packets larger than the underlying network allows directly.
Without fragmentation, an IP packet needs to fit into the current link layer's data frame. For standard Ethernet, the maximum payload is 1500 bytes, so the maximum unfragmented UDP datagram is 1480 bytes for IPv4 or 1460 bytes for IPv6.
If you don't know the underlying network's frame size, the answer is more complicated. In theory, the MTU may be as small as 68 bytes (see RFC 791), so only UDP datagrams of 48 bytes are absolutely guaranteed without fragmentation over IPv4. IPv6 increases the minimum MTU to 1280 bytes, so a UDP datagram of 1240 bytes is guaranteed unfragmented.
The application layer protocol is carried as payload in the UDP datagram, so above limitations apply.