Eighth season fourth episode,Ross recorded making love to Rachel????!!!!!

[Scene: The Hallway, Chandler and Monica are returning from their honeymoon.]

Chandler: Wait. Before we go in, I just want you to know I love you. I had a great time on our honeymoon, and I can't wait to go in there and spend the rest of our life together.

Monica: You're really sticking with the shell necklace huh? (Points to necklace of shells he's wearing.)

(Joey and Phoebe burst forth from his apartment.)

Phoebe: Hi!

Joey: Hey! You're back! (Hugs and kisses all around.)

Monica: Hi sweetie!

Phoebe: Come on in!

(They grab the luggage and drag it into Joey and Rachel's forcing Monica and Chandler to follow.)

Phoebe: So how was the honeymoon?

Monica: Oh, so much fun. But the best part is, we met this incredible couple on the way back.

Phoebe: That was the best part? (To Chandler) Good honeymooning tiger.

Monica: No, they were really cool. They were on their honeymoon too!

Chandler: They're terrific, and they live right here in the city.

Monica: Yeah, can we go call them? Is it too soon to call? I wanna call.

Chandler: I'm sorry, we're just kinda excited because we finally have a couple to hang out with.

Monica: I know.

Joey: A couple? Like two people? Like (points to himself) one (points to Phoebe), two people?

Monica: This is different! Greg and Jenny are in a relationship.

Phoebe: Oh, Greg and Jenny yuck! (Angrily) Hi Greg, I'm Chandler this is Monica. Hi Monica, this is Jenny. Hi Jenny. Hi Greg.

Chandler: Listen, they are really great. If you just got a chance…

Joey: Y'know what? Why don't you just give us our souvenirs and get the hell out of here?

Chandler: We really…didn't get a chance to…

Phoebe: You have got to be kidding me!

Monica: We didn't get anything for anyone.

Joey: Hm-mm! Yeah nice necklace!

Monica: That you can have.

Opening Credits

{Transcriber's Note: Tradition was broken here as there were no commercials immediately after the opening credits, just more show.}

[Scene: Monica and Chandler's, Ross and Rachel are entering with the rest of the gang already inside.]

Rachel: Hi!

All: Hey!

Ross: Hello!

Rachel: Welcome home.

Ross: So, how was the honeymoon?

Monica: It was great! It was great! How about you?! I mean you're having a baby!

Rachel: Oh! Look! I have a sonogram picture!

Monica: Oh great! (Shows them the picture.)

Chandler: Ross! It's got your wavy black lines!

Monica: All right, so now that Ross knows can you tell us y'know how it happened? I mean, when did it happen? How many times did it happen?

Phoebe: Monica! That's not right! Start with where.

(Rachel looks at Ross and gets his approval.)

Rachel: Well it happened about six weeks ago, and uh I had just got home from work and Ross was already there 'cause I guess he had been hanging out with Joey.

Joey: You're welcome buddy.

Ross: (glaring at him) Yeah, thanks. (Joey nods no problem.)

Rachel: And so I had a lot of work to do so Ross, nice guy that he is, offered to help me out. And then we had a little wine, we got to talking, and the next thing you know out of nowhere Ross comes on to me.

Ross: (laughs) Umm that's…that's a little misleading.

Rachel: What is?

Ross: The lie you just told.

Rachel: That-that you came on to me?

Ross: There's the one!

Rachel: But you did! I mean, let's be honest.

Ross: Yes let's. Y'know what? Uh, it's-it's not important. What is important is that, is that we're having a baby. And it's not—Doesn't matter who came on to who.

Joey: Whom. (Everyone looks at him shocked.) That's right.

Rachel: You know you kissed me first.

Ross: What? What?! You were begging me to kiss you! You-you-you were sending me signals all over the place!

Rachel:** I** was sending you signals?

Ross: Yeah!

Rachel: Oh please. Okay, anyone in this room think that I would send Ross begging symbols, please show of hands. (Ross raises his hand and no one else.)

Ross: Y'know what?! It doesn't matter! It doesn't matter what you believe! What matters is what happened!

Rachel: Okay. So these signals Ross, explain this to me, 'cause maybe I need to be more careful. I mean, am I sending you these signals right now?

Ross: Y'know what? Y'know what? Rachel, just-just drop it.

Rachel: No please, show me how I begged you!

Ross: I can show you, I have it on videotape! (Stunned silence) It's an expression.

Commercial Break

[Scene: Monica and Chandler's, time has lapsed, Phoebe, Joey, Chandler, and Monica are sitting at the kitchen table.]

Phoebe: I can't believe he taped the two of them having sex!

Joey: Yeah! You gotta tell a girl before you tape her. Such a rookie mistake.

Chandler: Y'know who has a great video camera?

Phoebe: (nasally) Greg and Jenny?

Monica: Do you still wanna call 'em? I wanna call 'em.

Chandler: Let's call 'em.

Joey: Yeah! Ask them if they brought their friends any souvenirs!

(Monica goes over and dials their number.)

Monica: (on phone) Hello? (Listens) Eighth street deli?

Joey: Hey, hang up! You get food poisoning just talkin' to that place.

Monica: (on phone) Uh sorry, wrong number. (Hangs up)

Chandler: Here you go. (Shows her the number again.)

Monica: (on phone) Hello? (Listens) (To All) It's the deli again!

Joey: All right! I'll have a sandwich!

Monica: (hangs up) I don't think this number's right!

(Joey and Phoebe laugh.)

Chandler: What?

Phoebe: You got fake numbered.

Monica: What?! People don't do that!

Joey: Oh I think we do.

Monica: They gave us a fake number? Why? Why would they do that?

Chandler: I don't know! You were a delight to talk to. You asked all those insightful, great questions.

Monica: And you've never been funnier. Joke, joke, joke, you were a hoot!

Joey: Y'know what? Don't worry about it, you still got me and Phoebe.

Phoebe: Excuse me, I don't want Greg and Jenny's rejects.

Ross: (entering) Rachel won't talk to me! She won't even open the door!

Phoebe: Hmm, I wonder why. Pervert!

Ross: Okay, listen I am not a pervert!

Phoebe: That's like the pervert motto! Yeah! Yeah! They have you raise your right hand, put your left hand down your pants, and repeat that!

Ross: Filming Rachel is not something I planned. Okay look, here's what happened, and Joey you-you can back me up on this. All right, about-about a month and a half ago I came to you with a problem? Umm, a personal thing.

Joey: Personal thing? What personal thing? I don't know.

Ross: About…about sex? (Joey looks at him confused) That I hadn't had sex in months?

Joey: (laughs) Yeah I knew what you were talkin' about.

Six Weeks Earlier

[Scene: Joey and Rachel's, Joey is reading a cereal box as Ross enters wearing the red sweater.]

Ross: Hey!

Joey: Hey.

Ross: Do you have a minute? I'd like to talk to you about something I'm, I'm really uncomfortable talking about.

Joey: Sure. What? About uh, you showering with your mom?

Ross: I actually had a topic in mind! I'm, I'm kinda going through a dry spell, sex wise.

Joey: Whoa, for like months?

Ross: Five to be lying, six.

Joey: Six months? Whoa that's rough.

Ross: Well, I mean it's not all bad. I'm learning to appreciate the uh, smaller things in life. Like the sound of a bird and the color of the sky.

Joey: The sky's blue Ross and I had sex yesterday!

Ross: Please, help me! I have a date tonight. It has to go well okay—I'm scared for my health!

Joey: Okay. Okay. Umm…Ooh! Oh-oh, I got something. It's this story I came up with, very romantic. I swear any woman that hears it; they're like putty.

Ross: Really? Well then tell it to me.

Joey: Okay. Now you're gonna want to have sex with me when you hear it, but you have to remember it is just the story.

Ross: (sarcastic) I'll try to control myself.

Joey: Okay. (Clears throat) Years ago, when I was backpacking across Western Europe…

Ross: (laughs) You were backpacking across Western Europe?

Joey: Have a nice six more months Ross! (Starts to leave.)

Ross: (stopping him) Okay! Okay! Okay. I'm sorry. Please, please, you were in Western Europe and?

Joey: I was just outside Barcelona hiking in the foothills of Mount Tibidabo. I was at the end of this path and I came to a clearing and there was a lake, very secluded. And there were tall trees all around. (Whispering) It was dead silent. Gorgeous. (Softly) And across the lake I saw…a beautiful woman…bathing herself…but she was crying…

Ross: (intently listening) Why?

[Scene: Ross's Apartment, Ross is on his date with Kristen and they're drinking wine.]

Kristen: Umm, this is great wine.

Ross: It's from France…In Europe…Western Europe. Y'know umm, a few years ago I actually was backpacking across Western Europe.

Kristen: Really?

Ross: Uh-hmm—Wait! It gets better. Um, yeah I was in Barcelona.

Kristen: I studied for a year in Barcelona. (Ross is stunned and worried.)

Ross: Anyway, umm so I was um, I was hiking…

Kristen: I love hiking!

Ross: (whines) Oh that's great! I was hiking along the foothills of Mount Tibidaybo…

Kristen: I think its Tibidabo.

Ross: Okay! Do you wanna tell the story?!

[Scene: Joey and Rachel's, Joey is standing at the counter as Ross enters.]

Joey: Whoa! What are you doing here? How did your date go?

Ross: Great! I'm across the street having sex with her right now. Your story sucks!

Joey: Hey! Look, if it didn't work it's because you didn't tell it right! Show me how you did it.

Ross: No! No, I don't…don't want to.

Joey: How long since you've seen a girl naked?

Ross: I was backpacking across Western Europe.

Joey: I'm not feeling it.

Ross: I was just outside Barcelona, hiking…

Joey: No! No! No Ross! I'm not hot! Are you hot?

Ross: It's been six months! I'm always hot!

Joey: Well you're not selling the story! It's like; it's like you don't believe it! Look, I gotta go. I got a date, but try this. Do what I do when I'm preparing for an audition. Okay? I'll set you up with my video camera and you can record yourself and-and see what you're doing wrong.

Ross: I'll try that.

Joey: All right now… All right, you're all set up. You're good to go. Just hit record. All right?

Ross: Thanks.

Joey: Good luck.

Ross: Thanks. And-and hey Joe?

Joey: Yeah?

Ross: Listen, if you ever have any problem with the ladies you know I'll help you out.

Joey: (trying not to laugh) That means a lot to me man. (Exits.)

(Ross pours himself a glass of wine, hits record, and sits down in front of the camera.)

Ross: Hello! Can I get you anything? Huh? Lens cleaner? Your battery okay? (Rachel bursts in carrying two boxes and Ross jumps up.) Rachel!

Rachel: Oh Ross!

Ross: Hi!

Rachel: Thank God you're here! You have to help me! Were you just talking to yourself?

Ross: That's less embarrassing, yes. Yes I was.

(They sit down on the couch, which is in front of the still recording camera.)

Ross: (voiceover) So when she came in, I got distracted and totally forgot about the camera. [Cut back to the present day.] It kept rolling and recorded everything.

(Pause)

Chandler: Yeah, we're gonna need to see that tape. (They rest of them agree.)

Monica: Yeah, definitely.

Ross: What a great idea! That will get Rachel to forgive me!

Joey: Y'know what? This is not fair to her. Let's just forget the tape!

Ross: Thank you. (Joey mouths to Ross, "You'll show me right?") No!

Joey: You're right. (Mouths, "I know you'll show me, right?)

Ross: Joey! No!

Joey: Loud and clear! (Mouths, "You'll show me," and nods.)

(Ross storms out.)

[Scene: Monica and Chandler's, Monica, Chandler, Joey, and Phoebe are now sitting in the living room.]

Monica: I still don't get why Greg and Jenny would give us a fake number.

Joey: Y'know, if they knew what they were doing they probably didn't give you real names either.

Monica: Okay, maybe people give out fake numbers, but they don't give out fake names.

Joey: Oh yeah? (To Phoebe) Hi, Ken Adams, nice to meet you.

Phoebe: Regina Philange. (Ken and Regina shake hands.)

Chandler: I still don't get it, we didn't do anything wrong.

Monica: I know! Although, you did tell an awful lot of jokes.

Chandler: I thought you said those jokes were funny. Joke! Joke! Joke!

Monica: (rolling her head from side to side) Joke. Joke. Blah! Blah! (Joey and Phoebe laugh.)

Chandler: Well maybe it was all of your questions.

Monica: What about my questions?

Chandler: The sheer volume, it was like flying with the Riddler!

Monica: Oh, I'm sorry. Was that another joke?

Chandler: (angrily) Was that another question?

Rachel: (entering) Hey! Is Ross still here?

Joey: Uh no Rach, he's gone. But listen, he told us what happened and it does, it sounds like an honest mistake.

Rachel: Oh really? Well how would you like it if I had sex with you and I taped it? (Joey smiles luridly) Oh forget it! (Ross enters.) Oh there he is now, the father of my child, the porn king of the west village.

Ross: Look, it was accident! Okay? I-I feel bad that it happened, but I swear, I didn't even watch it! Anyway, here. (He takes the tape out of his coat pocket.) I thought you might be more comfortable destroying it yourself. (Tosses her the tape.)

Rachel: Thank you. (She sets it on the floor and is about to stomp on it with her shoe when the rest of the gang jumps up and yells simultaneously.) What? (They all yell again.) You don't want to see this do you?

Monica: Hell yeah!!!

Rachel: I am not gonna show you this!

Phoebe: No! Not the sex part, just the stuff leading up to it.

Ross: Forget it, she's destroying it.

Phoebe: Okay fine! Fine! We'll just have to think of some other way to put the whole 'Who came onto who,' thing to rest! Come on now, think!!

Ross: Look, forget it Phoebe. Okay? It's Rachel's tape and she can do whatever she wants with it. And she wants to destroy it. So, end of story.

Rachel: I wanna see it.

Ross: What?!

Rachel: Clearly you don't want people to see this tape. Now I don't want people to see this tape either, but you so badly don't people to see it makes me want to see it. You see?

Joey: (confused) Are we watchin' the tape or not?!

Ross: I don't want people to see it for your sake.

Rachel: Ahh, I don't believe you. I think you don't want them to see you begging me. (Goes to put the tape in the VCR)

Ross: Rachel, please…

Rachel: Ah, a little preview!

Ross: Fine. Fine, but I want the record to show that I tried to take the high road, because in about five minutes I'm gonna be saying…(He laughs and points at Rachel sarcastically.)

(They both sit down.)

Rachel: Okay, here we go. (Pushes play.)

Ross: (on tape) Hello! Can I get you anything?

Joey: (To Phoebe) I'm so happy!

Commercial Break

[Scene: Monica and Chandler's, the scene is continued from earlier.]

Rachel: (on tape) Oh, thank God you're here! You have to help me! Were you just talking to yourself?

Rachel: There I am.

Phoebe: You're gonna get pregnant.

Rachel: (on tape) I screwed up so bad, I told Monica that I would stuff and send all these wedding invitations like weeks ago and I-I…

Ross: (on tape) You didn't do it?

Rachel: (on tape) I-I know—I had put them in…in-in my desk at work and I completely forgot about them until today.

(Chandler is shocked and Rachel gets scared of Monica very quickly.)

Monica: (taking Rachel's hand) Sweetie okay. It's okay. Everybody made it to the wedding. I'm fine.

Rachel: Kinda hurtin' my hand though.

Monica: I know.

Rachel: (on tape) (Ross hands her a glass of wine) I cannot believe that I did this. Especially after Monica just went on and on and on about it! (Mimicking Monica) "Okay Rachel! Here are the invitations Rachel! Now be very careful Rachel! Please, drinking no liquids around the invitations Rachel!" (She tilts her wine glass above and moves it back and forth across the invitations) Whoa oh! Oh-oh-oh! Oh…oh-oh-oh…

(Rachel hits fast forward. Monica is completely shocked.)

Chandler: Did you do it on our invitations?!

Ross: (pause) Not on the ones we sent out.

Chandler: So, just the ones gave back to us and we had framed! (Slams the framed invitation down onto the table.)

(Rachel stops fast forwarding.)

Rachel: (on tape) Can you believe this is already happening? I mean it seems like yesterday they just got engaged.

Ross: (on tape) I know. Hey remember…remember the night they got engaged? How uh, you and I almost…

Rachel: (on tape) Oh, I remember how we almost. Do you think we would've gone through with it? Y'know, if we hadn't gotten caught. Do you think we would've done it?

Ross: (on tape) I mean I…I know I wanted to. I just, I just wasn't sure if you wanted to.

Rachel: (on tape) Oh I wanted to.

(Ross and Rachel trade looks while watching the tape.)

Ross: (on tape) So we…we both wanted to.

Rachel: (on tape) Interesting.

Ross: (on tape) Yeah. (Pause) Anyway umm, it probably worked out for the best.

Rachel: (on tape) Oh yeah, sure.

Rachel: Okay, in about ten seconds you're gonna see him kiss me.

Ross: And in about five seconds you're gonna see why.

Rachel: (on tape) Ross did I ever tell you about the time that I went backpacking through Western Europe?

(Joey's shocked and everyone else looks at Rachel.)

Rachel: Okay, get ready to see some beggin'!

Phoebe: Oh, you came on to Ross!

Rachel: What?!

Ross: Now I'm so happy.

Rachel: What are you talking about?!

Monica: You used the Europe story!

Chandler: That's the magic story you use when you wanna have sex!

Rachel: How do you know about that story?!

Joey: How do you know about that story?!

Rachel: I heard it from my friend Irene who heard it from some guy!

Joey: (raises his hand) Some guy!! (Points to himself.)

Rachel: No. No, she told me his name was Ken Adams.

Joey: (raises his hand and points to himself again) Ken Adams!!

[Scene: Joey and Rachel's, Rachel is looking at the tape sitting on the counter as Ross enters.]

Ross: Hi.

Rachel: So uh, apparently people are familiar with the Europe story?

Ross: Yeah. Listen about that, the whole uh, who came on to who thing really doesn't matter. I mean, I think it would've happened either way. I mean if you hadn't initiated it I-I-I know I would've.

Rachel: It was an amazing night.

Ross: It was. It was an amazing night.

(Pause)

Rachel: You think it looked amazing?

Ross: I uh… I don't know. I mean I…I honestly didn't watch it.

Rachel: Yeah, me neither. Yet…

Ross: Uhhhhhh…that-that may be weird.

Rachel: Yeah, it would be really weird.

(Ross grabs the tape and heads for the VCR as Rachel goes over and puts the chain on the door and locks it.)

Ross: Good luck.

Rachel: Good luck to you.

(Ross pushes play.)

Ross: Mind if I mute?

Rachel: Oh please. (He does so.)

Ross: Oh, oh there go the clothes.

Rachel: You are undressing very quickly.

Ross: Six months Rachel, six months.

Ross and Rachel: Ah. (Pause) Oh.

Ross: Hey. We-we look…we look pretty good.

Rachel: That's what I was gonna say.

Ross: Oh nice tan!

Rachel: Thank you! I had just gone to the beach that weekend.

Ross: Ah….

Rachel: Have you been working out?

Ross: I have been working out.

Rachel: Really? Wow, this is so much better than I…

Ross and Rachel: Ohh! Ew!

Ross: Oh that's not pretty.

Rachel: Oh! Oh!

Ross: No!

Rachel: Oh God!

Ross: Oh no!

Rachel: Oh, make it stop!

Ross: Oh no!!

Rachel: Make it stop!!

Ross: No!!

Rachel: Have to make it stop!!

Ross: No!!!

(They both get out of the chair and run for the VCR.)

Closing Credits

[Scene: Monica and Chandler's, Monica and Chandler have gone through the phone book and found Greg and Jenny's number which Monica has just dialed.]

Monica: (on phone) Hello Greg? (Listens) Hi, this is Monica from the plane? Listen, the number that you gave me 853-5… (Listens) (To Chandler) That is their old number! Jenny's been giving it out since they moved!

Chandler: Jenny! That is so Jenny!

Monica: (on phone) Hey listen umm, how would you like to get together? Say next Saturday? (Listens) Okay, how about Sunday? (Listens) Okay umm, the week after that? (Listens) The week after that? (Listens) Y'know what Greg? Y'know what? We are good, interesting, funny people with good questions and if you and your precious Jenny can't see that then… (Listens) January 15th? (Chandler dances.) We'll see you then! (Listens) Okay!

(She hangs up the phone and they hug.)

1JAVA SE 1.1深入JAVA API 1.1.1Lang包 1.1.1.1String类和StringBuffer类 位于java.lang包中,这个包中的类使用时不用导入 String类一旦初始化就不可以改变,而stringbuffer则可以。它用于封装内容可变的字符串。它可以使用tostring()转换成string字符串。 String x=”a”+4+”c”编译时等效于String x=new StringBuffer().append(“a”).append(4).append(“c”).toString(); 字符串常量是一种特殊的匿名对象,String s1=”hello”;String s2=”hello”;则s1==s2;因为他们指向同一个匿名对象。 如果String s1=new String(“hello”);String s2=new String(“hello”);则s1!=s2; /*逐行读取键盘输入,直到输入为“bye”时,结束程序 注:对于回车换行,在windows下面,有'\r'和'\n'两个,而unix下面只有'\n',但是写程序的时候都要把他区分开*/ public class readline { public static void main(String args[]) { String strInfo=null; int pos=0; byte[] buf=new byte[1024];//定义一个数组,存放换行前的各个字符 int ch=0; //存放读入的字符 system.out.println(“Please input a string:”); while(true) { try { ch=System.in.read(); //该方法每次读入一个字节的内容到ch变量中。 } catch(Exception e) { } switch(ch) { case '\r': //回车时,不进行处理 break; case '\n': //换行时,将数组总的内容放进字符串中 strInfo=new String(buf,0,pos); //该方法将数组中从第0个开始,到第pos个结束存入字符串。 if(strInfo.equals("bye")) //如果该字符串内容为bye,则退出程序。 { return; } else //如果不为bye,则输出,并且竟pos置为0,准备下次存入。 { System.out.println(strInfo); pos=0; break; } default: buf[pos++]=(byte)ch; //如果不是回车,换行,则将读取的数据存入数组中。 } } } } String类的常用成员方法 1、构造方法: String(byte[] byte,int offset,int length);这个在上面已经用到。 2、equalsIgnoreCase:忽略大小写的比较,上例中如果您输入的是BYE,则不会退出,因为大小写不同,但是如果使用这个方法,则会退出。 3、indexOf(int ch);返回字符ch在字符串中首次出现的位置 4、substring(int benginIndex); 5、substring(int beginIndex,int endIndex); 返回字符串的子字符串,4返回从benginindex位置开始到结束的子字符串,5返回beginindex和endindex-1之间的子字符串。 基本数据类型包装类的作用是:将基本的数据类型包装成对象。因为有些方法不可以直接处理基本数据类型,只能处理对象,例如vector的add方法,参数就只能是对象。这时就需要使用他们的包装类将他们包装成对象。 例:在屏幕上打印出一个*组成的矩形,矩形的宽度和高度通过启动程序时传递给main()方法的参数指定。 public class testInteger { public static void main(String[] args) //main()的参数是string类型的数组,用来做为长,宽时,要转换成整型。 { int w=new Integer(args[0]).intValue(); int h=Integer.parseInt(args[1]); //int h=Integer.valueOf(args[1]).intValue(); //以上为三种将字符串转换成整形的方法。 for(int i=0;i<h;i++) { StringBuffer sb=new StringBuffer(); //使用stringbuffer,是因为它是可追加的。 for(int j=0;j<w;j++) { sb.append('*'); } System.out.println(sb.toString()); //在打印之前,要将stringbuffer转化为string类型。 } } } 比较下面两段代码的执行效率: (1)String sb=new String(); For(int j=0;j<w;j++) { Sb=sb+’*’; } (2) StringBuffer sb=new StringBuffer(); For(int j=0;j<w;j++) { Sb.append(‘*’); } (1)和(2)在运行结果上相同,但效率相差很多。 (1)在每一次循环中,都要先将string类型转换为stringbuffer类型,然后将‘*’追加进去,然后再调用tostring()方法,转换为string类型,效率很低。 (2)在没次循环中,都只是调用原来的那个stringbuffer对象,没有创建新的对象,所以效率比较高。 1.1.1.2System类与Runtime类 由于java不支持全局函数和全局变量,所以java设计者将一些与系统相关的重要函数和变量放在system类中。 我们不能直接创建runtime的实例,只能通过runtime.getruntime()静态方法来获得。 编程实例:在java程序中启动一个windows记事本程序的运行实例,并在该运行实例中打开该运行程序的源文件,启动的记事本程序5秒后关闭。 public class Property { public static void main(String[] args) { Process p=null; //java虚拟机启动的进程。 try { p=Runtime.getRuntime().exec("notepad.exe Property.java"); //启动记事本并且打开源文件。 Thread.sleep(5000); //持续5秒 p.destroy(); //关闭该进程 } catch(Exception ex) { ex.printStackTrace(); } } } 1.1.1.3Java语言中两种异常的差别 Java提供了两类主要的异常:runtime exception和checked exception。所有的checked exception是从java.lang.Exception类衍生出来的,而runtime exception则是从java.lang.RuntimeException或java.lang.Error类衍生出来的。    它们的不同之处表现在两方面:机制上和逻辑上。    一、机制上    它们在机制上的不同表现在两点:1.如何定义方法;2. 如何处理抛出的异常。请看下面CheckedException的定义:    public class CheckedException extends Exception    {    public CheckedException() {}    public CheckedException( String message )    {    super( message );    }    }    以及一个使用exception的例子:    public class ExceptionalClass    {    public void method1()    throws CheckedException    {     // ... throw new CheckedException( “...出错了“ );    }    public void method2( String arg )    {     if( arg == null )     {      throw new NullPointerException( “method2的参数arg是null!” );     }    }    public void method3() throws CheckedException    {     method1();    }    }    你可能已经注意到了,两个方法method1()和method2()都会抛出exception,可是只有method1()做了声明。另外,method3()本身并不会抛出exception,可是它却声明会抛出CheckedException。在向你解释之前,让我们先来看看这个类的main()方法:    public static void main( String[] args )    {    ExceptionalClass example = new ExceptionalClass();    try    {    example.method1();    example.method3();    }    catch( CheckedException ex ) { } example.method2( null );    }    在main()方法中,如果要调用method1(),你必须把这个调用放在try/catch程序块当中,因为它会抛出Checked exception。    相比之下,当你调用method2()时,则不需要把它放在try/catch程序块当中,因为它会抛出的exception不是checked exception,而是runtime exception。会抛出runtime exception的方法在定义时不必声明它会抛出exception。    现在,让我们再来看看method3()。它调用了method1()却没有把这个调用放在try/catch程序块当中。它是通过声明它会抛出method1()会抛出的exception来避免这样做的。它没有捕获这个exception,而是把它传递下去。实际上main()方法也可以这样做,通过声明它会抛出Checked exception来避免使用try/catch程序块(当然我们反对这种做法)。    小结一下:    * Runtime exceptions:    在定义方法时不需要声明会抛出runtime exception;    在调用这个方法时不需要捕获这个runtime exception;    runtime exception是从java.lang.RuntimeException或java.lang.Error类衍生出来的。    * Checked exceptions:    定义方法时必须声明所有可能会抛出的checked exception;    在调用这个方法时,必须捕获它的checked exception,不然就得把它的exception传递下去;    checked exception是从java.lang.Exception类衍生出来的。    二、逻辑上    从逻辑的角度来说,checked exceptions和runtime exception是有不同的使用目的的。checked exception用来指示一种调用方能够直接处理的异常情况。而runtime exception则用来指示一种调用方本身无法处理或恢复的程序错误。    checked exception迫使你捕获它并处理这种异常情况。以java.net.URL类的构建器(constructor)为例,它的每一个构建器都会抛出MalformedURLException。MalformedURLException就是一种checked exception。设想一下,你有一个简单的程序,用来提示用户输入一个URL,然后通过这个URL去下载一个网页。如果用户输入的URL有错误,构建器就会抛出一个exception。既然这个exception是checked exception,你的程序就可以捕获它并正确处理:比如说提示用户重新输入。 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值