retour HomePage

javacompatible.gif (3134 bytes)

applications Java    50 heures
byte code s'exécutant dans le système d'exploitation par une Java virtual machine

écran rafraichi le
updated 18 janv. 2002-feuillade@freesurf.fr

à propos de Java, en direct de Balien direct de Bali

Plan du cours IPA2002:

Java Tutorials

Java Newsgroup   comp.lang.java

Java Mailing List   http://java.sun.com/mail.html
http://developer.java.sun.com

Bibliographie

Programmer en Java   par Anne Tasso - Eyrolles initiation
Programmer en Java   par Delannoy - Eyrolles
Core Java2 tome I et tome II   par SUN
Thinking in Java   by B.Eckel

autres livres
sur amazon.fr      +autres

Programmer en Java sous Linux avec emacs

  1. lancer emacs
  2. menu File /Open File /Find file:~/Prog1.java
  3. menu File /Save Buffer
  4. compiler avec menu JDE /compile
  5. exécuter avec menu JDE /Run

Programmer en Java sous Windows  en installant un éditeur :

JDK  Java2 Developpement Kit from SUN   http://javasun.com :

JBuilder environnement  from  www.borland.com

Class
a Java prog. consists of a set of Class definitions
method ( )
n'existe que dans une Classe
variable
to store values or expression in variable
an instance of a Class is an object
Classe d'objets
instance method ( )
the prog. calls an instance method ( ) :
<object>
.<method name>(arg1, arg2… argN)
instance variable
Java assigns default initial values = 0 , null, boolean false
use the new operator to create a new instance of a Class (Java runtime system allocates memory for that instance); then the constructor for the current Class is called to initialize that memory

public class MyClass <class constructor, methods, variables>  }

use super to explicitly call a constructor from the superclass of ths current Class

use this to call a constructor already defined within the Class

static Class method ( )
the prog. calls a Class method ( ):
<Class name>
.<method name>(arg1, arg2… argN)
static Class variable
the default constructor doesnot have arguments the main method ( ) controls program's execution
Must be declared in the top-level Class of the program:

public static void main (String [] args) {}
local variable
no default initial value; Java requires you initialize local variables before they are used
ex:
for (int i=0; i<9; i++);
  method ( ) modifier w/o scope affect variable modifier
  • "normal" Class
  • public Class
  • abstract Class
  • interface
    variables must be final
    External interface of a Class is like a contract with users of the Class
  • static method ( )     is a Class method ( )
  • final method ( )
    cannot be overriding by a method in a subclass
  • native method ( )
  • abstract method ( ) is not defined in the Class ; must be defined :
    in a subclass
    in another Class (abstract Class or interface)
  • public method  ( )
  • native method  ( )
  • synchronized method  ( )

finalize ( )    is a method to clean up any outstanding resources

  • static variable  is a Class variable
  • final variable = value cannot be changed
  • public variable
  • protected variable
  • private variable
  • transient variable
  • volatile variable

Package & import statement

affecting scope method ( )  modifier
vs everything in a Basic prog. is accessible from everywhere

variable scope & variable extent in java

From within a package, all classes can access each other's friendly members.

From outside a package, only public and protected classes, methods ans varaibles may be accessed

import <package_name>.<Class_name>;

  • public method ( )
    can be accessed by any Class, just like a Basic prog.
  • private method ( )
    can be accessed only by methods within the same Class
  • public protected method ( )
    can be accessed by methods in subclasses of the Class
  • private protected method ( )
    may be accessed by same Class or its subclasses
  • not explicitly  a friendly modifier
    can be accessed by methods in the Class
    can be accessed by methods in other classes in same package as the Class
the scope of a variable, is the region of prog. from which the variable can accessed

 

arrays in Java are objects
array must be created with the
new operator

int[] scores;
does not creat
an array but creates a variable "scores" that can hold an array

scores = new int[10];
create an array of integers with all elements initialized to default value "0"

   
 

overriding methods ( )  
overloading (surcharge de fonctions) is the ability to use the same name for mutiple methods

variable type

attributes and methods ( ) are inherited from the parent Class (superClass) Java primitive type
char, int, float, double, boolean

an instance of a particular Class

 

Cast operator
ex :   int n = (int) x ;

Quick reference

equality operators

= =

x,y: arithmetic types
x,y: boolean
x,y: object
x equals y
x and y both true or both false
x and y refer to same object

 

keywords

abstract a Class or method( ) modifier.
An
abstract class is used for classes that include abstract methods
An
abstract method( ) is used for methods that are generic and that will have their operations fully defined in sub-classes of the abstract class.
interface class its methods have their operations defined in the classes that implement the interface
boolean one of java's primitive types; by default, initialized to false
break standard control transfer statement. Passes control to the end of an enclosing iteration
class keyword to introduce a new type
extends keyword that specifies the superclass or superclasses of the sub-class or interface being declared
implements keyword that specifies the interface(s) that will be provided by the class being declared
import keyword that specifies packages or classes that can be used with a program
final a class, method( ), or variable modifier.
A
final class cannot be subclassed
A
final method( ) cannot be overridden
A
final variable cannot have its initialized value changed
new keyword used to create an instance of a class
null keyword indicating the absence of a reference
private a constructor, method( ) or variable modifier.
A
private constructor, method ( ) or variable can be accessed only within the same Class
protected a constructor, method( ) or variable modifier.
A
protected constructor, method( ) or variable can be accessed by other methods in the Class, methodsin subclasses of the Class, or methods in classes in the same package as the Class.

Private protected members may be accessed by methods in the Class or methods in subclasses of the Class
public a class, constructor, method( ), or variable modifier.
A
public class, constructor, method( ), or variable can be directly accessed or imported from other packages
return standard control transfer statement. Passes control to the caller of the current method( )
static a method( ) or variable modifier.
A
static  method( ) is used to declare a Class method( )
A
static  variable is used to declare a Class variable, which will be shared among all instances of a class
switch standard conditional control flow
synchronized a method( ) or block modifier.
A
synchronized  method( ) or block acquires a lock on a resource, executes the specified code and releases the lock. Used for multithreading
this keyword used to reference the current Class or a constructor defined in the current Class
throw standard control transfer statement. Indicates a runtime exception.
By convention, the argument to
throw is a subclass of the Exception class
Exception  
throws a method( ) keyword that lists all the exceptions the method( ) can throw
transient  
try keyword used in exception handling
void standard null return type
volatile a variable modifier indicating the variable may be asynchronously modified
   
   

Fonctions rencontrées


Microsoft csharp Microsoft C# features derived from Java