Java / JRE/ JDK

Working with Java

Language Basics

This is in a separate guide, available here.

"Regular" Java Programs

"Hello World" in a "Regular" Java Program

public class HelloWorld {

   public static void main (String args[]) {

      System.out.println("Hello World!");
   }

}

Java Applets

Example Applet: HelloWorld.java

// These are some of the standard "imports" we'll be using, explained in class
import java.awt.*;
import javax.swing.*;
import java.applet.*;

public class HelloWorld extends Applet {

   public void paint(Graphics g) {

      // Set the background color to red
      setBackground(Color.red);

      // Draw the text "Hello World" at (x,y) = (100,200)
      g.drawString("Hello World", 100, 200); 

   }
}

The Above Applet actually Running!!! OMG!!!

Error: You need a Java plugin installed on this browser to view this applet!

How Java Applets Work

HTML to load a Java Applet

   <applet code="HelloWorld.class" height="300" width="400">
      Error: You need a Java plugin installed on this browser to view this applet!
   </applet>

Key Applet Methods

Restrictions on Java Applets

Developing Java Applets