• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

problem in enhanced for loop

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried to compile the program
but it is showing errors
should i use any commands to enable the feautures
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not getting any compile-time error.

Are you sure you are compiling with at least version 1.5?

The enhanced for loop was not added until version 1.5.
 
Prasanna RamKumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes iam compiling wiht the version of 1.5 only
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you double-check that with javac -version?

What is the compile-time error that is reported?
 
Prasanna RamKumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it is showing the version as java version 1.5.0 _06

the complie time errors generated are

; expected

and illegal start of expression
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you compiling at the command line or in Eclipse?
 
Prasanna RamKumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
iam compiling at command prompt
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you got the version, did you type javac -version or java -version?
 
Prasanna RamKumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java -version
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That tells you the version of the runtime environment.

You need to type javac -version to find the version of the compiler you are using.

You will get a list of the options for javac when you type it, but at the top of the list, it will tell you the version of javac.
[ November 28, 2006: Message edited by: Keith Lynn ]
 
Prasanna RamKumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that is not showing any information regarding version
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should get something like this.

 
Prasanna RamKumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
iam compiling at command prompt
 
Prasanna RamKumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C:>javac -version
invalid flag : -version
Usuage :javac <options> <source files>
where possible options include:
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this and see if it works.

 
Prasanna RamKumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no still it doesnot work
it was showing the previous error
; expected
illegal start of expression
i think this was not the solution for the problem
--------------------------------
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please post the complete error stack?
Also, what is there in your classpath and path variables?

-Lalitha
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only thing I can think of is that you may have some small typo between the source file you are compiling and the one that you posted.

As I said, I copied what you posted and was able to compile it and interpret it, and there weren't any compile-time or run-time errors.
 
Prasanna RamKumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have made the initial settings correctly
i have set the JAVA_HOME
and path in environment variables
the code i have pasted is what i have compiled


even i have checked the version
it is showing as 1.5.0_06
 
Prasanna RamKumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can anyone give the solution for this problem
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Prasanna, this is what I get:


That's with your cut and pasted code.
So you must have a problem with your jdk installation. I think, like Keith, you are not actually using the Java 5.0 compiler.
[ November 29, 2006: Message edited by: Barry Gaunt ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Prasanna, please try to compile this:


If it compiles you are using the Java 5.0 compiler, otherwise 1.4 or earlier.
 
Prasanna RamKumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
iam getting compilation error and moreover
when i typed the javac -version it is showing invalid flag
but for java -version it is showing
1.5.0_06
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then you are indeed not running the correct compiler.
What do you get when you type "echo %PATH%" (without quotes).
Please cut and paste the output here.
 
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Versions of javac prior to Java 5 actually didn't support the -version flag, so if the flag is invalid, then the version is prior to Java 5. You can also try....

javac -J-version

Henry
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Prasanna, if you tell us what your PATH variable (echo %PATH%) is set to, then we can probably tell you how to fix this problem.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Henry Wong:
Versions of javac prior to Java 5 actually didn't support the -version flag, so if the flag is invalid, then the version is prior to Java 5.


This is the root of the problem. You are not using JDK (compiler) 5.0.

Regards,
Abdul Rehman.
 
get schwifty. tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic