Reading input fast in Java for competitive programming
In my experience, non-buffered I/O based on plain System.in and System.out are not fast enough for some competitive programming problems. I wrote a template based on BufferedReader and BufferedWriter, which are much faster. They aren't necessary for every problem, but I haven't found any downside to using them by default.

Some example code:

BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in);
while (stdin.ready())
    String line = stdin.readLine();

BufferedWriter stdout = new BufferedWriter(new OutputStreamWriter(System.out));
stdout.write("test");
stdout.flush();
stdout.close();


I wrote a couple of blog posts with more details and some benchmark numbers:


Solving UVa 11340 in Java
Why is Java I/O Slow?