Christopher Guest

See also: Java

Java is at the same time a Computer programming language Informatique Orienté object and a Environnement of execution portable Informatique created by James Gosling and Patrick Naughton employed Sun Microsystems with the support of Bill Joy (cofounder of Sun Microsystems in 1982), officially presented the May 23rd 1995 to the SunWorld .

Presentation

Java is at the same time a Computer programming language and a Environnement of execution. The language Java with the principal characteristic to be portable on several operating systems such as Unix, Microsoft Windows, Mac OS or Linux… It is the platform which guarantees the portability of the applications developed in Java.

The language takes again mainly the syntax of the language C++, very much used by the data processing specialists. Nevertheless, Java was purified the most subtle concepts of the C++ and at the same time more diverting, such as the multiple Héritage replaced by the implementation of the interfaces. The originators privileged the directed approach object so that in Java, all is object except for the primitive types (integers, numbers with floating decimal point, etc).

Java makes it possible to develop autonomous applications but also, and especially, applications Client-serveur. Side customer, the Applet S are at the origin of the notoriety of the language. It is especially side waiter which Java was essential in the medium of the company thanks to the Servlet S, during waiter of the applet, and more recently the JSP (JavaServer Pages) which can replace, ASP and ASP.NET.

The Java applications can be carried out on all the operating systems for which was developed a Java platform, whose technical name is JRE (Java Runtime Environment - Environment of Java execution). The latter consists of a JVM (Java Virtual Machine - Virtual Machine Java), the program which interprets the Java code and converts it into native code. But the JRE especially consists of a standard library from which must be developed all the programs in Java. It is the guarantee of portability which made the success of Java in customer-server architectures by facilitating the migration between waiters, very difficult for the large systems.

History

This history comes from a free translation of an article of the wikipedia anglophone Java programming language.
do not hesitate to check the translation quality to be certain that there is no misinterpretation.

The origin of the language

The platform and the Java language result from a project of Sun microsystem going back to 1990. Engineer Patrick Naughton was not satisfied by the language C++ used at Sun, his application program interfaces in language C, as well as the associated tools. Whereas it considered a migration towards NeXT, one proposed to him to work on a new technology and thus the Projet Stealth (Furtif) was born.

The Projet Stealth was quickly renamed Green Project with the arrival of James Gosling and Mike Sheridan. , And helped together of other engineers, they started to work in a small office of the street Sand Hill de Menlo Park in California. They tried to work out a technology for the development of applications of a new generation, offering to Sun the prospect for single opportunities.

The team initially planned to use the C++ language, but gave up it for various reasons. First of all, they developed on a system embarked with limited resources, estimated that the use of C++ required a too important investment and that this complexity was a source of error for the developers. The gaps of this language on the level of the Ramasse-miettes implied that the management of the memory was to be programmed manually, a challenge but also a source of error. The team was also disturbed by the gaps of the language on the level of safety, the distributed programming, the multi-threading. Moreover, they wanted a platform which can be related to any type of apparatuses.

Bill Joy had considered a new language combining best computer programming language Mesa and language C. In an article called Plus far (Further) , it proposed in Sun that its engineers develop an environment directed object based on the C++ language. In the beginning, Gosling planned to modify and improve the C++ language, which it called C++ ++ --, but the idea was soon abandoned with the profit of the development of a new computer programming language which they called Oak (oak) in reference, one thinks, with a tree planted right in front of the window of their office.

The team worked with eagerness and, at the summer 1992, they were able to make a demonstration including the operating system Green, the language Oak (1992), the libraries and the material. Their first realization, presented on September 3rd, 1992, was the construction of a PDA called Star7 having an graphical interface and an intelligent agent called Duke to lend assistance to the user. In November of the same year, the Green Project was abandoned to become FirstPerson, Inc , belonging entirely at Sun Microsystems and the team was relocated in Palo Alto. The team FirstPerson was interested by the construction of highly interactive tools and when Time Warner published an invitation to tender in favor of a multifunction decoder, FirstPerson changed objective to propose such a platform. However, the industry of the TV by cable found that it offered too many possibilities to the user and FirstPerson lost the market with the profit of Silicon Graphics. Incompetent to interest audio-visual industry, the company was reintroduced within Sun.

Java meets Internet

