Java Forum / General / July 2005
import magic
Roedy Green - 05 Jul 2005 11:16 GMT I understand that I import classes in Java so that it can figure out if the method signatures on the calls match those off the imported callees. IT need help finding the packages of the class names I use.
Why is it that if I write:
Font temp = x.getFont(); y.setFont( temp );
I need to import java.awt.Font;
but If I write:
y.setFont( x.getFont() );
I don't.
It seem on first breath they are equally difficult problems. So how come Java needs help with import on the first but not the second.
It seems odd that some trivial detail as to whether you use a temp variable somewhere, e.g. added for debugging, that it should any bearing on something so overarching as imports. I am still using the exact same classes!
I hate the way you have to keep putting them in and taking them out.
 Signature Bush crime family lost/embezzled $3 trillion from Pentagon. Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video. http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm
Canadian Mind Products, Roedy Green. See http://mindprod.com/iraq.html photos of Bush's war crimes
Tim Miller - 05 Jul 2005 11:38 GMT > I understand that I import classes in Java so that it can figure out > if the method signatures on the calls match those off the imported [quoted text clipped - 12 lines] > > I don't. Because you don't reference the identifier "Font" in the second statement. While instances of "Font" are still being used, the compiler can detect that x.getFont() returns an instance of java.awt.Font, and y.setFont(..) takes as a parameter java.awt.Font. The package name is already apparent from the method signatures, so you don't need to import them. In the first statement, however, "Font temp =.." could be referring to a class called "Font" from different packages.
Roedy Green - 05 Jul 2005 12:24 GMT >Because you don't reference the identifier "Font" in the second >statement. While instances of "Font" are still being used, the [quoted text clipped - 4 lines] >statement, however, "Font temp =.." could be referring to a class >called "Font" from different packages. Many thanks. that has been as itch I have never got around to scratching since Java 1.0.
 Signature Bush crime family lost/embezzled $3 trillion from Pentagon. Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video. http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm
Canadian Mind Products, Roedy Green. See http://mindprod.com/iraq.html photos of Bush's war crimes
Boudewijn Dijkstra - 05 Jul 2005 17:27 GMT > [...about imports...] > > I hate the way you have to keep putting them in and taking them out. Once you have put one in, you can leave it there.
IchBin - 05 Jul 2005 18:59 GMT >> [...about imports...] >> >> I hate the way you have to keep putting them in and taking them out. > > Once you have put one in, you can leave it there. For Eclipse just use menu item Source \ Organize Imports
or [Ctrl Shift O]
 Signature Thanks in Advance... IchBin, Pocono Lake, Pa, USA __________________________________________________________________________
' If there is one, Knowledge is the "Fountain of Youth"' -William E. Taylor, Regular Guy (1952-)
Raymond DeCampo - 05 Jul 2005 19:38 GMT >>[...about imports...] >> >>I hate the way you have to keep putting them in and taking them out. > > Once you have put one in, you can leave it there. Or just don't use them, if you don't like them.
Ray
 Signature XML is the programmer's duct tape.
Roedy Green - 05 Jul 2005 21:54 GMT >Once you have put one in, you can leave it there. Eclipse calls it an error if you don't remove it.
 Signature Bush crime family lost/embezzled $3 trillion from Pentagon. Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video. http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm
Canadian Mind Products, Roedy Green. See http://mindprod.com/iraq.html photos of Bush's war crimes
George Cherry - 06 Jul 2005 04:58 GMT >>Once you have put one in, you can leave it there. > > Eclipse calls it an error if you don't remove it. You could stop using Eclipse. : o )
> Bush crime family lost/embezzled $3 trillion from Pentagon. > Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video. > http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm > > Canadian Mind Products, Roedy Green. > See http://mindprod.com/iraq.html photos of Bush's war crimes Roedy Green - 06 Jul 2005 07:36 GMT >You could stop using Eclipse. : o ) It did a very nasty bad to me today totally scrambling my program moving all implementation of the same method next to each other and tossing out some declarations. that method reorder thing is pretty darn dangerous.
Is it just me or do eclipse people never split the screen to look at two parts of the same program at once or two versions of a similar program side by side. It can rapidly flip, but I like to see.
Also I miss being able to sort without leaving the IDE, just select some the column and range with the mouse to reorder static init data etc.
I was overwhelmed looking at the plugins available. I had not the vaguest clue what most of them were for.
There is so much arcane vocabulary to learn.
I wish plugin descriptions were not just for people who wanted a thing but to but also for the novice to know roughly what it is for. When all you see in an acronym you have no idea of whether to pursue the matter further.
 Signature Bush crime family lost/embezzled $3 trillion from Pentagon. Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video. http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm
