Lecture Slides on Applications and Applets - Introduction to Computing Using Java | CS 1110, Study notes of Computer Science

Material Type: Notes; Professor: Gries; Class: Introduction to Computing Using Java; Subject: Computer Science; University: Cornell University; Term: Fall 2008;

Typology: Study notes

Pre 2010

Uploaded on 08/31/2009

koofers-user-mzu
koofers-user-mzu 🇺🇸

5

(1)

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1!
1!
CS100J 2 December 2008!
Applications and Applets!
Read Chapter 16 of the text "
We also look at html, since !
we need it to use applets.!
Top finalists from a real-life “Dilbert quotes contest”!
As of tomorrow, employees will be able to access"the building only using
individual security cards."Pictures"will be taken next Wednesday and employ-
ees will receive"their cards in two weeks." (Fred Dales,"Microsoft)!
I need an exact list of specific unknown problems"we might encounter. (Lykes
Lines Shipping)!
Email is not to be used to pass on information or data.""It should be used!
only for company business. (Accounting manager, Electric Boat Company)!
This project is so important, we can't let things that"are more important
interfere with it. (Advertising/Marketing manager, United Parcel Service)!
Doing it right is no excuse for not meeting the schedule. (Plant manager, Delco
Corporation)!
2!
Online Course Evaluations "
Completing the online course evaluation for CS1110!
is a part of the course. It counts the same amount!
toward your final total weighted score as a quiz.!
Please complete it! !
You received an email about it, with the web address.!
Engineering started online evaluations in about 2004. Now
A&S, CALS, and HE also do it, and there will be ONE site
for all courses. Togetherness! !
3!
Executing Java programs outside the DrJava Interactions pane. "
Every Java program is either an application or an applet."
public class C {!
!
public static void main(String[] args) {!
!
}!
!
}!
A Java application needs
a class with a method
main that is defined like
this.!
To start the application,
method main is called.!
The parameter, an array of Strings, can
be used to pass information into the
program.!
4!
public class CLAS {!
!
public static void main(String[] args) {!
!
}!
!
}!
> cd!
> dir!
(list of files)!
> java CLAS!
Terminal window"
(can type “java CLAS” in DrJava Interactions pane)"
Causes method call!
CLAS.main(null);!
to be executed!
5!
jar file (Java Archive file)"
(like tar file (Tape Archive file))!
Contains (among other things)!
(1).class files!
(2)a “manifest”, which says which class has method main!
Manifest:"
A list of passengers or an invoice of cargo for a vehicle
(as a ship or plane).!
6!
Standalone Java programs"
Suppose images.jar contains a Java application"
It has a class with a static procedure main,!
and its manifest names the class.!
• Execute it by double clicking its icon in a directory.!
• Execute it by typing!
java -jar images.jar!
in a terminal window (or DOS, or command-line window)!
pf2

Partial preview of the text

Download Lecture Slides on Applications and Applets - Introduction to Computing Using Java | CS 1110 and more Study notes Computer Science in PDF only on Docsity!

1

CS100J 2 December 2008

Applications and Applets

Read Chapter 16 of the text

We also look at html, since 

we need it to use applets.

Top finalists from a real-life “Dilbert quotes contest” As of tomorrow, employees will be able to access the building only using individual security cards. Pictures will be taken next Wednesday and employ- ees will receive their cards in two weeks." (Fred Dales, Microsoft) I need an exact list of specific unknown problems we might encounter. (Lykes Lines Shipping) Email is not to be used to pass on information or data. It should be used only for company business. (Accounting manager, Electric Boat Company) This project is so important, we can't let things that are more important interfere with it. (Advertising/Marketing manager, United Parcel Service) Doing it right is no excuse for not meeting the schedule. (Plant manager, Delco Corporation) 2

Online Course Evaluations

Completing the online course evaluation for CS

is a part of the course. It counts the same amount

toward your final total weighted score as a quiz.

Please complete it!

You received an email about it, with the web address.

Engineering started online evaluations in about 2004. Now

A&S, CALS, and HE also do it, and there will be ONE site

for all courses. Togetherness!

3 Executing Java programs outside the DrJava Interactions pane. Every Java program is either an application or an applet. public class C { … public static void main(String[] args) { … } … }

A Java application needs

a class with a method

main that is defined like

this.

To start the application,

method main is called.

The parameter, an array of Strings, can

be used to pass information into the

program.

4 public class CLAS { … public static void main(String[] args) { … } … }

> cd

> dir

(list of files)

> java CLAS

Terminal window (can type “java CLAS” in DrJava Interactions pane)

Causes method call

CLAS.main(null);

to be executed

5

jar file (Java Archive file)

(like tar file (Tape Archive file))

Contains (among other things)

(1) .class files

(2) a “manifest”, which says which class has method main

Manifest:

A list of passengers or an invoice of cargo for a vehicle

(as a ship or plane).

6

Standalone Java programs

Suppose images.jar contains a Java application

It has a class with a static procedure main,

and its manifest names the class.

  • Execute it by double clicking its icon in a directory.
  • Execute it by typing

java -jar images.jar

in a terminal window (or DOS, or command-line window)

7

Creating a jar file

1. Navigate to the directory that contains the .class files.

2. Create a text file x.mf that contains one line (with a line-feed):

Main-class:

3. In the directory, type:

jar -cmf x.mf app.jar *.class

Create Manifest File

name of

manifest file

name of file

to create

expands to

name all

the .class files 8

Inspecting jar files

jar -tf images.jar

type (list)

File name of

jar file

List the contents of jar

file images.jar

9

Applet: a java program that can be called

from a web page (in your browser)

public class C { public static void main(String[] args) { … } } application import javax.swing.; public class* A extends JApplet{ public void init() { … } public void start() { …} public void stop() { … } public void destroy() { … } } applet

Four inherited procedures:

called to initialize

called to start processing

called to stop processing

called to destroy resources

(just before killing the applet)

10

tags

An html (HyperText Markup Language) file

Just a title

Demo Links and Images

This is a link

This link opens a new window

Below is an image

**** start an html page **** start the “heading” **** the title for the page <body> start the body, content, of the page <p> begin a paragraph <a> begin a link <img> begin an image 11 An html (HyperText Markup Language) file <html> <head> <title>FacultyApplet

This is an Applet!

**tags ** start an html page **** start the “heading” **** the title for the page <body> start the body, content, of the page <p> begin a paragraph <b> begin boldface <i> begin italics <applet> start a Java applet <br> line break (no end tag)