Whisk the egg yolks together with the sugar and cornstarch.
Heat the milk and vanilla in a saucepan over medium heat until it is scalding hot.This means that there is steam rising from it and you can see tiny bubbles starting to appear on the surface. Do not let it boil.
When it begins to get warm, drizzle a small amount of hot milk into the egg yolk mixture and whisk, then add a little more, repeat until everything is together in the bowl, then pour the whole mixture back into the saucepan. It's important to do this slowly and gradually so you don't scramble the eggs.
Keep heating the mixture, whisking constantly until it begins to boil. Boil for 1-2 minutes until you see thick bubbles bursting on the surface. It should be thick enough that you can draw a line in it on the back of a spoon - if it isn't, keep boiling until you reach that stage. Remove from the heat.
Pass the pastry cream through a sieve into a bowl to make sure there are no lumps.
Whisk in the butter one small piece at a time, making sure it melts into the mixture completely before adding the next piece.
Cover with plastic wrap (make sure the plastic wrap is touching the surface of the pastry cream to prevent a skin from forming) and refrigerate for at least two hours. I like to make this the day before and let it sit overnight, but it can be used after 2 hours.
Notes
Make sure you whisk constantly while your custard is on the heat - if you let it sit, you will end up with lumps of egg or burnt pastry cream!When your pastry cream is ready, you will be able to coat the back of a spoon and run your finger through it to make a line - the line will not fill in, it should stay visible. This means your pastry cream is cooked enough. If left to develop overnight, the custard has a much richer flavor - if you have time I highly recommend this!