Java is
...

Simple and powerful

Safe

Object oriented

Robust

Interactive

Architecture neutral

Interpreted and high performance

Easy to learn
Internet Classes
![[]](images/red-square-sm.gif)
TCP/IP
Networking
![[]](images/red-square-sm.gif)
WWW and
HTML
![[]](images/red-square-sm.gif)
Distributed
Programs
Core Classes

Language

Utilities

Input/Output

Low-level
Networking

Abstract
Graphical User Interface Classes
Object-Oriented Programming
![[]](images/red-square-sm.gif)
Encapsulation
![[]](images/red-square-sm.gif)
Inheritance
![[]](images/red-square-sm.gif)
Polymorphism
How Java Is Better Than C++
![[]](images/red-checkmark.gif)
Global Variables
![[]](images/red-checkmark.gif)
Goto
![[]](images/red-checkmark.gif)
Pointers
![[]](images/red-checkmark.gif)
Memory Allocation
![[]](images/red-checkmark.gif)
Fragile Data Types
![[]](images/red-checkmark.gif)
Unsafe Type Casting
![[]](images/red-checkmark.gif)
Separate Header Files
![[]](images/red-checkmark.gif)
Unsafe Argument Lists
![[]](images/red-checkmark.gif)
Unsafe Structures
![[]](images/red-checkmark.gif)
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
- Edit a Java source code file someName.java.
- Compile your program with javac
someName.java.
- 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>
Download the source
code (HelloWorldApplet.java)
Download the
byte code (HelloWorldApplet.class)
Compiling and Running Java Applets
- Edit a Java source code file someAppletName.java.
- Compile your program with javac
someAppletName.java.
- 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
- Uppercase and lowercase letters (A-Z, a-z)
- Numbers (0-9). Must not begin with a
number.
- Underscores (_)
- 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 |
Back to the CTEC1641 Page