- Java EE 8 Development with Eclipse
- Ram Kulkarni
- 274字
- 2025-04-04 16:37:02
Creating JavaBeans for data storage
We will first create JavaBean classes for Student, Course, and Teacher. Since both student and teacher are people, we will create a new class called Person and have Student and Teacher classes extend it. Create these JavaBeans in the packt.book.jee.eclipse.ch4.beans package as follows.
The code for the Course bean will be as follows:
package packt.book.jee.eclipse.ch4.bean; public class Course { private int id; private String name; private int credits; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getCredits() { return credits; } public void setCredits(int credits) { this.credits = credits; } }
The code for the Person bean will be as follows:
package packt.book.jee.eclipse.ch4.bean; public class Person { private int id; private String firstName; private String lastName; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } }
The code for the Student bean will be as follows:
package packt.book.jee.eclipse.ch4.bean; public class Student extends Person { private long enrolledsince; public long getEnrolledsince() { return enrolledsince; } public void setEnrolledsince(long enrolledsince) { this.enrolledsince = enrolledsince; } }
The Teacher bean will be as follows:
package packt.book.jee.eclipse.ch4.bean; public class Teacher extends Person { private String designation; public String getDesignation() { return designation; } public void setDesignation(String designation) { this.designation = designation; } }