I am trying to learn Java, I was reading a tutorial that said something like this:
while (N <= 0) {
TextIO.put("The starting point must be positive. Please try again: ");
N = TextIO.getlnInt();
}
It seems like when you ask the user for input it suspends until the response is recieved? I am used to these things happening asynchronously. Is this normal for Java? or can you do both?
Thanks.
I'm not familiar with that TextIO library, but when calling InputStream.read(), i.e. when using System.in.read(), it will block until input data is available. This makes it synchronous.
You can avoid this (i.e. make it asynchronous) by using another thread to capture input.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With