-3

I am very new to Java and I am trying to reproduce the functionality of a c program. In the command line which starts the program there is an option to specify an output file. In c, I initialised a pointer to char as a Null pointer and then set this to point to the required output file if the option appeared on the command line.

If my understanding of Java is correct, this approach is impossible and the only option I can see is to initalise a boolean variable to false and then set it to true if an output file is specified.

Have I got this right? Thanks.

Thank you Henry for that clear answer. I will go away and think.

I have been programming for more than 40 years in a variety of languages but I find java extremely obscure, and the learning curve is very steep.

user3195694
  • 33
  • 1
  • 3
  • 2
    A String variable can have the value null: _String s = null;_ This can be stested as well: _if (s == null) ..._ – schmop May 22 '14 at 10:50
  • This question shows no effort. Have you tried googling "_java command line arguments_"? This is basic stuff... and no, there is no need for a boolean. – jahroy May 22 '14 at 10:53

1 Answers1

2

A string in Java is an Object and a variable of type String holds a reference to such an object. It can therefore also have the value null meaning it does not point to an object.

Henry
  • 42,982
  • 7
  • 68
  • 84