The Sample program given below will test your understanding about the Locale class of Java.
The Sample program given below will test your understanding about the Locale class of Java.Given below the sample code :
1 // import class here
2 public class dateclass {
3 public static void main(String args[]){
4 Locale locale = Locale.getDefault();
5 System.out.println(locale);
6 locale = new Locale("fr", "CA");
7 Locale.setDefault(locale);
8 System.out.println(locale);
9 DateFormat df = DateFormat.getDateInstance();
10 Date myDate = new Date();
11String myString = df.format(myDate);
12 System.out.println(myString);
13 }
14 }
In the above code , errors are at lines 4,6,7 & 10 ,Which class need to 'import' at line 1 to correct these errors ?
1. import java.text.*;
2. import java.lang.Object;
3. import java.util.*;
4. import java.io.*;
(3)
The "java.util" class contains the definition of "locale" and "date".