Results 1 to 7 of 7
  1. #1
    arefeh is offline Member
    Join Date
    Dec 2009
    Posts
    76
    Rep Power
    0

    Default for-each loop in jdk1.2

    Hello

    i write this code for "for-each" loop for J2SE

    int nums[]={1,2,3,4,5};
    for(int i:nums){System.out.println(i);}

    but i get this error:
    ForEach.java:6: ';' expected.

    why?

    are not there for-each in jdk1.2?

    with thanks

  2. #2
    CodesAway's Avatar
    CodesAway is offline Senior Member
    Join Date
    Sep 2009
    Location
    Texas
    Posts
    238
    Rep Power
    6

    Default

    For each loops were added in J2SE 5.0.
    CodesAway - codesaway.info
    writing tools that make writing code a little easier

  3. #3
    arefeh is offline Member
    Join Date
    Dec 2009
    Posts
    76
    Rep Power
    0

    Default

    thank you:)

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I'm curious why you're tied to the 1.2 JDK?

  5. #5
    arefeh is offline Member
    Join Date
    Dec 2009
    Posts
    76
    Rep Power
    0

    Default

    I am very young in java. I Endeavor to know java more,Therefore i have defect in this way,but i try to underestand more.
    thanks

  6. #6
    CodesAway's Avatar
    CodesAway is offline Senior Member
    Join Date
    Sep 2009
    Location
    Texas
    Posts
    238
    Rep Power
    6

    Default

    Even if you are new in Java, I would recommend using Java 6, the latest version.

    Java 5 introduced several additions that not only make the code more usable, but also changed the way people write code. With the introduction of generics, for-each loops, and autoboxing, among other new features, Java is a vastly different programming language.

    Additionally, Java 5, as well as Java 6, introduced several new classes and has since made some older ones fade away.

    Since you are a new programmer, there is no reason for you to check out Java 7, but Java 7 will introduce several new features as well.


    In summary, if you were to use an old version, you would always be playing catch-up on the current programming practices and design. Not only that, but by using an old version, you are teaching yourself poor programming practices that have since become obsolete. For example, use of generics is a BIG change from pre-Java 5 and post-Java 5. No one writes pre-Java 5 code anymore (unless they have to).
    Last edited by CodesAway; 12-05-2009 at 09:49 PM.
    CodesAway - codesaway.info
    writing tools that make writing code a little easier

  7. #7
    arefeh is offline Member
    Join Date
    Dec 2009
    Posts
    76
    Rep Power
    0

    Default

    I saw your Message
    and i thank you about your Guidance very much.

Similar Threads

  1. Difference between jdk1.5 and jdk1.6
    By pradnya in forum New To Java
    Replies: 10
    Last Post: 12-08-2010, 11:52 AM
  2. How to uninstall jdk1.4 or jdk1.5
    By ran_sushmi in forum Advanced Java
    Replies: 0
    Last Post: 07-20-2009, 12:45 PM
  3. Differnce Between JDK1.5 to JDK1.6
    By kallamrajareddy in forum New To Java
    Replies: 2
    Last Post: 03-12-2009, 07:43 AM
  4. JNLP - Swing application compiled in jdk1.5 not working in jdk1.6
    By mahendra.athneria in forum AWT / Swing
    Replies: 4
    Last Post: 01-20-2009, 08:27 PM
  5. What is JDK1.5?
    By pawankumarom in forum New To Java
    Replies: 2
    Last Post: 09-05-2008, 07:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •