Java ![]() |
ähnliche Sprachen: | C C# C++ C-Talk D Cilk Objective-C Pike TOM | |
Hello World (Applet) | Michael Neumann |
import java.applet.*; import java.awt.*; public class HelloWorld extends Applet { public void paint(Graphics g) { g.drawString("Hello World",10,10); } } |
Gibt "Hello World" auf dem Bildschirm
aus. |
Hello World (Application) | Michael Neumann |
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } } |
Gibt "Hello World" auf dem Bildschirm
aus. |
Hello World (Servlet) | Michael Neumann |
/* * Hello World in Java (Servlet) */ import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorld extends HttpServlet { public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out; String text = "Hello World in Java (Servlet)"; response.setContentType("text/html"); out = response.getWriter(); out.println("<html><head><title>"); out.println(text); out.println("</title></head><body>"); out.println(text); out.println("</body></html>"); out.close(); } } |
Gibt "Hello World" auf dem Bildschirm
aus. |
Hello World (Swing-GUI) | Michael Neumann |
import javax.swing.*; class HelloWorldSwing { public static void main(String args[]) { JFrame mainWin = new JFrame("MainWindow"); JButton button = new JButton("Hello World"); mainWin.getContentPane().add(button); mainWin.pack(); mainWin.show(); } } |
Gibt "Hello World" auf dem Bildschirm
aus. |
Multi-threading | Michael Neumann |
public class ThreadTest implements Runnable { public static void main(String args[]) { int i, j; // create 1000 threads for (i=0; i<=1000; i++) { Thread th = new Thread(new ThreadTest()); th.start(); } // do some calculation for(i=j=0; i<=100000; i++) { j = j + i; } } public void run() { try { // sleep forever Thread.currentThread().sleep(1000000); } catch (InterruptedException e) {} } } |
Create 1000 threads that
sleep. |