public class Sample {
public void method()
{
System.out.println("normal hai");
}
public static void method1()
{
System.out.println("static hai");
}
public static void main(String[] args) {
Sample s = null;
s.method1();
s.method();
}
}
and the output is:
Exception in thread "main" java.lang.NullPointerException
at com.csvfile.sample.main(Sample.java:22)
static hai
Why has the order changed? It should output:
static hai
Exception in thread "main" java.lang.NullPointerException
at com.csvfile.sample1.main(Sample.java:22)
That is because the
exception
is printed to STDERR andSystem.out.println()
is printed to STDOUT and both streams are not synchronized.If you call it a second time the order can change.