• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java :The Complete Reference (Herb Schildt) p 542  RSS feed

 
Mahadeva Sarma
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

On this page in the source code for an example of Observer interface for a class of Observable type lists a for-loop inside a method. The for-loop is shown thus: for( ; period>=0; period--). This the Netbeans IDE is flagging off as "Illegal start of expression.". Hence the program does not compile. What should be done?

OCA/OCP Java SE7 Programmer I & II study guide on p326 through 328 list various formats for the for loop wherein : for( ; ; ) is an endless loop. The Netbeans IDE passes it as "legal" . Then there is a for( ; i < 10 ; ) with an inside-the-loop iteration expression. But this usage aslo is flagged as "Illegal".

I have Emailed a query to the author Herb Schildt, but in all likelihood this may not be answered in the near future. But I am working all by myself for certification. Please help.

Thanks in advance.
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Could you post more of the code, or all of it if it's not too long? Especially the line before the for loop. And remember to UseCodeTags (←click).
 
Mahadeva Sarma
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code has since worked! Now, what did I do? First I modified the for-loop statement to for( ; ; ) from what was given, but I was hesitating to run the program for that would be an infinite loop-anyway it wouldn't have mattered for I was working inside the IDE with the safety of an "abort" button. After once modifying this way I re entered the same i.e for( ; period>=0; period--) and surprised to see that the NDE didn't flag it off as "illegal start of expression". Gingerly I came to the end of the source file chose Run File. The program ran without problems and produced the output given in the book.

Could we call it as a case of RESET WIND-UP as in Instrumentation Controllers?

Anyway, I thank you very much for the Immediate Attention given to my query. Thanks a ton! Today morning one more such situation but that was due to an entry error the program was running without an end esp one which was executed at the Command Line. Tried all the usual keys for aborting it. But what worked was simply closing the command window(DOS-mode) and reopening it!!
Well on my way to getting ready for certification!
 
Ashwin Rao
Ranch Hand
Posts: 89
C++ Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest you not to use an IDE until you're well versed with the Java language. Please read this.
 
Mahadeva Sarma
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ashwin,

You are right.I agree with you and HFJ K&B also strongly advises against the use of an IDE. And rightly so. I have since been extensively using the Command Line and the npp editor. This gives a lot of practice and convenience, while preparing source file(I mean the npp editor). But initially I had started with Netbeans IDE and had done quite a lot of my learning in that env. The advantage is you are helped by the IDE's features, avoiding some elementary pitfalls. Now, having gained quiet confidence I am already on Command Line. Thank you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!