• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

the famous ; error revisited

 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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�.
 
Author
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read this
http://java.sun.com/docs/books/tutorial/java/javaOO/innerclasses.html
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much to you also Marlene.
 
javac author
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Admittedly, the diagnostic did change between 1.4.1 and 1.4.2.
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Neal. I need to upgrade to 1.4.2.
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Doug Dunn
Author
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic