This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Mock Exam Errata and the fly likes Java Rules Round #154 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Reply Bookmark "Java Rules Round #154" Watch "Java Rules Round #154" New topic
Author

Java Rules Round #154

Win jones
Ranch Hand

Joined: Dec 12, 2004
Posts: 38
Question )
Assuming all variables are declared and initialized properly will the following code compile
for (i = 1; k <5;j++){};

why is there a semi-colon after the last curly brace
because of that the code will not compile
Mukesh Poddar
Greenhorn

Joined: Jan 14, 2005
Posts: 8
As your Question itself says ...all the variables i,j,k are declared and initialized properly.....
The program will run Succesfully.....

Since in Java an ; separates the One statement from the other......

And the Bracket before the "{}" dosen't signify anything it just gives compiler the infiormation that a new block is started....

so te compiler will treate as a null statement.... and compile the program succesfully.....
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 806
just tell me that
whether
;
statement in java program will not cause compiler error ?
just asking...



Thanks and Regards,<br />Amit Taneja
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9033
    
  10
Originally posted by amit taneja:
just tell me that
whether
;
statement in java program will not cause compiler error ?

An extra semicolon after the curly brace will not cause a compiler error.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Rick O'Shay
Ranch Hand

Joined: Sep 19, 2004
Posts: 531
Originally posted by amit taneja:
just tell me that
whether
;
statement in java program will not cause compiler error ?
just asking...



The semicolon designates an empty statement:

// OK
class Foo {
void bar() {}
int x;
}

// OK
class Foo {
void bar() {}
;
}

// OK
class Foo {
void bar() {};
}

// OK
class Foo {
;;;;;;;;;;;void bar(){;;};;;;;;;;;;;;;;;;;;;;
}
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Java Rules Round #154
 
Similar Threads
Return type concept problem
SCJP Brainteaser (12)
Deploying Servlet in Webshere
can we have * as a command line argument
Two methods into one