Differences between system. Out and system. Err

Source: Internet
Author: User

public class TestCodeSeg{static{System.out.println("1");}{System.out.println("2");}public TestCodeSeg(){System.err.println("3");}public static void main(String[] args){new TestCodeSeg();}}



The sequence 1 and 2 are unchanged because they are static (executed during class loading) and 3 is in the constructor. Therefore, the execution sequence of the program is the static part and then the constructor. However, the output results will also be affected by system. Out and system. Err. System. Out is a row buffer while system. Err is not a buffer, so system. Err. println ("3") is an immediate output. However, system. Out. println ("1") and system. Out. println ("2") may be later due to buffering (but the order of 1 and 2 remains unchanged ). The specific output result 1 is absolute after 2, but where 3 appears is related to the execution of the program. If system. Err. println ("3") is executed, 1 and 2 are not output yet, then 3 first:

3
2
1
If 1 has been output but the line break has not been output, it is:
13

2
And so on:
1
3
2

And so on



Reprinted: http://bbs.csdn.net/topics/390420249

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.