Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Questions...

 
john leeman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12125
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Hentay Duke
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic