File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes problem in enhanced for loop 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 "problem in enhanced for loop" Watch "problem in enhanced for loop" New topic
Author

problem in enhanced for loop

Prasanna RamKumar
Ranch Hand

Joined: Nov 30, 2005
Posts: 31
i tried to compile the program
but it is showing errors
should i use any commands to enable the feautures
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
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

Joined: Nov 30, 2005
Posts: 31
yes iam compiling wiht the version of 1.5 only
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Can you double-check that with javac -version?

What is the compile-time error that is reported?
Prasanna RamKumar
Ranch Hand

Joined: Nov 30, 2005
Posts: 31
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

Joined: Feb 07, 2005
Posts: 2367
Are you compiling at the command line or in Eclipse?
Prasanna RamKumar
Ranch Hand

Joined: Nov 30, 2005
Posts: 31
iam compiling at command prompt
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
When you got the version, did you type javac -version or java -version?
Prasanna RamKumar
Ranch Hand

Joined: Nov 30, 2005
Posts: 31
java -version
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
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

Joined: Nov 30, 2005
Posts: 31
that is not showing any information regarding version
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
You should get something like this.

Prasanna RamKumar
Ranch Hand

Joined: Nov 30, 2005
Posts: 31
iam compiling at command prompt
Prasanna RamKumar
Ranch Hand

Joined: Nov 30, 2005
Posts: 31
C:>javac -version
invalid flag : -version
Usuage :javac <options> <source files>
where possible options include:
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Try this and see if it works.

Prasanna RamKumar
Ranch Hand

Joined: Nov 30, 2005
Posts: 31
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

Joined: May 24, 2005
Posts: 45
Can you please post the complete error stack?
Also, what is there in your classpath and path variables?

-Lalitha
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
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

Joined: Nov 30, 2005
Posts: 31
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

Joined: Nov 30, 2005
Posts: 31
can anyone give the solution for this problem
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
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 ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
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

Joined: Nov 30, 2005
Posts: 31
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

Joined: Aug 03, 2002
Posts: 7729
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
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
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

Joined: Nov 07, 2006
Posts: 65
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.


SCJP 5.0 (100%)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in enhanced for loop
 
Similar Threads
Fibonacci Algorithms and their different manifestations. Which is the best?
creating abstract classes within an interface in java
Recursion of Fibonacci Numbers
power () and cube()
Problems calculating 2^n with For loop