Transcript 13X11

Java Lecture 1
CS 1311
Introduction
X11
13
Serious Stuff
X11
13
Put these in order
•
•
•
•
Avoid damage to equipment and material
Get the job done
Avoid injuries
Maintain good community relations
X11
13
Normal World
•
•
•
•
Avoid injuries
Avoid damage to equipment and material
Get the job done
Maintain good community relations
X11
13
Military@War
•
•
•
•
Get the job done
Avoid injuries
Avoid damage to equipment and material
Maintain good community relations
X11
13
Ballistics
v0

?
X11
13
Ballistics
v0

X11
13
Ballistics
v0

vy
vx
X11
13
Ballistics
t
v0

vy
vx
X11
13
Ballistics
t
v0

vy
vx
t
X11
13
Ballistics
t
v0

vy
vx
t
X11
13
Ballistics
Assumptions
• Flat non-rotating earth
• Vacuum
• Constant gravity
t
v0

vy
vx
t
X11
13
Ballistics Calculations
• Required rooms full of mathematicians
• Very slow, tedious work
• Anything that would help could help to win the war
• Money no object
• Commercialization not considered
• Software Engineering?
X11
13
Let's invent a computer
X11
13
Computer Programming
•
•
•
•
Initially by hand
Big breakthrough: Machine translation
Analysis of computation
Church-Turing
Functional
Imperative/Procedural
X11
13
Paradigm Review
• Functional Programming
– Mathematical base
– Provably correct
– Disassociated from machine model
• Imperative/Procedural Programming
– Machine oriented
– Mathematical ties
• Object Oriented Programming
– Some features of both
– Result of industry maturation & growth
X11
13
Origins of OO
• USAF ATC Randolph AFB B220
Locations
Routines
Data
X11
13
Origins of OO
• USAF ATC Randolph AFB B220
• Simulation
Products
Conveyor
Workers
Machines
X11
13
Origins of OO
• USAF ATC Randolph AFB B220
• Simulation
• Large scale projects
X11
13
Origins of OO
•
•
•
•
USAF ATC Randolph AFB B220
Simulation
Large scale projects
GUI's
X11
13
So what is it?
• A brief overview
• My favorite example
Queue
X11
13
Chez Guillaume
• Application to maintain 2 queues
• Allow adding to either list
• Allow removing from either list
X11
13
How might it be done?
head.tail
Restaurant Module
Enqueue Module
Data Structure
Dequeue Module
isEmpty Module
head.tail
Input Module
Output Module
Data Structure
Menu Module
X11
13
How might it be done?
head.tail
Restaurant Module
Enqueue Module
Data Structure
Dequeue Module
isEmpty Module
head.tail
Input Module
Output Module
Data Structure
Where is
the queue?
Menu Module
X11
13
The OO Approach
Queue Object
head.tail
Enqueue Module
Restaurant Object
Ref
Queue Object
head.tail
Dequeue Module
isEmpty Module
Enqueue Module
Input Module
Output Module
Menu Module
Dequeue Module
isEmpty Module
Data Object
Cust Data
Data Objects
Get Data Module
Set Data Module
The OO Approach
• Why do we want a new language?
• Why do we want to arrange things in such a
fashion?
• What are the goals?
X11
13
Goals
•
•
•
•
Encapsulation
Reusability
Adaptability/Flexibility
Decentralization/Distribution
X11
13
OOP Terminology
•
•
•
•
•
•
Abstract Data Type
Class
Object
Method
Fields/Attributes
References
X11
13
Characteristics of OOP Language
• Everything is an object
• A program is a bunch of objects telling each other
what to do by sending each other messages
• Each object has its own memory made up of other
objects
• Every object has a type which in OO terms means
that every object is an instance of some class
• All objects of a particular type can receive the
same messages. An object of type circle will also
be an object of type shape thus...
X11
13
Java
•
•
•
•
Toasters
Smart cards
Killer apps
The wwweb
X11
13
Java, the good news
•
•
•
•
•
Real
Very powerful
In demand
Software engineering
Universal
X11
13
Java, the bad news
•
•
•
•
•
Real
Very powerful
Not an educational language
Jack of all trades/Master of none
Slow
X11
13
Clever Java Stuff
•
•
•
•
•
Java program can be run by web browser
Borrowed a lot of syntax from c and c++
Give it away
WORA
Security
X11
13
Translation
• Compilation
–
–
–
–
–
Fortran
Cobol
Pascal
Algol
C/C++
• Interpretation
– Basic
– Lisp
– Scheme
X11
13
Emulation
• How to sell a new computer to someone with lots
of software?
• Emulate the old hardware!
New Computer
Old
Software
Program
Emulating
Old Computer
X11
13
The Java Approach
• Compilation into ByteCode
Java
Source
Javac Compiler
Byte
Code
X11
13
The Java Approach
• Interpretation by the Java Virtual Machine
Any Computer
Byte
Code
Java
Virtual
Machine
X11
13
Why is this cool?
X11
13
The Internet
Java
Source
©Al Gore
Do this once
Javac Compiler
Byte
Code
Your Computer
Web Server
Your Favorite Browser
Java
Virtual
Machine
X11
13
Compilation/Execution
“Source
Code” [.java]
Java
compiler
Execute
program
Generic
“Byte Code” [.class]
OS-specific
JVM
interpreter
Need one of these
for every different
OS
X11
13
Sample Application
We create a file (using an editor) called “HelloWorld.java”
public class HelloWorld
{
public static void main(String argv[])
{
System.out.println(“Hello World!”);
}
}
We compile by typing (at the OS prompt):
javac HelloWorld.java
Hello World!
Which produces HelloWorld.class
Then we execute by typing:
java HelloWorld
X11
13
Demo
>javac HelloWorld.java
>java HelloWorld
Hello World!
>
X11
13
Quick Trix
• The name of the file must match the name of the
class EXACTLY!!!
• File: Bubba.java
Capitalization counts
• Contains:
class Bubba
{...
• Everything must be EXACTLY correct!!!
X11
13
A Final Word
• static
• static is a source of great confusion and
sometimes even frustration
• Here's the basic idea (don't worry if this is
confusing we'll explain it again
• and again
• and again
• and again
X11
13
Java Structure
• Java programs consist entirely of files containing
classes
• Classes are like blueprints or templates
• They describe the structure and operation of
objects.
• Objects are like whatever is made from a
blueprints or template.
• Objects are considered to be dynamic
• Sometimes there is a need for something to not
be dynamic hence you may declare it static.
X11
13
Questions?
X11
13
X11
13