Java


JAVA!

http://java.sun.com

Other relevant Java lecture material:

Java Hello World

As an Application...

class HelloWorldApp [Macro error: Can't compile this script because of a syntax error.]

Java Hello World

As an Applet...


import java.awt.Graphics;

import java.applet.Applet;

public class HelloWorld extends Applet [Macro error: Can't compile this script because of a syntax error.]

Referencing it in HTML...


<HTML>

<HEAD>

<TITLE> A Simple Program </TITLE>

</HEAD>

<BODY>

Here is the output of my program:

<APPLET CODE="HelloWorld.class" WIDTH=150 HEIGHT=25>

</APPLET>

</BODY>

</HTML>

Building a Class in Java

class Motorcycle [Macro error: Can't compile this script because of a syntax error.]

public static void main(String args[]) [Macro error: Can't compile this script because of a syntax error.]

}

Issues in Java class structures and behaviors

Terms: methods, classes, subclasses, superclasses

Single inheritance

"extends"

No "virtual" - Smalltalk-like overriding

Can define a "package"

a way of grouping together related classes and interfaces (a

collection of method names, without actual definitions, that indicate

that a class has a set of behaviors in addition to the behaviors

the class gets from its superclasess.)

Issues in Java data

Real Strings and booleans

"fred" + " " + "jones"

No pointers!

All object references are Smalltalk-like references

Dot-notation goes further

myobject.instance

myobject.instance.its_instance

myobject.getClass().getName()

Class methods and data are "static"

Java Class Libraries

java.lang: Object, String, System, Integer, Character, Float,

etc.

java.util: Date, Vector, Hashtable

java.io

java.net: Socket, URL

java.awt (Abstract Window Toolkit): Window, Menu, Button,

Font, Checkbox

java.applet: Applet, AudioClip

A More Complex Example:


class Count [Macro error: Can't compile this script because of a syntax error.]

Using the command line

import java.io.*;

class CountFile [Macro error: Can't compile this script because of a syntax error.]

Exceptions

public static void main(String args[])

throws java.io.IOException

An exception is an event that occurs

during the execution of program that prevents the continuation

of the normal flow of instructions.

In Java, when an error occurs, the program

throws an exception. You can catch exceptions and try to handle

them within a special code segment known as an exception handler.

Differences between Java and

C++

Not const but "final"

Not ~class but "finalize()"

No pointers

Strings are objects in Java, not

arrays

Java uses garbage collection

No operator overloading

No multiple inheritance

ALL

methods and objects


News Page | CS2390 Sum'97 Home Page | MMC-CaMILE | STABLE
Questions/comments/concerns to guzdial@cc.gatech.edu
Page last updated 8/13/97; 11:55:27 AM