Tenth season seventh episode,Rachael never swings?????

[Scene: Central Perk]

(Joey and Ross enter. Phoebe and Mike are sitting on the couch, reading a magazine.)

Ross: Hey you guys!

Phoebe : Hey!

Ross: Hey, what are you doing?

Mike: Oh, figuring out our wedding plans.

Chandler: That's funny, we were doing the same thing!

Ross: Yeah!

Phoebe: It's really crazy! The hall, the dress, the food… I-I had no idea how expensive this stuff was!

Chandler: Yeah it is really pricey. I mean, I freaked when I first heard the numbers.

Phoebe: So what did you two do about it?

Chandler: It was pretty simple actually, I came up with a couple of cost-cutting solutions, wrote out a list and Monica told me to go to hell.

Ross: There's no way around it Pheebs, you just gonna have to accept the fact that this is gonna cost you a lot of money.

Mike: I heard that weddings are like a 40 billion dollar a year industry.

Ross: Yeah, and I'm responsible for just like half of that.

Phoebe: But really, it does seem like this money could be put to better use?

Mike: Are you serious?

Phoebe: Yeah! Now, how would you feel if we gave all the wedding money to charity and we just got married at City Hall?

Mike: I think it would make me wanna marry you even more. (he kisses her)

Ross: I've got to say you guys, that's an incredible gesture!

Chandler: (to Ross) Maybe you do that next time you get married!

Ross: No, no, no. The next time it's gonna be a Hawaii at sunset. [pause] But maybe the time after that!

Opening Credits

