I'm learning Java and one of the examples of the book runs perfectly from command line, but throws an error from Eclipse. The script is this:
/**
* This program displays a greeting from the authors.
* @version 1.20 2004-02-28
* @author Cay Horstmann
*/
public class Welcome
{
public static void main(String[] args)
{
String[] greeting = new String[3];
greeting[0] = "Welcome to Core Java";
greeting[1] = "by Cay Horstmann";
greeting[2] = "and Gary Cornell";
for (String g : greeting)
System.out.println(g);
}
}
The error I get in Eclipse is 'Exception in thread "main" java.lang.Error: Unresolved compilation problem: Syntax error, 'for each' statements are only available if source level is 1.5 or greater' The book says I would get an error in that line (the for) if the JDK was too old, but then why does it run well from the command line? Thanks