Originally posted by Sylvester James:
what if there's no code in the constructor. object's take memory , correct, but irrespective of their constructor code, wouldn't creating something in memory take x time.
You can try creating lots of Objects and see how long it takes. I believe the time required to create lots of objects is very minute (independent of how large/complex the class is), unless there are heavyweight operations within the constructor.
A poor but reasonable example: Creating a SimpleDateFormat requires a
pattern String. It is imagineable that some processing took place when you instantiate the SimpleDateFormat with a pattern, such that subsequent calls to format dates can be optimized.
If you are creating SimpleDateFormat with the same pattern String over and over again, it may be a good idea to reuse the same object and save some processing time.