Top Banner
13X11 Java Lecture 1 CS 1311 Introduction 13X11
47
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Java Lecture 1

CS 1311

Introduction

13X11

Page 2: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Serious Stuff

Page 3: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Put these in order

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

Page 4: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Normal World

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

Page 5: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Military@War

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

Page 6: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Ballistics

?

v0

Page 7: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Ballistics

v0

Page 8: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Ballistics

vx

vy

v0

Page 9: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Ballistics

vx

vy

v0

t

Page 10: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Ballistics

vx

vy

v0

t

t

Page 11: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Ballistics

vx

vy

v0

t

t

Page 12: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Ballistics

vx

vy

v0

t

t

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

Page 13: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

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?

Page 14: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Let's invent a computer

Page 15: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Computer Programming

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

Functional Imperative/Procedural

Page 16: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

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

Page 17: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Origins of OO

• USAF ATC Randolph AFB B220

Locations

Routines

Data

Page 18: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Origins of OO

• USAF ATC Randolph AFB B220• Simulation

MachinesWorkers

Products

Conveyor

Page 19: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Origins of OO

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

Page 20: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Origins of OO

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

Page 21: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

So what is it?

• A brief overview• My favorite example

Queue

Page 22: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Chez Guillaume

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

Page 23: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

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

Page 24: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

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?

Page 25: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

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

Page 26: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

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?

Page 27: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Goals

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

Page 28: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

OOP Terminology

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

Page 29: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

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

Page 30: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Java

• Toasters• Smart cards• Killer apps• The wwweb

Page 31: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Java, the good news

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

Page 32: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Java, the bad news

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

Page 33: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

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

Page 34: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Translation

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

• Interpretation– Basic– Lisp– Scheme

Page 35: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Emulation

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

• Emulate the old hardware!

OldSoftware

New Computer

ProgramEmulating

Old Computer

Page 36: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

The Java Approach

• Compilation into ByteCode

JavaSource

ByteCode

Javac Compiler

Page 37: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

The Java Approach

• Interpretation by the Java Virtual Machine

Any Computer

JavaVirtual

Machine

ByteCode

Page 38: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Why is this cool?

Page 39: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

The Internet©Al Gore

JavaSource

ByteCode

Javac Compiler

Do this once

Web Server

Your Computer

Your Favorite Browser

JavaVirtual

Machine

Page 40: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

“Source Code” [.java]

Javacompiler

Generic“Byte Code” [.class]

OS-specificJVM

interpreter

Executeprogram

Compilation/Execution

Need one of these for every different

OS

Page 41: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

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!

Page 42: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Demo

>javac HelloWorld.java

>java HelloWorld

Hello World!

>

Page 43: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

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

Page 44: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

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

Page 45: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

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.

Page 46: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11

Questions?

Page 47: 13 X 11 Java Lecture 1 CS 1311 Introduction 13 X 11.

13X11