5

I heard this statement many times when reading some java books/articles.My question is very straightforward that when we say that creating some object will be very expensive?

Here expensive is for what and at what scenario we should use this term.It would be very easy for me to understand if some one illustrate with small example and how to avoid this?

4 Answers 4

4

Expensive usually means it'll take a while, but it can also mean it'll take a lot of some other resource, such as memory, bandwidth, hosting budget, disk space, or anything else you'd like to use less of. For example,

new int[1000000000]

will be expensive, because it allocates and zeros an incredible amount of memory.

2
  • what about JDBC object? is it always expensive? Commented Dec 4, 2013 at 3:45
  • @PrashantShilimkar : yes... in most cases. Commented Dec 4, 2013 at 3:55
2

Expensive means it requires quite a good amount of system resources like memory, disk I/O. A good example would be creation of a databse connection object which requires quite a number of steps before you get an actual connection object. Each step in itself may perform operations like reading configuration from a file which requires I/O, loading the database driver, registering the driver etc.

Creating big arrays are also expensive because it takes a big chunk of memory.

2

Expensive word in used in sense of Activity performed (like io operations), actions, or creation of object. In simplest words, anything that can make a slight performance hit is called expensive.

2

In case of object oriented programming Expensive is related to memory, resources etc your object is using.If unnecessarily your object is uses lots of memory or resources then somewhere you are not doing good programming.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.