Results 1 to 17 of 17
Thread: formatting..
- 12-10-2007, 10:27 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 50
- Rep Power
- 0
formatting..
i saw this code in a book.
but when i compile this i got some errors.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); } }
like..
what is wrong with this code ?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
is it necessary to import any other packages ?
please tell me....
- 12-10-2007, 10:57 PM #2
Member
- Join Date
- Aug 2007
- Posts
- 30
- Rep Power
- 0
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
- 12-11-2007, 01:41 AM #3
Member
- Join Date
- Nov 2007
- Posts
- 50
- Rep Power
- 0
Hi,
I installed jdk6 in my pc.
am i using correct version ?
what i have to install ?
please tell me.
- 12-11-2007, 02:19 AM #4
Member
- Join Date
- Nov 2007
- Posts
- 11
- Rep Power
- 0
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
- 12-11-2007, 02:42 AM #5
Senior Member
- Join Date
- Nov 2007
- Location
- Newport, WA
- Posts
- 141
- Rep Power
- 0
Are you sure that you are using java 6? Meaning do you have the right java folder in your PATH?
Do:
It tells you the version that you are running.Java Code:java -version
- 12-11-2007, 05:56 PM #6
Member
- Join Date
- Nov 2007
- Posts
- 50
- Rep Power
- 0
I tried it.Result is
now what i have to do.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)
is this the correct version ?
- 12-13-2007, 06:35 PM #7
Member
- Join Date
- Nov 2007
- Posts
- 50
- Rep Power
- 0
please give me advise
please see previous posts in this thread..give me advise..
thankq verymuch
- 12-31-2007, 04:41 AM #8
sireesha, since you are having problems compiling, post the output of
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.Java Code:javac -version
- 01-04-2008, 11:43 PM #9
Member
- Join Date
- Nov 2007
- Posts
- 50
- Rep Power
- 0
hi
i tried javac -version
but the output is
javac: invalid flag: -version
now what i have to do ?
please tell me,
thankq
- 01-04-2008, 11:45 PM #10
Strange .. !!Java Code:C:\>javac -version javac 1.6.0_02 C:\>
dont worry newbie, we got you covered.
- 01-07-2008, 07:51 AM #11
Member
- Join Date
- Jan 2008
- Posts
- 1
- Rep Power
- 0
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
- 06-26-2009, 10:10 AM #12
Member
- Join Date
- Jun 2009
- Posts
- 1
- Rep Power
- 0
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.
- 06-26-2009, 11:01 AM #13
Hi Sireesha
Try with java -version not javacRamya:cool:
- 06-26-2009, 11:17 AM #14
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:
- 06-26-2009, 05:39 PM #15
- 06-26-2009, 05:41 PM #16
Zombie alert!!
hmmm... why do I need mod approval when posting this??USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 06-26-2009, 07:11 PM #17
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
Similar Threads
-
Formatting a number to currency
By Java Tip in forum java.textReplies: 0Last Post: 04-16-2008, 10:59 PM -
Data formatting for the <display:table>
By yuchuang in forum Web FrameworksReplies: 3Last Post: 12-14-2007, 10:52 AM -
formatting String
By bugger in forum New To JavaReplies: 1Last Post: 11-16-2007, 07:27 PM -
Correct Number formatting
By paul in forum New To JavaReplies: 1Last Post: 08-07-2007, 04:59 AM -
Formatting the date
By yuchuang in forum New To JavaReplies: 5Last Post: 05-07-2007, 06:08 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks