Declaring instance or class variables public is not a good practice. One should only do this if absolutely required. The usual and preferred practice is to declare the variables as private and provide public getter and setter methods.

Java Code:
        private String userName;

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}