Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
Doubt:Sequence of the output
mansi gupte
Ranch Hand
Posts: 72
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import java.io.*; class writer { public static void main(String args[]) { try { boolean newfile = false; File file = new File("abc.txt"); System.out.println(file.exists()); newfile = file.createNewFile(); System.out.println(newfile); System.out.println(file.exists()); } catch(IOException e) { } }}
answer: false
true
true
how do we arrive at this answer shouldn't it be
false
false
true
according to the sequence in which the print statements are written?
Swastik Dey
Bartender
Posts: 2270
20
I like...
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import java.io.*; class writer { public static void main(String args[]) { try { boolean newfile = false; File file = new File("abc.txt"); //File may not exist so false System.out.println(file.exists()); newfile = file.createNewFile(); //New file is created now so true System.out.println(newfile); //the following line has to be true System.out.println(file.exists()); } catch(IOException e) { } }}
Swastik
mansi gupte
Ranch Hand
Posts: 72
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
newfile = file.createNewFile(); //New file is created now so true System.out.println(newfile);
i understand this, but doesn't it print the value assigned to newfile , like a good compiler?? or is it that it resolves to a boolean expression?
mansi gupte
Ranch Hand
Posts: 72
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
ok.... the print statement actually does resolve into a boolean expression
and the question for the 2nd answer is -> did the createNewFile method create a new file?
Swastik Dey
Bartender
Posts: 2270
20
I like...
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Yes it does, see the api declaration
http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html#createNewFile(
)
Swastik
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Files
Writing a FileOutputStream into a File
file Deletion
Creating files using Class file
[solved]what the syntax for "if file not exists"?
More...