Core Java Interview Questions and Answers
Prepare for your Interview today!
1 | FileOutputStream(File file) This creates a file output stream to write to the file represented by the specified File object. |
2 | FileOutputStream(File file, boolean append) This creates a file output stream to write to the file represented by the specified File object. |
3 | FileOutputStream(FileDescriptor fdObj) This creates an output file stream to write to the specified file descriptor, which represents an existing connection to an actual file in the file system. |
4 | FileOutputStream(String name) This creates an output file stream to write to the file with the specified name. |
5 | FileOutputStream(String name, boolean append) This creates an output file stream to write to the file with the specified name. |
file = new File("c:/newfile.txt"); fop = new FileOutputStream(file); if (!file.exists()) { file.createNewFile(); } // get the content in bytes byte[] contentInBytes = content.getBytes(); fop.write(contentInBytes); fop.flush(); fop.close();
A static method can be synchronized. If you do so, the JVM will obtain a lock on the java.lang. Class instance associated with the object. It is similar to saying:
synchronized(XYZ.class) { }
Yes, the JVM maintains a cache by itself. It creates the Objects on the HEAP, but references to those objects are on the STACK.
Most helpful rated by users: