java keyboard input

KeyAdapter and KeyEvent Simple Example

Java permits to handle low-level events of mouse and keyboard. For keyboard the java.awt.event package comes with KeyListener and KeyAdapter. KeyAdapter is an abstract class that replaces the usage of KeyListener. Instead of implementing KeyListener and overriding its 3 abstract methods, we can as well extend KeyAdapter and override the interested abstract methods – may …

KeyAdapter and KeyEvent Simple Example Read More »

Ten questions for you, perhaps you are very much interested?

1. Why java.awt.event package is to be imported when java.awt is already imported. Does java.awt not include java.awt.event also? 2. How many ways you can do scanf in Java? 3. Can a string be converted to byte, short, int, long, float, double, char and boolean? 4. What is instanceof keyword? 5. Why the methods of …

Ten questions for you, perhaps you are very much interested? Read More »

Keyboard Input BufferedReader Java

The previous program (KeyboardReading1.java) of reading keyboard input, using DataInputStream, raises a deprecation warning. To overcome this, in the following program, the readLine() method of BufferedReader is used. Example on Keyboard Input BufferedReader Java The following program takes input from keyboard to fill the array elements. The elements and their average are printed. import java.io.*; …

Keyboard Input BufferedReader Java Read More »

Keyboard Input DataInputStream

In keyboard reading, three programs are given using DataInputStream, BufferedReader and Scanner. Of all, using java.util.Scanner is the easier and includes many methods to check the input data is valid to read. Example on Keyboard Input DataInputStream Following program uses readLine() method of DataInputStream to read data from the keyboard. import java.io.*; public class KeyboardReading1 …

Keyboard Input DataInputStream Read More »