• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

import confusion

 
Ranch Hand
Posts: 97
Python VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Python VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ah, the API has three timer classes, I could see where that could create conflict, thanks.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Python VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Python VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic