Standard for programming 'beautiful' code in Java?

  1. Mostly following the Java code convention.
  2. I try to not make it matter what kind of class an object is. If I for instance have five different strings, the name of each variable should describe what information/content the variable represents, and not that is is a string.
  3. I find it often silly to try coming up with variations of a variable just because it exists both as a method argument and a class variable. I mostly use the same name with this syntax this.theVariable = theVariable
  4. A method should be as short as possible: as few lines as possible, and as few nested levels as possible (i.e. max one if-statement, and not ifs inside ifs etc.)
  5. Robert Martin's Clean Code is highly recommended!

Just to address one specific point, because it's one I commonly see people doing horrific things with:

If you have more than one object from same class, how do you name the second one?

By their purpose, surely. If you have two different objects of the same class, you must be using them for different purposes, so name it after that purpose. I think all of these examples would be pretty self-explanatory to most readers:

public void copyAddresses(Customer source, Customer destination) {


public void sendMessage(Mailbox sender, Mailbox recipient) {


public void changeContactCompany(User contact, Company from, Company to) {


public void eatWatermelon(Bowl servingBowl, Bowl bowlForSeedSpitting) {

or whatever... you get the idea.


You should start with the official Java Code Conventions.

They will explain why code conventions are needed, different conventions and, what your question seems to be about, naming conventions. They add various examples too.