Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-17-2003, 05:50 PM   PM User | #1
weronpc
Regular Coder

 
Join Date: Apr 2003
Location: Canada, Ontario, Mississauga
Posts: 312
Thanks: 0
Thanked 0 Times in 0 Posts
weronpc is an unknown quantity at this point
what is impelements (Java)

Can someone tell me what is implements mean??

import java.awt.*;
import java.awt.event.*;
public class MyClass extends JFrame implements ActionListener{

I understand what extends mean (super class and sub class), but what is implements mean?

Also, I am new with Java, when explaining, pleae keep it simple... example will be great.

Mike
weronpc is offline   Reply With Quote
Old 06-17-2003, 06:47 PM   PM User | #2
DoubleV
Regular Coder

 
Join Date: Dec 2002
Location: the windy city
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
DoubleV is an unknown quantity at this point
Mike,
it's hard for me to explain this in just a couple of sentences.
"implements" is a keyword that deals with interfaces.
you can look at interfaces as java's way around multiple inheritance (which, as you probably know, java doesn't have). interfaces are a huge topic of their own.
think of this example (not exactly "real world", but should get the point across): you need to define a class Orange. Orange is a fruit, so you think that class Orange should be a child of class Fruit (or may be class Fruit is devided into more sub-classes, and Orange would fall into class Citrus. those details are not as important right now). let's imagine that you wanted to define some behaviour of an orange (for example, how it would behave when you threw it, or bounced off the wall ). orange has a spherical shape, but not every fruit does. this means that class Orange needs to have some kind of behavior that is not common to every fruit, but is common among certain type of fruit (like, citrus, for example). to ensure that all citrus fruit is capable of performing the same behaviour, you write an interface that will define what a class should do. then, when you implement an interface within a class, you actually write how each particular behaviour will be for this class.
in short, "an interface defines what, but not how". the "how" will be defined within a class that implements an interface. inteface is a set of requirements. those requirements look like empty methods.
Code:
public interface CitrusBehaviour {
    void bounceoffTheWall(int speed, int angle, int weight);
    void flyWhenThrown(int speed, int angle, int weight);
}
any class that wants to implement this interfacemust have bounceoffTheWall and flyWhenThrown methods, and those methods must take the parameters specified in an interface. (methods in an interface are automatically public, so you don't have to specify that separately). of course, when those methods will be defined in classes, they shoudl do whatever they are "meant" to do, i.e. bounceoffTheWall method should provide taht behaviour. etc.

interfaces are used the most for callbacks (that's what is in your example), but the topic is really huge. i'll write something up tonight.
DoubleV is offline   Reply With Quote
Old 06-17-2003, 06:48 PM   PM User | #3
Jason
Regular Coder

 
Join Date: Feb 2003
Location: California
Posts: 925
Thanks: 0
Thanked 0 Times in 0 Posts
Jason is an unknown quantity at this point
implements is basically saying that it is using the "actionlistener" class as part of its operations. So now you can find mouse click and use other methods that are part of the actionlistener class


Jason
Jason is offline   Reply With Quote
Old 06-17-2003, 07:51 PM   PM User | #4
DoubleV
Regular Coder

 
Join Date: Dec 2002
Location: the windy city
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
DoubleV is an unknown quantity at this point
how about this tutorial from sun?
http://java.sun.com/docs/books/tutor...nterfaces.html
DoubleV is offline   Reply With Quote
Old 06-26-2003, 08:02 PM   PM User | #5
weronpc
Regular Coder

 
Join Date: Apr 2003
Location: Canada, Ontario, Mississauga
Posts: 312
Thanks: 0
Thanked 0 Times in 0 Posts
weronpc is an unknown quantity at this point
Double V

Wow wow wow...

You do know you Java, I kinda understand what you are saying but not totally. I guess time and pratice will take care of that.

Anyway, thanx...
weronpc is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:36 PM.


Advertisement
Log in to turn off these ads.