Sometimes I miss the laziness of using an IDE that let me just write the attribute of a Java class and then let the IDE generate the required getter/setter.
Can Emacs do
If you use the java-mode YASnippets by nekop you get the snippet prop which lets you define a private variable and it automatically makes a getter and a setter for that variable. The snippet reads as follows:
# -*- mode: snippet -*-
# name: property
# key: prop
# --
private ${1:String} ${2:name};$0
public $1 get${2:$(upcase-initials text)}() {
return $2;
}
public void set${2:$(upcase-initials text)}($1 $2) {
this.$2 = $2;
}
As can be seen this snippet does not differ much from the other answers except that it may be better formatted. Another advantage is that it is part of a package of snippets for Java.