Créer un site internet

Java Blog

First Steps For Windows Users

Setting up the Enviornment:

In order not to have any conflit during setup or excution of the IDE Intellij you'd better follow these instructions on the right order:

- Install the JDK ( Java Development Kit), you can download it from the following web page click here make sure you checked the agreement box before and chose the appropriate JDK for your OS.

- Then you can download and install the Intellij IDE, for that, please refer to the following web page

IdeaintellijNow your environment is ready for use, so let's create our first program

Our First Java Program

 

After starting Intellij, click on Create New Project  :

 

Createhelloworldprojetct1

Next, click on Java project on the left side and don't select any additional libraries then click on Next:

Createhelloworldprojetct2

and don't select any template just click on next:

Createhelloworldprojetct3 1

and choose a project Name : "HelloWorld"

Createhelloworldprojetct4

 

After that, expand the folder display "HelloWord" and right click upon src folder and click-> New-> Java Class: And choose a Name to your Java Class :

 

Createhelloworldprojetct5

 

I suggest you to call it "MyHelloProgram". By the way, in java all the classes'names start with a capital letter. then the Intellij wizard will generate an empty class file,

with a class named MyHelloProgram as it is shown in the snapshot below

  Createhelloworldprojetct6

 

Now let's create a method inside the class MyHelloProgram, which we are going to call "main": this class will be public and static ( we are going to eplain later on the meaning

of these keywords):

Createhelloworldprojetct9

 

After that, let's apply the following configuration upon Intellij in order to make it considering the "main method " as  the principal method to be called during the compilation

and execution: for that go to the menu Run -> Edit Configurations

Createhelloworldprojetct10

 

then the following popup menu will be opened -> go to the + button and choose the application option:

Createhelloworldprojetct7

 

finally it becomes abvious to fill the form: on the top: enter the name of the main method which is: main then the name of the main class: MyHelloProgram then click on apply and ok.

Createhelloworldprojetct8In order to test our configuration and our program, Let's add the following portion of code which will print into the screen "Hello world!" as a result in the buttom of the IDE.

And in order to compile and execute click on the green play in the top of the IDE page which will compile and run our program:Createhelloworldprojetct11

 

 

 

First Easy Application For Internationalization

If you're new to internationalizing software, then, this chapter is for you.

By a simple example you'll learn how Locale and ResourceBundle objects work together and how to use properties files:

  1. Before Internationalization:

Simply, lets consider the following program:  (which is NOT internationalized): and analyze the underlined information

public class NotI18N

{

static public void main(String[] args)

{

        System.out.println("Hello.");
        System.out.println("How are you?");
        System.out.println("Goodbye.");
  }

  }

  1. After Internationalization:

Let's suppose that we want to Internationalize our code into three language French, English and German:

In order to insure that we need to create four property files: (each one contains the content below)

  • MessagesBundle.properties:

greetings = Hello.
farewell = Goodbye.
inquiry = How are you?

  • MessagesBundle_de_DE.properties:

greetings = Hallo.
farewell = Tschüß.
inquiry = Wie geht's?

  • MessagesBundle_en_US.properties:

greetings = Hello.
farewell = Goodbye.
inquiry = How are you?

 

  • MessagesBundle_fr_FR.properties:

greetings = Bonjour.
farewell = Au revoir.
inquiry = Comment allez-vous?

 

import java.util.*;

public class I18NSample {

    static public void main(String[] args) {

        String language;
        String country;

        if (args.length != 2) {
            language = new String("en");
            country = new String("US");
        } else {
            language = new String(args[0]);
            country = new String(args[1]);
        }

        Locale currentLocale;
        ResourceBundle messages;

        currentLocale = new Locale(language, country);

        messages = ResourceBundle.getBundle("MessagesBundle", currentLocale);
        System.out.println(messages.getString("greetings"));
        System.out.println(messages.getString("inquiry"));
        System.out.println(messages.getString("farewell"));
    }
}

 

Internationalization - Introduction

Internationalization is the process of designing an application so that it can be adapted to various languages and regions without engineering changes. Sometimes the term internationalization is abbreviated as i18n, because there are 18 letters between the first "i" and the last "n."

An internationalized program has the following characteristics:

  • With the addition of localized data, the same executable can run worldwide.
  • Textual elements, such as status messages and the GUI component labels, are not hardcoded in the program. Instead they are stored outside the source code and retrieved dynamically.
  • Support for new languages does not require recompilation.
  • Culturally-dependent data, such as dates and currencies, appear in formats that conform to the end user's region and language.
  • It can be localized quickly.

Localization is the process of adapting software for a specific region or language by adding locale-specific components and translating text. The term localization is often abbreviated as l10n, because there are 10 letters between the "l" and the "n."

The primary task of localization is translating the user interface elements and documentation. Localization involves not only changing the language interaction, but also other relevant changes such as display of numbers, dates, currency, and so on. Other types of data, such as sounds and images, may require localization if they are culturally sensitive. The better internationalized an application is, the easier it is to localize it for a particular language and character encoding scheme