From June in July 1994, after three days of stir up-meninx with John Guarantees, James Gosling, Joy, Naughton, Wayne Rosing and Eric Schmidt, the team centred the platform on the Web. They thought that with the advent of the Mosaic navigator, Internet was the place where was going to develop the same kind of interactive tool as that which they had considered for the industry of the cable. Naughton developed like prototype a small Web navigator, WebRunner which will become HotJava thereafter.

The same year the language was famous Java after it had been discovered that the name Oak was already used by a video board manufacturer. The name Java was invented in a small bar attended by some members of the team. It is not clear to know or not the name so yes is an acronym, although some claim that it means J Gosling hearts, has rthur V year Hoff and has ndy Bechtolsheim or quite simply J ust has nother V ague has cronym literally (" just a vague acronym of plus"). The belief according to which Java owes its name with the market products in the bar is the fact that the code on 4 bytes (also called magic number) of the files of class is into hexadecimal 0xCAFEBABE. Certain people also claim that the name of Java comes owing to the fact that the program was intended to be able to run on embarked systems, as from the coffee machines (Java means coffee in American slang). In October 1994, HotJava and the Java platform were presented for Sun Executives. Java 1.0a was available in remote loading in 1994 but the first public version of the HotJava navigator arrived on May 23rd, 1995 at the conference SunWorld . The advertisement was carried out by John Gage, the scientific director of Sun Microsystems. Its advertisement was accompanied by the surprised advertisement of Marc Andressen, defect chair executive of Netscape that Netscape was going to include the support of Java in its navigators. January 9th, 1996, the Javasoft group was consisted Sun Microsystems to develop this technology. Two weeks later the first version of Java was available.

Recent history

Web use

Dimensioned customer
The possibility of the navigators Web of launching Java applet guarantees the perenniality of the use of Java by the general public. The recent competitors of the Java applet are mainly Macromedia Flash and Javascript, but soon Xul or XAML will compete with these technologies.

The advantages of Java compared to Javascript are primarily the portability. The heavier the interface is, the more it is exhausting even impossible to adapt the interface to all the navigators of the market. The advantages of Java compared to Flash are also valid compared to Javascript : Java proposes a style of more elegant language, and documented extremely well and proposes especially a very effective Environnement of development integrated.

The applet on the Client station can communicate with servlets on the Waiter, just like Javascript can communicate with the Waiter by means of AJAX. Flash uses technology Flex (Macromedia).

The power of Java is often used for more consistent applications like the video Yahoo plays and more recently readers multiplates-forms (for example).

Side waiter
On the Web side waiter, Java forever be also popular with many Web servers which use the technology Java Server Pages (JSP) and the other technologies based on Java.

Use on the work station

The native use of the Java language for applications on a work station remained until now relatively rare because of their lack of speed. However, with the fast increase in the power of the computers, the improvements during the last decade of the virtual machine Java and the quality of the compilers, several technologies gained ground such as for example Netbeans and the environment Eclipse, technologies of divided files Limewire and Azureus. Java is also used in the program of Matlab mathematics on the level of the interface man machine and for formal calculation. The Swing applications also seem an alternative to technology .NET.

Microsoft and other systems

  • Microsoft provided an work environment of the Java type, named J++, with its operating systems before the exit of Windows XP in 2001. Following legal decision, and within sight of the non-observance of the specifications of this language, Microsoft had to give up this one (cf chapter " Independence with respect to punt-forme" low)
  • Beaucoup of computer makers continues to include an environment JRE on their Windows systems.
  • Java also seems a standard on the level of Mac OS X of Apple as well as for the Linux distributions. Nowadays, the majority of the users can launch Java applications without any problem.

Passage under free license

The November 13rd 2006, Sun announces the passage of Java, i.e. the JDK (JRE and development tools) and the environments Java EE (already under license CDDL) and Java ME under license LPG. Java thus becomes a Free software.

History of the versions

