How do I get the username from the user ID?
You can use user_load or \Drupal\user\Entity\User::load to do this. Below code will provide the solution

 public function content() {
     $account = \Drupal\user\Entity\User::load('uid'); // pass your uid
     $name = $account-&gt;getUsername();
     drupal_set_message($name);
 }


$name gives the username of the user.