Both methods work, but they do not produce the same flavor. Vegetables charred directly over a flame take on smoky notes; the skin chars quickly while the inside cooks only a little, which is why this is the preferred method for eggplant. The oven cooks more evenly and cleanly and can handle many vegetables at once, but it does not provide that smoky flavor. Choose based on whether the recipe calls for smokiness.
Direct flame is the fastest method. Place the vegetable on the stovetop grate and let the flame char the skin directly; as the skin blackens, the flesh inside cooks only partially. The defining feature of this method is its flavor: smoke from the burning skin infuses the flesh and gives charred eggplant its familiar note. Turn the vegetable with tongs until every side is blackened. This method does not work on an electric stove because there is no flame; use a cast-iron pan or the oven instead. Clean the stovetop grate immediately after charring, because cooled bits of skin stick to it and are difficult to remove later.
The oven is a gentler method and requires organization. Arrange the vegetables in a single layer on a baking sheet, place it on the oven's top rack, and turn on the broiler. The skins will still blacken, but smoke does not infuse the flesh to the same degree; the result is a milder, sweeter char. In return, you can char fifteen peppers at once without filling the kitchen with smoke. Do not put vegetables of different sizes on the same baking sheet, because the small ones will burn while the large ones remain raw. Do not line the sheet with parchment paper; it can easily scorch under the broiler, so use the bare baking sheet.
A charcoal grill is better than either method and gives the best result outdoors. The coals provide both high heat and smoke; if you place the vegetable on the edge of the grill rather than directly over the coals, the skin can char while the inside has time to cook. Put vegetables to be charred on the grill before the meat is cooked, because vegetables added later pick up smoke from fat dripping off the meat, which changes their flavor. Vegetables can also be charred on the grill during the final stage, as the fire begins to die down, because the embers are still hot enough.
Which method suits each vegetable is also clear. Eggplant needs a flame; much of the flavor of charred eggplant comes from that smoke. Peppers turn out well with either of the two methods, and the oven is more practical when charring a large number. Tomatoes do better in the oven because they fall apart easily over a flame. Roast garlic and onions in the oven with their skins on; a flame burns them before the insides cook. Firm vegetables such as zucchini and carrots are better suited to being sliced and grilled than charred.
A few precautions make the job easier. Before charring eggplant, prick it in several places with a fork; if the steam trapped inside has no way to escape, the skin can burst suddenly. Lining the area under the stovetop with foil makes drips and bits of skin easier to clean up. Turn on the kitchen ventilation, because charring produces a lot of smoke. Choose long-handled tongs, and do not turn vegetables over the flame by hand. As soon as charred vegetables are removed from the heat, put them in a covered container; this makes them easier to peel and keeps the counter clean.