Java Interview Question

Use this advanced question and answer to prepare for your next Java interview.

Should you use external libraries in your code? What are the benefits and drawbacks? What precautions can be taken?


External libraries are extremely helpful when writing large and complex programs - they save the effort of having to code something which has already been implemented by someone else.

  • There are a few drawbacks to using an external library:
  • It can have bugs in the implementation, especially corner cases which only surface when some users use the library.
  • The library may not be frequently maintained and it may be difficult to contact the owner regarding bugs.
  • The library or some of the used features can be deprecated or deleted at any time.

But this does not mean you should not use external libraries. There are some excellent ways to protect programs from being impacted very badly by such problems. One of the best ways to protect from external dependencies is to design that part of the code using Interfaces. Interfaces allow defining a contract or a specification that is binding on all implementers of the interface when implemented correctly. This frees the consumer to directly use the interface without having to care about the implementation.

If a bug is discovered in the implementation of a library, or the library gets deprecated, then it can be switched out for another library without having to modify the consumers of the interface. This type of design will make the whole program more robust.

Looking for developers?

Want to learn more about Gigster? Enter your email and we'll be in touch.