[Scene: Monica and Chandler's apartment]

(Monica is cleaning the table, Chandler is sitting on the sofa. Joey enters.)

Joey: Hey!

Chandler: Hey!

Joey: What's going on?

Chandler: Our adoption social worker is coming by today so we are cleaning the apartment.

Monica: (sarcastically) We?

Chandler: You know you don't want me to help. You can't have it both ways!

Joey: Hey, is this person who decides whether or not you… get a baby?

Chandler: Kind of. She's coming by to interview us and see where we live.

Monica: And it has to go perfectly, because if she doesn't like something about us she can keep us off every adoption list in the state.

Joey: Hey, maybe I should stop by! She could be a soap opera fan! It's very impressive when the little people know a celebrity.

Chandler: (pointing at himself) Little people?

Joey: (pointing at himself) Celebrity.

Monica: Ok, so I think I'm just about done here, unless you have any bad stuff hidden somewhere, like… porn or cigarettes?

Chandler: What…? NO!

Monica: Chandler?

Chandler: (he stands up and he feels very offended) I don't, and I'm offended by the insinuation!

Monica: Ok, so there's not a magazine under the couch, or a pack of cigarettes taped to the back of the toilet tank, or a filthy video in the VCR?

Chandler: I'll admit to the cigarettes and the magazine, but that tape is not mine.

Monica: It isn't mine!

Joey: (going out with the VCR in his hand) Well, I guess we'll never know whose it is!

[Scene: The New York City Children's fund hallway.]

Charity guy: May I help you?

Phoebe: Yes. We're here to make a rather sizeable donation to the children.

Charity guy: Well, any contribution, large or small, is always appreciated.

Phoebe: Well, I think you're gonna appreciate it the crap out of this one (she gives him a check)

Charity guy: Well, this is very generous!

Phoebe: And we don't want any recognition. This is completely anonymous.

Mike: Completely anonymous. From two kind strangers.

Phoebe: Mr. X and Phoebe Buffay.

Charity guy: Well if you like, we can include your names in our newsletter.

Mike: Not necessary.

Phoebe: Buffay is spelled B-U-F-F-A-Y.

Mike: And "X" is spelled uhm… "Mike Hannigan".

Charity guy: Right. Well, on behalf of the children: thank you both very much.

Phoebe: Sure, I so glad we did this. It feels so good!

Mike: It does. It feels really good!

Phoebe: Oh, look! And we get these free t-shirts! (she takes a t-shirt which was on the counter)

Charity guy: Oh, actually, that's the shirt I wore to the gym.

Phoebe: Mhm… it's moist.

[Scene: Joey and Rachel's apartment.]

Ross: (he enters) Hi!

Rachel: Hi! Emma will be up in a minute!

Ross: Oh, good!

Rachel: Oh hey Ross… Listen, I heard about you and Charlie. I'm really sorry.

Ross: Oh, that's OK. I'm sure there are tons of other beautiful paleontologists out there.

Rachel: Absolutely.

Ross: There was one! She's it! All the rest look like they should live under a bridge!

Rachel: So, uhm… what are you gonna do today?

Ross: Well, I was thinking of taking Emma to the playground!

Rachel: Oh my God, what!?

Ross: Like I said I was thinking of taking Emma to the museum of knives and fire!

Rachel: Ok, look, Ross. I do not want Emma going to the playground.

Ross: Be-caaauuuse…

Rachel: (upset) All right, well, if you must know… I had a traumatic… swing incident… when I was little.

Ross: Seriously?

Rachel: Yes, I was 4 years old and I was on the swing and then all of a sudden my hair got tangled in the chain. And to get me out my mom had to-had to cut a big chunk of my hair! (crying) And it was uneven for weeks!

Ross: (sarcastic) And you made it through that? I wonder who's gonna play you in the movie!

Rachel: Ok, fine! You can make fun of me. I do not want Emma going there. And I was thinking Claire Danes.

Ross: Look, I'm sorry to hear about your tragedy, ok? But the swings are perfectly safe, and besides Emma loves them. You know what, you should come with us and you'll see!

Rachel: Ross, those things go like 40 miles an hour! Ok? When you're… and there is that moment when you are at the top, when you just don't know if you're gonna return back to earth!

Ross: Space is filled with orbiting children. (pause) Look, please, just come on, you know, when you see the look on Emma's face, I swear you won't regret it.

Rachel: All right!

Ross: Good, you don't want to be one of those mothers who pass on their irrational fears on their children, do you?

Rachel: Irrational, huh? All right, well, I'll remember that the next time you freak out about a spider in your apartment!

Ross: Oh, yeah, that's the same, I am sure there are thirty different species of poisonous swings!

[Scene: Monica's apartment. Somebody knocks the door]

Monica: Oh my God, the adoption lady is early!

Chandler: Ok, ok, here we go.

Monica: Ok.

Chandler: Here we go. Stand up straight. (smiling) Big smile. (opens the door and both are smiling exaggeratedly)

Phoebe: Hello, is this the creepy residence?

Monica: We're waiting for the adoption lady, but, hey, I'm glad you're here. I was cleaning this morning and I found this (she puts a box on the table and opens it). I don't know if you wanna use it, but…

Phoebe: Awe, this is so sweet of you! But you know what? I won't be needing a veil, I actually won't be wearing a dress at all!

Monica: I told you! I am not coming to a naked wedding!

Phoebe: No, no, no, we're not having a big reception, we took the money we were gonna spend on a wedding and we donate them to the children charity.

Monica: That's crazy! (Phoebe looks bewildered). I am sorry. I just can't imagine giving up my one wedding day like that!

Phoebe: We, you know, we're different! We don't care about having a huge party. (She picks up the veil) This is really nice for you, but, oh, please, I put this on? (she puts it on) And, ow, I look (she looks her reflex image on a toaster), why, well, radiant. (pause) All right, well, who cares, I don't need a pretty veil and a fancy dress.

Monica: That's right. You're making a commitment and that's the same, whether you do that at the Plaza or, where are you gonna do it?

Phoebe: City Hall.

Monica: Ow! (Chandler slaps her on her back) Oh, that sounds nice! I am just there for jury duty. They really spruce that place up!

Phoebe: It's ok, it's ok. I made my decision. What I really want is a great big wedding (she covers her mouth)

Monica: Yay!

Chandler: But you already gave all your money to charity!

Phoebe: Well, I'll just ask for it back!

Chandler: I don't think you can do that!

Monica: Why not! This is her wedding day, this is way more important than some stupid kids!

Chandler: That's sweet, honey, but save something for the adoption Lady.

[Scene: The playground. Ross put Emma on the swing and they're ready to play]

Rachel: Ok, careful.

Ross: Ok.

Rachel: Careful, watch her hair. WATCH HER HAIR!

Ross: Rach, she's got like three hairs!

Rachel: I know (she touches Emma's head) but they're just so beautiful! Oh, my God, I just pulled one out.

Ross: I promise you she's safe! No watch how much she loves this.

Rachel: Ok.

Ross (to Emma): Ready sweety?

Rachel: Ok.

Ross: Here we go! (He starts pushing Emma)

Rachel: Ok, careful, ok. (Emma giggles) Oh, she's smiling! Oh my God, she does like it!

Ross: See, I told you!

Rachel: Awe! (Emma laughs) Oh my God! Looks, she's a little dare-devil! Oh, let me push, can I push?

Ross: Oh, absolutely!

Rachel: Ok. Oh God. (To Ross) Get the camera, it's in the diaper bag.

Ross: Ok! (he takes the camera and walks backwards to take a shot) See? Scared of swings, I bet you feel pretty silly (a swinging boy knocks him down) Ow!

[Scene: The New York City Children's fund]

Mike: We're seriously asking for our money back?

Phoebe: It's for our wedding day! Right, now, is this guy gay or straight, because one of us gonna have to start flirting.

Charity guy: Wow! Are you here to make another donation the same day? I don't think that that's ever happened before.

Phoebe (to Mike): Gay, go.

Mike (to the charity guy): Oh my God, I love your shirt!

Phoebe: The donation we made earlier, we k…, we w…, we want it back.

Charity guy: Excuse me?

Phoebe: Yeah. See, that money was for a big wedding, that we thought we didn't want, but it turns out we do.

Charity guy: So you're asking us to refund your donation to the children?

Mike: Yeah! This feels really good.

Phoebe: I am sorry. I am, but this wedding is just really important to me.

Charity guy: Hey, it's not my business, (he takes their check from a drawer) besides it's probably a good thing. We really would have been spoiling the children, all those food, and warm clothing…

Phoebe: Hey, that's not fair! A person's wedding is important! And especially to me! Ok? I didn't have a graduation party! And I didn't go to Prom. And I spent my sweet sixteen being chased round a tire yard by an escaped mental patient who is his own words wanted to "kill me" or whatever. So I deserve a real celebration and I am not gonna let some sweaty little man make me feel badly about it.( She storms out)

Mike: She could have been talking about either one of us.

[Scene: Monica's apartment. Somebody knocks the door]

Laura: Hi, I am Laura, I am here for your adoption interview.

Monica: Hi, I am Monica and this is Chandler. Please come in.

Laura: Thank you!

Monica: Would you like something to drink?

Laura: Oh, water would be fine.

Monica: Ok. Great. I am so glad that you are here. We're really excited about getting this process started.

Chandler: Oh, because we love kids. Love 'em to death.Well, not actually to death, that's just a figure of speech - we love kids the appropriate amount… as allowed by law.

Laura: Your place is just lovely.

Monica: Ah, thank you. This building does have a wholesome family feel to it.

Laura: You know, I… I feel like I've been here before. Are any other couples in the building adopting?

Monica: Is that that couple on the first floor? Because we should get a baby before them. Yeah! That guy tried to sell me drugs. (Laura looks shocked)

Chandler: But other than that… wholesome, wholesome building.

Laura: Oh…

Chandler: What?

Laura: I just realized why I remember this place.

Monica: Really? What is it?

Laura: Oh, it's nothing. I went on a date with a guy who lived in this building and it didn't end very well.

Monica: Ohh… that wouldn't by any chance be… Joey Tribbiani?

Laura: Yes!

Chandler: Of course it was!

Laura: Yeah, we had a really great night and in the morning he promised he would call me and he didn't.

Chandler: RAT BASTARD!

Laura: So you're not friends with him?

Monica and Chandler: OH GOD NO! Nope, no, no, no. No! No, no. Nope! No, no, no, no, no, no, no, no, no. NO! (finally Monica concludes) No!

Laura: Well, I'm sorry I brought it up. So, are either one of you planning on staying at home with your child… (someone knocks on the door)

Joey: (form the other side of the door) Hellooo? Anybody in there order a celebrity? (He starts to enter the apartment and Chandler runs to the door and shuts it back in his face) OW!

Laura: What was that?

Chandler: Oh, it's just some crazy guy who roams the halls here. He's great with kids though.

[Scene: Ross and Rachel are at the playground with Emma. Rachel in putting her back in the stroller and Ross is tending to his wound]

Rachel: Oh, oh Ross, oh my God, are you okay?

Ross: SON OF A BITCH! (turns to his right to see three kids staring at him)__(To the kids) Oh relax! I didn't say the 'F' word! (They go away)

Rachel: Ross, see! I told you, those swings are evil! Alright, that is it. That is the last time Emma is getting on one of those things for her entire life.

Ross: No! No, no, no, no, okay, it wasn't the swing's fault. It was my fault and kind of that (point to the kid that kicked him) kids fault. Who is still laughing. Nice.

Rachel: Ross, c'mon, please. Can we just get out of here, before somebody else gets hurt?

Ross: No wait, okay, okay, I have an idea. I want you to get on the swing, okay? And you'll see that there's nothing to be afraid of.

Rachel: (looks at him suspiciously) I know what this is all about… You've always been jealous of my hair.

Ross: Look, I just think you're an adult, okay? And you should get over your silly fears.

Rachel: Alright fine. I'll do it.

Ross: Good.

Rachel: If you hold a spider.

Ross: (He freaks out and starts jumping around brushing his sweater) WHAT? WHERE? WHERE?

Rachel: IF you hold a spider.

Ross: I know. (Rachel bends down to Emma and Ross looks over his shoulder again, afraid)

[Scene: Chandler and Monica's apartment. Chandler is still leaning against the door, keeping Joey out, who is still banging and shouting on the other side.]

Joey: Guys? Everything ok? It's me, Joe…

Chandler: (Screams to interrupt Joey) AAAAAAAAAAAAAAAAAAAAA…AAAaaa-doption!!

Laura: What's going on?

Chandler: Oh, just like I said. That crazy… Bert… roaming the halls. (Joey bangs on the door again)

Joey: Guys!?

Monica: Keep on roaming Bert! We don't want any crazy today!

Joey: What's going on?

Chandler: WE'LL TALK TO YOU LATER, BERT. EVERYTHNG'S FINE!!

(cut to Joey on the other side, who finally leaves the door and goes to his apartment)

Joey: Everything doesn't sound fine!

Laura: Is he alright out there by himself?

Chandler: Oh yeah! He has a caretaker. His older brother… Ernie.

Laura: Bert and Ernie!

Chandler: (nervous smile) You can't make this stuff up!

[Scene: Central Perk. Phoebe and Mike enter]

Mike: You never told me about that guy on your sweet sixteen. Oh, ugh. I'm sorry about that.

Phoebe: (Lightly) Oh! It ended okay. One of my friends shot him.

Mike: Well, hey, at least you're getting a proper wedding. I mean, you really deserve that.

Phoebe: Yeah, I really do. You know, I had nothing growing up. (thinks for a few seconds) Just like the kids I took the money from.

Mike: No! No, no. I see where this is going. Don't make me go back there.

Phoebe: Look, I can't have a wedding with this money now. It's tainted.

Mike: Alright, fine. We'll give the money back.

Phoebe: And if that guy at the charity gives us a hard time, my friend hasn't shot anyone in a really long time.

[Scene: Monica and Chandler's. They are preparing to show Laura around. Laura is standing with her back to the window, Chandler and Monica are standing on either side of her, facing each other.]

Laura: Well, I must say, this seems like a lovely environment to raise a child in.

Monica: Oh, by the way, you are more than welcome to look under any of the furniture, because, believe me, you won't find any porn or cigarettes under there!

Laura: Oh! Well, actually, before we look around, let me make sure I have everything I need up to here…

(She starts checking her form. Chandler sees movement near the window from the corner of his eye and when he looks he spots Joey climbing up the fire escape and onto their balcony. He warns Monica silently.)

Monica: (Pulls Laura into the spare room) Why don't I show you the baby's room?

(Joey enters through the side window and jogs towards the kitchen holding a baseball bat)

Chandler: What the hell are you doing?

Joey: Well, you wouldn't let me in, so I thought you were in trouble.

Chandler: Well, we're not.

Joey: But you called me 'Bert'!? That's our code word for danger!

Chandler: We don't have a code word.

Joey: We don't? We really should. From now on, 'Bert' will be our code word for danger.

(Monica talks loudly in the baby's room)

Monica: So that was the baby's room. (They come out and Chandler throws Joey behind the couch and puts his foot on him. Monica looks at Chandler)

Monica: (To Chandler) What room should we see next?

Chandler: Any room that isn't behind this couch! (laughs nervously)

Monica: (laughs nervously as well, Laura looks confused)__(To Laura) Some people don't get him, but I think he's really funny! (She takes Laura to their own bedroom).

(Joey gets up and look annoyed)

Joey: (quivering with anger) I did not care for that!

Chandler: (escorting Joey to the door) You have to get out of here. You slept with our social worker and you never called her back and she is still pissed, so she can't see you.

Joey: Ok, ok! (He leaves)

Chandler: Ok!

(Joey leaves and closes the door behind him. Chandler walks towards the living room, but then Joey enters again.)

Chandler: What?

Joey: I forgot my bat.

(He picks up his bat and holds it up, but then Monica and Laura enter the living room again. When Laura sees Joey, she freezes…)

Laura: Oh my God!

Chandler: And for the last time, we do not want to be friends with you! And we don't want to buy your bat! (Joey lowers his bat)

Laura: What are you doing here?

Joey: (to Chandler) Bert! Bert! Bert! Bert!

Laura: Are you friends with him?

Chandler: I can explain… Joey…

Joey: Uhm… ok… uhm… Well, yeah… You have got some nerve, coming back here. I can't believe you never called me.

Laura: Excuse me?

Joey: Oh… yeah… Probably you don't even remember my name. It's Joey, by the way. And don't bother telling me yours, because I totally remember it… lady. Yeah! I waited weeks for you to call me.

Laura: I gave you my number, you never called me.

Joey: No, no! Don't try to turn this around on me, ok? I'm not some kind of… social work, ok, that you can just… do.

Laura: (embarrassed towards Chandler and Monica) Well, I'm pretty sure I gave you my number.

Joey: Really? Think about it. Come on! You're a beautiful woman, smart, funny, we had a really good time, huh? If I had your number, why wouldn't I call you?

Laura: I don't know… Well, maybe I'm wrong… I'm sorry…

Joey: No, no, hey, no! Too late for apologies… ok? You broke my heart. You know how many women I had to sleep with to get over you? (and he leaves the apartment, leaving her shocked)

Laura: Joey, wait!

Joey: (acting sad) NO! I waited a long time, I can't wait anymore… (and closes the door behind him)

Laura: (laughing nervously) I'm sorry that you had to see that. I'm so embarrassed…

Chandler: Oh, that's really ok.

Monica: Yeah, that we totally understand. Dating is hard.

Laura: Boy, you people are nice… And I've got to say… I think you're going to make excellent parents.

(Chandler and Monica hug each other, and then Joey enters the apartment again.)

Joey: LAURA! (and points to her, very confident)

[Scene: The New York City Children's Fund building. Phoebe and Mike are entering.]

Phoebe: (to the Charity guy) We're back!

Charity guy: Are you here to take more money? Because, I think what you're looking for is an ATM.

Mike: No, no, we're here to give the money back.

Phoebe: Yeah, because you know what, it's… it's all about the children.

(the Charity guy smiles wanting to take the check, but Phoebe pulls it back again. His smile fades.)

Phoebe: Although… it's also about the wedding… Ugh, alright… here. (she gives the check and pulls it back again) No… Oh God… Oh!

Charity guy: If I haven't said so already sir, (sarcastically pointing to Phoebe) congratulations!

Mike: (takes the check from Phoebe) Ok, look! Enough! Alright? I'm stepping in. I'm putting my foot down! As your future husband I'm going to make this decision for us. (thinking) Now… what do you think we should do?

Charity guy: You know what? It's not your decision anymore.

Mike: What?

Charity guy: On behalf of the Children of New York, I reject your money.

Phoebe: But… but… but we're giving you this!

Charity guy: Yeah… And I'm giving it back to you… Come on! Consider it a contribution. (gives the check to Phoebe)

Phoebe: (looks at the amount on the check, and gasps) Well, this is very generous!

Charity guy: Please, take the check, go have a great wedding and a wonderful life together.

Mike: Well, I mean… It sounds good to me. And that way we can save up, come back in a few years and make an even bigger donation.

Charity guy: Absolutely! And when you do, make sure you ask for Brian.

Phoebe: Oh, is that you?

Charity guy: No!

[Scene: Chandler and Monica's apartment. They are sitting in their living room when the phone rings.]

Monica: Hello…? Oh hi… Oh my God…! Really…? I can't wait to tell Chandler… Ok, goodbye. (hangs up)

Chandler: Wrong number?

Monica: It was Laura… She gave us a great report and we are officially on the waiting list.

Chandler: That's great!

Monica: Now we just have to wait for a call and… and someone tells us there's a baby waiting for us. Oh…

(Chandler and Monica hug and after a while the telephone rings again… Monica's eyes get bigger. Chandler answers.)

Chandler: Hello…? Have you seen Joey's bat?

[Scene: The playground. Ross, Rachel and Emma are still there. Rachel comes walking to Ross and Emma with something between her hands.]

Rachel: Ok… I got a spider. There were two, I picked the bigger one.

Ross: (nervously) Ok…

Rachel: Ok… (and passes the spider to Ross who holds it in between his hands)

Ross: (Gasps and speaks at a higher pitch) This feels perfectly normal. Ok, get on the swing!

Rachel: (reluctantly) Ok… O-k…

(She slowly grabs the chains of the swing, swings her hair back, and sits down.)

Rachel: (more confident) Ok…

(She slowly walks forward and backward, to gain speed…)

Rachel: whoo… ok… wow… ok… OH!

Ross: See?

Rachel: A-alright! I can do this.

Ross: There you go! Good for you! And you know what, I'm actually getting used to this little guy. I don't really even feel him in here anymore.

Rachel: That's because he's on your neck.

Ross: Well… (realizes, screaming like a little girl, trying to get rid of the spider) Whaa… aaah… aaahhh…

(Ross is now preoccupied with the spider, and forgets that Rachel is still using the swing. While trying to get rid of the spider, he stands in front of Rachel, who bumps into him, throwing him on the ground again.)

Rachel: ROSS!

(Rachel tries to stop mid-swing, and the swing starts to turn from side to side)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
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、付费专栏及课程。

余额充值