I looked on the java docs for FileOutputStream http://docs.oracle.com/javase/7/docs/api/java/io/FileOutputStream.html#FileOutputStream(java.io.File) and saw that one constructor took just a file object and another one took a file object and a boolean append. Will the first constructor just call the second constructor with false passed as append? Java docs didn't talk about this
-
1Does it matter? Whether it calls the other constructor or not, the effects are the same. – user2357112 Jul 25 '14 at 04:44
-
The java source is available and one can always view to understand the underlying implementation. – Khanna111 Jul 25 '14 at 04:45
-
what you want to achieve? – Braj Jul 25 '14 at 04:45
-
Curiosity, just want to see how the constructors are implemented – committedandroider Jul 25 '14 at 04:46
-
Here is [source code](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/io/FileOutputStream.java#FileOutputStream.%3Cinit%3E%28java.io.File%2Cboolean%29) it calls two argument constructor with `false` as second value. – Braj Jul 25 '14 at 04:47
3 Answers
Yes, (the Oracle JDK) FileOutputStream
makes use of constructor chaining. This is simply an implementation detail and you should not rely on it unless referred to in the API specification (javadoc).
Here's the OpenJDK JDK implementation which also chains constructor calls.

- 274,122
- 60
- 696
- 724
-
It is not correct to talk about Oracle's JDK and OpenJDK's JDK. They are developed by the same (Oracle) team; see http://stackoverflow.com/a/22358234/139985. The copyright for "OpenJDK's JDK" is owned by Oracle. – Stephen C Jul 25 '14 at 04:55
-
1@StephenC Sure, but aren't they two different implementations even if they are owned by the same team? How would I refer to the Java JDK you get [here](http://www.oracle.com/technetwork/java/javase/downloads/index.html)? – Sotirios Delimanolis Jul 25 '14 at 04:57
-
1) Well yes and no. In fact, they are almost identical. 2) I would refer to them as the "The Oracle JDK" or "The Hotspot JDK" versus "The OpenJDK JDK". (Or Hotspot versus OpenJDK.) Note - no use of the possessive. – Stephen C Jul 25 '14 at 05:36
Following happens if you use constructor without boolean.
FileOutputStream(File file) throws FileNotFoundException {
this(file, false);
}
Normally in these kind of scenarios values true or false are decided based on most used operation. So if you are writing on OutputStream you will be creating a new file most of the time, hence it passes false
as default.
Cheers !!

- 3,559
- 4
- 24
- 42
yes that's true. The FileOutputStream(File file) invokes FileOutputStream(File file, boolean append) setting append=false. For your reference, the source code looks like
public FileOutputStream(File file) throws FileNotFoundException {
this(file, false);
}
public FileOutputStream(File file, boolean append)
throws FileNotFoundException
{
String name = (file != null ? file.getPath() : null);
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkWrite(name);
}
if (name == null) {
throw new NullPointerException();
}
this.fd = new FileDescriptor();
this.append = append;
fd.incrementAndGetUseCount();
open(name, append);
}
Normally, JavaDoc does not say internal details. It is for the API description only.

- 2,287
- 1
- 23
- 27