Construct a locale from language and country. This constructor normalizes the language value to lowercase and the country value to uppercase. Note: . ISO 639 is not a stable standard; some of the language codes it defines (specifically "iw", "ji", and "in") have changed. This constructor accepts both the old codes ("iw", "ji", and "in") and the new codes ("he", "yi", and "id"), but all other API on Locale will return only the OLD codes. . For backward compatibility reasons, this constructor does not make any syntactic checks on the input. Parameters: language An ISO 639 alpha-2 or alpha-3 language code, or a language subtag up to 8 characters in length. See the Locale class description about valid language values. country An ISO 3166 alpha-2 country code or a UN M.49 numeric-3 area code. See the Locale class description about valid country values. Throws: NullPointerException - thrown if either argument is null.
The toString() method of Locale class returns a string representation of the Locale object consisting of language, country, variant
Question : You have been given below code, what is the behavior expected? package com.hadoopexam; class ParentException extends Exception {}
class ChildException extends ParentException {}
public class Welcome { public void subscribeForCourse(String courseName, int fee) throws ParentException, ChildException { if (courseName.length() < 6) { throw new ParentException(); } else if (fee >= 60) { throw new ChildException(); } else { System.out.println("You are allowed for this course"); } }
public static void main(String[] args) throws ParentException { Welcome t = new Welcome(); t.subscribeForCourse("Hadoop", 60); } }
1. It will print : You are allowed for this course
2. It will print : Hadoop
3. It will throw Exception in thread "main" com.hadoopexam.ChildException
4. It will give compile time error.
5. It will throw Exception in thread "main" com.hadoopexam.ParentException
Correct Answer : 3 Explanation:
Question : You have been given below code, what is the expected behavior when executed?
package com.hadoopexam;
import java.util.Locale;
class Welcome { public static void main(String[] args) { Locale l1 = new Locale("en"); Locale l2 = new Locale("en", "in"); Locale l3 = new Locale("th", "TH", "TH"); Locale l4 = new Locale(l3); System.out.println(l1 + " " + l2 + " " + l3 + " " + l4); } } 1. It will give compile time error.
2. It will give run time error.
3. It will compile and run with output as "en en_IN th_TH_TH_#u-nu-thai th_TH_TH_#u-nu-thai"
4. It will compile and run with output as "en en_IN th_TH_TH_#u-nu-thai th_TH_TH_#u-nu-IN"
Correct Answer : 1 Explanation: You cannot create Locale using another locale instance. The Locale class provides three constructors: Locale(String language) Locale(String language, String country) Locale(String language, String country, String variant)
These constructors allow you to create a Locale object with language, country and variant, but you cannot specify script or extensions. Factory Methods The method forLanguageTag creates a Locale object for a well-formed BCP 47 language tag.