Java 中 System.out.println 是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3406703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the meaning of System.out.println in Java?
提问by prosseek
Is this static println
function in out
class from System
namespace?
这是来自命名空间的类中的静态println
函数吗?out
System
namespace System { class out { static println ... }
How can I interpret this name? And where in JRE this function is defined? In java.lang.System
/java.lang.Object
?
我该如何解释这个名字?这个函数在 JRE 的什么地方定义的?在java.lang.System
/ java.lang.Object
?
采纳答案by kennytm
No. Actually out
is a static member in the System
class (not as in .NET), being an instance of PrintStream
. And println
is a normal (overloaded) method of the PrintStream
class.
不。实际上out
是类中的静态成员System
(不像在 .NET 中),是PrintStream
. 并且println
是类的正常(重载)方法PrintStream
。
See http://download.oracle.com/javase/6/docs/api/java/lang/System.html#out.
请参阅http://download.oracle.com/javase/6/docs/api/java/lang/System.html#out。
Actually, if out
/err
/in
were classes, they would be named with capital character (Out
/Err
/In
) due to the naming convention(ignoring grammar).
其实,如果out
/ err
/in
是类,它们将与资本字符(命名Out
/ Err
/ In
)由于命名约定(忽略语法)。
回答by cHao
System
is a class, that has a public static field out
. So it's more like
System
是一个类,它有一个公共静态字段out
。所以它更像是
class System
{
public static PrintStream out;
}
class PrintStream
{
public void println ...
}
This is a slight oversimplification, as the PrintStream
class is actually in the java.io
package, but it's good enough to show the relationship of stuff.
这有点过于简单化了,因为PrintStream
类实际上在java.io
包中,但它足以显示事物之间的关系。
回答by YoK
Check following link:
检查以下链接:
http://download.oracle.com/javase/1.5.0/docs/api/java/lang/System.html
http://download.oracle.com/javase/1.5.0/docs/api/java/lang/System.html
You will clearly see that:
你会清楚地看到:
System
is a classin the java.lang
package.
System
是一个类中的java.lang
包。
out
is a static memberof the System
class, and is an instance of java.io.PrintStream
.
out
是一个静态成员的的System
类,并且是的一个实例java.io.PrintStream
。
println
is a methodof java.io.PrintStream
. This method is overloaded to print message to output destination, which is typically a console or file.
println
是一个方法的java.io.PrintStream
。此方法被重载以将消息打印到输出目标,通常是控制台或文件。
回答by Omprakash.K
println
and print
are the two overloaded methods which belong to the PrintStream
class.
println
和print
是属于PrintStream
该类的两个重载方法。
To access them we need an instance of this class.
要访问它们,我们需要一个此类的实例。
A static propertycalled out
of type PrintStream
is created on the System
class.
在类上创建了一个名为type 的静态属性。out
PrintStream
System
Hence to access the above methods we use the following statements:
因此,为了访问上述方法,我们使用以下语句:
System.out.println("foo");
System.out.print("foo");
回答by being_j
? System
is a class in java.lang
package
? System
是java.lang
包中的一个类
? out
is a static
object of PrintStream
class in java.io
package
? out
是包static
中PrintStream
类的对象java.io
? println()
is a method in the PrintStream
class
? println()
是PrintStream
类中的一个方法
回答by Shyam
It is quite simple to understand the question, but to answer it we need to dig deeper in to Java native code.
理解这个问题很简单,但要回答它,我们需要更深入地研究 Java 本机代码。
System
is static class and cannot be instantiatedout
is a reference variable defined inSystem
println()
is the method used to print on standard output.
System
是静态类,不能被实例化out
是定义在的引用变量System
println()
是用于在标准输出上打印的方法。
A brief and nice explanationis always welcome on this as we can learn much from this single line of statement itself!
一个简单而漂亮的解释是非常欢迎这个我们可以从语句本身的这个单行学到很多东西!
回答by mohd zeeshan
System
is a class in java.lang
package.
System
是java.lang
包中的一个类。
out
is the static data member in System
class and reference variable of PrintStream
class.
out
是类中的静态数据成员和System
类的引用变量PrintStream
。
Println()
is a normal (overloaded) method of PrintStream
class.
Println()
是类的正常(重载)方法PrintStream
。
回答by Isabella Engineer
System.out.println("Hello World");
System
: It is the name of standard class that contains objects that encapsulates the standard I/Odevices of your system.
System
: 它是标准类的名称,包含封装系统标准I/O设备的对象。
It is contained in the packagejava.lang
. Since java.lang
package is imported in every java program by default,therefore java.lang
packageis the only package in Java API which does not require an import declaration.
它包含在包中java.lang
。由于java.lang
默认情况下每个java程序都会导入包,因此java.lang
包是Java API中唯一不需要导入声明的包。
out
:The object out represents output stream(i.e Command window)and is the static data member of the classSystem
.
out
:对象out代表输出流(即命令窗口),是类的静态数据成员System
。
So note here System.out
(System
-Class & out
- static object i.e why its simply referred to by classname and we need not create any object).
所以请注意这里System.out
(System
-Class & out
- static object ,即为什么它只是由 classname 引用,我们不需要创建任何对象)。
println
:Theprintln()
is method ofout
object that takes the text string as an argument and displays it to the standard output i.e on monitor screen.
println
:该println()
是方法的out
目的,是以文本字符串作为参数并将其显示到标准输出即监视器画面上。
NoteSystem
-Classout
-static Objectprintln()
-method
Remember a function (in java function is called method) always has the format function()
注意System
-Class out
-static Object println()
-method
记住一个函数(在java中函数被称为方法)总是具有function()的格式
回答by kuldeep rawat
System.out.println
System
is a class in the java.lang
package.
System
是java.lang
包中的一个类。
out
is a static
data member of the System
class and references a variable of the PrintStream
class.
out
是类的static
数据成员System
并引用类的变量PrintStream
。
回答by user3819423
System
:is predefined class of java.lang
package.
System
:是预定义的java.lang
包类。
out
:is a static
member of printStream
class and its connect with console.
out
:是类的static
成员,printStream
它与控制台连接。
Println
:is a method of printstream
class and its not a static
.
Println
:是printstream
类的方法,而不是static
.