Beruflich Dokumente
Kultur Dokumente
Subjects
Two ways to write and execute a Java Program
Java Applications
writing, compiling, running a Java Application
anatomy of a java program
Java Applets
writing, compiling, running an Java Applet
anatomy of a Java Applet
Java Jumpstart
Java Jumpstart
Java Jumpstart
Java Jumpstart
Java Jumpstart
10
Applet Edit
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
10
11
Applet Compile
The same as with Java Application
Enter on a commandline:
javac HelloApplet.java
Java Jumpstart
11
12
<html>
<head>
<title>HelloApplet html file</title>
</head>
<body>
<h1>HelloApplet html file</h1>
<applet code="HelloApplet.class" height="100" width="200">
</applet>
</body>
</html>
12
13
13
14
14
15
Java Jumpstart
15
16
16
17
Java Jumpstart
17
18
Anatomy drawString()
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
Calling drawString()
...
g.drawString("Hello World", 50, 50);
...
Java Jumpstart
18
19
Java Jumpstart
19
LABS
1. HelloWorld Application
This lab is meant to make you familiar with the J2SE environment. by making the HelloWorld application.
1. Create HelloWorld.java with a text editor.
2. Compile HelloWorld.java with the "javac" command.
3. Run HelloWorld with the "java" command.
If you see something like
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
.
13. Where is the HelloWorld.class now located ?
14. Run the HelloWorld program by typing "java mypackage.HelloWorld". What do you observe ?
15. Adapt the CLASSPATH by typing
set CLASSPATH=myclasses;%CLASSPATH%
16. Run the HelloWorld program by typing "java mypackage.HelloWorld". What do you observe ?
2. Add a line that reads the int from the standard input (keyboard) using i = System.in.read()
3. Compile and run.
4. Type a number. What do you observe ? (Hint: what about bytes?)
21
22
RESOURCES
[javasoft52]
JavaSoft ; The Java Tutorial Trail: Getting Started ; From the Java Tutorial. Contains
detailed instructions for compiling and running your first program.
http://www.javasoft.com/docs/books/tutorial/getStarted/TOC.html
[baldwin010]
Richard G. Baldwin ; Hello World ; This lesson introduces you to Java programming by
presenting and discussing some different versions of the Hello World program.
http://www.dickbaldwin.com/java/Java010.htm
[baldwin012]
[baldwin014]
[baldwin016]
[baldwin017]
[baldwin018]
[baldwin032]
[baldwin052]
[baldwin054]
23