java,System.out.println();

我请教下,java,System.out.println();?

System里面也没有println()方法呀?怎么回事?
System.out不就是System的out字段?谢谢。
ps:还有这个什么意思?
System.out.println 能重定向到别的输出流,这样的话你在屏幕上将看不到打印的东西了,
而System.err.println只能在屏幕上实现打印,即使你重定向了也一样。
最新回答
冷巷

2024-10-22 13:11:56

out是System提供的用于标准输出的流,在没有重定向的情况下,会直接打印到终端,而println这个方式实际上是PrintStream类提供的功能

重定向错误输出在jdk中有一段说明:
通常,此流对应于显示器输出或者由主机环境或用户指定的另一个输出目标。按照惯例,此输出流用于显示错误消息,或者显示那些即使用户输出流(变量 out 的值)已经重定向到通常不被连续监视的某一文件或其他目标,也应该立刻引起用户注意的其他信息。
与我归江南

2024-10-22 18:34:45

System.out.println() 这条语句是使用了类 PrintStream 的 println()。
System.out 为类 System 的数据成员 out,它属于 PrintStream 类。PrintStream 类能将任意类型数据输出为字符串形式。
下面是System的部分源码
/**
* The "standard" output stream. This stream is already
* open and ready to accept output data. Typically this stream
* corresponds to display output or another output destination
* specified by the host environment or user.
* <p>
* For simple stand-alone Java applications, a typical way to write
* a line of output data is:
* <blockquote><pre>
* System.out.println(data)
* </pre></blockquote>
* <p>
* See the <code>println</code> methods in class <code>PrintStream</code>.
*
* @see java.io.PrintStream#println()
* @see java.io.PrintStream#println(boolean)
* @see java.io.PrintStream#println(char)
* @see java.io.PrintStream#println(char[])
* @see java.io.PrintStream#println(double)
* @see java.io.PrintStream#println(float)
* @see java.io.PrintStream#println(int)
* @see java.io.PrintStream#println(long)
* @see java.io.PrintStream#println(java.lang.Object)
* @see java.io.PrintStream#println(java.lang.String)
*/
public final static PrintStream out = nullPrintStream();

上面的内容你应该能知道System out 和 println()方法的意思了吧?

能重定向到别的输出流的意识就是,System.out.println不一定一定输出在屏幕上,而可以输出到日志文件甚至打印机,数据库里。

如果你看不懂,没有关系,说明你的基础不够扎实,再多接触和学习就会懂了
血染素衣泪倾城

2024-10-22 09:23:53

out是System类里的一个字段,它是标准的一个输出流,println()方法应该是printStream里的方法,且out也是printStream里的一个字段,大致是这意思吧,我也不是很清楚,我没去研究这个众人都会用的方法
憇憇圏

2024-10-22 09:53:00

System其实是jdk自带的一个类,他有很多的方法,这些方法都是静态的,也就是static的,他还有一个类变量out是PrintStream类型的,PrintStream有一个方法那就是print和println啦,
err也是同样的道理,你要学会怎么去看帮助文档,这的确很重要
微浅笑°

2024-10-22 14:01:54

println是System.out的方法,并不是System的方法,你查下API就会发现out的类型。

PS后面的那两句话不用管它,也不知道是国内哪个人写的教材