Javabean vs. class instantiation

M

mazdotnet

Hi all,

I'm very new to Java and JSP (ASP.NET and PHP background) and I was
wondering which of the following 2 ways are the preferred way using
objects.

After you write a class,

1. To instantiate it and use object x = new object()

or

2. Use it as a bean? <jsp:useBean>

Thanks
Maz
 
A

Arne Vajhøj

mazdotnet said:
I'm very new to Java and JSP (ASP.NET and PHP background) and I was
wondering which of the following 2 ways are the preferred way using
objects.

After you write a class,

1. To instantiate it and use object x = new object()

or

2. Use it as a bean? <jsp:useBean>

Only the first is possible in a .java file.

The second is usually recommended in a .jsp file.

Arne
 
L

Lew

mazdotnet said:
Suggestion:
Only the first is possible in a .java file.

The second is usually recommended in a .jsp file.

In addition to the <jsp:useBean> tag, there are Expression Language (EL)
constructs you can use in a Web application.
<http://java.sun.com/javaee/5/docs/tutorial/doc/bnadp.html>

Whether a class is a bean depends on how the class is written, not on how it's
used. The minimum requirement for a class to be a bean is to have accessor
and mutator methods (getX() and setX()) corresponding to its attributes.
There are additional capabilities possible.
<http://java.sun.com/javase/6/docs/technotes/guides/beans/index.html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,121
Latest member
LowellMcGu
Top