Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all,
Vanilla are planning an update to the site on April 24th (next Wednesday). It is a major PHP8 update which is expected to boost performance across the site. The site will be down from 7pm and it is expected to take about an hour to complete. We appreciate your patience during the update.
Thanks all.

JavaBeans

  • 12-11-2014 8:59pm
    #1
    Registered Users Posts: 635 ✭✭✭


    Could someone give me a clear explanation of what JavaBeans are. What are their purpose? Could you give me an example of their use?

    Thanks in advance!


Comments

  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins


    Not being funny, but there's no harm in using Google on occasion. http://en.wikipedia.org/wiki/JavaBeans This should give a good explanation of what a Javabean is.


  • Registered Users Posts: 635 ✭✭✭MillField


    Itzy wrote: »
    Not being funny, but there's no harm in using Google on occasion. http://en.wikipedia.org/wiki/JavaBeans This should give a good explanation of what a Javabean is.

    I've googled the death out of it. I was just curious to see what peoples definitions were. :)


  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins


    :o Sorry, haven't had a need to use Java Beans yet. If I need to though, it's a handy little concept to have knowledge of and appreciation for it.


  • Registered Users Posts: 635 ✭✭✭MillField


    Itzy wrote: »
    :o Sorry, haven't had a need to use Java Beans yet. If I need to though, it's a handy little concept to have knowledge of and appreciation for it.

    You're grand. It's something that I will be getting familiar with soon (well actually EJB) so I want to try get it in my head at least at a high level for now.


  • Closed Accounts Posts: 433 ✭✭MaggotBrain


    High level a bean is a format to write your class in. It's really nothing to get hung up on.


  • Advertisement
  • Registered Users Posts: 400 ✭✭irishbuzz


    Bean's are essentially just ordinary Java objects where:
    • Their properties are private
    • The property values are accessible via standard getter and setter methods

    Here's an example of an implementation of a Person 'bean'

    [PHP]
    public class Person
    {
    private String name;
    private boolean alive;

    public Person()
    {}

    public String getName()
    {
    return name;
    }

    public void setName(String name)
    {
    this.name = name;
    }

    public boolean isAlive()
    {
    return alive;
    }

    public void setAlive(boolean alive)
    {
    this.alive = alive;
    }
    }[/PHP]


  • Moderators, Technology & Internet Moderators Posts: 1,333 Mod ✭✭✭✭croo


    read this


  • Closed Accounts Posts: 8,016 ✭✭✭CreepingDeath


    colmulhall wrote: »
    I've googled the death out of it. I was just curious to see what peoples definitions were. :)

    It's basically a naming convention for fields and methods.
    Using reflection you can then get and set the public methods and fields that you expose via the naming convention ( getters & setters ).

    It's widely used in the Spring framework.
    There's also the Apache beanutils library which lets you copy one bean to another, eg. if you had a hibernate object and wanted to copy the contents to a simpler class to pass to the web layer.


  • Registered Users Posts: 635 ✭✭✭MillField


    So pretty much all fields are private and methods are public? Like with encapsulation? Also, would you need to use reflection to access the getters/setters?


  • Closed Accounts Posts: 8,016 ✭✭✭CreepingDeath


    You should be using encapsulation regardless of whether you're using the Javabeans naming convention.

    You can directly call your getters and setters as normal methods.
    No problem there.

    Reflection might only come into it if you wanted to copy the contents of one class to another, but didn't necessarily want to list all the matching fields or have to alter that copying code each time someone added another field.
    So you could iterate through all the fields of one class, see if it existings on the other and copy them across.
    If you follow the Javabeans standard then you can assume that getting a field called "Name" would require calling "String getName()" and setting that on the other object would require calling "void setName(String name)".


  • Advertisement
Advertisement