Results 1 to 7 of 7

Thread: JavaBeans

  1. #1
    Senior Member
    Join Date
    Dec 2001
    Posts
    134

    JavaBeans

    Hello guys,
    I am new to Java World.
    I want to know what are JavaBeans and how can we use them with basic Java.
    Like I want to know how do we make a JavaBean Objects.
    Answers and References will be appricated.
    Thanx
    U get What U pay for.

  2. #2
    Senior Member
    Join Date
    Dec 2003
    Location
    LA, CA
    Posts
    292
    A mind full of questions has no room for answers

  3. #3
    The easiest way to describe a java bean is that it is a class file that has a bunch of fields i.e. private int foo and then it has getter and setter methods to access these private fields, this would be something like public int getFoo() { return foo; } and public void setFoo (int foo) { this.foo = foo; } and they would be there for all of the fields.
    -BigDick
    --BigDick


    \"When in Rome, eat Rome!\" -Godzilla

  4. #4
    Senior Member
    Join Date
    Dec 2001
    Posts
    134
    Thanx a lot BigDick.
    It would be really kind of you if you coulld explain a bit more, I am interested in exactly what u r talking about, but i would like to have some more information about this.
    like i have the following class:
    ----------
    class MBFFEE
    {
    private int foo;
    private String Type;
    }
    --------------
    now my problem is that i am new to all this i am not understanding where and how will setfoo() and getfoo() will be used, and how will they be defined.
    I will be really greatfull to you if u could help me.
    One more this, is there any data type like int, string that can store date.
    Regards
    Harbir
    U get What U pay for.

  5. #5
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,255
    Getters/Setters are used to expose access to private member variables.

    Here's an example of a getter/setter for foo in your class above:
    Code:
    public int getFoo()
    {
      return this.foo;
    }
    public void setFoo(int newfoo)
    {
      this.foo = newfoo;
    }
    The primary use of getters and setters is data validation.

    A Java bean is well more than a simple struct-style element. It is really meant to allow you to write a piece of code once, and run it everywhere (applets, desktop apps, JSP, etc). Basically let's say you have a class that deals with outputting customer data. You might have this class written once but be using it on your secured site via JSP, in a desktop Java app, or in a Java applet served from the web.

    The FAQ for Java Beans is here: http://java.sun.com/products/javabea...q.general.html
    Chris Shepherd
    The Nelson-Shepherd cutoff: The point at which you realise someone is an idiot while trying to help them.
    \"Well as far as the spelling, I speak fluently both your native languages. Do you even can try spell mine ?\" -- Failed Insult
    Is your whole family retarded, or did they just catch it from you?

  6. #6
    Ninja Code Monkey
    Join Date
    Nov 2001
    Location
    Washington State
    Posts
    1,027
    A better term than getters/setters is accessors (getters) or mutators (setters). And a java bean is not a struct. It may be better to compare then to a com component.
    "When I get a little money I buy books; and if any is left I buy food and clothes." - Erasmus
    "There is no programming language, no matter how structured, that will prevent programmers from writing bad programs." - L. Flon
    "Mischief my ass, you are an unethical moron." - chsh
    Blog of X

  7. #7
    Senior Member
    Join Date
    Dec 2001
    Posts
    134
    Thanks guys.
    Actually i am sorry for not thanking earlier.
    But the help you guys offered was really helpfull, it did solve the purpose.
    Regards
    Harbir
    U get What U pay for.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •