wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes the famous ; error revisited Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "the famous ; error revisited" Watch "the famous ; error revisited" New topic
Author

the famous ; error revisited

Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391

E Compilation fails because of an error on line 8
F Compilation fails because of an error on a line other than 3,4 or 8
The answer is F.
In my opinion there is nothing wrong with line 7. There is an error on line 8. The problem is the �S�.
Doug Dunn
Author
Ranch Hand

Joined: Aug 03, 2003
Posts: 66
I can't tell if you are kidding Marlene, but the anonymous class is a variable initializer and must end with a semicolon. It is very common to see }; together when a field is initialized with a class instance creation expression for an anonymous class


Download a copy of <a href="http://www.javarules.com" target="_blank" rel="nofollow"><i>"Mastering The Fundamentals of The Java Programming Language"</i></a>
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

Read this
http://java.sun.com/docs/books/tutorial/java/javaOO/innerclasses.html


Groovy
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
There is nothing wrong with this }<CR><LF>
It is the end of the body of the anonymous class, although it is not the end of the statement. The JLS does not say the ; must be on the same line as the }
This is valid };<CR><LF>System
This is also valid }<CR><LF>;System
This is not valid }<CR><LF>System
The parser gets to the S but needs a ; The identifer System is the error. It is the wrong token. Therefore, the error occurs on line 8.
[ October 24, 2003: Message edited by: Marlene Miller ]
Doug Dunn
Author
Ranch Hand

Joined: Aug 03, 2003
Posts: 66
Marlene! Are picking apart Gafter's compiler because you don't like the line he chooses to say is missing the semicolon!? That's bizarre. I think he is doing you a favor saying that it is missing on line seven because that is where most people would code it. STOP THE PRESS...
Okay I couldn't believe that was your objection, and just went back and carefully reread your post. I see now it is the exam question you are objecting to. Yes, IT IS COMPLETELY ARBITRARY TO SAY THAT THE ERROR OCCURS ON LINE SEVEN BECAUSE JAVA IS A FREE FORMAT LANGUAGE. It is merely a matter of perspective and is equally valid to say (as you do) that the error occurs on line 8 when the next token arrives at the compiler and it becomes evident that the semicolon is missing.
The problem here is that the test exam writer is taking javac compiler errors as gospel, and that is a very dangerous thing to do. The JLS specifies compiler errors, not compiler error messages. Neil Gafter writes the javac compiler and has done a wonderful job making compiler error messages as helpful as possible. But in so doing, he introduces a measure of art. If the Sun test exam people do not understand this then they are indeed doing all of us a great disservice. I think you have hit the nail on the head with this example, Marlene. By the way, I was contacted by that Sun text exam manager and insisted she review your posts. I am going to make sure she sees this one by sending her the URL and saying that it is the quintessential example of what is gong wrong. On behalf of the millions of test exam takers around the world, HATS OFF TO MARLENE FOR STICKING TO HER GUNS. I feel confident in saying that Evelyn Cartagena will follow through on this, and not just this one example, but any notion the Neil's error messages are gospel in terms of what line an error occurs on.
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Doug, It�s so nice to be understood!
I have spent much time carefully studying the JLS and The Java Programming Language to understand the language, not caring what the exam wants. But now it is time for me to be sure I can understand and give correct answers for the exam. When the Sun ePractice exams and some prestigious mock exams ask for line numbers of errors, that means I have to know line numbers. So let�s get the Right line number.
It is a strange one, isn't it? I thought it was interesting.
I don�t doubt or deny that the compiler writer made the best choice for the error message.
I thank you for your time, Doug.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Thank you very much to you also Marlene.


SCJP2. Please Indent your code using UBB Code
Neal Gafter
javac author
Greenhorn

Joined: Oct 25, 2003
Posts: 12
Speaking of javac (my baby), here's what it has to say about this program:
Test.java:8: ';' expected
System.out.println(obj);
^
If the folks who wrote this exam question believe javac is wrong, they haven't bothered to submit a bug report yet.
jikes reports the error on lines 3 through 7 (incomplete block statement).
-Neal
Neal Gafter
javac author
Greenhorn

Joined: Oct 25, 2003
Posts: 12
Admittedly, the diagnostic did change between 1.4.1 and 1.4.2.
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Thank you Neal. I need to upgrade to 1.4.2.
bengt hammarlund
Ranch Hand

Joined: Oct 17, 2003
Posts: 78
Hi Neal.
First of all is an honor to chat with you here, I really like your compiler and the Java language, especialy now that I'm having Compiler classes in my Computer Science university here in Rio de Janeiro, Brazil.
But I really am curious: do you guys use LEX, YACC ou other tools (with?) to help build the J2SE javac compiler, or you do all that context-free-language stuff yourselfs?
I am writing a simple compiler using LEX & YACC on top of Conectiva Linux 9, and even with these tools it's a hell of a pain make a really SIMPLE compiler!
Any reply from you would make me happy! =]
PS.: even more off topic: do you guys know Brazil yet? =]
[ October 26, 2003: Message edited by: bengt hammarlund ]

<b><i>Bengt Hammarlund</i><br />� Sun Certified Java Programmer</b>
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8803
    
    5
Here I am, falling on my sword (again :roll: ), Marlene was generous enough to not mention the wayward author of this mock exam question (me). I agree that the question is incorrect - I also believe that the folks at Sun who wrote the REAL exam were more careful than I was, and I don't believe that you'll find the same error on the real exam.
The errata has been noted and the fix will be published soon!
-Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Hi Bert. It seems to me that Marlene has been getting rather nit-picky and fussy about the smallest things these days, don't you think. I guess she is warming up for the real exam and just doesn't let a single semicolon slip by. I think she is driving everyone else nuts.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by Marlene Miller:
Hi Bert. It seems to me that Marlene has been getting rather nit-picky and fussy about the smallest things these days, don't you think. I guess she is warming up for the real exam and just doesn't let a single semicolon slip by. I think she is driving everyone else nuts.

Marlene, I think you should be the technical editor for Doug's book.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Doug Dunn
Author
Ranch Hand

Joined: Aug 03, 2003
Posts: 66
Doug thinks so, too.

Meanwhile, I feel aweful that I assumed this was Sun exam question. I owe Sun Microsystems, Neal Gafter (who I misled into thinking this was a Sun exam question), and especially Evelyn Cartagena an apology.
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Doug, when you implicated Sun, I let that one slip by, because there was that other post of mine about the errors and line numbers and abstract methods. It all balances out in the end.
And I recently posted a flurry of suspect bugs or controversial issues in the Sun practice exams about the same time you appeared on the scene. So it was clearly an innocent deduction.
[ October 27, 2003: Message edited by: Marlene Miller ]
Neal Gafter
javac author
Greenhorn

Joined: Oct 25, 2003
Posts: 12
> But I really am curious: do you guys use LEX, YACC ou other tools (with?) to
> help build the J2SE javac compiler, or you do all that context-free-language
> stuff yourselfs?
We don't need no stinking tools!
See for yourself at
http://developer.java.sun.com/developer/earlyAccess/adding_generics/
-Neal
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by Doug Dunn:
Meanwhile, I feel awful that I assumed this was Sun exam question.
Doug, just to clarify... all Sun actual exam questions are copyrighted so you will never see an actual Sun exam question on JavaRanch. If anyone posts an actual test question it will be immediately deleted!
 
wood burning stoves
 
subject: the famous ; error revisited
 
Similar Threads
Clarification for 1 question from K and B book - Chapter 8 - Inner classes.
K&B SCJP 5: Chapter 8, Self Test 9, wrong answer?
Question in K&B Chapter 8
Inner Classes
K&B CHAPTER:8 q.no:9.........