System.out.println();
First question. What package holds this class?
Second question. I've encountered a lot of examples ofClassName.MethodName(), but this commond seems to have one too many periods. I mean, isn'tout a method of System? And if so, what status doesprintln()? Hmm, I'm very confused.
Third question. Can I not...import somepackage.*;
...so I can then just writeprintln(), or at leastout.println()?
out is a static nested class of System I believe.
> out is a static nested class of System I believe.Hmm. I wonder why it isn't "Out" instead of "out". I've been told class names are always capitalized...?
scratch that out is a static member variable of the type PrintStream... not a static class.
> Hmm. I wonder why it isn't "Out" instead of "out".> I've been told class names are always> s capitalized...?It's a member variable holding a PrintStream reference.
> Third question. Can I not... import
> somepackage.*;
...so I can then just write
> println(), or at least out.println()?
in Java 5.0, you can say in your imports:
import static java.lang.System.out;
And then you'll be able to say:
out.println();
but it's not a good idea.
sorry for being dumb... System is a static class and as of 1.5 you can do a static import to use it as you were requesting
import static java.lang.System;
. . .
out.println("this works");
> First question. What package holds this class?
java.lang
You can check this with the javadocs http://java.sun.com/j2se/1.5.0/docs/api/
> Second question. I've encountered a lot of examples
> of ClassName.MethodName(), but this commond
> seems to have one too many periods. I mean, isn't
> out a method of System? And if so, what
> status does println()? Hmm, I'm very
> confused.
Like the other poster said, out is a PrintStream.
> Third question. Can I not... import
> somepackage.*;
...so I can then just write
> println(), or at least out.println()?
No. Importing only lets you skip the package name. So with an import, you can go from saying
java.util.ArrayList =....
to
ArrayList = ...
But everything in java.lang is already imported, and System is a class, not a package.
it makes things look purty I guess.
> sorry for being dumb... System is a static class and
> as of 1.5 you can do a static import to use it as you
> were requesting
>
> import static java.lang.System;
good lord.
who wanted this put into java, and where can i find them so i can shoot them?
but now you can code so fast because you don't have to type System and Math!!!! lol.
> who wanted this put into java, and where can i find> them so i can shoot them? http://java.sun.com/j2se/1.5.0/docs/guide/language/static-import.htmlAnd then they mention that it should be used very sparingly!
This is like that episode of The Simpsons where there are bird eating lizards infesting the city so they bring in lizard eating gorrillas or something and then they get infested with gorrillas.
Sun must have been like.... "well people are writing bad code to get around typing static class names so lets implement a way for them to do this without writing bad code"... what happens now there is more bad code in a new form.
Wonderful. Well done java language developersThis is possibly the worst addition to java since adding subroutines to java bytecode (I guess that was pretty much right from the start tho):-(
There is only one valid reason to use static import: to prevent the Constant Interface Antipattern (see Effective Java, Item 17).Other than that, do not use static import.The example above is typically an example of where you do not want to use static import.
Is it a good idea if I will use System.out.println() a lot, and not use a out.println() from any other class?