RubyDubee
RubyDubee

Reputation: 2446

Can I remove any implicitly imported Java library?

Can I remove any implicitly imported Java library? It may not seem useful. But I think it may reduce some execution time!

Upvotes: 3

Views: 1271

Answers (3)

Nick Holt
Nick Holt

Reputation: 34321

This will have no effect on execution type - I think I'm correct in saying that, by default, classes are only loaded as and when they are needed, not on mass at start-up.

To improve performance you need to profile your application with a tool like Visual VM and address the bottlenecks it identifies (which will never be where you'd expect).

Upvotes: 4

Bill the Lizard
Bill the Lizard

Reputation: 405795

Java doesn't include all of the classes in java.lang.* in your program. The compiler only includes the ones you explicitly use (or are used by classes you use, etc.).

Upvotes: 3

Laurence Gonsalves
Laurence Gonsalves

Reputation: 143224

Imports are just syntactic sugar. All they do is let you access things in other packages without having to state their fully qualified name. The code that is produced is exactly the same as if you fully-qualified everything. So there is no runtime performance penalty to having imports.

This also goes for the "implicit imports" (ie: java.lang): you don't pay any price for the classes you don't actually use.

Upvotes: 22

Related Questions