IDEs have become very popular and intelligent to make programming easy for developers. Netbeans is one of the best IDE used for Java programming. In this post, I'm going to explain how to generate setters and getters using JDeveloper.

Just start adding a class with instance variables as shown below

public class Person
{
private String name;
private int age;
private boolean graduate;
}

Right click on source code and choose the Generate Accessors... option or you can alternatively choose this option from "Source" menu

You will get to see below dialog box with the above 3 instance variables. Just tidk the checkbox on the methods that are being displayed in the dialog box in a tree form. Click OK, that's it - getters and setters will be generated

Auto generated code will have below getters and setters as I've ticked everything


public void setName(String name)
{
this.name = name;
}

public String getName()
{
return name;
}

public void setAge(int age)
{
this.age = age;
}

public int getAge()
{
return age;
}

public void setGraduate(boolean graduate)
{
this.graduate = graduate;
}

public boolean isGraduate()
{
return graduate;
}