Both situations are daunting in their own way, but with experience and the right tools you'll be able to handle either without a problem, and perhaps even get to the point where one day you welcome those challenges as an interesting interlude in an otherwise inconspicuous day.
That said, what exactly do you do?
Well, let's take the first example. Your class is screaming out of control, students are up out of their desks and running around, and there is no way in heaven you are going to get them under control.
That depends. What is your class size? If it's 50, you might be able to get 25-35 of the students to quiet down. If your class is 10-15 you can get all of them to do just that.
Nothing grabs an unruly class's attention like a good book, if used properly. I like to take it in both hands and, in one quick motion, raise it above my head and then slam it down onto the floor as hard as I can. If you hit the cover just right it will give you an incredibly loud slapping sound that will produce a dead silence.
Now, this is the tricky part, and one that I find works a lot easier the less students you have: let them know you're angry. Tell them you're angry, but even better, show them. You just did it right? Well, rarely do people learn something the first time. Put on your angry face. Milk that silence, but also break it. This is probably the only time in class where you'll be able to talk quietly, perhaps even whisper, and everyone will hear you.
So what do you say? I shame them.
"Listen, I don't want to be here. I don't like you, any of you! You think I like being here? Ha! Why would I? Who would? Look at you, yeah, just look. Go head, take a good look around. Do you see it? Yeah, that's right, each other. You're the future of China. The country's hopes and dreams are riding on you, and if they saw what I'm seeing right now they'd never stop being sick. You should be ashamed of yourselves, but I guess that's not an emotion you often feel, shame. How could you when you've got four grandparents and two parents giving you whatever you want whenever you want? Well, in this class, do you know what I'll give you, nothing. And if you don't like it you can walk right out that door over there. In fact, please do, I would be happier if you all just left."
One of the biggest challenges is a class that is looking at you quietly and expectantly and ready to learn. All of a sudden you've got 25% more time on your hands, time that you thought you'd be spending dealing with behavioral problems. How do you fill it?
Every teacher needs backup materials. Tried-and-true, trusted, things that get the job done. Whether it's a dozen crosswords or word searches that you can pass out as the lesson dictates, a survey, running dictation, game, handout, PPT, or whatever, you will come to need these things, most often when you least expected it. It's just another one of those things that differentiates the good teachers from the merely able.