Canadian Mind Products, Roedy Green. See http://mindprod.com/iraq.html photos of Bush's war crimes
IchBin - 06 Jul 2005 19:19 GMT > I wish plugin descriptions were not just for people who wanted a thing > but to but also for the novice to know roughly what it is for. When > all you see in an acronym you have no idea of whether to pursue the > matter further. This is where the learning curve comes in, at least for me. This maybe the best place to start http://www.eclipse.org/projects
I think that you would be interested in the following
Tools Project (CDT) C/C++ Development Tools http://www.eclipse.org/cdt
Technology Project (WTP) Eclipse Web Tools Platform http://www.eclipse.org/webtools
Tools Project (VE) Visual Editor http://www.eclipse.org/webtools
Tools Project (UML2) is an EMF-based implementation of the UML http://www.eclipse.org/webtools
Not sure if you would be interested in SWT or compare it to AWT\SWING. Also PDE, the Eclipse plugin development.
You just have to be aware of the prerequisites with VE, WTP and UML2.
 Signature Thanks in Advance... IchBin, Pocono Lake, Pa, USA __________________________________________________________________________
' If there is one, Knowledge is the "Fountain of Youth"' -William E. Taylor, Regular Guy (1952-)
IchBin - 06 Jul 2005 19:28 GMT >> I wish plugin descriptions were not just for people who wanted a thing >> but to but also for the novice to know roughly what it is for. When [quoted text clipped - 22 lines] > > You just have to be aware of the prerequisites with VE, WTP and UML2. Sorry..
Tools Project (VE) Visual Editor http://www.eclipse.org/vep/
Tools Project (UML2) is an EMF-based implementation of the UML http://www.eclipse.org/uml2/
 Signature Thanks in Advance... IchBin, Pocono Lake, Pa, USA __________________________________________________________________________
' If there is one, Knowledge is the "Fountain of Youth"' -William E. Taylor, Regular Guy (1952-)
Henk van Voorthuijsen - 07 Jul 2005 09:49 GMT > Is it just me or do eclipse people never split the screen to look at > two parts of the same program at once or two versions of a similar > program side by side. It can rapidly flip, but I like to see. You can use the compare view to compare two compilation elements: In the package or outline view select two method names. The context menu on the selection hase a "Compare With/ Other Element..." item. This works across files as well.
Joan - 07 Jul 2005 18:17 GMT > >You could stop using Eclipse. : o ) > > It did a very nasty bad to me today totally scrambling my program > moving all implementation of the same method next to each other and > tossing out some declarations. that method reorder thing is pretty > darn dangerous. So read the f.cking warning before you f.cking click on it.
> Is it just me or do eclipse people never split the screen to look at > two parts of the same program at once or two versions of a similar [quoted text clipped - 21 lines] > Canadian Mind Products, Roedy Green. > See http://mindprod.com/iraq.html photos of Bush's war crimes Roedy Green - 08 Jul 2005 05:12 GMT >> It did a very nasty bad to me today totally scrambling my program >> moving all implementation of the same method next to each other and >> tossing out some declarations. that method reorder thing is pretty >> darn dangerous. > >So read the f.cking warning before you f.cking click on it. The UI is designed so that this dangerous feature is right next to "correct indentation" which I use routinely. It is very easy to hit "sort members" by mistake. This is why in my tips section I advise against removing the warning even if you know the danger.
I think Eclipse itself should refuse to invoke it unless it has a clean compile.
 Signature Bush crime family lost/embezzled $3 trillion from Pentagon. Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video. http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm
