Java에서 System.out.println의 의미는 무엇입니까?
이 정적 println
함수가 네임 스페이스의 out
클래스에 System
있습니까?
네임 스페이스 System { class out { 정적 println ... }
이 이름을 어떻게 해석 할 수 있습니까? 그리고 JRE에서이 함수는 어디에 정의되어 있습니까? 에서 java.lang.System
/ java.lang.Object
?
아니요. 실제로 out
는 System
.NET이 아닌 클래스 의 정적 멤버 이며 PrintStream
. 그리고 클래스 println
의 일반적인 (오버로드 된) 메서드입니다 PrintStream
.
http://download.oracle.com/javase/6/docs/api/java/lang/System.html#out을 참조 하십시오 .
실제로 out
/ err
/ in
가 클래스 인 경우 명명 규칙 (문법 무시 )으로 인해 대문자 ( Out
/ Err
/ In
)로 명명 됩니다.
System
public static field가있는 클래스입니다 out
. 그래서 더 좋아
class System
{
public static PrintStream out;
}
class PrintStream
{
public void println ...
}
PrintStream
클래스가 실제로 java.io
패키지에 포함 되어 있기 때문에 이것은 약간 지나치게 단순화 된 것이지만, 물건의 관계를 보여주기에는 충분합니다.
다음 링크를 확인하십시오.
http://download.oracle.com/javase/1.5.0/docs/api/java/lang/System.html
다음을 명확하게 볼 수 있습니다.
System
패키지 의 클래스 입니다 java.lang
.
out
클래스 의 정적 멤버 이며의 System
인스턴스입니다 java.io.PrintStream
.
println
의 방법 입니다 java.io.PrintStream
. 이 메서드는 일반적으로 콘솔 또는 파일 인 출력 대상에 메시지를 인쇄하도록 오버로드됩니다.
System.out.println ()
높은 수준의 이해
이를 이해하기 위해 자바의 몇 가지 기본 사항을 기억해야합니다.
- Java의 도트 (.) 연산자 : Java에서. (점 연산자)는 메서드 또는 변수를 호출하는 데만 사용됩니다. 그래서 우리는 방법 또는 변수라고 말할 수 있습니다.
- 자바의 메소드 : 메소드 이름 뒤에는 항상 괄호 '()'가 있다는 것을 알고 있으므로 out은 java의 메소드가 될 수 없습니다. 따라서 변수와 println ()은 메서드 입니다.
- Java의 클래스 이름 : 클래스 이름은 Java에서 이상적으로 대문자로 시작해야 하므로 System은 클래스 입니다.
이제 자바에 대한 기본 지식으로 우리는 다음을 알고 있습니다.
- 시스템은 클래스입니다
- out은 변수입니다.
- println ()은 메소드입니다.
자세히 알아 보겠습니다.
변수 출력 : 정적 또는 인스턴스?
클래스 이름을 사용하여 호출하므로 System 클래스의 정적 변수를 알고 있습니다.
그러나 println () 메서드를 호출하므로 'out'은 참조 유형 PrintStream의 객체입니다.
System 클래스는 java.lang 패키지에 속합니다.
class System {
public static final PrintStream out;
//...
}
Prinstream 클래스는 java.io 패키지에 속합니다.
class PrintStream{
public void println();
//...
}
println
및 print
에 속하는 두 개의 오버로드 된 메서드입니다 PrintStream
클래스.
액세스하려면이 클래스의 인스턴스가 필요합니다.
정적 속성 이라는 out
유형은 PrintStream
온 만든 System
클래스입니다.
따라서 위의 방법에 액세스하기 위해 다음 문을 사용합니다.
System.out.println("foo");
System.out.print("foo");
System.out.println("Hello World");
System
: 시스템의 표준 I / O 장치 를 캡슐화하는 객체를 포함하는 표준 클래스의 이름입니다 .
패키지에 포함되어 java.lang
있습니다. 이후 java.lang
패키지가 기본적으로 모든 자바 프로그램에서 가져 따라서 java.lang
패키지 가져 오기 선언을 필요로하지 않는 자바 API의 유일한 패키지입니다.
out
: 객체 출력은 출력 스트림 (예 : 명령 창)을 나타내며 클래스의 정적 데이터 멤버입니다System
.
따라서 여기에주의하십시오 System.out
( System
-Class &-static out
object 즉, 단순히 classname으로 참조되고 객체를 생성 할 필요가없는 이유 ).
println
: 는println()
것입니다 방법 의out
표준 출력 예에 인수와 디스플레이를 같은 텍스트 문자열 소요 객체 모니터 화면에이 .
참고
System
-Class
out
-static Object
println()
-method
함수 (Java 함수에서 메소드라고 함)는 항상 function () 형식을 갖습니다.
• 패키지 System
의 클래스java.lang
• out
is a static
object of PrintStream
class in java.io
package
• println()
is a method in the PrintStream
class
System
is a class of java.lang
package, out
is an object of PrintStream
class and also static
data member of System
class, print()
and println()
is an instance method of PrintStream
class. it is provide soft output on console.
It is quite simple to understand the question, but to answer it we need to dig deeper in to Java native code.
System
is static class and cannot be instantiatedout
is a reference variable defined inSystem
println()
is the method used to print on standard output.
A brief and nice explanation is always welcome on this as we can learn much from this single line of statement itself!
Because out is being called with the System
class name itself, not an instance of a class (an object), So out
must be a static variable belonging to the class System
. out
must be instance of a class, because it is invoking the method println()
.
// the System class belongs to java.lang package
class System {
public static final PrintStream out;
}
class PrintStream {
public void println();
}
System
is a class in java.lang package
. And out
is a PrintStream
object. Nice explanation @ http://lazy-geeks.blogspot.in/2015/01/what-is-systemoutprintln.html
System.out.println();
System
is the class
out
is a variable in the System
class and it is a static
and variable type is PrintStream
.
Here is the out
variable in System
class:
public final static PrintStream out = null;
You can see implementation of System
here.
println()
is a overloaded method in PrintStream
class.
PrintStream
includes three overloaded printing methods, those are:
print()
println()
printf()
You can see implementation of PrintStream
here.
You cannot instantiate System
class and it is child class of Object
and the Object
is the father(superclass) of every classes including classes that you defined.
Here is what the oracle docs says:
public final class System extends Object
The
System
class contains several useful class fields and methods. It cannot be instantiated.Among the facilities provided by the
System
class are standard input, standard output, and error output streams; access to externally defined properties and environment variables; a means of loading files and libraries; and a utility method for quickly copying a portion of an array.Since: JDK1.0
If you donot know what is meant by instantiate, read this questioh. It is C# question but the concept is same.
Also, What is the difference between an Instance and an Object?
If you donot know what is meant by overload read this quesiotn.
System
is a class in java.lang
package.
out
is the static data member in System
class and reference variable of PrintStream
class.
Println()
is a normal (overloaded) method of PrintStream
class.
From the javadoc about System
, here's what the doc says:
public final class System
extends Object
The System class contains several useful class fields and methods. It cannot be instantiated.
Among the facilities provided by the System class are standard input, standard output, and error output streams; access to externally defined properties and environment variables; a means of loading files and libraries; and a utility method for quickly copying a portion of an array.
Since:
JDK1.0
Regarding System.out
public static final PrintStream out
The "standard" output stream class Prinstream belongs to java.io package. This stream is already open and ready to accept output data.
When the JVM is initialized, the method initializeSystemClass() is called that does exactly what it’s name says – it initializes the System class and sets the out variable. The initializeSystemClass() method actually calls another method to set the out variable – this method is called setOut().
Typically this stream corresponds to display output or another output destination specified by the host environment or user.
Regarding println();
class PrintStream{
public void println();
}
For simple stand-alone Java applications, a typical way to write a line of output data is:
System.out.println(data);
System is the java class.
out is the instance and also static member of PrintStream.
println is the method of PrintStream.
System.out.println("...") in Java code is translated into JVM. Looking into the JVM gave me better understanding what is going on behind the hood.
From the book Programming form the Java Virtual Machine. This code is copied from https://github.com/ymasory/programming-for-the-jvm/blob/master/examples/HelloWorld.j.
This is the JVM source code.
.class public HelloWorld
.super java/lang/Object
.method public static main([Ljava/lang/String;)V
.limit stack 2
.limit locals 1
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc "Hello, world"
invokevirtual java/io/PrintStream/println
(Ljava/lang/String;)V
return
.end method
.end class
As "The JVM doesn't permit byte-level access to memory" the out
object in type Ljava/io/PrintSteram
; is stored in a stack with getstatic
JVM command. Then the argument is pushed on the stack before called a method println
of the java/io/PrintStream
class from an instance named out
. The method's parameter is (Ljava/lang/String
;) and output type is void (V).
System
: is predefined class of java.lang
package.
out
: is a static
member of printStream
class and its connect with console.
Println
: is a method of printstream
class and its not a static
.
System.out.println
System
is a class in the java.lang
package.
out
is a static
data member of the System
class and references a variable of the PrintStream
class.
System
- class which is final
in nature. public final class System{}
. Belongs to java.lang
package
out
- static
reference variable of type PrintStream
println()
- non static
method in PrintStream
class. PrintStream
belongs to java.io
package.
To understand it better you can visit : How System.out.println() Works In Java
참고URL : https://stackoverflow.com/questions/3406703/whats-the-meaning-of-system-out-println-in-java
'Nice programing' 카테고리의 다른 글
C에서 동적 다차원 배열을 어떻게 사용합니까? (0) | 2020.12.09 |
---|---|
Django 파일 업로드 크기 제한 (0) | 2020.12.09 |
ssh 로컬 포트 포워딩을 통한 JConsole (0) | 2020.12.09 |
현재 디렉터리를 확인할 수 없습니다. (0) | 2020.12.09 |
Swift 용 UITableView 예제 (0) | 2020.12.09 |