Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

import confusion

 
colton peterson
Ranch Hand
Posts: 97
Linux Python VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whenever I import code, I always use the wildcard eg:

import java.util.*;

but in a lot of people's code, they import a class at a time eg:

import java.util.ArrayList;

what are the advantages and disadvantages to each? I know that importing a whole package doesn't slow the code down at all, so I see no reason to import specific packages.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49459
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Importing individual classes allows you to see which classes are in use. It also allows you to see conflicts. For example import java.util.* and javax.swing.* and try to use the Timer class.
 
colton peterson
Ranch Hand
Posts: 97
Linux Python VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ah, the API has three timer classes, I could see where that could create conflict, thanks.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49459
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Embla Tingeling
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
colton peterson wrote:what are the advantages and disadvantages to each?


I'm using Eclipse, one of the major free Java IDE's, and one of the very convenient features it has is automatic import management. Eclipse knows exactly which specific imports you need so it tells you when one is missing or when there's one too many. Then you just click on an offer to fix it and it gets done for you.
 
colton peterson
Ranch Hand
Posts: 97
Linux Python VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh, that also makes sense, I'm trying not to use one of the IDE's until I know more about how java works on the inside.
 
Embla Tingeling
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
colton peterson wrote:oh, that also makes sense, I'm trying not to use one of the IDE's until I know more about how java works on the inside.


Well, that's a controversial topic.

If you were a C# programmer and didn't use Visual Studio right from the start you would be considered completely nuts. But for some reason exactly Java programmers think they must start out with Java using programming tools from the sixties before they can graduate to a decent IDE.

I think this is a waste of time really. You don't need to use development tools favoured by your grandpa to get a grip on Java. It's enougth to know that you can develop Java programs from the OS shell using a text editor. You don't have to go through all the pain and actually do it. It won't give you a better understanding of "how Java really works". It's because Java works in different ways depending on which tools you use and no tool-set is closer to the truth than any other. I'd say skip Sun's ancient tools and start using a modern IDE tomorrow.
 
colton peterson
Ranch Hand
Posts: 97
Linux Python VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh I use an IDE, it's called geany, it is a general purpose IDE for a lot of different languages. It doesn't have things like auto import managing, but it is much better than textpad + command prompt
 
Henry Wong
author
Marshal
Pie
Posts: 21216
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Embla Tingeling wrote:
I think this is a waste of time really. You don't need to use development tools favoured by your grandpa to get a grip on Java. It's enougth to know that you can develop Java programs from the OS shell using a text editor. You don't have to go through all the pain and actually do it. It won't give you a better understanding of "how Java really works". It's because Java works in different ways depending on which tools you use and no tool-set is closer to the truth than any other. I'd say skip Sun's ancient tools and start using a modern IDE tomorrow.


IMHO, a good reason for this is because we have a large number of people going for their certification here at the ranch. And unfortunately, the SCJP does test using how the command line compiler behaves.

In my case, I do use an IDE most of the time, but I also do on-site consulting quite a bit. When you are on-site, you may not get to choose your developement environment, and the command line is the lowest common denominator.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic