Search Java Code Snippets

  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.

Java - Code Samples

 Sample 1. Initialize object using Builder Pattern

public class Employee {
public String name;
public int age;
public int salary;

Employee withName(String name){ = name;
    return this;

Employee withAge(int age){
    this.age = age;
    return this;

Employee withSalary(int salary){
    this.salary = salary;
    return this;

public class BuilderPatternTest {
    public static void main(String[] args) {
       Employee employee = new Employee().withName("John").withAge(25).withSalary(10000);

   Like      Feedback     builder design pattern  builder pattern

Subscribe to Java News and Posts. Get latest updates and posts on Java from
Enter your email address:
Delivered by FeedBurner

comments powered by Disqus