The Java language knew several evolutions since the JDK (Java Development Kit) 1.0 with the addition of many classes and packages with the standard library. Since the J2SE1.4, the evolution of Java is directed by the JCP (Java Community Process) which uses the JSR (Java Specifications Requests) to propose additions and changes on the Java platform. The language is specified by the JLS (Java Language Specification). The modifications of the JLS are managed under code JSR 901

  • JDK 1.0 (January 23rd, 1996 - 211 classes and interfaces) - initial Version. press release

  • JDK 1.1 (February 19th, 1997 - 477 classes and interfaces) - many additions (press release) with notamment :

    • a complete recasting of the event-driven model AWT.
    • the internal classes are added to the language.
    • JavaBeans
    • JDBC
    • Java Remote Invocation (RMI)
  • J2SE 1.2 (December 9th, 1998 - 1524 classes and interfaces) - Code name Playground . This version and the following ones until J2SE 5.0 are renamed Java 2 and named version J2SE (Java 2 Platform, Standard Edition) replaces JDK to distinguish the basic platform from version J2EE (Java 2 Platform, Enterprise Edition) and from version J2ME (Java 2 Platform, Micro Edition). Several additions (press release) with notamment :

    • the key word strictfp
    • the reflection
    • the API Swing graph is integrated.
    • For the first time, the virtual machine Java of Sun includes a compiler " Just with temps" (Just in Time).
    • Java Plug-in
    • Java IDL, an implementation of IDL for interworking with CORBA.
    • the framework Collections.
  • J2SE 1.3 (May 8th, 2000 - 1840 classes and interfaces) - Code name Kestrel . The most important change (press release complete listing of the changes) with notamment :

    • HotSpot JVM included (the virtual machine HotSpot left in April 1999 for the virtual machine the J2SE 1.2)
    • Changement for the RMI to be based on CORBA.
    • JavaSound
    • JNDI (Java Naming and Directory Interfaces) included basic (available before like extension)
    • JPDA (Java Platform Debugger Architecture)
  • J2SE 1.4 (February 6th, 2002 - 2723 classes and interfaces) - Code name Merlin . It was the first revision of the platform under JCP (Java Community Processe) JSR 59. Principal changes (press release - complete listing of the changes sont :

    • the key word assert (Specified in JSR 41.)
    • rational expressions modelled while taking as a starting point the language Perl.
    • the chaining of exception makes it possible an exception to encapsulate the basic exception level of origin. (Specified in JSR 51.)
    • API
    • of journalizing (Specified in JSR 47.)
    • API Image I/O for reading and writing images in formats like JPEG and png.
    • integration of a parser XML and engine XSLT named JAXP (Specified in JSR 5 and JSR 63.)
    • integration of the extensions of safety JCE, JSSE and JAAS.
    • Java Web Start (introduced for the first time in March 2001 for J2SE 1.3 - Specified into JSR 56.)
  • J2SE 5.0 (September 30th, 2004 - 3270 classes and interfaces) - Code name Tiger . (initially numbered 1.5, which is always used as internal number of version). Developed by JSR 176, Tiger adds a significant number of innovations (press release) to the langage :

    • generic Programming - (Specified by JSR 14.)
    • Metadata - also called annotations, makes it possible the language to build classes and methods labelled with additional data which can be used as meta-data (Specified in JSR 175.)
    • Autoboxing/unboxing - automatic conversion enters of the primitive types (like the int type) and corresponding Wrapper of class (as the Integer class) (Specified in JSR 201).
    • Enumerations - the key word enum makes it possible to create an ordered list of values without type. Previously, this could only be carried out by constant entireties (Specified in JSR 201).
    • Varargs - syntax Object… used in a declaration of method makes it possible to specify a variable number of arguments for this method. It is an operation equivalent to the function " printf" out of C.
    • Imports statics - This functionality makes it possible to use the constants of a class without specifying the name of this class and without passing by " anti-pattern Constant Interface" (it is the expression used on the site of Sun).
    • Extension of the for for the loops - the syntax of the for is extended with a special syntax to reiterate them on any Itérable like a table, or a collection by using the syntaxe :

  • Java SE 6 (December 11th, 2006 -??? classes and interfaces) - Code name '' Mustang ''. (see JSR 270). A beta release left on February 15th, 2006, another beta in June 2006, a version " release candidate" in November 2006, and the final version on December 12th, 2006. With this version, Sun replaces name J2SE by Java SE and removes the .0 with the number of version (see).

  • Java SE 7 - Code name Dolphin . In 2006, this version is still at an early developmental stage. It is the last version with being planned. The development should start at the summer 2006 with an exit estimated in 2008 (see). It will be about the first version under the license LPG.

In addition to the changes on the level of the language, more important changes took place with the passing of years which led few hundreds of classes in the JDK 1.0 to more than 3000 in J2SE 5.0. The API whole ones, like Swing or Java2D were added and much of methods of original JDK 1.0 were declared deprecated (i.e. obsolete and being able to be removed constantly).

Philosophy

This part comes from a free translation of an article from the wikipedia anglophone Java programming language.

During the creation of the Java language, it had been decided that this language was to answer 5 objectifs :

  1. to use a directed method objet  ;
  2. to allow the same program to be carried out on several operating systems différents  ;
  3. to be able to use in a native way the networks informatiques  ;
  4. to be able to carry out distant code in manner sûre  ;
  5. to be easy to use and have the strong points of the directed computer programming languages object like C++.

A language directed object

The first characteristic, the character directed object (“OO”), refers to a method of programming and design of the language. Although there exist several interpretations of the expression directed object, an idea headlight in this type of development is that the various types of data must be directly associated with the various operations which one can carry out on these data. Consequently, the data and the code are combined in the same entity called object. An object can be seen like a single entity gathering a behavior , the code, with some state , the data. The principle is to separate the things which change those which do not change pas  ; often a change on the level of a structure of data will imply a change in the code being used to handle these data and reciprocally. This cutting in coherent entities called objects makes it possible to have more solid foundations to build a software architecture of quality. The objective is to be able to develop projects simpler to manage and to reduce the number of projects leading to a failure.

Another major goal of the directed programming object is to develop generic objects so that the code can be reusable between various projects. An object “customer” generic for example must have overall the same behavior in the various projects, in particular if these various projects are recut as it is often the case in the large organizations. In this direction, an object can be seen like a plug-in software component, allowing the software industry to build projects of scale starting from reusable basic elements and the stability tested while decreasing in a drastic way time of development.

The re-use of code, when it is subjected the practice proof, encounters two majeures  difficulties;: the creation of really reusable generic objects is a concept very badly included/understood and a methodology to disseminate necessary information with the re-use of code misses cruelly. Certain communities of the world “Open Source” want to contribute to solve this problem by providing to the programmers the possibility of widely disseminating information on the reusable objects and the libraries object.

Independence with respect to the platform

The second characteristic, independence with respect to the platform, means that the programs written in Java function in a perfectly similar way on various material architectures. One can carry out the development on a given architecture and make turn the application on all the others.

This result is obtained by the Java compilers which compile the source code " with moitié" in order to obtain a bytecode (more precisely the bytecode Java , a machine language specific to the platform Java). The code is then interpreted on a virtual machine Java (English JVM), a program writes specifically for the target machine which interprets and carries out the bytecode Java. Moreover, standard libraries are provided to be able to reach certain elements of the machine host (graphics, the multithreading, the programming network…) exactly in the same manner on all architectures. Let us note that even if there is explicitly a first early phase compilation, the bytecode Java is interpreted or then converted with flown into native code by a compiler Juste-with-time ( just in time , JIT).

There exist also Java compilers which compile the Java directly of native object code for the target machine, such as for example GCJ, removing the intermediate phase of the bytecode but the final code produced by these compilers can then be carried out only on only one architecture.

The license of Sun for Java insists on the fact that all the implementations must be compatible. This has leads to the complaint in Justice against Microsoft after Sun noted that the implementation of Microsoft did not support interfaces RMI and JNI and comprised elements specific to certain platforms compared to the initial platform of Sun. Sun obtained damages (20  million dollars) and the act of justice still reinforced the terms of the license of Sun. In answer, Microsoft adopted the support of Java on its platforms and, on the recent versions of Windows, Internet Explorer does not support the Java applet without adding plug-in. However, Sun places at the disposal free of the environments of execution of Java for the various Microsoft platforms.

The first implementations of the language used a virtual machine interpreted to obtain the portability. These implementations produced programs which were carried out more slowly than those written out of C or C++, so that the language suffered from a reputation of weak performances. More recent implementations of the virtual machine Java (JVM) produce programs much faster than before, by using various techniques.

The first technique is to compile directly in native code like a traditional compiler, removing the phase of bytecode completely. Good performances thus are obtained but with depend on the portability. Another technique called compilation Juste-with-time ( just in time , JIT). translated the byte codes in native code during the phase of launching of the program. Certain more sophisticated virtual machines use a dynamic recompiling during which the virtual machine analyzes the behavior of the program and in recompile selectively certain parts. The dynamic recompiling makes it possible to obtain better results that static compilation because the dynamic compilers can optimize according to their knowledge of the target environment and the classes which are used. Compilation JIT and the dynamic recompiling make it possible Java to benefit from the speed of the native code without losing the portability.

The portability is technically an objective difficult to reach and the success of Java in this field is mitigated. Though it is indeed possible to write programs for the Java platform which function correctly on many target machines, the big number of platforms with small errors and inconsistencies led to a diversion of the slogan of Sun " Write ounce, run anywhere" (" To write once, carry out partout") in " Write ounce, debug everywhere" (" To write once, déboguer partout") !

The independence of Java with respect to the platform is however a success with the applications side waiter like the Web services, the servlets and the Beans Java as well as the systems embarked on OSGi, using the environment Embedded Java .

Mechanism of the table tidy ( Garbage Collector )

A possible argument against languages as C++ is the heavy task to have to program the management of the memory manually. In C++, the memory is allocated directly by the programmer to create an object and is désallouée at the time of the destruction of this one. If the programmer forgets désallouer the memory, this can lead to a lack of memory, and the program gradually consumes memory without cleaning behind him. Worse still, if a zone memory is désallouée twice, the program can become unstable and lead to a planting.

In java, this problem is avoided thanks to the Ramasse-miettes (Garbage collector). The objects which are created are placed in a heap. The program and the other objects can reach the object thanks to its reference in the heap. When there does not remain any more any reference towards the object, the table tidy automatically destroys the object become inaccessible, releasing the memory and thus preventing a lack of memory. The lacks of memory can nevertheless occur when a program keeps a reference towards an object of which it does not have any more besoin  ; they continue to exist, but only on one level concept much higher. But as a whole, the table tidy returns the creation and the destruction of objects to simpler Java, potentially surer and often faster than in C++.

The table tidy is transparent for the developer and is called regularly and automatically. However, the programmer can with the need to force his launching using the method System.gc () .

Basic concepts

The Java system is based on the language Java , the virtual Machine Java and the API Java (these the last two components form the environment of execution, or JRE, for Java Runtime Environment ).

Four primary education goals governed the creation of the Java language. It devait :

  • To be Directed object   ;
  • To be independent of the Platform client  ;
  • To contain Assistance S and Library S for the Data-processing network   ;
  • To have the capacity to carry out code of source external in a protected way.

Java is usually compiled towards a standardized virtual machine, in the form of bytecode . This machine can function with an interpreter, a compiler just-in-time (with stolen), or, most usually, with a mixture of both.

There exist alternatives of this schéma :

  • allowing to compile the language Java nativement, i.e. to produce achievable able to function out of the environment Java, and to even produce achievable able to function in the environment CLR of Microsoft .NET, thanks to the alternative J# of Java, created by Microsoft  ;
  • allowing to produce an achievable Java starting from other languages, like Python using the compiler Jython, or Groovy.

A language directed object

The first characteristic, directed the object, refers to a modern method of programming and design of language. Its main feature is to gather ( to encapsulate ) in only one logical entity ( Classe ) a whole of data ( Propriétés ) and the functions which treat them ( Méthodes ). The code becomes thus more easily reusable, because it is intrinsically modular. Other mechanisms the such heritage make it possible to exploit all the characteristics of a Classe previously written (most of the time by someone else) in its personal programs without same having to know of it the inner working, one sees only the interface of it (principal orders).

This paradigm of programming aims at making the great projects software easier to manage, improve quality of the software and to reduce the number of failures of project.

In version 1.5 of the language were added the credits, mechanism of polymorphism similar (but different) with the templates of the language C++ or with the functors of Objective Caml. The credits make it possible to express in a simpler and surer way the properties of objects like containers (lists, trees…) : the list type is then considered génériquement compared to the type of object contained in the list.

Independence with respect to the platform

The second characteristic of the language, independence with respect to the platform, means that the programs written in Java can function on various types of Computer material without rewriting, according to the slogan Write ounce, run anywhere (to write the program only once, and to make it function on any computer).

This is allowed in compiling the Source code of a Java program in a intermediate Pseudo-code called Bytecode Java -- instructions machine standardized and intended for a virtual processor . The code is thereafter carried out by an implementation of this virtual machine (JVM), a program written in native Code on the target material which translates the Java pseudo code into code usable for the material concerned. Moreover, libraries are offered to provide the access to functionalities specific to the target machine -- like graphics or the network -- in a unified way. The Java language offers also the support of the programs with several light processes (threads).

The first implementation of the language used a virtual machine to offer the portability, and several implementations still do it. These last produce programs which function more slowly than the programs compiled nativement, like those written in C. This situation conferred a reputation of slowness on the Java programs. However, of the more recent implementations of the virtual machine Java produce programs which are carried out much more quickly thanks to the use of various techniques, but especially the power of the machines starting from 1,5GHz makes the interfaces traditional very comfortable. It is now Javascript which carries the burden of slowness.

The first technique consists in compiling directly in native code, like the traditional compilers, without passing by the pseudo code. This method allows a better performance, but at the price of the portability (cf GCJ). Another technique, compilation with stolen ( just-in-time or JIT), compiles the Java pseudo code in native code with the execution of the program. More sophisticated virtual machines also use the dynamic recompiling , which makes it possible the machine to analyze the behavior of the program and recompiler and to optimize the critical parts. These two techniques make it possible the application to take advantage the speed of execution of the native code while preserving the portability.

The portability is a goal technically difficult to reach, and the success of Java to this goal is prone to controversy. Even if it is indeed possible to write programs for the virtual machines Java which behave in a coherent way on various platforms, the great number of platforms with small errors or inconsistencies led to a parody of the slogan of Sun Write ounce, run anywhere (to write once, carry out anywhere) in Write ounce, debug everywhere (to write once, déboguer everywhere).
The virtual machines developed under license by Microsoft are not foreign with this reputation. Indeed, the editor of Redmond “had singularly adapted” its virtual machines to its own needs. It was condemned to cease the exploitation of the license and to withdraw the virtual machines nonin conformity of its products.

Protected execution of distant code

The Java platform was one of the first systems to offer the support of the execution of the code starting from distant sources. A Applet can function in the Navigateur Web of a user, executant of the downloaded code of a waiter HTTP. The code of an applet functions in a very restrictive space, which protects the user from the erroneous codes or badly intentioneds. This space is delimited by an object called gestionnaire of sécurité. Such an object also exists for local code, but it is then by inactive defect.

The manager of safety (the class SecurityManager) allows to define a certain number of authorizations of use of the resources of the local system (filesystem, network, properties system,…). An authorization defines

  1. a code accessor (typically, an applet - possibly signed - sent since a Web server)   ;
  2. a local resource concerned (for example a repertory)   ;
  3. a whole of rights (for example to read/write).

The editors of applet can ask for a Certificat to allow them to numerically sign an applet like sure, giving them thus potentially (with the help of the adequate authorization) the permission to leave restrictive space and to reach the resources of the local system.

The language

Here an example of a typical program Hello world written in Java : public class HelloWorld { public static void hand (String args) { System.out.println (" Hello world! "); } }

The source file must be called HelloWorld.java. You can test it with the following orders (under Linux)  : javac HelloWorld.java CLASSPATH=. HelloWorld java

Line “CLASSPATH=. ” is necessary to indicate to Java which it must also seek the programs class in the current directory. This way can also be specified with the launching of the program by the option - classpath (or - CP in summary)  : javac HelloWorld.java java - CP. HelloWorld

Reserved, primitive and literal words

abstract else instanceof strictfp while boolean false assert (JDK 1.4) enum (JDK 1.5) interface super null byte station-wagon extends native switch tank true double box final new synchronized wrestling finally package this float class for private throw int const (Not used) goto (Not used) protected throws long continue public yew transient shorts default implements return try void C importation static volatile

Structures of control

Collections of objects

It is often necessary to store many data in collections : list purchases, notes of the pupils, etc The collections can be consulted, modified, one can Trier, recopy them, remove them etc… They can have a fixed size or variable.
Collections of size fixes  :
  • tableaux : To initialize a table of entireties of 10 boxes one écrit : int = new int; the boxes of the table are numbered from 0 to 9. More generally, a table of size N, its boxes are numbered of 0 with n-1. One of the greatest advantages of the tables is the access in time constant O (1), with each box of the table. To reach or modify the iéme element of the table, for 0<= I tab=2; to allot value 2 to the first box of the table. To know the size of the table tab.length is written; . If one tries to modify a box which does not exist, for example = 4; one will obtain the error message suivant : IndexOutOfBoundsException because our table contains only 10 boxes.
Collections of variable size  :
  • ArrayList : to initialize ArrayList it is necessary to be important the class java.util.ArrayList   ; and to write list = new ArrayList (); since JDK 1.5 one with the possibility of indicating the type of the elements contained in ArrayList : entireties, string, etc
*Cette collection is empty after the call of the constructeur  ;
*On can add elements as many as one wants. To add an element liste.add is written (Object);
To reach elements of ArrayList : list.get (index);
To know the number of elements which a liste  contains;: liste.size ();
To remove a élément : liste.remove (index); the elements which follow the element removed will be shifted on the left.

Loops

Structure as long as  :

while ( ) { instruction (S) }

Structure to make … as long as  : C { instruction (S) } while ( );

Structure for  : for ( ; ; ) { instruction (S) }

Structure for (java 1.5)  : for (< Object recovering the following occurrence of the collection >: < Collection of objects >) { instruction (S) }

Conditional structures

Structure if  : simple condition yew ( ) { instruction (S) }

Structure if … if not  : condition with single alternative yew ( ) { instruction (S) } else { instruction (S) }

Structure if … or if … or if …  : condition with multiple alternatives yew ( ) { instruction (S) } else yew ( ) { instruction (S) } else yew ( ) { instruction (S) } else { instruction (S) }

Structure to reach … case X … case there … "  : junction towards a block of instructions enumerated switch ( ) { put : instruction (S) station-wagon; put : instruction (S) station-wagon; default: instruction (S) station-wagon; }

Note: you can also use the structure of control switch on an enumeration; in addition the switch does not function on all the constants of the numerical type but only on the entireties.

The order break leaves immediately the loop in progress (for, while, C), and makes it possible to leave a clause contained in a switch.

An expression continues finishes the iteration in progress and continues with the next one. She is written   as follows;: continue

The statement return finishes a method.

With return uneValor , uneValor will be returned to the appealing method.

Ternary operator ? :  : Conditional instruction being able to be employed like an expression ? :

Treatment of the exceptions

try { instruction (S) } wrestling ( ) { instruction (S) } finally { instruction (S) }

The block of code " finally" whatever the result will be carried out when the program leaves the block " try-catch".

Here an example of capture of a exception : FileOutputStream fos = no one; try { // <-- To create a flow to write in a file. The file //n ' is not specified since it is not essential for //l ' example. fos = new FileOutputStream (...); fos.write (a); // ' a' would have received a value later on } wrestling (IOException E) { e.printStackTrace (); } finally { //Fermer flow, whether there is a launched exception or not yew (fos! = no one) fos.close (); }

This example makes it possible to illustrate the mechanism of the exceptions in Java. In the case of an error of input/output in the block " try" , the execution includes in the block " catch" correspondent with this situation (exception of the " type; IOException"). In this block " catch" , the variable " e" reference the exception which occurred. Here, we call upon the method " printStackTrace () " who posts in the console of information on the exception which is produite : name, reason, state of the pile of calls to the moment of the lifting of the exception and, possibly, number of line to which the error occurred. The block finally is then carried out (to close again the resources used here). It is here only about one example, the action to be implemented when an exception occurs depends on the general operation of the application and the nature of the exception.

Slow code/exception

As opposed to what one could think, to raise an exception is not slow. On the contrary, that “accelerates” the code.

For example, between testing a condition : yew (condition1 == no one) and to catch up with an exception, it is preferable to catch up with the exception !
What is awkward is the fact of generating the exception in oneself (stack, message…).
The ratio (according to loops on 100  million tests) seems to be in the neighborhoods of 1/20  000.

Also, it is more expensive to catch up with an exception as from the moment when the risk to have an exception is higher than 1/20  000 (tests carried out in environment JDK 1.4.2_03, Eclipse 3.0, Pentium 4.3,0  GHz  ; no treatment carried out in wrestling).

encoding of the source

The specifications of the Java language specify that it is made of characters to the format UTF-16, which allows the use in the source code of all the characters existing in the world:

UTF-16 字符. Java 的程序遂可以使用 Unicode 字符进行书 - 下面就是一个合法的 Java 程序, 里面包含了 中文 字符作为类的名称而不是字符串, 这个程序可以在编译器中运行通过.

-->

public class hello world { private String text = " hello world" ; }

To ensure the portability between platforms, the names of classes should nevertheless be made only of characters ASCII.

JavaStyle

JavaStyle are the conventions of programming in Java language defined by Sun. The respect of strict conventions ensures a homogeneity in the Source code of an application developed by a whole team and supports the diffusion of the source code near a community sharing same conventions of coding.

Cf The conventions of naming enacted by Sun

Versions

Java is a registered trademark of Sun Microsystems. Kits of development Java ( Java development kit or JDK ) published by Sun, usable gratuitement :
  • JDK 1.0,1996

  • JDK 1.1,1997
  • JDK 1.2,1998 known as Java 2
  • JDK 1.3,2000
  • JDK 1.4,2002
  • JDK 1.5,2004 known as Java 5.0 (Tiger code name)
  • JDK 1.6,2006 known as Java SE 6.0 (Mustang)

The language is stable since the JDK 1.0  ; the libraries of provided classes increased and changed partly. Starting from version 1.2, the JDK were famous in J2SDK ( Java 2 Software Development Kit , kit of development of software Java 2) and one often calls these versions Java 2 .

Because of increase in the libraries and changes between version, compatibility is ensured in only one sens : the Java programs compiled with a previous version of the JDK (for example 1.2) will continue to function with a more recent JRE (for example 1.5), but the opposite is not true.

License

November 11th, 2006, the source code of the compiler javac and the virtual machine HotSpot were published in Open Source under the public License general GNU

November 13rd, 2006, Sun Microsystems announces that all the source code of Java will be published in Open Source under the public License general GNU by March 2007 under the name of project OpenJDK .

Frameworks and API

Sun provides a great number of Framework S and API in order to allow the use of Java for very diversified uses. One distinguishes primarily 4 large frameworks :

  • J2SE  : This framework is intended for the applications for work station. In theory, one must from now on speak about SE  Java; ;
  • J2EE  : This framework is specialized in the waiters applications. It with this intention contains a great number of API and extensions. In theory, one must from now on speak about EE  Java; ;
  • J2ME  : This framework is specialized in the mobiles  applications; ;
  • JavaCard  : This framework is specialized in the applications related to the chip cards and other SmartCards.

Persistence is based on the standards :

  • JDBC (Java DataBase Connectivity)
  • JDO (Java Dated Objects)
  • EJB (Enterprise Java Beans)

One finds however many other optional technologies, API and extensions for Java :

Interpreted version

There exist several interpreted versions of Java (languages of scripts being carried out on a JVM)  : beanshell and Groovy is the subject of standardizations within JCP (Java Community Process). Jython, JRuby, Jacl (Tcl) and other languages of scripts proposes languages on this same principle. The interpreter of these languages can be embarked in a Java application to return it scriptable . It should be noted that to leave Java 6, the engine Rhino (Javascript) is embarked in JRE.

An example with Jython

For the realization of prototype, of graphical interface, file XML,… or for the training of the JDK, it is possible to code in Java by script with Jython
from java.applet importation Applet
 

class HelloWorld (Applet): def Paint (coil, G): g.drawString (" Hello from Jython! " 20,30)

Name

Oak (" Chêne") is the name given to Java initially but this one was already used. One of the theories of sound appellation :
  • Java in the honor of the slang name (in North America) of the beverage more consumed by the developers, i.e. the coffee, of which part of the production comes from the island of Java.

One can notice that while shifting of a letter each consonant one obtains coffee which is also a slang name for coffee (coming from Arabic قهوة qahwa )!

Programming

The programming can be done for simple examples with the compiler javac, but to have more comfort it is preferable to use a Environnement of development integrated or IDE, some are free.

Construction

A Java program can be produced with tools which automate the process of construction. The most used sont :
  • Ant (portable generation in XML)
  • Scons (portable generation of Java/C/C++). Exemple :
      Java (target = “classes”, source = “src”)
      Gravel bank (target = “test.jar”, source = “classes”)
Results % let us scons - Q javac - D classes - sourcepath src src/Exemple1.java src/Exemple2.java src/Exemple3.java gravel bank cf test.jar classes

See too

Java|Java

Related articles

External bonds

  • http://www.java.com/fr/: official site for the users
  • http://www.java.net: official collaboratif site with a Wiki
  • http://java.sun.com: official site for the developers
  • http://java.sun.com/docs/white/langenv/: Original document of presentation of Java

Random links:The Slim Shady LP | Bush hammer | Cassida | Zasu Pitts | Indication of Smad sees