Dialogue is like human speech, but focused
A great place to start when becoming a master of dialogue is to transcribe a real conversation between real people. You'll see that people stutter, say "um" and "like", they repeat themselves, interrupt each other or jump from one subject to the next.
This would be profoundly uninteresting to read in a book. Thus, dialogue in a book resembles human speech, but it is focused, cutting out all the flab — the small talk, the unnecessary words, the repetition.
The purpose of dialogue
The purpose of dialogue falls in this order:
To reveal more about a character's personality.
To reveal information about the plot.
To advance the themes.
First and foremost, dialogue is about character — because without characters, we wouldn't have any dialogue! If you're using dialogue to simply convey information, chances are, it is going to be boring to read — sometimes, this is a necessary evil, so when you do, make sure we're learning more about the character in how they convey this information.
Dialogue is more than just talking
What's more interesting, to read about a discussion, or to read an argument? Give your characters the strongest possible playing field.
instead of discussing, have your characters argue
instead of talking, have your characters persuade
instead of informing, have your characters gossip
instead of chatting, have your character confessing or admitting.
Also, remember that characters are usually doing something while they talk, whether it is:
watching a football game
trying on clothes
writing a note
or simply fidgeting.
Build characters through dialogue
The way your character speaks is of upmost importance — we can discern a lot just by how someone speaks. We can understand characters better through:
their choice of words (do they swear? do they use fancy words or simple words? do they use colloquialisms?)
the grammar and sentence structure (do they speak in complete, grammatically correct sentences? do they skip words or use words in the wrong place?)
how much they say (do they blabber or do they use one word sentences?)
how they speak (do they brag? crack jokes? insult others? encourage others?)
Have your characters each speak in such a unique way that you don't need to put a dialogue tag ("Jane said") at the end of each line — people should be able to tell who is speaking simply by their manner of speech.
What you put around the dialogue counts
Here are some general tips:
you don't need a "he said" or "she said" after every line
decide when action is better than words (sometimes it may be better for a character to simply "nod stoically" than to say "yes")
add adjectives (instead of "Jane said", try "Jane argued", or "Jane persuaded", or "Jane yelled")
choose how they respond (what a character thinks someone said is often more important than what the character actually says. Additionally, people don't always directly respond to questions, sometimes they ignore a question, answer another question or change the subject).
Give them something interesting to say
First, think about the most interesting topic to talk about, then think about who the most interesting person is to say it. Think about who has the biggest stake, or the strongest opinion on an issue, and let that character speak.
“When characters have different goals and are intent on achieving them, conflict results. If the stakes are high and both sides are unyielding, you have the makings of high drama.” – James N. Frey
An example of dialogue done right
Patricia grinned. "Jane broke up with Greg two months ago; he's now single."
"Single, really?" Danielle asked.
Now, applying what we've talked about:
Patricia lowered her chin, her voice an excited whisper. "I heard from my dressmaker that Jane broke with Greg two whole months ago — called off the engagement without a reason!" A solemn expression rested on her face, but her eyes remained alight. "Greg is single. Ripe for anyone's taking."
Danielle clenched her hands, trying to stop them from shaking. "Single, really?"
The second example is much better. Not only do we find out the important information (Greg is single), we're also learning more about Patricia — that she's a gossip, loves drama and sees Greg as an prize object to possess.