473,320 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

What is POJO?

Hi Guys,
I am going new to enterprise development in java.
But quite frustrated with this term POJO.
Will anybody be kind enough to explain what actually is POJO.
What i am getting from the reading that it is the bean that has getter or setter methods.
Will it mean that every POJO is infact an "entity"(or entity bean as in ejb 2.x) in ejb3.0.
Mar 22 '07 #1
11 50709
sicarie
4,677 Expert Mod 4TB
Hi Guys,
I am going new to enterprise development in java.
But quite frustrated with this term POJO.
Will anybody be kind enough to explain what actually is POJO.
What i am getting from the reading that it is the bean that has getter or setter methods.
Will it mean that every POJO is infact an "entity"(or entity bean as in ejb 2.x) in ejb3.0.
Where were you reading that? What other things have you looked at and did you do any google and wikipedia searches?
Mar 22 '07 #2
Where were you reading that? What other things have you looked at and did you do any google and wikipedia searches?
Yes i am doing it . But there is no proper answer to them.
What only thing i am getting is that these are the entity beans.
Can anyone give me an exmple of a POJO?
Mar 23 '07 #3
Kirit
2
Yes i am doing it . But there is no proper answer to them.
What only thing i am getting is that these are the entity beans.
Can anyone give me an exmple of a POJO?
Actually, a POJO is a class that is NOT an entity bean. POJO stands for Plain Old Java Object, which if taken literally, refers to any java class. However, the implied meaning is a java class that does not extend any class. All entity beans extend the javax.ejb.EntityBean interface, so they are not POJOs. A pojo that might represent a telephone contact might look like:

Expand|Select|Wrap|Line Numbers
  1. public class PhoneRecord{
  2.   String name;
  3.   String phoneNumber;
  4. }
Notice how the class doesnt implement or extend anything. It is therefore a "plain old" java object. Typically in enterprise java development, you would write pojos as helper classes that support your business logic.

Generally, although ther are exceptional cases, a pojo will not extend any other class or implement any interfaces.
Mar 23 '07 #4
Actually, a POJO is a class that is NOT an entity bean. POJO stands for Plain Old Java Object, which if taken literally, refers to any java class. However, the implied meaning is a java class that does not extend any class. All entity beans extend the javax.ejb.EntityBean interface, so they are not POJOs. A pojo that might represent a telephone contact might look like:

[code]public class PhoneRecord{
String name;
String phoneNumber;
}/[code]

Notice how the class doesnt implement or extend anything. It is therefore a "plain old" java object. Typically in enterprise java development, you would write pojos as helper classes that support your business logic.

Generally, although ther are exceptional cases, a pojo will not extend any other class or implement any interfaces.
Hi thanks a lot for this code. I am much clearer about them now.
Could you provide me a sample program where they are useful and how to use them.?
Mar 23 '07 #5
Notice how the class doesnt implement or extend anything. It is therefore a "plain old" java object. Typically in enterprise java development, you would write pojos as helper classes that support your business logic.

Generally, although ther are exceptional cases, a pojo will not extend any other class or implement any interfaces.

Hi,

I dont agree with your statement abou POJOs. If POJO doesnt implement any thing then why we implement an interface serializable in a persistance class with hibernate. for example look at the code below.

Expand|Select|Wrap|Line Numbers
  1. import java.io.Serializable;
  2.  
  3. import javax.persistence.Column;
  4. import javax.persistence.Entity;
  5. import javax.persistence.Id;
  6. import javax.persistence.Table;
  7.  
  8. @Entity
  9. @Table(name = "employee")
  10. public class Employee implements Serializable {
  11.   public Employee() {
  12.  
  13.   }
  14.   @Id
  15.   @Column(name = "id")
  16.   Integer id;
  17.  
  18.   @Column(name = "name")
  19.   String name;
  20.  
  21.   public Integer getId() {
  22.     return id;
  23.   }
  24.  
  25.   public void setId(Integer id) {
  26.     this.id = id;
  27.   }
  28.  
  29.   public String getName() {
  30.     return name;
  31.   }
  32.  
  33.   public void setName(String name) {
  34.     this.name = name;
  35.   }
  36.  
  37. }
Thanks in advance if you like to comment.
Jun 26 '08 #6
RedSon
5,000 Expert 4TB
I like a healthy debate as much as the next person...but please use code tags and keep the flames to a minimum if you are planning on going there.
Jun 26 '08 #7
Dooghy
1
I kind of agree with Kirit; the only thing I don't agree with is that a POJO can extend a class or implement an interface. But the most important thing is that doesn't comply with the Java Bean's rules, i.e. have getter/setter methods for each attribute.

Still, the POJO term is quite confusing when reading docs from different framework vendors, e.g. Hibernate, Apache Struts etc.
Aug 1 '08 #8
JosAH
11,448 Expert 8TB
A POJO isn't a well defined entity; in the old days when Enterprise Beans were
supposed to be a one size fits all solution you had to implement interfaces, extend
from other mysterious classes an jump throuh hoops just to make your Java class
an Enterprise Bean; and then you hadn't implemented anything useful yet, i.e.
all the 'business logic' was still to come.

The 'server', some mysterious thing that could handle those Enterprise Beans
would create your objects, destroy them or put them to sleep; you had no control
over them, or almost no control.

People were longing for just Java classes without all the mandatory hulla baloo.
Then some other mechanisms saw the light; notably Dependency Injection or
also called Inversion of Control allowed you to write just a simple class and the
implementation of those patterns took care of the rest, i.e. they 'injected' the
context in which such a POJO could operate.

And again all those frameworks crept back in again, some wanted you to implement
a certain interface or extend from some magic base class in order to get the job
done; for convenience the POJO was redefined a bit; sometimes it had to be an
ordinary bean, sometimes you had to write wallpaper long xml declarations for
them and sometimes those frameworks wanted you to jump through hoops again.

And all those classes were called POJOs.

kind regards,

Jos
Aug 2 '08 #9
shivz
1
a POJO is a Java object not bound by any restriction other than those forced by the Java Language Specification. I.e., a POJO should not have to
1.Extend prespecified classes
2.implement prespecified interfaces
3.contain prespecified annotations..

However, due to technical difficulties and other reasons, many software products or frameworks described as POJO-compliant actually still require the use of prespecified annotations for features such as persistence to work properly. The idea is that if the object (actually class) was a POJO before any annotations were added, and would return to POJO status if the annotations are removed then it can still be considered a POJO. Then the basic object remains a POJO in that it has no special characteristics (such as an implemented interface) that makes it a "Specialized Java Object" (SJO or (sic) SoJO).


Hope this helps..
Apr 15 '14 #10
Sherin
77 64KB
POJO is a Java object not bound by any restriction other than those forced by the Java Language Specification.

Properties of POJO

All properties must public setter and getter methods
All instance variables should be private
Should not Extend prespecified classes.
Should not Implement prespecified interfaces.
Should not contain prespecified annotations.
It may not have no argument constructor

For example, this is a POJO:

Expand|Select|Wrap|Line Numbers
  1. class Point { 
  2.     private double x; 
  3.     private double y; 
  4.     public double getX() { return x; } 
  5.     public double getY() { return y; } 
  6.     public void setX(double v) { x = v; } 
  7.     public void setY(double v) { y = v; } 
  8.     public boolean equals(Object other) {...} 
  9.  
Aug 6 '20 #11
sarbjitgrewal
19 16bit
In Java Enterprise, POJO means Plain Old Java Object. POJO Object in Java is used for the readability and reusability of Java Program.
Sep 24 '20 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Al Davis | last post by:
Note: I tried cross-posting this message to several newsgoups, including comp.lang.perl.misc, c.l.p.moderated, comp.infosystems.www.authoring.cgi, comp.lang.javascript and comp.lang.php. Nothing...
15
by: lkrubner | last post by:
I want to give users the power to edit files from an easy interface, so I create a form and a PHP script called "fileUpdate". It does a reasonable about of error checking and prints out some...
2
by: thecrow | last post by:
Alright, what the hell is going on here? In the following code, I expect the printed result to be: DEBUG: frank's last name is burns. Instead, what I get is: DEBUG: frank's last name is...
220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
1
by: javaBoss | last post by:
Hi Guys, please any one can help me to give me the good example code for POJO's thanks
1
by: sumancal | last post by:
hallo guys, I am facing in a problem, i am creating a pojo thats take only name and i will take it in array list, and make a another class to make one jlable component. I Jtree which will...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.