Professional Documents
Culture Documents
POJO Class
POJO Class
POJO Class
We can store data in object and using a getter method we can retrieve data from object.
The standard of Pojo class Design is declare variable as private and create set and get method or
function with a variable name.
POJO class work as Container class
package org.techhub;
class Employee {
private int id;
private String name;
package org.techhub;
class Admission{
private String name;
private int id;
private float fees;
private String address;
void newAdmission(String name,int id,float fees,String address) {
this.name=name;
this.id=id;
this.fees=fees;
this.address=address;
}
void show() {
System.out.println(name+"\t"+id+"\t"+fees+"\t"+address);
}
}
public class AdmissionApplication {
public static void main(String[] args) {
// TODO Auto-generated method stub
Admission ad = new Admission();
ad.newAdmission("Ram", 1, 90.0f, "PUNE");
ad.show();
}
}
if we think about above code we have function name as newAdmission() and in this function
contain four types of data of different type but when we large number of parameter list of
different type then it is very complicated to remember every parameter type ,every type sequence
and number of parameter list so better we can store all data in single object and pass object
as parameter where we want to send multiple type of data.
Source code
_______________________________________________________________________
package org.techhub;
class Student {
private String name;
class Admission {
Student s;
void newAdmission(Student s) {
this.s=s;
}
void show() {
System.out.println(s.getId()+"\t"+s.getName()+"\t"+s.getFees()+"\t"+s.getAddress());
}
}
}
}
Object with variable arguments or reference with variable arguments.
Example:
We want to create application small shop for generate bill
and we have three classes in this application
1) Product: Product is POJO means it contain only setter and getter and Product contain
Following information or data or variable id, name, price, qty,company name
Use setter and getter method with all variables.
3) ShopApplication: this class contain main method where we crete 5 Product and
store information in Project object using a setter method and create object of Bill class
and call its calBill() method and pass customer name, customer contact and 5 product
objects in it and generate following type of output