It's way more complicated than you'd think. There isn't really such a thing as a 'terminal' to java. There is a stream of bytes that flow into the process, and a stream of bytes that flow out. If you write, for example:
java -jar someapp.jar >somefile.txt
then it starts to make sense that 'update a value' becomes impossible (yes, you can overwrite bytes in a file, but that >somefile.txt
could also be >/dev/printer
, and you can't exactly ask the printer to grow legs, walk over to the desk of the gal who just grabbed the paper out of it, swallow the paper back in, and unprint what it printed before.
Various terminals have 'rich support' and have certain byte sequences that don't print as characters but affect it in some other way: Move the 'cursor' around, make the background of any future text to be shown blue, clear the screen, etcetera.
That's how one would do this: Send these escape codes (Print them). Both the codes you need to send, as well as figuring out if the thing you are printing to even supports them, is OS dependent and are there are a lot of options, thus, java doesn't ship out of the box with a library that tries to sail this mess.
But, good news!
They do exist! Lanterna for example. You'd have to add the jar to your project (or add the group/artifact/version to your dependencies list if you use e.g. maven, gradle, or some other build system that takes care of this for you).
Alternatively, don't make a terminal app but a swing (desktop, graphical user interface) one, where updating a JTextField or what not is trivial.