aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Rules Round Up - Doubt - Errada? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Rules Round Up - Doubt - Errada?" Watch "Rules Round Up - Doubt - Errada?" New topic
Author

Rules Round Up - Doubt - Errada?

raja kanak
Ranch Hand

Joined: Oct 18, 2006
Posts: 135
Please check question number #154, it says
(#154) Assuming all variables are declared and initialized properly, will this compile?
for(i=1;k<5;j++){};
Options:
yes
No

I select "No" because of the semicolon at the end. But the applet says the answer is "Yes".

I guess that semicolon should be removed from the question. Am i right?


live
Sampath Satha
Greenhorn

Joined: Feb 19, 2007
Posts: 2
where java ends!
Sampath Satha
Greenhorn

Joined: Feb 19, 2007
Posts: 2
semicolon endsline after the empty braces
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18138
    
  39

Assuming all variables are declared and initialized properly, will this compile?


Well, if you put this line of code, along with all variables, declared and initialized properly, does it compile?

It takes less than a minute to actually try it out.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
raja kanak
Ranch Hand

Joined: Oct 18, 2006
Posts: 135
Originally posted by Henry Wong:


Well, if you put this line of code, along with all variables, declared and initialized properly, does it compile?

It takes less than a minute to actually try it out.

Henry


This is called communication gap :roll:
I want to mention the typo in Rules Roundup. thats it.
With semicolon - error
Without semicolon - no problem.
Once again I want to mention the typo in Rules Roundup. thats it
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
But I don't think it is a typo. One of the points of the question is that it's possible to have an extra ';' in code, and it doesn't cause any error. In this case it doesn't create any problem at all - it's just an empty statement, legal just about anywhere.


"I'm not back." - Bill Harding, Twister
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18138
    
  39

Originally posted by raja kanak:

This is called communication gap :roll:
I want to mention the typo in Rules Roundup. thats it.
With semicolon - error
Without semicolon - no problem.
Once again I want to mention the typo in Rules Roundup. thats it


This code will compile with (or without) the semicolon.

Why do you think that the semicolon will cause an error?

Henry
raja kanak
Ranch Hand

Joined: Oct 18, 2006
Posts: 135

This code will compile with (or without) the semicolon.

Why do you think that the semicolon will cause an error?

Sorry for my mistake. You are right. The code compiles with (or without) semicolon.

But in case of enum it is mentioned about semicolon. I don't find any mention about semicolon regarding if statement in K&B book. That's why I confused.
Javier Sanchez Cerrillo
Ranch Hand

Joined: Aug 02, 2006
Posts: 152
Hey raja kanak


Will this compile:?

public class Javier {
public static void main(String[] args) {
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
System.out.println("Hello World");;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;
}

}

I think you should better try the code by yourself before posting or reporting errata.


SCJP 5.0 95%<br /> <br />The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge.
raja kanak
Ranch Hand

Joined: Oct 18, 2006
Posts: 135


I really feel shy. I am very sorry. I will definitely take extra care before posting any thing in future.

The code you mentioned compiled. that is terrific.

Anybody please conclude this topic by giving the clear rules regarding semicolon.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Rules Round Up - Doubt - Errada?
 
Similar Threads
format question
Doubt in K&B SCJP 5: topic enum declaration
Java Round-Up game
Updated servlets assignment page
path