KDjava KDjava - 7 months ago 23
Java Question

What to do without System.out, to print on console?

I have been stuck with a problem that was asked recently at an interview. The problem is stated as--> Suppose you don't have access to System class in Jdk API, Also you cannot use ECHO, you are in JRE 5 environment, how will you print anything on console?? The question really started with -- Why has Java given us the PrintStream object System.out ??And why is it final?? Isn't there any other way to print anything on console.??

eis eis

You could bypass the System object if you want to. System.out does a lot of extra stuff (handling unicode, for instance), so if you really want just the raw output and performance, you actually probably even should bypass it.

import java.io.*;

public class PrintOutTest {
  public static void main(String args[]) throws IOException {
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new
      FileOutputStream(FileDescriptor.out), "ASCII"), 512);
    out.write("test string");

This has been elaborated a bit further in here.