Source de Equation6.java
public class Equation6 {
private int a, b;
public Equation6(int a, int b) {
this.a=a; this.b=b;
}
public void afficher() {
System.out.println(a+" * X = "+b);
}
int solution() throws EquationException {
if (a == 0)
throw new EquationException("pas de solution !");
return b/a;
}
}
|
public class EquationException
extends ArithmeticException {
public EquationException() {
super();
}
public EquationException(String s) {
super(s);
}
}
|
public class Prog107 {
public static void main(String args[]) {
int valeurA = Integer.valueOf(args[0]).intValue();
int valeurB = Integer.valueOf(args[1]).intValue();
Equation6 equa = new Equation6(valeurA,valeurB);
equa.afficher();
try {
int x = equa.solution();
System.out.println("resultat : X = "+x);
} catch (EquationException e) {
System.out.println("erreur : "+e);
}
}
}
|
EXECUTION
|
|
Source de prog.java
exemple client serveur client telnet -e $ localhost 3333 serveur echo resistant au close |
EXECUTION
|
|
exe |
Source de Except1.java
import java.io.*;
public class Except1 {
public static void main(String args[]) {
System.out.println("main : debut");
Except1 ex = new Except1();
try {
System.out.println("main : appel de methodeA");
ex.methodeA(args);
System.out.println("main : retour de methodeA");
} catch (Exception e) {
System.out.println("main : catch une Exception : "+e);
}
System.out.println("main : fin");
}
public void methodeA(String args[]) {
System.out.println(" methodeA : debut");
try {
System.out.println(" methodeA : appel de methodeB");
this.methodeB(args);
System.out.println(" methodeA : retour de methodeB");
if (args.length > 99)
throw new IOException();
} catch (IOException e) {
System.out.println(" methodeA : catch une Exception : "+ e);
} finally {
System.out.println(" methodeA : execute finally");
}
System.out.println(" methodeA : fin");
}
public void methodeB(String args[]) {
System.out.println(" methodeB : debut");
try {
System.out.println(" methodeB : tente d'acceder a args[99]");
String s = args[99];
System.out.println(" methodeB : a reussi a acceder a args[99]");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(" methodeB : catch une Exception : "+ e);
} finally {
System.out.println(" methodeB : execute finally");
}
System.out.println(" methodeB : fin");
}
}
|
EXECUTION
|
|
import java.io.*;
public class Except2 {
public static void main(String args[]) {
System.out.println("main : debut");
Except2 ex = new Except2();
try {
System.out.println("main : appel de methodeA");
ex.methodeA(args);
System.out.println("main : retour de methodeA");
} catch (Exception e) {
System.out.println("main : catch une Exception : "+e);
}
System.out.println("main : fin");
}
public void methodeA(String args[]) {
System.out.println(" methodeA : debut");
try {
System.out.println(" methodeA : appel de methodeC");
this.methodeC(args);
System.out.println(" methodeA : retour de methodeC");
if (args.length > 99)
throw new IOException();
} catch (IOException e) {
System.out.println(" methodeA : catch une Exception : "+ e);
} finally {
System.out.println(" methodeA : execute finally");
}
System.out.println(" methodeA : fin");
}
public void methodeC(String args[]) {
System.out.println(" methodeC : debut");
try {
System.out.println(" methodeC : tente d'acceder a args[99]");
String s = args[99];
System.out.println(" methodeC : a reussi a acceder a args[99]");
} finally {
System.out.println(" methodeC : execute finally");
}
System.out.println(" methodeC : fin");
}
}
|
EXECUTION
|
|
import java.io.*;
public class Except3 {
public static void main(String args[]) {
System.out.println("main : debut");
Except3 ex = new Except3();
try {
System.out.println("main : appel de methodeA");
ex.methodeA(args);
System.out.println("main : retour de methodeA");
} catch (Exception e) {
System.out.println("main : catch une Exception : "+e);
}
System.out.println("main : fin");
}
public void methodeA(String args[]) {
System.out.println(" methodeA : debut");
try {
System.out.println(" methodeA : appel de methodeD");
this.methodeD(args);
System.out.println(" methodeA : retour de methodeD");
} catch (IOException e) {
System.out.println(" methodeA : catch une Exception : "+ e);
} finally {
System.out.println(" methodeA : execute finally");
}
System.out.println(" methodeA : fin");
}
public void methodeD(String args[])
throws IOException {
System.out.println(" methodeD : debut");
try {
System.out.println(" methodeD : tente d'ouvrir fichierExistePas");
FileReader f = new FileReader("fichierExistePas");
System.out.println(" methodeD : a reussi a ouvrir fichierExistePas");
} finally {
System.out.println(" methodeD : execute finally");
}
System.out.println(" methodeD : fin");
}
}
|
EXECUTION
|
|
|
Source de AppliBienVendue.java
import java.io.*;
public class AppliBienVendue {
public static void main(String args[]) {
System.out.println("-- AppliBienVendue --\n"
+" bienvenue tres cher client");
AppliBienVendue ex = new AppliBienVendue();
System.out.println("main : debut");
FileOutputStream appliLog = null;
BufferedOutputStream buffLog = null;
try {
appliLog = new FileOutputStream ("fichierAppliLog");
buffLog = new BufferedOutputStream(appliLog);
moduleChere1(args);
moduleChere2(args);
} catch (IOException e) {
System.out.println("une erreur de VOTRE materiel s'est produite\n"
+" Appelez notre hot-line au 08 5 euros la minute" );
e.printStackTrace(new PrintStream(buffLog));
try {
buffLog.close();
} catch (IOException e2) {}
}
System.out.println("main : fin");
}
public static void moduleChere1(String args[]) {
System.out.println(" moduleChere1 : debut");
try {
System.out.println(" moduleChere1 : tente d'acceder a args[99]");
String s = args[99];
System.out.println(" moduleChere1 : a reussi a acceder a args[99]");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(" moduleChere1 : catch une Exception "
+" facile a traiter "+ e);
} finally {
System.out.println(" moduleChere1 : finally : cool ! ");
}
System.out.println(" moduleChere1 : fin");
}
public static void moduleChere2(String args[])
throws IOException {
System.out.println(" moduleChere2 : debut");
try {
System.out.println(" moduleChere2 : tente d'ouvrir fichierExistePas");
FileReader f = new FileReader("fichierExistePas");
System.out.println(" moduleChere2 : a reussi a ouvrir fichierExistePas");
} finally {
System.out.println(" moduleChere2 : finally : "
+"essaye de fermer proprement");
}
System.out.println(" moduleChere2 : fin");
}
}
|
EXECUTION
|
|
Source de Toutou.java
source |
EXECUTION
|
|
Source de Except4.java
public class Except4 {
public static void main(String args[]) {
Except4 ex = new Except4();
System.out.println("main : methodeA retourne : "
+ ex.methodeA());
System.out.println("main : methodeB retourne : "
+ ex.methodeB());
}
public String methodeA() {
try {
return "sortie bloc try";
}
catch (Exception e) {
return "sortie bloc catch";
}
}
public String methodeB() {
try {
return "sortie bloc try";
}
finally {
return "sortie bloc finally";
}
}
}
|
EXECUTION
|
|