When should we use console class? - console

I was reading about Console class, and in the very first line, it was written
New to Java 6 and when we are running Java SE 6 from command line, then we are typically using console class object
So, which means we are implicitly using console class through the command line ??
Then, I started looking for more detail about Console class and I found Input from console class in java and Console link. So, concluded some points
Console class are only usable outside the IDE using System.console().readLine();
Console class reads a password or passphrase from the console with echoing disabled using readPassword()
Although, we had Scanner class and BufferedReader class to read the input from console and that was added earlier than Java 5. So, only due to security reason Console class was added in Java 6 ? or are there any other advantage(s) to use this class.
Could anyone share more details about Console class ?

The Console class reads directly from the process console (usually /dev/console in Unix systems). The console differs from System.in in that it cannot be redirected when a command is launched. It is also used to read passwords because reading from the console you can control whether or not you echo the chars being typed.
To clarify more on this class, read about console and standard input in Unix systems (this is typically a Unix thing and I'm not really sure how it maps to Windows systems).
Finally, Scanner can read from any input: a file, an stream, or the console itself so it's different from Console.

The Console class tries to implement a platform independent way to handle with console input. All OS has a console in any way, but they are quiet diferent in implementation. So Console class gives you a Java platfrom independent runtime class to access things like password input, etc.

Whether a virtual machine has a console is dependent upon the
underlying platform and also upon the manner in which the virtual
machine is invoked. If the virtual machine is started from an
interactive command line without redirecting the standard input and
output streams then its console will exist and will typically be
connected to the keyboard and display from which the virtual machine
was launched. If the virtual machine is started automatically, for
example by a background job scheduler, then it will typically not have
a console.
How To Get Input From Console Class In Java?

Related

How to check if the biometric scanner is available and initialized in Xamarin android BiometricPrompt

Failed biometric(fingerprint) scan attempts are handled by OnAuthenticationFailed() callback of BiometricPrompt.AuthenticationCallback class.
The behavior I noticed is, it lets the user attempt 5 invalid fingerprint scans (each time the fail callback is invoked) and then the prompt dismisses. Within the next 30 secs, if we try to re-build a BiometricPrompt instance and try to authenticate, it does not show the prompt which I think is the default behavior of BiometricPrompt.
Is there anyway to check if the biometric scanner is available and initialised if the user attempts to re-invoke biometric prompt within the said 30secs?
How can I handle that use case?
xamarin android BiometricPrompt.AuthenticationCallback does not have an override method "onAuthenticationError" to handle error callbacks and thus I'm unable to handle error code "BIOMETRIC_ERROR_TIMEOUT".
If someone has a solution for this, please do let me know your resolution.
I believe that BiometricPrompt is not fully ported to Xamarin yet...
I'm still looking for a source that can double check this info for me, but I haven't found it either.

For CRaSH shell why do we need fully qualified name and if error messages can be displayed

With regards to CRaSH shell, we noticed that we need fully qualified names in certain running of functions e.e.g running the flow in startflowdynamics where the call function has to be net.core.newFlow. While i can appreciate that there could be same flow class names e.g. net.core1.newFlow or net.core2.newFlow, but other flows name like newFlow vs newNewFlow are very distinct.
Q1: why do we need to put fully qaulified names even when the class names are so distinct.
Q2: Can we modified the CRaSH shell to resolve the class names with fully qualifed names as it is quite annoying for CLS to input long lines.
Q3: The CRaSH shell doesn't display error messages which I would need to view the log instead. Are there ways I could get the CLS to display error messages when the flow has exception error or as a matter of fact any exception thrown?
Q1 and Q2: You don't need to use the fully-qualified class name when starting a flow, unless the unqualified class name is ambiguous. For example, when running the Example CorDapp, I can start a flow from the CRaSH shell by running:
flow start Initiator
Q3: Like every other application interacting with the node, the CRaSH shell communicates with the node via RPC. Any internal errors are not sent over RPC for security reasons.

How to capture stdout from a console application whose life cycle is very long by CreatePipe?

I tried to write an test application to capture the text from stdout of an 3rd console application.
I studied from many articles to use the CreatePipe API and have INDEED obtained the text AFTER the console application HAD FINISHED running.
I tried to make the console application keep printing something for more than 60 seconds, and the ReadFile funcion didn't return during this 60 seconds at all.
For the same purpose, I tried popen and fread, and everything went fine except the black console window created by popen.
Although the ReadFileEx and something about the overlapped I/O seems to be able to solve this problem but it's actually not.
Because the ReadFileEx required the file handle to be created to support overlapping, and this is always impossilbe because the file handle is created by the 3rd console application. It won't be under control unless we develop the console application by ourselves.
So is there any way to capture stdout from a 3rd console application whose life cycle is very long by CreatePipe?
Thanks in advance!
I finaly figured out the problem is the 3rd console application "MAC.EXE" doesn't invoke "fflush" after each progress output....
I manually append the fflush operation in the source code of mac.exe and the problem gets resolved.
So a new question is:
If the child process never call fflush and seldom print during running, how to read the content correctly?

sqoop2 client batch mode script example

Can anyone show me an example of script that can be run from sqoop2 client in batch mode?
I refered http://sqoop.apache.org/docs/1.99.2/Sqoop5MinutesDemo.html
and it says we can run sqoop2 client in batch mode using the following command
sqoop.sh client /path/to/your/script.sqoop
but that script.sqoop isn't like sqoop1 script, so how should it be?
Batch file is nothing but a list of the same commands you would otherwise type in interactive mode (plus comment lines starting with pound sign).
However! Some commands require manual input, thus cannot be easily fully automated (e.g., 'create link' command). See this thread for details.

Print to console with Jetty

I am creating a simple Jetty server and am wondering how to print something into the console, like variables at specific times or when a user connects. I am compiling the Jetty server with a java class with jetty-all jar files. I am not using any xml currently. Could anyone tell me how to print something into the console? Such as, when a user connects say, "User connected"
Thanks.
You better should output to a log file, you could use log4j for that.
Use
LOGGER.info("user connected");
on linux you then can use
tail -f logfile.log
to live output the content to the console

Resources