Prashant Shilimkar
Prashant Shilimkar

Reputation: 8840

What is mean by creating some object will be expensive in java/oop

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?

Upvotes: 5

Views: 963

Answers (4)

user3099444
user3099444

Reputation:

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.

Upvotes: 2

Abhishek Anand
Abhishek Anand

Reputation: 1992

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.

Upvotes: 2

Nishant
Nishant

Reputation: 1142

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.

Upvotes: 2

user2357112
user2357112

Reputation: 281586

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.

Upvotes: 4

Related Questions