13 x 11 java lecture 1 cs 1311 introduction 13 x 11

Post on 01-Apr-2015

223 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

13X11

Java Lecture 1

CS 1311

Introduction

13X11

13X11

Serious Stuff

13X11

Put these in order

• Avoid damage to equipment and material• Get the job done• Avoid injuries• Maintain good community relations

13X11

Normal World

• Avoid injuries• Avoid damage to equipment and material• Get the job done• Maintain good community relations

13X11

Military@War

• Get the job done • Avoid injuries• Avoid damage to equipment and material• Maintain good community relations

13X11

Ballistics

?

v0

13X11

Ballistics

v0

13X11

Ballistics

vx

vy

v0

13X11

Ballistics

vx

vy

v0

t

13X11

Ballistics

vx

vy

v0

t

t

13X11

Ballistics

vx

vy

v0

t

t

13X11

Ballistics

vx

vy

v0

t

t

Assumptions• Flat non-rotating earth• Vacuum• Constant gravity

13X11

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?

13X11

Let's invent a computer

13X11

Computer Programming

• Initially by hand• Big breakthrough: Machine translation• Analysis of computation• Church-Turing

Functional Imperative/Procedural

13X11

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

13X11

Origins of OO

• USAF ATC Randolph AFB B220

Locations

Routines

Data

13X11

Origins of OO

• USAF ATC Randolph AFB B220• Simulation

MachinesWorkers

Products

Conveyor

13X11

Origins of OO

• USAF ATC Randolph AFB B220• Simulation• Large scale projects

13X11

Origins of OO

• USAF ATC Randolph AFB B220• Simulation• Large scale projects• GUI's

13X11

So what is it?

• A brief overview• My favorite example

Queue

13X11

Chez Guillaume

• Application to maintain 2 queues• Allow adding to either list• Allow removing from either list

13X11

How might it be done?

Enqueue Module

Dequeue Module

isEmpty Module

head.tailRestaurant Module

head.tail Input Module

Output Module

Menu Module

Data Structure

Data Structure

13X11

How might it be done?

Enqueue Module

Dequeue Module

isEmpty Module

head.tailRestaurant Module

head.tail Input Module

Output Module

Menu Module

Data Structure

Data Structure

Where isthe queue?

The OO ApproachRestaurant Object

Input Module

Output Module

Menu Module

Data Objects

Queue Object

Enqueue Module

Dequeue Module

isEmpty Module

head.tail

Queue Object

head.tail

Enqueue Module

Dequeue Module

isEmpty Module

Data Object

Get Data Module

Set Data Module

Cust Data

Ref

13X11

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?

13X11

Goals

• Encapsulation• Reusability• Adaptability/Flexibility• Decentralization/Distribution

13X11

OOP Terminology

• Abstract Data Type• Class• Object• Method• Fields/Attributes• References

13X11

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...

13X11

Java

• Toasters• Smart cards• Killer apps• The wwweb

13X11

Java, the good news

• Real• Very powerful• In demand• Software engineering• Universal

13X11

Java, the bad news

• Real• Very powerful• Not an educational language• Jack of all trades/Master of none• Slow

13X11

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

13X11

Translation

• Compilation– Fortran– Cobol– Pascal– Algol– C/C++

• Interpretation– Basic– Lisp– Scheme

13X11

Emulation

• How to sell a new computer to someone with lots of software?

• Emulate the old hardware!

OldSoftware

New Computer

ProgramEmulating

Old Computer

13X11

The Java Approach

• Compilation into ByteCode

JavaSource

ByteCode

Javac Compiler

13X11

The Java Approach

• Interpretation by the Java Virtual Machine

Any Computer

JavaVirtual

Machine

ByteCode

13X11

Why is this cool?

13X11

The Internet©Al Gore

JavaSource

ByteCode

Javac Compiler

Do this once

Web Server

Your Computer

Your Favorite Browser

JavaVirtual

Machine

13X11

“Source Code” [.java]

Javacompiler

Generic“Byte Code” [.class]

OS-specificJVM

interpreter

Executeprogram

Compilation/Execution

Need one of these for every different

OS

13X11

Sample Application

public class HelloWorld

{

public static void main(String argv[])

{

System.out.println(“Hello World!”);

}

}

We create a file (using an editor) called “HelloWorld.java”

We compile by typing (at the OS prompt):

javac HelloWorld.java

Which produces HelloWorld.class

Then we execute by typing:

java HelloWorld

Hello World!

13X11

Demo

>javac HelloWorld.java

>java HelloWorld

Hello World!

>

13X11

Quick Trix

• The name of the file must match the name of the class EXACTLY!!!• File: Bubba.java• Contains:

• Everything must be EXACTLY correct!!!

class Bubba{...

Capitalization counts

13X11

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

13X11

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.

13X11

Questions?

13X11

top related