Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the point of beans?

I've bean doing some JSP tutorials and I don't understand what the point of a bean class is. All it is, is get and set methods. why do we use them?

public class UserData {

String username;
String email;
int age;

public void setUsername( String value )
{
    username = value;
}

public void setEmail( String value )
{
    email = value;
}

public void setAge( int value )
{
    age = value;
}

public String getUsername() { return username; }

public String getEmail() { return email; }

public int getAge() { return age; }

}

and the jsp is

<jsp:useBean id="user" class="user.UserData" scope="session"/> 
<HTML>
<BODY>
You entered<BR>
Name: <%= user.getUsername() %><BR>
Email: <%= user.getEmail() %><BR>
Age: <%= user.getAge() %><BR>
</BODY>
</HTML>
like image 488
brblol Avatar asked Nov 25 '10 10:11

brblol


People also ask

What is the purpose of beans?

Beans are a great source of fiber. That's important because most Americans don't get the recommended 25 to 38 grams each day. Fiber helps keep you regular and seems to protect against heart disease, high cholesterol, high blood pressure, and digestive illness.

What is the benefit of eating beans?

Beans and legumes are excellent sources of dietary fiber, protein, B vitamins, and many other important vitamins and minerals. There is some evidence that they can help reduce blood sugar, boost heart health, and maintain a healthy gut.

Why are beans so good for weight loss?

That's because beans are high in fiber and a good source of protein, both of which help you feel fuller on less food. Plus, a May 2016 review in ​The American Journal of Clinical Nutrition​ found that simply adding beans to your diet (without otherwise trying to cut calories) may help you shed some body fat.

Why are beans better than meat?

Beans and legumes Beans and legumes also keep you fuller, longer because they are so rich in fiber. Animal sources of protein, in contrast, have no fiber at all. Beans and legumes are also much higher in antioxidants.


1 Answers

  1. A Bean obtains all the benefits of Java's "write-once, run-anywhere" paradigm. The properties, events, and methods of a Bean that are exposed to an application builder tool can be controlled.

  2. A Bean may be designed to operate correctly in different locales, which makes it useful in global markets.

  3. Auxiliary software can be provided to help a person configure a Bean. This software is only needed when the design-time parameters for that component are being set. It does not need to be included in the run-time environment. The configuration settings of a Bean can be saved in persistent storage and restored at a later time.

  4. A Bean may register to receive events from other objects and can generate events that are sent to other objects.

    • Advantages of Bean

The use of scriptlets (those <% %> things) is indeed highly discouraged since the birth of taglibs (like JSTL) and EL (Expression Language, those ${} things) over a decade ago. The major disadvantages of scriptlets are:

  1. Reusability: you can't reuse scriptlets.

  2. Replaceability: you can't make scriptlets abstract.

  3. OO-ability: you can't make use of inheritance/composition.

  4. Debuggability: if scriptlet throws an exception halfway, all you get is a blank page.

  5. Testability: scriptlets are not unit-testable.

  6. Maintainability: per saldo more time is needed to maintain mingled/cluttered/duplicated code logic.

    • Check Whole...BalusC's answer here
like image 169
jmj Avatar answered Nov 07 '22 16:11

jmj