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()?

[493 byte] By [ConanOfOza] at [2007-10-2 4:38:30]
# 1
out is a static nested class of System I believe.
Briganda at 2007-7-16 0:11:31 > top of Java-index,Java Essentials,New To Java...
# 2
> 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...?
ConanOfOza at 2007-7-16 0:11:31 > top of Java-index,Java Essentials,New To Java...
# 3
scratch that out is a static member variable of the type PrintStream... not a static class.
Briganda at 2007-7-16 0:11:31 > top of Java-index,Java Essentials,New To Java...
# 4
> 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.
aniseeda at 2007-7-16 0:11:31 > top of Java-index,Java Essentials,New To Java...
# 5

> 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.

FuzzyOniona at 2007-7-16 0:11:31 > top of Java-index,Java Essentials,New To Java...
# 6

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");

Briganda at 2007-7-16 0:11:31 > top of Java-index,Java Essentials,New To Java...
# 7

> 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.

tjacobs01a at 2007-7-16 0:11:31 > top of Java-index,Java Essentials,New To Java...
# 8
it makes things look purty I guess.
Briganda at 2007-7-16 0:11:31 > top of Java-index,Java Essentials,New To Java...
# 9

> 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?

tjacobs01a at 2007-7-16 0:11:31 > top of Java-index,Java Essentials,New To Java...
# 10
but now you can code so fast because you don't have to type System and Math!!!! lol.
Briganda at 2007-7-16 0:11:31 > top of Java-index,Java Essentials,New To Java...
# 11
> 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!
aniseeda at 2007-7-16 0:11:31 > top of Java-index,Java Essentials,New To Java...
# 12

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.

Briganda at 2007-7-16 0:11:31 > top of Java-index,Java Essentials,New To Java...
# 13
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):-(
tjacobs01a at 2007-7-16 0:11:31 > top of Java-index,Java Essentials,New To Java...
# 14
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.
jesperdja at 2007-7-16 0:11:31 > top of Java-index,Java Essentials,New To Java...
# 15
Is it a good idea if I will use System.out.println() a lot, and not use a out.println() from any other class?
Bahamuta at 2007-7-20 18:20:35 > top of Java-index,Java Essentials,New To Java...