(c) Copyright 2000, 2001, 2002, 2003, 2004 by Daniel Berleant 

Announcements:

Today's topic: introduction to Java

  History of Java


 


A "Hello World" Java Program


import java.lang.*;
public class HelloWorld 
   {
   public static void main
     (String [ ] args)
     {
     System.out.println
        ("Welcome to CPRE 486.");
     }
   }
First, save it in a file HelloWorld.java

File name must correspond to a class name in the file!

Compile, using command
javac HelloWorld.java
  1. To run, type   

    java HelloWorld, or

      jdb HelloWorld  to run it in the debugger

Analyzing HelloWorld.java


A HelloWorld.java with a GUI


import java.lang.*;

import javax.swing.JOptionPane;

public class Hello{

   public static void main(String [ ] args){

      JOptionPane.showMessageDialog(null, "Welcome to CPRE 486");

      System.exit(0);

   }

}

 

Some key differences:

import javax.swing.JOptionPane;

JOptionPane.showMessageDialog(null, "Welcome to CPRE 486");

System.exit(0);