What is system.in

前端 未结 9 1042
隐瞒了意图╮
隐瞒了意图╮ 2021-02-06 05:50

Consider this Scanner input example.

Scanner user_input = new Scanner( System.in );

Here Scanner is the CLASS.

相关标签:
9条回答
  • 2021-02-06 06:13

    The Scanner constructor's parameter System.in references the static InputStream field in defined in the final System class. As a static field in requires its class identifier.

    Oracle states that in is the "standard" input stream1, not that System.in is. The quotes around standard likely refer to the irony that inputting from a keyboard using a command line interface is no longer the standard, what with them newfangled GUIs and all.

    0 讨论(0)
  • 2021-02-06 06:19

    System.in is the "standard" input stream.

    Take a look at the following documentation: http://docs.oracle.com/javase/7/docs/api/java/lang/System.html

    0 讨论(0)
  • 2021-02-06 06:24

    Scanner class accepts input stream as a parameter and System class have a static variable in which is of type InputStream. System.in gives you a instance of of type InputStream.

    Check this doc of public static final InputStream in

    The "standard" input stream. This stream is already open and ready to supply input data.

    0 讨论(0)
  • 2021-02-06 06:25

    "System.in" is a parameter that is taken by Scanner Class where "System" is a class and "in" is a static variable of type InputStream which tells the Java Compiler that System input will be provided through console(keyboard).

    0 讨论(0)
  • 2021-02-06 06:27

    Scanner class has a constructor Scanner(InputStream) in its profile i.e when we call Scanner() constructor during the object creation time it will let you to pass the object of InputStream class.

    "in" is an object of "InputStream" class defined in System class(like "out" is an object of PrintStream class defined in System class).

    Thus System.in is nothing but calling the "in" object of InputStream class defined in System class when Scanner constructor is called during object creation time.

    Scanner(InputStream) is pre-defined constructor in Scanner class which when calls requires the object of InputStream class as the parameter and that object is System.in.

    0 讨论(0)
  • 2021-02-06 06:36

    From the source:

    System.in is an InputStream which is typically connected to keyboard input of console programs. System.in is not used as often since data is commonly passed to a command line Java application via command line arguments, or configuration files. In applications with GUI the input to the application is given via the GUI. This is a separate input mechanism from Java IO.

    0 讨论(0)
提交回复
热议问题