• Post Reply Bookmark Topic Watch Topic
  • New Topic

import class, decrease performance  RSS feed

 
ashish sujaka
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all !!

i just want to ask that does importing more classes increase runtime programming overhead ???


please explain!!
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No! there is no performance overhead.

Import statements are just there to tell the compiler which classes to use. You could even remove import statements completely by using full qualified class names everywhere in your code. So import statements make it easier to read and write code but there no difference regarding the Java runtime.

Marco
 
Randall Twede
Ranch Hand
Posts: 4696
8
Java Scala
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i agree. from what i know there is no performance problem from importing lots of classes. the only thing that might be of concern is importing complete packages. there is a possibility of conflict. for example java.util.Date and java.sql.Date. if you have
import java.util.*
import java.sql.*
and you declare a Date object, which one do you mean?
 
Stephan van Hulst
Saloon Keeper
Posts: 7987
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that in this case, you can still explicitly import one of the two Date classes, even if you already imported the entire sql and util packages. I often do this in GUI applications:
 
Satyaprakash Joshii
Ranch Hand
Posts: 205
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
imports are resolved at the compile time....and there wont be runtime overhead
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!