There are times when a working example or code sample is the best way to explain a concept.
JavaRanch has no shortage of
Java Sample Code for those times.
That being said, the best approach is often to show enough code to point the questioner in the right direction. Show the key part of a method or class, not the entire method or class (unless absolutely required). The value here is that someone else who later has a similar, but not exact, problem as the questioner will be able to extrapolate an answer for him or herself.
Do you think the questioner is asking you to do their homework? Read
LetThemDoTheirOwnHomework about how to handle this.
If a questioner keeps pressing you to expand your original code or pseudo-code, you are not in any obligation to respond. If you feel that you have answered their question sufficiently, then you need not continue the
thread.
Other valuable resources you can use are references to APIs, specifications, online articles, etc., but be aware that linkrot will render these meaningless.
Back to
HowToAnswerQuestionsOnJavaRanch
See also:
DoYourOwnHomeworkNotACodeMillUseCodeTags