Heavy quarks, such as charm or bottom quarks, are predominantly produced in the initial hard partonic scatterings of heavy-ion collisions due to their large masses. Therefore,
they participate in the entire evolution of the created medium. Moreover, their production cross-sections can be calculated using perturbative QCD (pQCD), making them ideal
probes of the Quark-Gluon Plasma (QGP), the strongly interacting matter under extreme conditions. Heavy quarks can be studied using heavy-flavor hadrons.
Heavy-flavor hadrons can be divided into open heavy-flavor hadrons, which carry a single heavy quark, and quarkonia, which are bound states of a heavy
quark and its antiquark. Both quarkonia and open heavy-flavor hadrons can be employed as tools for investigating heavy-quark dynamics in the QGP created in heavy-ion collisions.
The observation of quarkonium suppression in heavy-ion collisions has been considered strong evidence of QGP formation and an important probe of the QGP
medium's thermodynamic properties. Changes in the production rate of quarkonia in the QGP are indicative of hot matter effects, such as static and dynamic
dissociation processes induced by the medium, as well as contributions from regeneration and cold nuclear matter effects. On the other hand, the reduction
in production rate and the directional asymmetry of open heavy-flavor hadrons are linked to heavy-quark energy loss and the level of thermalization in the QGP medium.
STAR is a versatile experiment that examines a range of physics phenomena observed in high-energy $p$+$p$ and heavy-ion collisions. One of the primary objectives
of the STAR experiment is to investigate the properties of the QGP. This contribution discusses recent measurements of open heavy-flavor hadrons and quarkonia
in $p$+$p$ and heavy-ion collisions from the STAR experiment at RHIC.