import java.beans.PropertyChangeListener;
public class Person {
private String name;
public void setName(String name) {
this.name = name;
firePropertyChange("name", null, name);
}
public void addPropertyChangeListener(PropertyChangeListener listener) {
// ...
}
}
import java.beans.Introspector;
import java.beans.BeanInfo;
public class Main {
public static void main(String[] args) throws IntrospectionException {
BeanInfo beanInfo = Introspector.getBeanInfo(Person.class);
// Get property descriptors, event descriptors, etc.
}
}
import java.beans.PropertyEditor;
public class ColorPropertyEditor implements PropertyEditor {
// ...
}
import java.beans.Customizer;
public class PersonCustomizer implements Customizer {
// ...
}
public class PersonBuilder {
private String name;
private int age;
public PersonBuilder setName(String name) {
this.name = name;
return this;
}
public PersonBuilder setAge(int age) {
this.age = age;
return this;
}
public Person build() {
return new Person(name, age);
}
}
import javax.swing.*;
public class SwingExample {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setTitle("JavaBeans Example");
frame.setVisible(true);
}
}
import org.eclipse.jface.viewers.IStructuredSelection;
public class PropertySheetExample {
public static void main(String[] args) {
// Get the selected object from the Eclipse property sheet viewer
IStructuredSelection selection = (IStructuredSelection) EclipseUI.getSelection();
Object selectedObject = selection.getFirstElement();
}
}
import javafx.beans.property.SimpleStringProperty;
public class JavaFXExample {
private final SimpleStringProperty name = new SimpleStringProperty();
public final void setName(String name) {
this.name.set(name);
}
public final String getName() {
return name.get();
}
}
import javax.servlet.*;
import javax.servlet.http.*;
public class IntrospectionServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Get the name of the bean class from the request parameter
String className = request.getParameter("beanClass");
// Introspect the bean class
Class<?> beanClass = Class.forName(className);
BeanInfo beanInfo = Introspector.getBeanInfo(beanClass);
// Get the bean properties
PropertyDescriptor[] properties = beanInfo.getPropertyDescriptors();
// Print the bean properties to the response
for (PropertyDescriptor property : properties) {
response.getWriter().write(property.getName());
}
}
}
<%@ page import="java.beans.*" %>
<jsp:useBean id="person" class="com.example.Person" scope="request" />
<jsp:setProperty name="person" property="name" value="John Doe" />
<p>The person's name is ${person.name}</p>
public class PersonAction extends ActionSupport {
private String name;
public String execute() throws Exception {
// Set the name property using the setter method
setName("John Doe");
// Return the success result
return SUCCESS;
}
}
@Component
public class PersonService {
private Person person;
@Autowired
public PersonService(Person person) {
this.person = person;
}
public String getName() {
return person.getName();
}
}
@Entity
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private int age;
}
import org.osgi.framework.*;
public class PersonActivator implements BundleActivator {
@Override
public void start(BundleContext context) throws Exception {
// Register the Person service as a JavaBean
ServiceRegistration<Person> registration = context.registerService(Person.class, new Person(), null);
// Get the Person service from the bundle context
Person person = (Person) context.getService(registration.getReference());
}
}
public class Person implements Parcelable {
private String name;
private int age;
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeInt(age);
}
}
class Person {
String name
int age
}
def p = new Person(name: 'John Doe', age: 30)
class Person(val name: String, val age: Int)
case class Person(name: String, age: Int)
import org.apache.commons.beanutils.PropertyUtils;
public class Main {
public static void main(String[] args) throws Exception {
Person person = new Person("John Doe", 30);
PropertyUtils.setProperty(person, "name", "Jane Doe");
}
}
import com.fasterxml.jackson.databind.ObjectMapper;
public class Main {
public static void main(String[] args) throws Exception {
Person person = new Person("John Doe", 30);
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(person);
}
}
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
public class Main {
public static void main(String[] args) throws Exception {
Person person = new Person("John Doe", 30);
JAXBContext context = JAXBContext.newInstance(Person.class);
Marshaller marshaller = context.createMarshaller();
marshaller.marshal(person, System.out);
}
}
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public class PersonService {
@WebMethod
public Person getPerson() {
return new Person("John Doe", 30);
}
}
import javax.ejb.Stateless;
@Stateless
public class PersonService {
public Person getPerson() {
return new Person("John Doe", 30);
}
}
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface PersonService extends Remote {
Person getPerson() throws RemoteException;
}
import javax.jms.Message;
import javax.jms.MessageListener;
public class PersonMessageListener implements MessageListener {
@Override
public void onMessage(Message message) {
// Get the Person object from the message
Person person = (Person) message.getObject();
}
}
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class Main {
public static void main(String[] args) throws NamingException {
Context context = new InitialContext();
PersonService personService = (PersonService) context.lookup("java:global/PersonService");
}
}
import javax.xml.bind.annotation.*;
@XmlRootElement
public class Person {
@XmlElement
private String name;
@XmlElement
private int age;
}
import org.apache.axis2.AxisFault;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
public class Main {
public static void main(String[] args) throws AxisFault {
ServiceClient client = new ServiceClient();
Options options = client.getOptions();
options.setTo("http://localhost:8080/axis2/services/PersonService");
Object[] results = client.invokeBlocking("getPerson", new Object[] {});
Person person = (Person) results[0];
}
}
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
public class Main {
public static void main(String[] args) {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setAddress("http://localhost:8080/cxf/services/PersonService");
PersonService personService = (PersonService) factory.create();
Person person = personService.getPerson();
}
}
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
public class Main {
public static void main(String[] args) throws TException {
TTransport transport = new TSocket("localhost", 9090);
TProtocol protocol = new TBinaryProtocol(transport);
PersonService.Client client = new PersonService.Client(protocol);
Person person = client.getPerson();
}
}
import org.apache.avro.io.Decoder;
import org.apache.avro.io.DecoderFactory;
import org.apache.avro.io.Encoder;
import org.apache.avro.io.EncoderFactory;
import org.apache.avro.specific.SpecificDatumReader;
import org.apache.avro.specific.SpecificDatumWriter;
public class Main {
public static void main(String[] args) throws Exception {
Person person = new Person("John Doe", 30);
SpecificDatumWriter<Person> writer = new SpecificDatumWriter<>(Person.class);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Encoder encoder = EncoderFactory.get().directBinaryEncoder(outputStream, null);
writer.write(person, encoder);
encoder.flush();
byte[] bytes = outputStream.toByteArray();
Decoder decoder = DecoderFactory.get().directBinaryDecoder(bytes, null);
SpecificDatumReader<Person> reader = new SpecificDatumReader<>(Person.class);
Person person2 = reader.read(null, decoder);
}
}
import org.apache.parquet.io.api.Binary;
import org.apache.parquet.io.api.PrimitiveConverter;
import org.apache.parquet.io.api.RecordConsumer;
import org.apache.parquet.schema.MessageType;
public class PersonRecordConsumer extends RecordConsumer {
private final MessageType schema;
public PersonRecordConsumer(MessageType schema) {
this.schema = schema;
}
@Override
public void startMessage() {
// ...
}
@Override
public void addField(int fieldIndex, PrimitiveConverter converter) {
switch (fieldIndex) {
case 0:
converter.addBinary(Binary.fromString("John Doe"));
break;
case 1:
converter.addInt(30);
break;
}
}
@Override
public void endMessage() {
// ...
}
}
import com.datastax.driver.core.BoundStatement;
import com.datastax.driver.core.PreparedStatement;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Session;
public class PersonDao {
private final Session session;
private final PreparedStatement insertStatement;
private final PreparedStatement selectStatement;
public PersonDao(Session session) {
this.session = session;
this.insertStatement = session.prepare("INSERT INTO people (name, age) VALUES (?, ?)");
this.selectStatement = session.prepare("SELECT name, age FROM people WHERE name = ?");
}
public void insert(Person person) {
BoundStatement statement = insertStatement.bind(person.getName(), person.getAge());
session.execute(statement);
}
public Person select(String name) {
BoundStatement statement =