Jan 23

given the necessary declarations and additionally:

System.out.println(c.getTime()); // Output: Sun Jul 11 22:14:37 CEST 2010

What is the output of the following code?:

c.set(Calendar.DAY_OF_MONTH, 40);

Antwort/ answer
Tagged with:
Jan 22

Change the code

DateFormat d = DateFormat.getDateInstance(DateFormat.SHORT);
Calendar c = new GregorianCalendar(1978,5,18);

in a way that it compiles successfully and prints in English way the current date (1/22/11).

Antwort/ answer

Tagged with:
Jan 21

What is the output of the following code?

DateFormat d = DateFormat.getDateInstance(DateFormat.SHORT);
Calendar c = new GregorianCalendar(1978,5,18);

Antwort/ answer
Tagged with:
Jan 20

What is the Output of the following code?

Date dateA = new Date();
Date dateB = new Date(0);
Date dateC = new Date(1);


Antwort/ answer
Tagged with:
Jan 19

To finish the theoretical part of this chapter I would like to explain how to parse values in relation to NumberFormat:

NumberFormat a = NumberFormat.getInstance();

try {

System.out.println(a.parse(“1234,56″)); // parsing into a float-value, Output: 1234,56
// Change; parse should be done from no on into int-values
System.out.println(a.parse(“1234,56″)); // parsing into int-value; Output: 1234

} catch (Exception e){e.printStackTrace(); }

Tagged with:
Jan 18

Analogue to Locale I would like also present some methods in relation to NumberFormat. First of all – as usual – the needed definitions:

float number = 123.45678f;
NumberFormat a = NumberFormat.getInstance();

a little surprise while printing the formatted value:

System.out.println(a.format(number)); // Output: 123,457

quite confusing, we defined the number differently… but there is an explanation: Class NumberFormat is that powerfull that it pre-defines the amount of digits after the decimal point. With


the number of digits after the decimal points is printed, the amount can be changed with


Tagged with:
Jan 17

Let’s move on to formatting of figures and currencies, respectively first of all the needed variables:

float number = 123.45f;
Locale loc = new Locale(“en”,”US”); // new Locale of US-English

NumberFormat a = NumberFormat.getInstance(); // get default-format which is the German one in my case
System.out.println(a.format(number)); // Output: 123,45

a=NumberFormat.getInstance(loc); // get US-format
System.out.println(a.format(number)); // Output: 123.45

a=NumberFormat.getCurrencyInstance(); //get default-currency (keep in mind that it is the German one since I am living in Germany)
System.out.println(a.format(number)); // Output: 123,45 €

a=NumberFormat.getCurrencyInstance(loc); // get US-currency
System.out.println(a.format(number)); // Output: $123.45

Tagged with:
Jan 16

Last but not least I would like to introduce some methods of class java.util.Locale to you:

Let’s start with the already known definitions:

Locale germany = new Locale(“de”, “DE”);
Locale english_uk = new Locale (“en”,”UK”);
Locale portuguese_brazil = new Locale (“pt”,”BR”);

.. and here a few “new” methods:

System.out.println(germany.getCountry()); // Output of the short-country-sign: DE
System.out.println(germany.getDisplayCountry()); //
Output of the country in default language (here: German): Deutschland
System.out.println(germany.getDisplayCountry(portuguese_brazil)); // Output of country in given language; Portuguese: Alemanha

Tagged with:
Jan 15

Today a few hints in relation to Locale:

Let’s start with the definition of a Chinese object of Locale:

Date date = new Date (123456789L);

Locale chinese= new Locale(“zh”,”CN”);
DateFormat df_chinese= DateFormat.getDateInstance(DateFormat.FULL,chinese);

Everything is compiling and running without problems, but the output on my screen is a little bit strange: 1970?1?2? ???

Background is that class java.util.Locale is providing the methods but my System does not know these signs :(

Most of you will have the same results while trying to do German full settings for march; we have a special sign (char a with 2 dots over it) which your computer might not be able to display:

Date date = new Date (6999959989L);

Locale german= new Locale(“DE”,”de”);
DateFormat df_german= DateFormat.getDateInstance(DateFormat.FULL,german);

Additionally please keep in mind that once a Locale is set there is no possibility to change – there is simply no method for that. So watch out in case a question in direction is asked during certification.

Tagged with:
Jan 14

I already talked about my German settings, but not how to change them:

Here a few examples:

Locale germany = new Locale(“de”, “DE”);
Locale english_uk = new Locale (“en”,”UK”);
Locale portuguese_brazil= new Locale (“pt”,”BR”);

first of all the language is defined, in our example German, English and Portuguese. The second value indicates to which country the language is referring to – meaning German in Germany, English in UK and Portuguese in Brazil.

Now these settings have be be put into DateFormat:

DateFormat df_germany = DateFormat.getDateInstance(DateFormat.FULL,germany);
DateFormat df_uk = DateFormat.getDateInstance(DateFormat.FULL, english_uk);
DateFormat df_brazil =DateFormat.getDateInstance(DateFormat.FULL,

The only thing which needs not be done to have the settings changed is to wrap a Date-Object by DateFormat as already discussed:

Date date = new Date (123456789L);

System.out.println(df_germany.format(date )); //German format: Freitag, 2. Januar 1970
System.out.println(df_uk.format(date )); // UK-English format: Friday, January 2, 1970
System.out.println(df_brazil.format(date )); // Brazil-Portuguese format: Sexta-feira, 2 de Janeiro de 1970

Tagged with:
preload preload preload
http://www.wikio.de Blog Top Liste - by TopBlogs.de Blogverzeichnis - Blog Verzeichnis bloggerei.de Bloggeramt.de Software
Webbhotell Top Blogs