0

I am trying to understand outputStream first.I am reading from the book Java network programming 2ns edition by Merlin Hughes . There is a sample program in the book which i am trying to run and get its output but there is no output.i understand it but could not identify the problem .

here is the code

import java.io.*;

public class SimpleOut 
{
  public static void main(String[] args) throws IOException
  {
    for (int i=0; i<args.length; i++)
    {
        println (args[i]);
    }
  }

  public static void println(String msg) throws IOException
  {
    synchronized (System.out)
    {
        for (int i=0 ; i<msg.length(); i++)
            System.out.write(msg.charAt (i) & 0xff);

        System.out.write('\n');
    }
    System.out.flush();
  }
}
4
  • 3
    Are you passing command-line arguments to the program? Commented Feb 22, 2014 at 17:25
  • what do you want to understand? sysout!!!<!--------> Commented Feb 22, 2014 at 17:28
  • Got it ,Thanks .Didnt know about command line arguments (Y) Commented Feb 22, 2014 at 17:32
  • I understood the code.i didnt know about CLA ,i am noob if thats what you wanna hear NFE :( Commented Feb 22, 2014 at 17:33

1 Answer 1

2

It seems like you are not passing any command-line arguments while running the program.

When an application is launched, the runtime system passes the command-line arguments to the application's main method via an array of Strings.

Example: User should enter

java NameOfFile arg1 arg2 arg3
Sign up to request clarification or add additional context in comments.

4 Comments

Could you tell me what happens when synchronized (System.out) is executed.synchronized is used for synchronizing a thread ,how System.out is a thread?
Not an expert in that field. Try to do some research and if you can't figure it out, post it in StackOverflow as a different question. Feel free to accept this answer if it was useful and solved your problem: How does accepting an answer work
i am not allowed to ask more questions for 24 hours :(
Try to do some research an read this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.