Community
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DateFormat syntax error

 
Post new topic   Reply to topic    Community Forum Index -> Java
View previous topic :: View next topic  
Author Message
jon80



Joined: 28 May 2009
Posts: 24

PostPosted: Sat Jun 16, 2012 11:48 am    Post subject: DateFormat syntax error Reply with quote

The following code does not compile in TextPad 5.4.2, although similar code compiles within Eclipse.

Code:

import java.text.*;
import java.util.*;
class DateFormatPlay
{
   Calendar c = Calendar.getInstance();
   c.set(2012, 11, 25); //christmas day due to zero based indexed month
   Locale l = new Locale("it", "IT");
   DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
   System.out.println(df.format(c.getTime()));
}


Error
C:\Documents and Settings\Jon\Desktop\DateFormatPlay.java:6: error: <identifier> expected
c.set(2012, 11, 25); //christmas day due to zero based indexed month
^
C:\Documents and Settings\Jon\Desktop\DateFormatPlay.java:6: error: illegal start of type
c.set(2012, 11, 25); //christmas day due to zero based indexed month
^
C:\Documents and Settings\Jon\Desktop\DateFormatPlay.java:6: error: illegal start of type
c.set(2012, 11, 25); //christmas day due to zero based indexed month
^
C:\Documents and Settings\Jon\Desktop\DateFormatPlay.java:6: error: illegal start of type
c.set(2012, 11, 25); //christmas day due to zero based indexed month
^
C:\Documents and Settings\Jon\Desktop\DateFormatPlay.java:9: error: <identifier> expected
System.out.println(df.format(c.getTime()));
^
C:\Documents and Settings\Jon\Desktop\DateFormatPlay.java:9: error: <identifier> expected
System.out.println(df.format(c.getTime()));
^
C:\Documents and Settings\Jon\Desktop\DateFormatPlay.java:9: error: ';' expected
System.out.println(df.format(c.getTime()));
^
C:\Documents and Settings\Jon\Desktop\DateFormatPlay.java:9: error: illegal start of type
System.out.println(df.format(c.getTime()));
^
C:\Documents and Settings\Jon\Desktop\DateFormatPlay.java:9: error: ';' expected
System.out.println(df.format(c.getTime()));
^
9 errors

Tool completed with exit code 1

Usually when I post this as a bug, the technical support team refuses it, for some reason unknown, so I posted the issue here. The code within Eclipse reads as follows:



Code:

package code;
import java.text.*;
import java.util.*;
class DateFormatPlay
{
   public static void main (String[] args)
   {   Calendar c = Calendar.getInstance();
      c.set(2012, 11, 25); //Christmas Day
      Locale l = new Locale("it", "IT");
      DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
      System.out.println(df.format(c.getTime()));
   }
}



Output
25-Dec-2012

Is there a way I can re-write this code in single lines, other than writing a function? Smile
_________________
Jon
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
MudGuard



Joined: 02 Mar 2003
Posts: 1254
Location: Munich, Germany

PostPosted: Sat Jun 16, 2012 12:57 pm    Post subject: Re: DateFormat syntax error Reply with quote

jon80 wrote:

Usually when I post this as a bug, the technical support team refuses it


Does this surprise you? Why should textpad support team fix your programming errors?

Even if it were not your fault, but a fault of the java compiler: the java compiler is no helios product, so why should helios care about bugs in non-helios products?

Java code never compiles in Textpad, simply because Textpad is a text editor, not a compiler. All it does with your (faulty) code is pass it on to the java compiler.


For your Java code:

It is not allowed in Java to put "normal" code in the class without wrapping it in a function.
It is allowed to put member declarations there, together with member initialisation.
That is why the
Calendar c = Calendar.getInstance();
line is ok.

So your first example is simply wrong. It will not compile not regarding which program you use to start the compiler.

The algorithm in your second example is wrapped in a function. This is a very important difference.
Back to top
View user's profile Send private message Visit poster's website
jon80



Joined: 28 May 2009
Posts: 24

PostPosted: Sat Jun 16, 2012 1:49 pm    Post subject: Re: DateFormat syntax error Reply with quote

Oops, sorry about that, I should take coffee before coding Very Happy
_________________
Jon
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Community Forum Index -> Java All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB