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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 23:02:27  来源:igfitidea点击:

What's the meaning of System.out.println in Java?

javasystem.out

提问by prosseek

Is this static printlnfunction in outclass from Systemnamespace?

这是来自命名空间的类中的静态println函数吗?outSystem

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 outis a static member in the Systemclass (not as in .NET), being an instance of PrintStream. And printlnis a normal (overloaded) method of the PrintStreamclass.

不。实际上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/inwere 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

Systemis 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 PrintStreamclass is actually in the java.iopackage, 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:

你会清楚地看到:

Systemis a classin the java.langpackage.

System是一个中的java.lang包。

outis a static memberof the Systemclass, and is an instance of java.io.PrintStream.

out是一个静态成员的的System类,并且是的一个实例java.io.PrintStream

printlnis 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

printlnand printare the two overloaded methods which belong to the PrintStreamclass.

printlnprint是属于PrintStream该类的两个重载方法。

To access them we need an instance of this class.

要访问它们,我们需要一个此类的实例。

A static propertycalled outof type PrintStreamis created on the Systemclass.

在类上创建了一个名为type 的静态属性outPrintStreamSystem

Hence to access the above methods we use the following statements:

因此,为了访问上述方法,我们使用以下语句:

System.out.println("foo");
System.out.print("foo");

回答by being_j

? Systemis a class in java.langpackage

? Systemjava.lang包中的一个类

? outis a staticobject of PrintStreamclass in java.iopackage

? out是包staticPrintStream类的对象java.io

? println()is a method in the PrintStreamclass

? 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 本机代码。

  • Systemis static class and cannot be instantiated
  • outis a reference variable defined in System
  • 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

Systemis a class in java.langpackage.

Systemjava.lang包中的一个类。

outis the static data member in Systemclass and reference variable of PrintStreamclass.

out是类中的静态数据成员和System类的引用变量PrintStream

Println()is a normal (overloaded) method of PrintStreamclass.

Println()是类的正常(重载)方法PrintStream

回答by Isabella Engineer

System.out.println("Hello World");
  1. System: It is the name of standard class that contains objects that encapsulates the standard I/Odevices of your system.
  1. System: 它是标准类的名称,包含封装系统标准I/O设备的对象。

It is contained in the packagejava.lang. Since java.langpackage is imported in every java program by default,therefore java.langpackageis the only package in Java API which does not require an import declaration.

它包含在包中java.lang。由于java.lang默认情况下每个java程序都会导入包,因此java.lang是Java API中唯一不需要导入声明的包。

  1. out:The object out represents output stream(i.e Command window)and is the static data member of the class System.
  1. 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.outSystem-Class & out- static object ,即为什么它只是由 classname 引用,我们不需要创建任何对象)。

  1. println:The println()is method of outobject that takes the text string as an argument and displays it to the standard output i.e on monitor screen.
  1. printlnprintln()方法out目的,是以文本字符串作为参数并将其显示到标准输出即监视器画面上

Note
System-Class
out-static Object
println()-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

Systemis a class in the java.langpackage.

Systemjava.lang包中的一个类。

outis a staticdata member of the Systemclass and references a variable of the PrintStreamclass.

out是类的static数据成员System并引用类的变量PrintStream

回答by user3819423

System:is predefined class of java.langpackage.

System:是预定义的java.lang包类。

out:is a staticmember of printStreamclass and its connect with console.

out:是类的static成员,printStream它与控制台连接。

Println:is a method of printstreamclass and its not a static.

Println:printstream类的方法,而不是static.