Results 1 to 17 of 17

Thread: formatting..

  1. #1
    sireesha is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Question formatting..

    i saw this code in a book.
    Java Code:
    import java.util.*;
    public class test4
    {
    public static void main(String args[])
     {
    Calendar c=Calendar.getInstance();
    System.out.format("%tB %td,%tY%n",c,c,c);
    System.out.format("%tl:%tM %tp%n",c,c,c);
    System.out.format("%tD%n",c);
     }
    }
    but when i compile this i got some errors.
    like..
    Java Code:
    test4.java:12: cannot resolve symbol
    symbol  : method format (java.lang.String,java.util.Calendar,java.util.Calendar,
    java.util.Calendar)
    location: class java.io.PrintStream
    System.out.format("%tB %td,%tY%n",c,c,c);
              ^
    test4.java:13: cannot resolve symbol
    symbol  : method format (java.lang.String,java.util.Calendar,java.util.Calendar,
    java.util.Calendar)
    location: class java.io.PrintStream
    System.out.format("%tl:%tM %tp%n",c,c,c);
              ^
    test4.java:14: cannot resolve symbol
    symbol  : method format (java.lang.String,java.util.Calendar)
    location: class java.io.PrintStream
    System.out.format("%tD%n",c);
              ^
    3 errors
    what is wrong with this code ?
    is it necessary to import any other packages ?
    please tell me....

  2. #2
    dmacvittie is offline Member
    Join Date
    Aug 2007
    Posts
    30
    Rep Power
    0

    Default

    Hello sireesha,

    You are probably using an older version of Java. Format is a relatively recent addition to PrintStream. (meaning a recent addition to System.out)

    Don.
    Don MacVittie F5 Networks - DevCentral

  3. #3
    sireesha is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Default

    Hi,
    I installed jdk6 in my pc.
    am i using correct version ?
    what i have to install ?
    please tell me.

  4. #4
    rajiv_bang is offline Member
    Join Date
    Nov 2007
    Posts
    11
    Rep Power
    0

    Default

    Hi Sireesha,

    System.out.format was introduced in J2SE 5.0. If you have a jdk later than that, it should work.

    If you are facing problems, try replacing the format with printf. For most practical purposes System.out.format and System.out.printf are the same.

    HTH
    Rajiv

  5. #5
    staykovmarin is offline Senior Member
    Join Date
    Nov 2007
    Location
    Newport, WA
    Posts
    141
    Rep Power
    0

    Default

    Are you sure that you are using java 6? Meaning do you have the right java folder in your PATH?
    Do:
    Java Code:
    java -version
    It tells you the version that you are running.

  6. #6
    sireesha is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Default

    I tried it.Result is
    Java Code:
    E:\WINDOWS\java>java -version
    java version "1.6.0_03"
    Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
    Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode)
    now what i have to do.
    is this the correct version ?

  7. #7
    sireesha is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Default please give me advise

    please see previous posts in this thread..give me advise..
    thankq verymuch

  8. #8
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    sireesha, since you are having problems compiling, post the output of
    Java Code:
    javac -version
    which is different from above. java is the command for running the application while javac is used for compiling your classes. By default, some systems (like my Ubuntu system), contains symlinks to the 1.4 version for the javac command, which obviously can present problems. If this is the case for you, you would simply need to make the link for the javac command to your more updated jvm, in your case 1.6.

  9. #9
    sireesha is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Default

    hi
    i tried javac -version
    but the output is
    javac: invalid flag: -version

    now what i have to do ?
    please tell me,
    thankq

  10. #10
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    Java Code:
    C:\>javac -version
    javac 1.6.0_02
    
    C:\>
    Strange .. !!
    dont worry newbie, we got you covered.

  11. #11
    Schmidty is offline Member
    Join Date
    Jan 2008
    Posts
    1
    Rep Power
    0

    Default Javac link bad in Ubuntu Linux

    All Ubuntu users who upgrade to Java 6 need to check their javac compiler link as it is still pointing to the Java 1.4 if they didn't install the Java source. I noticed this when I did a check on my system and was having a problem compiling a 'System.out.format()' and couldn't figure out why I was getting the following error;

    Format.java:33: cannot resolve symbol
    symbol : method format (java.lang.String,java.util.Calendar)
    location: class java.io.PrintStream
    System.out.format("Local time: %tT", Calendar.getInstance());

    Check your links in Ubuntu;

    schmidty@laptop:~/java_work$ ls -alh /etc/alternatives/javac
    lrwxrwxrwx 1 root root 27 2007-12-20 18:17 /etc/alternatives/javac -> /usr/lib/j2se/1.4/bin/javac
    schmidty@laptop:~/java_work$ ls -alh /etc/alternatives/java
    lrwxrwxrwx 1 root root 36 2007-12-20 18:22 /etc/alternatives/java -> /usr/lib/jvm/java-6-sun/jre/bin/java
    schmidty@laptop:~/java_work$ ls -alh /etc/alternatives/javac
    lrwxrwxrwx 1 root root 33 2008-01-06 22:42 /etc/alternatives/javac -> /usr/lib/jvm/java-6-sun/bin/javac
    schmidty@laptop:~/java_work$ ls -alh /etc/alternatives/java
    lrwxrwxrwx 1 root root 36 2007-12-20 18:22 /etc/alternatives/java -> /usr/lib/jvm/java-6-sun/jre/bin/java

    Again, the solution would be to install the source for Java6 in Ubuntu.

    Schmidty

  12. #12
    kirbygao is offline Member
    Join Date
    Jun 2009
    Posts
    1
    Rep Power
    0

    Default maybe you have installed some old version of Java

    I met the same question this afternoon. After I remove the older version of Java(1.4) in my computer, the program with System.out.format(..) can run.

  13. #13
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    832
    Rep Power
    6

    Default

    Hi Sireesha
    Try with java -version not javac
    Ramya:cool:

  14. #14
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Default

    You can also use the command "java -fullversion" and produce output such as:

    java full version "1.6.0_03-b05"
    We Learn Through Mistakes..,
    Manfizy:rolleyes:

  15. #15
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    zombie alert!!
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  16. #16
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    Zombie alert!!
    hmmm... why do I need mod approval when posting this??
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  17. #17
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

Similar Threads

  1. Formatting a number to currency
    By Java Tip in forum java.text
    Replies: 0
    Last Post: 04-16-2008, 10:59 PM
  2. Data formatting for the <display:table>
    By yuchuang in forum Web Frameworks
    Replies: 3
    Last Post: 12-14-2007, 10:52 AM
  3. formatting String
    By bugger in forum New To Java
    Replies: 1
    Last Post: 11-16-2007, 07:27 PM
  4. Correct Number formatting
    By paul in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 04:59 AM
  5. Formatting the date
    By yuchuang in forum New To Java
    Replies: 5
    Last Post: 05-07-2007, 06:08 PM

Posting Permissions

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