Canadian Mind Products, Roedy Green. See http://mindprod.com/iraq.html photos of Bush's war crimes
Stefan Schulz - 06 Jul 2005 11:11 GMT >>Once you have put one in, you can leave it there. > > Eclipse calls it an error if you don't remove it. Well, mine does call it a Warning - a warning i told the compiler not to emit, by the way.
 Signature You can't run away forever, But there's nothing wrong with getting a good head start. --- Jim Steinman, "Rock and Roll Dreams Come Through"
Bryce - 06 Jul 2005 18:37 GMT >>Once you have put one in, you can leave it there. > >Eclipse calls it an error if you don't remove it. I believe its just a warning, not an error in Eclipse.
-- now with more cowbell
Tim Tyler - 09 Jul 2005 16:28 GMT Bryce <spamtrap@berzerker-soft.com> wrote or quoted:
> On Tue, 05 Jul 2005 20:54:52 GMT, Roedy Green > >On Tue, 5 Jul 2005 18:27:24 +0200, "Boudewijn Dijkstra"
> >>Once you have put one in, you can leave it there. > > > >Eclipse calls it an error if you don't remove it. > > I believe its just a warning, not an error in Eclipse. It /can/ be an error.
Basically it all depends on whether you have the:
"Compiler -> Unnecessary code -> Unused imports"
...configuration option set to Error, Warning or Ignore.
 Signature __________ |im |yler http://timtyler.org/ tim@tt1lock.org Remove lock to reply.
Roedy Green - 10 Jul 2005 05:40 GMT >It /can/ be an error. I am discovering the way you do this is to make it loose to start then gradually tighten up so that even javadoc flaws count as errors.
I would rather it did something more useful with its list of errors, sorting them by severity and grouping them so you can easily tell if you pared it down sufficiently for your current purpose. There is no point in turning off the messages completely, only to discover later you have been doing the Javadoc all wrong.
 Signature Bush crime family lost/embezzled $3 trillion from Pentagon. Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video. http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm
Canadian Mind Products, Roedy Green. See http://mindprod.com/iraq.html photos of Bush's war crimes
Tim Tyler - 10 Jul 2005 08:56 GMT Roedy Green <look-on@mindprod.com.invalid> wrote or quoted:
> I am discovering the way you do this is to make it loose to start then > gradually tighten up so that even javadoc flaws count as errors. FWIW, I have everything permanenetly set to "warn" in the compiler settings - except "Access to a non-accessible member of an enclosing type" - which is an *evil* setting - and "Usage of non-externalised strings" which is just too anal for me.
> I would rather it did something more useful with its list of errors, > sorting them by severity and grouping them so you can easily tell if > you pared it down sufficiently for your current purpose. It /does/ sort by severity - it's just that there are only three categories.
You can filter on the error text - and filter based on the resource containing the error.
It's good enough for me. My main remaining bitch with Eclipse is that its editor still sucks - though these days it certainly sucks a *lot* less than it used to.
Thank goodness they've now dealt with many of the worst of these:
http://www.eclipse.org/eclipse/development/performance/ http://www.eclipse.org/eclipse/development/performance/bloopers.html
 Signature __________ |im |yler http://timtyler.org/ tim@tt1lock.org Remove lock to reply.
Chris Smith - 12 Jul 2005 17:20 GMT > I am discovering the way you do this is to make it loose to start then > gradually tighten up so that even javadoc flaws count as errors. I rather prefer for the compiler to continue compiling all valid Java code. Instead, I prefer to make a lot of things into warnings, and just take warnings very seriously. That way, for example, I don't have to fix up all manner of anal-retentive stuff in code copied from this newsgroup just to get it to compile and reproduce someone's problem!
Unfortunately, Sun screwed up royally with Java 1.5 and generics, and it's now well-nigh impossible to get a clean build because at some point you'll need to get a reference of a generic type from a servlet session or something like that, and there's just no way to do it without a warning. For the moment, I've turned off the warning for unsafe type operations just because of this.
 Signature www.designacourse.com The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation
Chris Smith - 12 Jul 2005 17:28 GMT > I would rather it did something more useful with its list of errors, > sorting them by severity and grouping them so you can easily tell if > you pared it down sufficiently for your current purpose. I definitely would like to see you be able to specify a severity level for each warning, and then sort by that. I might be persuaded to turn back on the unchecked cast warnings if this were the case. I could set them to a lower priority because they are often impossible to solve; and they would no longer prevent me from seeing real, important warnings such as unused variables or assignments with no effect.
Even better, yacc used to have (and probably still has) a warning that was impossible to get rid of in many situations, and the tool provided a mechanism to acknowledge the issue so that it would stop issuing the warning again until something changed. I didn't like the details of the situation with yacc (it used the number of warnings, which was dangerous), but the idea was great. I would love to be able to tell the compiler (Eclipse, in this case) that I know I have an unchecked cast and it's okay with me... and then it would shut up until I actually changed something in that logical area of code -- such as any change to that line, or a change that modifies the type of the expression that is assigned or the type of the variable being assigned to.
A feature like that would essentially bail Sun out of the tar pit they have created with generics. I'd rather avoid a language feature because I still hope Sun comes to its senses and fixes generics to eliminate type erasure some time soon.
 Signature www.designacourse.com The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation
david@tribble.com - 07 Jul 2005 17:07 GMT Roedy Green schrieben:
>> [...about imports...] >> I hate the way you have to keep putting them in and taking them out.
> Once you have put one in, you can leave it there. I prefer to use specific imports (e.g. "import java.io.File") instead of wildcard imports ("import java.io.*"). This makes my compilations faster (at least in theory). It also forces me to list all of the classes used in my code, which tends to be of some help when I (or the other guy who has the joy of maintaining my code) track the classes down.
It also tends to alleviate problems of using twin class names that appear in more than one package, especially if my code uses a lot of third-party packages.
-drt
Roedy Green - 08 Jul 2005 05:12 GMT >I prefer to use specific imports (e.g. "import java.io.File") instead >of wildcard imports ("import java.io.*"). This makes my compilations >faster (at least in theory). It also forces me to list all of the >classes used in my code, which tends to be of some help when I (or the >other guy who has the joy of maintaining my code) track the classes >down. it also helps when it comes time to build a zip or jar.
 Signature Bush crime family lost/embezzled $3 trillion from Pentagon. Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video. http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm
Canadian Mind Products, Roedy Green. See http://mindprod.com/iraq.html photos of Bush's war crimes
Tor Iver Wilhelmsen - 08 Jul 2005 16:16 GMT > it also helps when it comes time to build a zip or jar. Why? The dependency analysis should only concern itself with classes actually used; imports are only used by the compiler, all types are fully qualified in the class file. E.g. if you import com.foo.* and only use the class Fie from that package, only com.foo.Fie will be considered a dependency.
Roedy Green - 09 Jul 2005 09:50 GMT >Why? The dependency analysis should only concern itself with classes >actually used; imports are only used by the compiler, all types are >fully qualified in the class file. E.g. if you import com.foo.* and >only use the class Fie from that package, only com.foo.Fie will be >considered a dependency. if you are bundling up source code to give to someone, you have to figure out what to include. One starting point is looking at the aggregate imports of classes you wrote.
 Signature Bush crime family lost/embezzled $3 trillion from Pentagon. Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video. http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm
Canadian Mind Products, Roedy Green. See http://mindprod.com/iraq.html photos of Bush's war crimes
Tim Tyler - 09 Jul 2005 16:50 GMT Roedy Green <look-on@mindprod.com.invalid> wrote or quoted:
> >Why? The dependency analysis should only concern itself with classes > >actually used; imports are only used by the compiler, all types are [quoted text clipped - 5 lines] > figure out what to include. One starting point is looking at the > aggregate imports of classes you wrote. In theory, IDEs should do all that for you.
In practice, there are deployment tools that do pretty comprehensive dependency analysis for class files - and they mean that the programmer doesn't have to look at import statements - since the tool does it all for them.
The results of that analysis can be applied pretty directly to the problem of redistributing project fragements as source code - by ignoring inner classes, and replacing ".class" files with ".java" ones.
 Signature __________ |im |yler http://timtyler.org/ tim@tt1lock.org Remove lock to reply.
