Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in enhanced for loop

 
Prasanna RamKumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • 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
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
yes iam compiling wiht the version of 1.5 only
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • 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
  • 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: 2409
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
iam compiling at command prompt
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
java -version
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
that is not showing any information regarding version
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should get something like this.

 
Prasanna RamKumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
iam compiling at command prompt
 
Prasanna RamKumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • 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: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this and see if it works.

 
Prasanna RamKumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • 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
--------------------------------
 
Lalitha Gottumukkula
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • 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: 2409
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
can anyone give the solution for this problem
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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.
 
Henry Wong
author
Marshal
Pie
Posts: 21385
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Abdul Rehman
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic