Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
CS413: Java
Programming language
Applications
Applets
Conceived by Sun Microsystems
Benefits
Runs on any Java enabled Web Browser
No installation or setup adjustments
No need to scan for viruses
Can create large graphics (charts, tables) on the fly
No need to download large graphics
Increase download speed
Security Features
Runtime examination: program is examined line-by-line for
valid Java only code
Restricted Interactivity:
Built-in restrictions on establishing connections to other
computers
The Java applet can only connect to the Internet location it
came from
Restricted Access Rights:
Built in restrictions on a program being able to
read and write data
A program can only access the parts of a
computer where it has received advance
permission to access
cs413_java01.ppt
CS413: Java
Usage samples
Interaction with a user
Calculate information of a web page
Administer a quiz
‘Dress’ a web page
Control animation on a web page
Control GUI interfaces
Open System
Any hardware or software product that matches the published
specifications
Published specifications establish a shared definition of how
components must work together
Sun Microsystems has published detailed specifications
for Java
A program written in Java can run on any Java-enabled system
with no adaptation required
Permits programs to be:
More widely distributed
More easily easily used
cs413_java01.ppt
CS413: Java
Java Applet (Internet Web Page)
Manipulate words, numbers, and pictures
Create and control GUI interface
Display windows, buttons, and menus
User to point and click with a mouse to control actions
Information displayed in a variety of colours, styles, and sizes
Graphical User Interface (GUI)
Enables the user to do all of the above to make the web page/site
easier and more interesting to use
cs413_java01.ppt
CS413: Java
Java Applet
•
A mini program written Java and attached to a
web page
Fast to download
•
Enhance the web page display
•
Enable the user to interact with the web page
•
Enable the user to complete specific tasks
•
Manipulates data
•
Creates graphics
cs413_java01.ppt
CS413: Java
Programmer
Text file
Extension of
.java
Java
compiler
Executable Java
applet
.class
HTML page
Java enabled
browser
anyname.html
cs413_java01.ppt
User
Source Code
anyname.java
Java compiler
javac
Applet file
‘Bytecode’
anyname.class
HTML page
anyname.html
HTML page
Java translator
anyname.html
CS413: Java
Assembler
• Creates a machine language executable file (program)
• Programs written in Assembler language
• Each Assembler language instruction generates one
machine language instruction
• Fast execution
Compiler
• Creates a machine language executable file (program)
• Programs written in higher level languages
COBOL, PL1, RPG, FORTRAN
• Each programming language instruction generates one
or more machine language instructions
• Fast execution
cs413_java01.ppt
CS413: Java
Translator
• DOES NOT create machine language executable file
(program)
• Limited instruction set (compared to Assembly and
Compiler languages)
• Slow processing
Every instruction is read from the input file and
processed individually
1. Instruction is read into the translator
2. Converted by the ‘Translator’ to 1 or more
machine language instructions
3. Instruction is executed
4. Cycle starts again with next instruction
• Slow processing due to
• Loops
• Decision blocks
cs413_java01.ppt
CS413: Java
Java creation/compile/execution (translation)
Using DOS
1.
Create the Java code in a text editor
2.
Save the file somename.java extension
3.
Open a DOS window
4.
Enter path command at the c:\windows> prompt
path=c:\jdk1.2.2\bin
5.
Change DOS directory to where the .java file is located
6.
Enter javac somename.java
To compile the Java code to a .class file
7.
Fix any errors and re-compile (Step 6)
8.
When no more errors - continue
9.
Enter java somename
To execute the compiled version
cs413_java01.ppt
CS413: Java
Java creation/compile/execution (translation)
Using Java Development Kit (JDK)
cs413_java01.ppt
CS413: Java
LAB I: Java program
import java.applet.*;
import java.awt.*;
/**
This is a comment block
*/
public class HelloWorld extends Applet {
Label helloLabel = new Label(“Yo, you lookin’ at me?”);
public void init() {
setBackground(Color.yellow);
add(helloLabel);
}
}
cs413_java01.ppt
CS413: Java
Java code in a Web page
1.
Create an HTML document in a text editor
Save as .htm or .html file
2.
Insert the following Java code in the <body> area of
the HTML file
3.
<APPLET CODE= “somename.class”
width=300 height = 50></APPLET>
4.
Open the .htm/.html file in a browser
Basic HTML Document
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
</BODY>
</HTML>
cs413_java01.ppt
CS413: Java
Java Program Description
import java.applet.*;
Reference a Java library of pre-written code
* = make all library code members accessible
import java.awt.*;
Reference a Java library of pre-written code
* = make all library code members accessible
/**
begin comment area
This is a comment block
*/
end comment area
public class HelloWorld extends Applet {
public = the applet is accessible by outside programs
class = defines this applet as a Java class
HelloWorld = name of the Java class
extends Applet = required for a Java class declaration
Label helloLabel = new Label(“Yo, you lookin’ at me?”);
Label = Java code from the Java.awt library
Display something on the screen
helloLabel = programmer name of the Label
new Label = Java definition creating the Label
( ….) = Text to be displayed on the screen
cs413_java01.ppt
CS413: Java
Java Program Description
public void init() {
Define what is to happen at applet initalization
setBackground(Color.yellow);
Set the background color to yellow
add(helloLabel);
Add the data from helloLabel to the graphic
}
}
cs413_java01.ppt
end of ‘public void’ method
end of entire applet