Kamis, 08 Januari 2015

Input/Output in Java

Java Input/Output

Hello(again) :D

After we understand about Basic Input/Output, now i'm going to post about Input/Output in Java Programming.

The Java platform is an isolated entity, a space on your OS in a way, where everything outside this system is its environment. The interaction between the system and its environment is a two-way dialog of sorts. Either the system receives messages from its environment, or it conveys its messages to the same. When a message is received to the system, it is called an input, its opposite is an output. On a whole, this communication is termed input/output abbreviated as I/O.

The following chapters are designed to introduce basic input and output in Java, including reading text input from the keyboard, outputting text to the monitor, and reading/writing files from the file system. More advanced user interaction using Graphics and Graphical User Interface (GUI) programs is taken up in the later section on Swing.

Simple Java Output: Writing to the Screen :
Writing to the screen is very easy, and can be accomplished using this method :

Print "Hello world" :

System.out.print("Hello world");

On the screen it will look like this :












Simple Java Input: Inputting from the keyboard
As of version 1.5.0, Java provides a class in the java.util package called Scanner that simplifies keyboard input.

Inputting with Scanner :

Scanner kbdIn = new Scanner(System.in); // Instantiating a new Scanner object
System.out.print("Enter your name: "); // Printing out the prompt
String name = kbdIn.nextLine(); // Reading a line of input (until the user hits enter) from the keyboard
// and putting it in a String variable called name
System.out.println("Welcome, " + name); // Printing out welcome, followed by the user's name.

On the scree it will look like this :












Just like that, it is some simple input/output in Java Programming. Hope it help you.

1 komentar:

  1. Lucky Club Casino Site ᐈ Review + 100 Free Spins | LuckyClub.live
    Lucky Club Casino is a new site to the Lucky Club Online Casino where luckyclub you can play slots and table games from the comfort of your own home.

    BalasHapus