PDA

Click to See Complete Forum and Search --> : JavaBeans


harbir
October 1st, 2004, 03:45 PM
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

hiddeninclouds
October 2nd, 2004, 05:38 AM
http://docs.rinet.ru/JavaBeans/

BigDick
October 11th, 2004, 10:40 PM
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

harbir
October 13th, 2004, 05:16 PM
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

chsh
October 13th, 2004, 05:55 PM
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:

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/javabeans/faq/faq.general.html

Juridian
October 13th, 2004, 06:02 PM
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.

harbir
October 19th, 2004, 10:58 AM
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