Introduction to Java - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

Introduction to Java

Description:

Java: A simple, object-oriented, network-savvy, interpreted, robust, secure, ... end of their eggs, by which he would remain the sole monarch of the whole world. ... – PowerPoint PPT presentation

Number of Views:21
Avg rating:3.0/5.0
Slides: 31
Provided by: kurtdfens
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Java


1
Introduction to Java
Java A simple, object-oriented, network-savvy,
interpreted, robust, secure, architecture
neutral, portable, high-performance,
multithreaded, dynamic language.
  • CS 102-02
  • Lecture 1-2

April 1, 1998
CS102-02 Lecture 1-2
2
A History of the Java-Speaking Peoples
  • Video on demand needs set-top boxes
  • Set-top boxes need a small, network-friendly
    programming language
  • Do you have video on demand? Neither does anyone
    else.
  • Web catches on, needs small, network-friendly
    programming language
  • And the rest is history...

3
What is Java?
Java A simple, object-oriented, network-savvy,
interpreted, robust, secure, architecture
neutral, portable, high-performance,
multithreaded, dynamic language.
  • Programming language
  • Computers are stupid
  • Step-by-step instructions
  • Human languages allow for too much ambiguity
  • The policeman hit the boy with the stick.

April 1, 1998
CS102-02 Lecture 1-2
4
Object-oriented
Java A simple, object-oriented, network-savvy,
interpreted, robust, secure, architecture
neutral, portable, high-performance,
multithreaded, dynamic language.
  • A world full of objects
  • Programming a computer means translating those
    objects
  • OO languages make it easy to specify objects and
    their relationships

April 1, 1998
CS102-02 Lecture 1-2
5
Writing for Networks
Java A simple, object-oriented, network-savvy,
interpreted, robust, secure, architecture
neutral, portable, high-performance,
multithreaded, dynamic language.
  • Network rules of the road
  • Protocols TCP/IP, HTTP FTP
  • Understand URLs
  • Distributed programming
  • Get other computers to do your work for you
  • Example RC5 code-breaking

April 1, 1998
CS102-02 Lecture 1-2
6
Interpreted
Java A simple, object-oriented, network-savvy,
interpreted, robust, secure, architecture
neutral, portable, high-performance,
multithreaded, dynamic language.
  • Computers dont speak Java as a native language
  • Two ways to translate a book
  • One line at a time for each person who reads it
  • Do the whole thing at once

April 1, 1998
CS102-02 Lecture 1-2
7
Run Anywhere
Java A simple, object-oriented, network-savvy,
interpreted, robust, secure, architecture
neutral, portable, high-performance,
multithreaded, dynamic language.
  • Different strokes for different folks
  • Should you break eggs at the little end or the
    big end?
  • Look feel
  • Byte-codes are universal
  • Virtual machines are virtually the same

April 1, 1998
CS102-02 Lecture 1-2
8
My Platform is Better than Yours
His Majesty desired I would take some other
opportunity of bringing all the rest of his
enemy's ships into his ports. And so unmeasurable
is the ambition of princes, that he seemed to
think of nothing less than reducing the whole
empire of Blefuscu into a province, and governing
it by a Viceroy of destroying the Big-Endian
exiles, and compelling that people to break the
smaller end of their eggs, by which he would
remain the sole monarch of the whole world. --
Gullivers Travels by Jonathan Swift
April 1, 1998
CS102-02 Lecture 1-2
9
How to Do More thanOne Thing at a Time
Java A simple, object-oriented, network-savvy,
interpreted, robust, secure, architecture
neutral, portable, high-performance,
multithreaded, dynamic language.
  • One processor means one thing at a time
  • Switching among many tasks quickly is tough
  • Lots to track
  • Use the computer to track it all

April 1, 1998
CS102-02 Lecture 1-2
10
Simple?! (Maybe Similar)
Java A simple, object-oriented, network-savvy,
interpreted, robust, secure, architecture
neutral, portable, high-performance,
multithreaded, dynamic language.
  • Looks like C/C
  • Good for existing programmers
  • Scheme is simple, but Java isnt

April 1, 1998
CS102-02 Lecture 1-2
11
Simple Harder to Hurt Yourself
Java A simple, object-oriented, network-savvy,
interpreted, robust, secure, architecture
neutral, portable, high-performance,
multithreaded, dynamic language.
  • Removed some of C/Cs foot-shooting ability
  • Useful but difficult to use well
  • Memory management
  • Multiple inheritance
  • Operator overloading

April 1, 1998
CS102-02 Lecture 1-2
12
Do You Know Where Your Code Has Been?
Java A simple, object-oriented, network-savvy,
interpreted, robust, secure, architecture
neutral, portable, high-performance,
multithreaded, dynamic language.
  • Robust means its hard to break things
  • Dont talk to strangers
  • How do you know whos a stranger over a network?
  • Use a secret code!

April 1, 1998
CS102-02 Lecture 1-2
13
The Dynamic Uno
Java A simple, object-oriented, network-savvy,
interpreted, robust, secure, architecture
neutral, portable, high-performance,
multithreaded, dynamic language.
  • Dont do today what you can put off until
    tomorrow
  • Either always carry suntan lotion and an
    umbrella, OR wait for the sun to come out
  • Waiting is dynamic, or run-time, lookup

April 1, 1998
CS102-02 Lecture 1-2
14
High-Octane Programming
Java A simple, object-oriented, network-savvy,
interpreted, robust, secure, architecture
neutral, portable, high-performance,
multithreaded, dynamic language.
  • Java runs more slowly for two reasons
  • Dynamic means waiting 'til a program runs to do
    some housekeeping
  • Interpreted means translating each line every
    time
  • Just-in-time compilation

