class MijnThread extends Thread {
@Override
public void run() {
for (int i = 1; i <= 5; i++) {
System.out.println("Thread " + getName() + ": Stap " + i);
try {
Thread.sleep(1000); // Pauzeer 1 seconde
} catch (InterruptedException e) {
System.out.println("Thread onderbroken!");
}
}
}
}
public class ThreadVoorbeeld {
public static void main(String[] args) {
MijnThread thread1 = new MijnThread();
MijnThread thread2 = new MijnThread();
thread1.start(); // Start de eerste thread
thread2.start(); // Start de tweede thread
}
}
class MijnRunnable implements Runnable {
@Override
public void run() {
for (int i = 1; i <= 5; i++) {
System.out.println("Runnable Thread: Stap " + i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println("Runnable onderbroken!");
}
}
}
}
public class RunnableVoorbeeld {
public static void main(String[] args) {
MijnRunnable runnable = new MijnRunnable();
Thread thread1 = new Thread(runnable, "Runnable-1");
Thread thread2 = new Thread(runnable, "Runnable-2");
thread1.start();
thread2.start();
}
}
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ExecutorVoorbeeld {
public static void main(String[] args) {
ExecutorService executor = Executors.newFixedThreadPool(2); // Threadpool met 2 threads
Runnable taak = () -> {
for (int i = 1; i <= 3; i++) {
System.out.println("Taak in thread " + Thread.currentThread().getName() + ": Stap " + i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println("Taak onderbroken!");
}
}
};
// Voer twee taken uit
executor.submit(taak);
executor.submit(taak);
executor.shutdown(); // Sluit de executor na afronding
}
}
public class LambdaVoorbeeld {
public static void main(String[] args) {
Thread thread = new Thread(() -> {
for (int i = 1; i <= 5; i++) {
System.out.println("Lambda Thread: Stap " + i);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
System.out.println("Lambda onderbroken!");
}
}
});
thread.start();
}
}
<?php
$leeftijd = 20;
if ($leeftijd >= 18) {
echo "Je bent oud genoeg om te stemmen!";
} else {
echo "Je bent nog te jong om te stemmen.";
}
?>
<?php
$score = 85;
if ($score >= 90) {
echo "Uitstekend! Je hebt een A.";
} elseif ($score >= 80) {
echo "Goed gedaan! Je hebt een B.";
} elseif ($score >= 70) {
echo "Niet slecht! Je hebt een C.";
} else {
echo "Oefen nog wat meer.";
}
?>
<?php
$dag = "maandag";
switch ($dag) {
case "maandag":
echo "Begin van de werkweek!";
break;
case "vrijdag":
echo "Bijna weekend!";
break;
case "zondag":
echo "Rustdag!";
break;
default:
echo "Gewoon een dag.";
break;
}
?>
<?php
$isIngelogd = true;
$bericht = $isIngelogd ? "Welkom terug!" : "Log in om verder te gaan.";
echo $bericht;
?>
<?php
$leeftijd = 16;
$heeftToestemming = true;
if ($leeftijd >= 18) {
echo "Je mag de film bekijken.";
} elseif ($leeftijd >= 16 && $heeftToestemming) {
echo "Je mag de film bekijken met toestemming.";
} else {
echo "Toegang geweigerd.";
}
?>