Java is ...

* Simple and powerful
* Safe
* Object oriented
* Robust
* Interactive
* Architecture neutral
* Interpreted and high performance
* Easy to learn

Internet Classes

[] TCP/IP Networking
[] WWW and HTML
[] Distributed Programs

Core Classes

* Language
* Utilities
* Input/Output
* Low-level Networking
* Abstract Graphical User Interface Classes

Object-Oriented Programming

[] Encapsulation
[] Inheritance
[] Polymorphism

How Java Is Better Than C++

[] Global Variables
[] Goto
[] Pointers
[] Memory Allocation
[] Fragile Data Types
[] Unsafe Type Casting
[] Separate Header Files
[] Unsafe Argument Lists
[] Unsafe Structures
[] Preprocessor Hacks

HelloWorld.java

class HelloWorld {
        public static void main(String args[]) {
                System.out.println("Hello, World!");
        }
}
Download the source code (HelloWorld.java)
Download the byte code (HelloWorld.class)

Compiling and Running Java Applications

  1. Edit a Java source code file someName.java.
  2. Compile your program with javac someName.java.
  3. Execute java someName to run your application.

HelloWorld Java Applet

import java.awt.*;
import java.applet.*;
public class HelloWorldApplet extends Applet {
        public void paint(Graphics g) {
                g.drawString("Hello, World!", 20, 20);
        }
}

hello.html

<HTML>
<HEAD>
<TITLE>Hello World Java Applet</TITLE>
</HEAD>
<BODY>
<APPLET CODE="HelloWorldApplet" WIDTH=200 HEIGHT=40>
</APPLET>
</BODY>
</HTML>

If you had a Java-compatible browser, you would see the actual HelloWorldApplet running.

Download the source code (HelloWorldApplet.java)
Download the byte code (HelloWorldApplet.class)

Compiling and Running Java Applets

  1. Edit a Java source code file someAppletName.java.
  2. Compile your program with javac someAppletName.java.
  3. Execute appletviewer someName to run your applet.

Reserved Keywords

abstract boolean break byte byvalue
case cast catch char class
const continue default do double
else extends false final finally
float for future generic goto
if implements import inner instanceof
int interface long native new
null operator outer package private
protected public rest return short
static super switch synchronized this
throw throws transient true try
var void volatile while
black = Keywords common to Java, C and/or C++
blue = Keywords specific to Java only
red = Keywords reserved by Java but not defined

Identifiers

  1. Uppercase and lowercase letters (A-Z, a-z)
  2. Numbers (0-9). Must not begin with a number.
  3. Underscores (_)
  4. Dollar sign ($)

Comments

/**
 * This class does incredibly wonderful things and
 * anyone looking to make their applets cooler should
 * subclass it fer sure.
 * @see java.applet.Applet
 * @author James Gosling  ;-)
 * @version 1.2
 */
class CoolApplet extends Applet {
        /**
         * This method takes two parameters:
         * @param key is the name of symbol to store.
         * @param value is what to store associated with this key.
         */
        void put(String key, Object value) {
                int a = 42; // if a is the answer, what's the question 
                /*
                 * This code is a little tricky...
                 * Let me try to explain here:
                 */

Operators

+ += - -= * *= && ? :
/ /= | |= ^ ^= || .
& &= % %= > >= == [ ]
< <= ! != ++ -- = ~
>> >>= << <<= >>> >>>= instanceof

Go Back to the CTEC1641 Page