Java Crash Course: A Tutorial Introduction For C++ Programmers
Java Crash Course: A Tutorial Introduction For C++ Programmers
source code
run HelloWorld.class
Put in test.html:
<html>
<title>Test the applet</title>
<body>
<h3>Test the applet</h3>
<applet code=“HelloWorld.class” height=“200”
width=“300”>
</applet>
</body></html>
Cool Applet Methods
Basic methods on Applet
init(): called once for your applet
start(): called every time you enter the page
stop(): called every time you leave the page
destroy(): called when your page is discarded
Funky methods on Applet
AudioClip getAudioClip(URL url): gets audioClip object (play
with audioClip.play())
Image getImage(URL url): starts asynchronous image loading
java.net.URL constructor takes normal string argument (used to
store URLs)
void showDocument(URL url): tells browser to load new
document
void showStatus(String msg): writes to browser status line
Applet repainting
paint(): defaults to nothing
update(): clears screen, calls paint()
repaint(): passes events to Motif/Win32 don’t override/change this
Java Language Basics
Data types same as in C++ (except bool)
bool,char,byte,short,int,long,float,
double,string, etc.
Operators (same as C++)
Assignment: =, +=, -=, *=, …
Numeric: +, -, *, /, %, ++, --, …
Relational: ==. !=, <, >, <=, >=, …
Boolean: &&, ||, !
Bitwise: &, |, ^, ~, <<, >>, …
Point p;
int[] values;
int total=0;
for (int i=0;i<value.length;i++) {
total += values[i];
}
Array Literals
You can use array literals like
C/C++ (no need for new keyword):