Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I import specific classes ?

 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
Lately I seem to import a lot of classes, and I suspect that it would create a large foot-print e.g.
import java.awt.image.MemoryImageSource;
is in my view better than
import java.awt.image.*;
So how do I find out which specific classes I need ???
I tried the javac -verbose , is that the only way ?
 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To answer your question. import on demand, importing packageName.*;,
is just as efficient.

I'd reference the jls, but somebody stole my copy [damned people].
Who the fuk steals a jls, anyway?
 
Ryan Bailey
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no difference.
import java.awt.*; versus
import java.awt.Button is the same.
When importing you are not 'including' resources in your program. It is just a convenient way to write code so you don't have to specify
the fully qualified path to an object.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java:
The power, elegance, and simplicity of a hand grenade

I thought that was C++. Or maybe it was perl.
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all
I wish I could buy you people drinks or something for all the free help I have gotten here over the last few months...
 
Philip Shanks
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After reading this thread, I realized that the reason that I write specific import statements like java.util.LinkedHashMap instead of java.util.*, is for documentation. I can look at the first few lines of code and see the detailed dependencies.
With a relatively small package, such as java.util.regex, it doesn't matter, but for java.util.* or java.sql.* I kind of like to know what parts of the API I'm leveraging. So I will probably continue to import specific classes most of the time.
It is nice to know that there aren't any performance penalties for using the "splat" version though.
Happy importing!
PCS
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic