-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaBeansExample.java
More file actions
87 lines (72 loc) · 1.75 KB
/
Copy pathJavaBeansExample.java
File metadata and controls
87 lines (72 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package java1_1.javabeans;
import java.io.Serializable;
/**
* Java 1.1 JavaBeans Example Demonstrates JavaBean conventions
*/
public class JavaBeansExample
{
public static void main(String[] args)
{
System.out.println("=== Java 1.1 JavaBeans ===\n");
// Create JavaBean
PersonBean person = new PersonBean();
person.setName("John Doe");
person.setAge(30);
person.setEmail("john@example.com");
System.out.println("Person Information:");
System.out.println("Name: " + person.getName());
System.out.println("Age: " + person.getAge());
System.out.println("Email: " + person.getEmail());
System.out.println("\nJavaBean Conventions:");
System.out.println("- No-argument constructor");
System.out.println("- Getter methods (getPropertyName)");
System.out.println("- Setter methods (setPropertyName)");
System.out.println("- Serializable (optional)");
System.out.println("- Property change support (optional)");
System.out.println("\nBenefits:");
System.out.println("- Reusable components");
System.out.println("- Standard conventions");
System.out.println("- Tool support");
System.out.println("- Framework integration");
}
}
/**
* JavaBean following conventions
*/
class PersonBean implements Serializable
{
private static final long serialVersionUID = 1L;
private String name;
private int age;
private String email;
// No-argument constructor (required)
public PersonBean()
{
}
// Getter methods
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
public String getEmail()
{
return email;
}
// Setter methods
public void setName(String name)
{
this.name = name;
}
public void setAge(int age)
{
this.age = age;
}
public void setEmail(String email)
{
this.email = email;
}
}