In NetBeans 12.4 and verified to also behave this way on NetBeans
12.5-beta2, System.out.print is buffered such that it does not show up in
the NetBeans Output window until a System.out.println (or probably things
like program end, and some buffer full scenario).
Using JDK 15 and a Maven Project. I am using macOS but my students who hit
this problem are using Windows.
Example code:
package dgreen.printbug;
import java.util.Scanner;
/**
* Demo program showing that System.out.print's are not pushed to output
window until a
* System.out.println
*/
public class NewMain {
/** @param args the command line arguments */
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter your name: ");
System.out.flush(); // should not be necessary but does not work either
String name = sc.nextLine();
System.out.println("Hi " + name);
}
}
—-
Running it after Clean & Build (or before)
--- exec-maven-plugin:3.0.0:exec (default-cli) @ printbug ---
dave
Enter your name: Hi dave
------------------------------------------------------------------------
BUILD SUCCESS
where "dave" was typed in without the benefit of seeing the prompt.
This works fine when run from true command line either inside a NetBeans
Terminal Window or the real command line.
In Jira as https://issues.apache.org/jira/browse/NETBEANS-5961
Dave