Q:

What value should be returned for "int create()" method that does not perform the operation?

I have a method that due to specifications for a project must return an int.
The method is a create() method that creates an object and puts it into an array. 
It then returns where in the array it put the object.
Right then.......so far so good.
The problem starts when you try to create an object which already exists in the array. My code prevents duplicates from being created. But it still needs to return an int.
What int should i return for an object that hasn't been created?
-1?
null?
an exception?

A:

Another alternative is to return id of the existing item - after all, isn't that what determines a "duplicate"?
Since this code has to work within an existing "specification", values like -1 (or throwing an Exception) may do more (or less) to break that infrastructure than returning the id of the existing element.
In whichever case, make sure to document the behavior and integration-test the implementation.

A:

For starters, if you have to return an int, trying to run would be a compile error (null is for objects, ints are primatives and thus not objects).
This leaves us with two options, neither of which are implicitly better than the other:
Throw an Exception
This is fine, so long as adding an object that exists is "Exceptional" behavior, after all it is an exception.
Return -1
This may be the preferred option due to the fact that by my understanding, adding an already existing item does not constitute exceptional behavior, rather this is what is to be expected. As -1 is a value that can never be returned otherwise, it would be sufficient here.

Remember, either of these is OK, so long as it is fully specified what will happen and you are consistent (Don't have one method throwing whilst the other returns -1 on error) and you stick to your design choice
As a side note, it is worth mentioning interfaces like java.util.Set, which define two methods one which returns false when trying to add a duplicate and one which throw an Exception.