April 1, 1998
CS102-02 Lecture 1-2
15
A First Java Program
  • // A first program in Java
  • // import Applet class
  • import java.applet.Applet
  • // import Graphics class
  • import java.awt.Graphics
  • public class Welcome extends Applet
  • public void paint( Graphics g )
  • g.drawString( "Welcome to Java
    Programming!", 25, 25 )

16
Run It, and Ta-Da!
Prints out the message Welcome to Java
Programming! at a specified location
April 1, 1998
CS102-02 Lecture 1-2
17
Got Something to Say?
// A first program in Java // import Applet
class import java.applet.Applet // import
Graphics class import java.awt.Graphics public
class Welcome extends Applet public void
paint( Graphics g ) g.drawString(
"Welcome to Java Programming!", 25, 25 )
Comments are key The life you save might be your
own...
18
It Aint International Trade
// A first program in Java // import Applet
class import java.applet.Applet // import
Graphics class import java.awt.Graphics public
class Welcome extends Applet public void
paint( Graphics g ) g.drawString(
"Welcome to Java Programming!", 25, 25 )
import puts your code on a first-name basis with
existing class(es)
19
Everythings a Class
// A first program in Java // import Applet
class import java.applet.Applet // import
Graphics class import java.awt.Graphics public
class Welcome extends Applet public void
paint( Graphics g ) g.drawString(
"Welcome to Java Programming!", 25, 25 )
In Java, writing a program means creating a
class Call me Welcome -- Moby Java
20
Using Someone Elses Wheel
// A first program in Java // import Applet
class import java.applet.Applet // import
Graphics class import java.awt.Graphics public
class Welcome extends Applet public void
paint( Graphics g ) g.drawString(
"Welcome to Java Programming!", 25, 25 )
Inheritance in action A Welcome is a kind of
Applet
21
Why Bother?
Put away that checkbook! Look at all you get
with the amazing new Applet class!
getParameterInfo() Returns information about
the parameters than are understood by this
applet. init() Called by the browser or applet
viewer to inform this applet that it has been
loaded into the system. isActive() Determines
if this applet is active. play(URL) Plays the
audio clip at the specified absolute URL.
play(URL, String) Plays the audio clip given
the URL and a specifier that is relative to it.
resize(Dimension) Requests that this applet be
resized. resize(int, int) Requests that this
applet be resized. setStub(AppletStub) Sets
this applet's stub. showStatus(String) Requests
that the argument string be displayed in the
"status window". start() Called by the browser
or applet viewer to inform this applet that it
should start its execution. stop() Called by
the browser or applet viewer to inform this
applet that it should stop its execution.
destroy() Called by the browser or applet viewer
to inform this applet that it is being reclaimed
and that it should destroy any resources that it
has allocated. getAppletContext() Determines
this applet's context, which allows the applet to
query and affect the environment in which it
runs. getAppletInfo() Returns information about
this applet. getAudioClip(URL) Returns the
AudioClip object specified by the URL argument.
getAudioClip(URL, String) Returns the AudioClip
object specified by the URL and name arguments.
getCodeBase() Gets the base URL.
getDocumentBase() Gets the document URL.
getImage(URL) Returns an Image object that can
then be painted on the screen. getImage(URL,
String) Returns an Image object that can then be
painted on the screen. getLocale() Gets the
Locale for the applet, if it has been set.
getParameter(String) Returns the value of the
named parameter in the HTML tag.
22
Applets Inherit Too
23
Painting Pretty Pictures
// A first program in Java // import Applet
class import java.applet.Applet // import
Graphics class import java.awt.Graphics public
class Welcome extends Applet public void
paint( Graphics g ) g.drawString(
"Welcome to Java Programming!", 25, 25 )
When the browser wants to show an applet, it
calls paint() Welcome ? Applet because Welcome
has its own paint()
24
Is There an Artist in the House?
// A first program in Java // import Applet
class import java.applet.Applet // import
Graphics class import java.awt.Graphics public
class Welcome extends Applet public void
paint( Graphics g ) g.drawString(
"Welcome to Java Programming!", 25, 25 )
Browser says, Paint this! and passes a Graphics
object Call it g for short
25
Scribbling Strings
// A first program in Java // import Applet
class import java.applet.Applet // import
Graphics class import java.awt.Graphics public
class Welcome extends Applet public void
paint( Graphics g ) g.drawString(
"Welcome to Java Programming!", 25, 25 )
Graphics objects know how to print strings
26
Pick a String, Any String
// A first program in Java // import Applet
class import java.applet.Applet // import
Graphics class import java.awt.Graphics public
class Welcome extends Applet public void
paint( Graphics g ) g.drawString(
"Welcome to Java Programming!", 25, 25 )
If you want to draw a string, youve gotta
specify A string (Given in quotes here because
we want a literal string) and...
27
Where do you want it?
// A first program in Java // import Applet
class import java.applet.Applet // import
Graphics class import java.awt.Graphics public
class Welcome extends Applet public void
paint( Graphics g ) g.drawString(
"Welcome to Java Programming!", 25, 25 )
Start in the upper-left hand corner and count 25
(pixels) over, then 25 down
28
Graphics Know-It-All
// A first program in Java // import Applet
class import java.applet.Applet // import
Graphics class import java.awt.Graphics public
class Welcome extends Applet public void
paint( Graphics g ) g.drawString(
"Welcome to Java Programming!", 25, 25 )
g.drawOval(5, 5, 220, 35)

29
New Improved
30
What is Java?
  • Convenient language for building networked
    applications
  • Designed to be easy for current programmers to
    learn
  • Protects you from yourself
  • Handy for creating dancing babies
Write a Comment
User Comments (0)
About PowerShow.com