David R Tribble - 27 Jul 2005 20:59 GMT Roedy Green wrote:
>> if you are bundling up source code to give to someone, you have to >> figure out what to include. One starting point is looking at the >> aggregate imports of classes you wrote.
> In theory, IDEs should do all that for you. A brute-force way of doing this is to dump the contents of the .class file and look for the names of all the classes embedded within it.
But there should be a standard tool for doing this.
-drt
Roedy Green - 27 Jul 2005 21:39 GMT >A brute-force way of doing this is to dump the contents of the .class >file and look for the names of all the classes embedded within it. > >But there should be a standard tool for doing this. I have created a crude tool. I use Ant/genjar to build the jar. Then I use wzunzip -t to give me a directory listing. I am finding manually maintaining forjar.lists is too tedious. I am just going to give my users ant build.xmls.
Then I run this Funduc script to tidy it up. You could also work with the manifest, and prune that.
[Script for Search and Replace] convert wzunzip to forjar.list [Options] Search_subdir=1 Prompt_flag=0 Max Display Chars=512 Show Progress Dialog=1 Count across files=0 Replace Processing=0 Process Binary Files=1 Buffer Size=102400 Num Buffers To Process=0 Output_File= Show_Files=1 Backup Path= Before Hit=< After Hit=> Max Reg Expr=4000 Write to Backup Dir=0 Unzip Dir=C:\DOCUME~1\ADMINI~1.ROE\LOCALS~1\Temp\ Show Files Without Hits=0 Display Replace String=0 Display File Stats=1 Show File Date and Size=0 Reverse Filters=0 Min Size Filter=0 Max Size Filter=0 Min Date Filter= Max Date Filter= Skip Files Mask=0 Ignore Attributes=55 Keep file time stamp=0 One hit=0 Sort File Names=0 Sort Ascending=1 Append to output file=0 [Search] META-INF\MANIFEST.MF [Replace]
[Search] OK [Replace]
[Search] testing: com [Replace] com [Search] \ [Replace] / [End of Search and Replace Script]
 Signature Bush crime family lost/embezzled $3 trillion from Pentagon. Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video. http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm
Canadian Mind Products, Roedy Green. See http://mindprod.com/iraq.html photos of Bush's war crimes
Tim Tyler - 28 Jul 2005 10:44 GMT Roedy Green <look-on@mindprod.com.invalid> wrote or quoted:
> "David R Tribble" <david@tribble.com> [needed class files to needed source files - for source distribution?]
> >A brute-force way of doing this is to dump the contents of the .class > >file and look for the names of all the classes embedded within it. [quoted text clipped - 7 lines] > > Then I run this Funduc script to tidy it up. [...] You also need something to strip out inner class names, no?
 Signature __________ |im |yler http://timtyler.org/ tim@tt1lock.org Remove lock to reply.
Dale King - 15 Jul 2005 04:41 GMT > I understand that I import classes in Java so that it can figure out > if the method signatures on the calls match those off the imported > callees. IT need help finding the packages of the class names I use. No you don't. Imports have nothing to do with methods (except for the new static import). You import to tell the compiler how to turn unqualified class names into qualified class names.
 Signature Dale King
Roedy Green - 15 Jul 2005 09:57 GMT >No you don't. Imports have nothing to do with methods (except for the >new static import). You import to tell the compiler how to turn >unqualified class names into qualified class names. But why do you want to do that? -- so that you can find the class files and then the proper method signatures so you can generate the correct code.
Your point is taken that all imports do is help find the class file and let the compiler know which version of a class you mean, e.g. java.awt.List or java.util.List.
The import does not cause anything to be loaded or compiled.
 Signature Bush crime family lost/embezzled $3 trillion from Pentagon. Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video. http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm
Canadian Mind Products, Roedy Green. See http://mindprod.com/iraq.html photos of Bush's war crimes
Andrew McDonagh - 15 Jul 2005 19:59 GMT >>No you don't. Imports have nothing to do with methods (except for the >>new static import). You import to tell the compiler how to turn [quoted text clipped - 9 lines] > > The import does not cause anything to be loaded or compiled. No, imports have nothing to do with methods, they are purely about saving us from having to fully qualify every CLASS usage, not the usage of class's methods.
for example (note no usage of the methods):
without import usage we have to do the following...
public java.net.InetAddress getSomeonesAddress() { return null; }
with imports we can simplify...
import Java.net.InetAddress;
public InetAddress getSomeonesAddress() { return null; }
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|