This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Java Questions... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Questions..." Watch "Java Questions..." New topic
Author

Java Questions...

john leeman
Greenhorn

Joined: Jun 02, 2005
Posts: 10
I am preparing for my test for tomorrrow, but I can't seem to find answers to these questions, please help.

Textfiles - close operations() what can go wrong without them?

Any variable declared in a loop. Can it be accessed only inside of the loop? or outside as well? the scope of it.

If a loop terminates, what will display?




Thanks in advance.
Philip Heller
author
Ranch Hand

Joined: Oct 24, 2000
Posts: 119
An open file consumes system resources. I'm not sure if it's a similar story in Windows, but in UNIX there's a system thingy called a file descriptor. You only get a limited number of them. When you close an open file, the file descriptor is released and becomes available to other code that wants to open a different file.

A variable declared in a scope may only be used in that scope. Scopes are easy to spot: they begin with { and run to the corresponding }. A loop body is one kind of scope.

What do you mean by "if a loop terminates, what will display?" Do you mean command line output? Nothing displays on the command line except uncaught exception info and text that you deliberately program to be output. So unless you have some kind of System.out.println at the end of your loop, nothing will display, because termination of a loop isn't an exception condition.


Consultant to SCJP team.<br />Co-designer of SCJD exam.<br />Co-author of "Complete Java 2 Certification Study Guide".<br />Author of "Ground-Up Java".
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11448
    
  16

Scopes are easy to spot: they begin with { and run to the corresponding }


i would add one caveat to this... a variable declared inside the initialization part of a for statement is available only within the for's block...

i.e.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Hentay Duke
Ranch Hand

Joined: Oct 27, 2004
Posts: 198
"I am preparing for my test for tomorrrow, but I can't seem to find answers to these questions, please help."

What test? The SCJP exam?

"Textfiles - close operations() what can go wrong without them?"

They can throw an I/O Exception I believe. Is that what you mean?

"Any variable declared in a loop. Can it be accessed only inside of the loop? or outside as well? the scope of it."

Variable declared inside a loop is only available inside the loop.


"If a loop terminates, what will display?"

Not sure what you mean here.
 
Don't get me started about those stupid light bulbs.
 
subject: Java Questions...