That's an easy one: It makes no difference.
If there were two voices on this staff, upward and downward stems might be used to distinguish them, e.g. to show whether the two voices cross or merely intersect briefly. But as it is, stem direction has no meaning and is chosen solely for aesthetic reasons.
With vocal music, beams are traditionally following the lyric syllables. This is not uniformly so these days and does not match the beaming used for non-vocal instruments.
Beaming direction is used for distinguishing voices when several are present.
The manuscript (and consequently the Urtext) of the preludio in Bach's Partita III for solo violin shows some more subtle variants: in the first two lines, beaming direction is without semantic significance and is chosen in order to minimize total size. In the third line, beaming direction indicates voicing as expressed by string choice (beam up->E, the higher-sounding string, beam down->A the lower-sounding string but fingered in a manner where its notes may be higher than those on the empty E string).
In the fourth line, a three-string passage starts. However, the beaming only indicates the continued use of the E-string: the additional use of the D-string is only implied because of the covered range of all beam-down notes.
Adaptions to multi-manual keyboard instruments (including by Bach himself) single out only the E-string notes since three-voiced play in that manner does not work well beyond two hands.
Now with regard to the notes produced, the beam direction and beam grouping is not all that relevant. But it gives hints to the musical idea behind it and consequently for phrasing and execution.
In a single line of notes - one voice, it's only to tidy up the presentation. Notes which are on the middle line and above generally have stems down, notes below, stems up. In your example, the first is slightly easier to read. There's also the thought that in 4/4 and 6/8, bars could be split in half, again easier to read, so if, for example,(4/4) there was a dotted crotchet followed by another dotted crotchet, it's easier to read as a dotted crotchet followed by a quaver tied to a crotchet. Some disagree, but that's how it used to be done. Now, things are more lax.
Grouping of similar notes tidy up too. With 8 quavers in 4/4, they look better as 2 groups of 4. With multiples, there's no need to write singles as in your second example, although if they had words, and a phrase ended on ,say, the 3rd quaver, it's not bad to separate that to help show phrasing.
Other answers have already mentioned different voices, satb for instance being stem specific - s treble clef up, a treble clef down, t bass clef up, b bass clef down.
The notes are also grouped differently in the two bars. Technically this doesn't make any difference to what's written, but depending on how pedantic you want to be they "should" be grouped correctly for the time signature (see e.g. mymusictheory.com).
Insisting on correct grouping may seem like nit-picking but it can make all the difference to someone sight-reading a score, particularly if there are changes of time signature.