k01-einstieg/ 000755 000765 000024 00000000000 13267622016 013401 5 ustar 00sven staff 000000 000000 k01-einstieg/hello.jad 000644 000765 000024 00000001031 13267622016 015157 0 ustar 00sven staff 000000 000000 // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: hello.java
import java.io.PrintStream;
public class hello
{
public hello()
{
}
public static void main(String args[])
{
System.out.println("Hello World");
for(int i = 0; i < args.length; i++)
System.out.println((new StringBuilder()).append("args[").append(i).append("] = ").append(args[i]).toString());
}
}
k01-einstieg/index.html 000644 000765 000024 00000000303 13267622016 015372 0 ustar 00sven staff 000000 000000
k1:DemoFuerApplet
Hello World als Applet
Quellprogramm
k01-einstieg/DemoFuerApplet.java 000644 000765 000024 00000000347 13267622016 017124 0 ustar 00sven staff 000000 000000
import java.applet.Applet;
import java.awt.Graphics;
public class DemoFuerApplet extends Applet {
public void paint (Graphics g) {
g.drawString ("Hello World", getSize().width / 2, getSize().height / 2);
}
}
k01-einstieg/hello.java 000644 000765 000024 00000000345 13267622016 015351 0 ustar 00sven staff 000000 000000 public class hello {
public static void main (String args[]) {
System.out.println ("Hello World");
for (int i = 0; i < args.length; i++) {
System.out.println ("args[" + i + "] = " + args[i]);
}
}
}
k01-einstieg/Frame1.java 000644 000765 000024 00000001652 13267622016 015363 0 ustar 00sven staff 000000 000000
// Der Einstieg in Graphical User Interfaces (GUI) in Java
import java.awt.*;
import java.awt.event.*;
class Frame1 extends Frame implements WindowListener {
Frame1 (String Title) {
super (Title);
setSize (300, 200);
setVisible(true);
addWindowListener(this);
}
// Pflichten als WindowListener
public void windowClosed(WindowEvent event) {}
public void windowDeiconified(WindowEvent event) {}
public void windowIconified(WindowEvent event) {}
public void windowActivated(WindowEvent event) {}
public void windowDeactivated(WindowEvent event) {}
public void windowOpened(WindowEvent event) {}
public void windowClosing(WindowEvent event) {
System.exit(0);
}
public void paint (Graphics g) {
g.drawString ("Hello World---2", getSize().width / 2, getSize().height / 2);
}
public static void main (String [] args) {
new Frame1 ("1. Frame");
}
}
k02-prozedurale_programmierung/ 000755 000765 000024 00000000000 13267622016 017245 5 ustar 00sven staff 000000 000000 k02-prozedurale_programmierung/Ueberladen.java 000644 000765 000024 00000001040 13267622016 022151 0 ustar 00sven staff 000000 000000
// Ueberladen von Funktionen in Java
public class Ueberladen {
static int min (int i, int j) {
System.out.print ("int min (int, int): ");
if (i < j)
return i;
return j;
}
static long min (long i, long j) {
System.out.print ("long min (long, long): ");
if (i < j)
return i;
return j;
}
public static void main (String args []) {
long al = 1l, bl = 99999l;
int ai = 1, bi = 99999;
System.out.println (min (al, bl));
System.out.println (min (ai, bi));
}
}
k02-prozedurale_programmierung/DemoFuerFor.java 000644 000765 000024 00000001115 13267622016 022263 0 ustar 00sven staff 000000 000000
// Das Applet zeichnet Strahlen in seinem Feld
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
public class DemoFuerFor extends Applet {
public void paint (Graphics g) {
int n = 10;
int breite = getSize ().width;
int hoehe = getSize ().height;
int deltax = breite / n;
int deltay = hoehe / n;
for (int i = 0; i <= n; i++)
g.drawLine (i*deltax, 0, breite - i*deltax, hoehe);
g.setColor (Color.red);
for (int i = 1; i < n; i++)
g.drawLine (0, i*deltay, breite, hoehe - i*deltay);
}
}
k02-prozedurale_programmierung/DemoFuerSwitch.java 000644 000765 000024 00000000675 13267622016 023010 0 ustar 00sven staff 000000 000000
public class DemoFuerSwitch {
public static void main (String args []) {
for (int i = 0; i <= 10; i++)
switch (i) {
case 1:
case 2: System.out.println (i + " Fall 1,2"); // Weiter bei Fall 3
case 3: System.out.println (i + " Fall 3"); // Weiter bei Fall 7
case 7: System.out.println (i + " Fall 7"); break;
default : System.out.println (i + " sonst");
}
}
}
k02-prozedurale_programmierung/NameDemo/ 000755 000765 000024 00000000000 13267622016 020732 5 ustar 00sven staff 000000 000000 k02-prozedurale_programmierung/PackageDemo.java 000644 000765 000024 00000000245 13267622016 022251 0 ustar 00sven staff 000000 000000
import NameDemo.MyFirstClass;
public class PackageDemo {
public static void main (String args []) {
new MyFirstClass ("PackageDemo").print ();
}
}
k02-prozedurale_programmierung/Array_2_Dim.java 000644 000765 000024 00000001154 13267622016 022201 0 ustar 00sven staff 000000 000000
// Demo fuer 2-dimensionales Feld
public class Array_2_Dim {
final static int IMAX = 2, JMAX = 2;
public static void main (String args []) {
int feld[][]; // Deklaration einer nxn-Matrix
feld = new int[IMAX][JMAX]; // Speicher holen
for (int i = 0; i < feld.length; i++)
for (int j = 0; j < feld[i].length; j++)
feld[i][j] = i*10 + j;
for (int i = 0; i < feld.length; i++)
for (int j = 0; j < feld[i].length; j++) {
System.out.print ("i = " + i + " j = " + j +
" feld[i][j] = " + feld[i][j]);
System.out.println ();
}
}
}
k02-prozedurale_programmierung/ParameterDemo.java 000644 000765 000024 00000000577 13267622016 022646 0 ustar 00sven staff 000000 000000
// Die Parameteruebergabe wird untersucht
public class ParameterDemo {
static void swap (int [] feld) {
int a = feld[0];
feld[0] = feld[1];
feld[1] = a;
}
public static void main (String args []) {
int feld [] = {1, 2};
System.out.println (feld[0] + " " + feld[1]);
swap (feld);
System.out.println (feld[0] + " " + feld[1]);
}
}
k02-prozedurale_programmierung/DemoFuerContinue.java 000644 000765 000024 00000000467 13267622016 023332 0 ustar 00sven staff 000000 000000
class DemoFuerContinue {
public static void main (String args []) {
int i;
// Division durch 0 mit continue vermeiden
for (i =- 10; i <= 10; i++) {
if (i == 0)
continue; // Naechster Durchlauf
System.out.println ("Kehrwert von " + i + " = " + 1.0/i);
}
}
}
k02-prozedurale_programmierung/NameDemo/MyFirstClass.java 000644 000765 000024 00000000271 13267622016 024160 0 ustar 00sven staff 000000 000000
package NameDemo;
public class MyFirstClass {
String Name;
public MyFirstClass (String Name) { this.Name = Name; }
public void print () { System.out.println (Name); }
}
k03-objektorientierte_programmierung/ 000755 000765 000024 00000000000 13267622016 020442 5 ustar 00sven staff 000000 000000 k03-objektorientierte_programmierung/Konstruktor.java 000644 000765 000024 00000001227 13267622016 023654 0 ustar 00sven staff 000000 000000
// Noch ein Demo fuer die Reihenfolge der Initialisierung
import java.io.*;
class klasse1 {
public klasse1 () {
System.out.println ("Konstruktor klasse1");
}
public klasse1 (int dummy) {
System.out.println ("Konstruktor mit dummy klasse1");
}
}
class klasse2 extends klasse1 {
public klasse2 () {
System.out.println ("Konstruktor klasse2");
}
public klasse2 (int dummy) {
//super (dummy);
System.out.println ("Konstruktor mit dummy klasse2");
}
}
public class Konstruktor {
public static void main (String args []) {
klasse2 k = new klasse2 ();
klasse2 l = new klasse2 (1);
}
}
k03-objektorientierte_programmierung/CloneDemo.java 000644 000765 000024 00000002304 13267622016 023151 0 ustar 00sven staff 000000 000000
// Clonen als Implementierung von Cloneable
import java.io.*;
/* Alternative zum Clonen:
class klasse {
static int i = 0;
int no;
public klasse () { no = i++; }
public klasse (klasse clone) { no = clone.no; }
public void setno (int no) { this.no = no; }
public void print () { System.out.println ("no " + no); }
}
*/
class klasse implements Cloneable {
static int AnzahlElemente = 0;
int no;
public klasse () { no = AnzahlElemente++; }
public klasse (klasse clone) { no = clone.no; }
public Object clone() {
try {
klasse c = (klasse)super.clone();
c.no = no;
return c;
}
catch (CloneNotSupportedException e) {
// eigentlich nicht zu erwarten
throw new InternalError();
}
}
public void setno (int no) { this.no = no; }
public void print () { System.out.println ("no " + no); }
}
public class CloneDemo {
public static void main (String args []) {
klasse objekt1, objekt2;
objekt1 = new klasse ();
objekt2 = (klasse)(objekt1.clone ());
klasse objekt3 = new klasse (objekt2);
objekt1.print ();
objekt2.print ();
objekt3.print ();
System.out.println (klasse.AnzahlElemente);
}
}
k03-objektorientierte_programmierung/ObstHaendler.java 000644 000765 000024 00000004271 13267622016 023663 0 ustar 00sven staff 000000 000000
// Ein uebliches Beispiel aus der OOP
// Klasse Obst
// Unterklassen Apfel Pfirsich Birne Orange usw...
// Elemente dieser Klasse werden in Container aufbewahrt und bearbeitet
//
// Klassenhierarchie
//
//Object
//+-------+ Obst
// +------- Birne
// +------- Pfirsich
// \\------ Apfel
// Obst ist eine abstrakte Basisklasse, denn es gibt kein
// abstraktes Obst, es gibt nur konkret : Apfel, Birne usw...
abstract class Obst {
protected int Gewicht; // Das Gewicht. Jedes Obst hat ein Gewicht.
Obst (int Gewicht) { this.Gewicht = Gewicht; }
abstract void wiege () ; // Jedes Obst kann gewogen werden
final void print () { System.out.print ("Gewicht " + Gewicht + " "); }
abstract void printme ();
}
class Birne extends Obst {
private String Name;
Birne (String Name, int Gewicht) {
super (Gewicht);
this.Name = Name;
}
void wiege () { System.out.println ("Wiege die Birne " + Gewicht); }
void printme () { System.out.println (Name); }
}
class Pfirsich extends Obst {
private String Name;
Pfirsich (String Name, int Gewicht) {
super (Gewicht);
this.Name = Name;
}
void wiege () { System.out.println ("Wiege den Pfirsich " + Gewicht); }
void printme () { System.out.println (Name); }
}
class Apfel extends Obst {
private String Name;
Apfel (String Name, int Gewicht) {
super (Gewicht);
this.Name = Name;
}
void wiege () { System.out.println ("Wiege den Apfel " + Gewicht); }
void printme () { System.out.println (Name); }
}
public class ObstHaendler {
static public void main (String args[]) {
System.out.println ("----------- start ------------");
Birne Helene = new Birne ("Helene", 2);
Pfirsich Melba = new Pfirsich ("Melba", 1);
Apfel NoName = new Apfel ("?", 3);
// Die Fruechte werden in den Container gelegt
Obst Fruchtkorb [] = new Obst [3];
Fruchtkorb[0] = Helene;
Fruchtkorb[1] = Melba;
Fruchtkorb[2] = NoName;
// Einfache Ausgabe des Containers
for (int i = 0; i < Fruchtkorb.length; i++)
Fruchtkorb[i].printme ();
for (int i = 0; i < Fruchtkorb.length; i++)
Fruchtkorb[i].wiege ();
}
}
k03-objektorientierte_programmierung/Wertzuweisung.java 000644 000765 000024 00000001236 13267622016 024211 0 ustar 00sven staff 000000 000000
// Die Wertzuweisung in Java ist bei "First Class Objects" eine
// Zuweisung der Referenzen auf die Instanzen
import java.io.*;
class klasse {
static int i = 0;
int no;
public klasse () { no = i++; }
public klasse (klasse clone) { no = clone.no; }
public void setno (int no) { this.no = no; }
public void print () { System.out.println ("no " + no + " id = " + toString()); }
}
public class Wertzuweisung {
public static void main (String args []) {
klasse objekt1, objekt2;
objekt1 = new klasse ();
objekt2 = new klasse (objekt1);
objekt1.print ();
objekt2.print ();
objekt1 = objekt2;
objekt1.print ();
}
}
k03-objektorientierte_programmierung/ExceptionDemo.java 000644 000765 000024 00000001761 13267622016 024055 0 ustar 00sven staff 000000 000000
// Reihenfolge und Behandlung von Programmausnahmen
class Exception1 extends Exception {
Exception1 (String text) { super (text); }
}
class Exception2 extends Exception1 {
Exception2 (String text) { super (text); }
}
public class ExceptionDemo {
void demo (int i) throws Exception1, Exception2, Exception {
if (i == 1)
throw new Exception1 ("Zusatz 1");
else if (i == 2)
throw new Exception2 ("Zusatz 2");
else
throw new Exception ("Zusatz 3");
}
public static void main (String args []) throws Exception {
ExceptionDemo e = new ExceptionDemo ();
for (int i = 1; i <= 3; i++)
try {
e.demo (i);
}
catch (Exception2 ex) {
System.out.println (ex);
}
catch (Exception1 ex) {
System.out.println (ex);
}
catch (Exception ex) {
System.out.println (ex);
}
finally {
System.out.println ("Abschlussbehandlung " + i);
}
}
}
k03-objektorientierte_programmierung/Personen.java 000644 000765 000024 00000002424 13267622016 023100 0 ustar 00sven staff 000000 000000
// Chefs sind spezielle Personen
// Einstieg in die objektorientierte Denkweise
class Person {
String Name;
String Vorname;
int PersonalNummer;
Person (String Name, String Vorname, int PersonalNummer) {
this.Name = Name;
this.Vorname = Vorname;
this.PersonalNummer = PersonalNummer;
}
void print () {
System.out.print (" Name " + Name);
System.out.print (" Vorname " + Vorname);
System.out.print (" PersonalNummer " + PersonalNummer);
}
}
class Chef extends Person {
String Abteilung;
Chef (String Name, String Vorname, int PersonalNummer, String Abteilung) {
super (Name, Vorname, PersonalNummer);
this.Abteilung = Abteilung;
}
void print () {
super.print ();
System.out.print (" Leitung Abteilung " + Abteilung);
}
}
public class Personen {
public static void main (String args[]) {
Person personal [] = new Person[4];
personal[0] = new Person ("Meier", "Karl", 100);
personal[1] = new Person ("Huber", "Manfred", 101);
personal[2] = new Person ("Schmidt", "Egon", 102);
personal[3] = new Chef ("Bauer", "Karl", 103, "Einkauf");
for (int i = 0; i < personal.length; i++) {
personal[i].print ();
System.out.println ();
}
}
}