Java Lecture 1 CS 1311 Introduction 13 X







































![Compilation/Execution “Source Code” [. java] Java compiler Execute program Generic “Byte Code” [. class] Compilation/Execution “Source Code” [. java] Java compiler Execute program Generic “Byte Code” [. class]](https://slidetodoc.com/presentation_image/39517f11642bbb7c7ff18047889ba454/image-40.jpg)







- Slides: 47
Java Lecture 1 CS 1311 Introduction 13 X 11
Serious Stuff 13 X 11
Put these in order • • Avoid damage to equipment and material Get the job done Avoid injuries Maintain good community relations 13 X 11
Normal World • • Avoid injuries Avoid damage to equipment and material Get the job done Maintain good community relations 13 X 11
Military@War • • Get the job done Avoid injuries Avoid damage to equipment and material Maintain good community relations 13 X 11
Ballistics v 0 ? 13 X 11
Ballistics v 0 13 X 11
Ballistics v 0 vy vx 13 X 11
Ballistics t v 0 vy vx 13 X 11
Ballistics t v 0 vy vx t 13 X 11
Ballistics t v 0 vy vx t 13 X 11
Ballistics Assumptions • Flat non-rotating earth • Vacuum • Constant gravity t v 0 vy vx t 13 X 11
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? 13 X 11
Let's invent a computer 13 X 11
Computer Programming • • Initially by hand Big breakthrough: Machine translation Analysis of computation Church-Turing Functional Imperative/Procedural 13 X 11
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 13 X 11
Origins of OO • USAF ATC Randolph AFB B 220 Locations Routines Data 13 X 11
Origins of OO • USAF ATC Randolph AFB B 220 • Simulation Products Conveyor Workers Machines 13 X 11
Origins of OO • USAF ATC Randolph AFB B 220 • Simulation • Large scale projects 13 X 11
Origins of OO • • USAF ATC Randolph AFB B 220 Simulation Large scale projects GUI's 13 X 11
So what is it? • A brief overview • My favorite example Queue 13 X 11
Chez Guillaume • Application to maintain 2 queues • Allow adding to either list • Allow removing from either list 13 X 11
How might it be done? head. tail Restaurant Module Enqueue Module Data Structure Dequeue Module is. Empty Module head. tail Input Module Output Module Data Structure Menu Module 13 X 11
How might it be done? head. tail Restaurant Module Enqueue Module Data Structure Dequeue Module is. Empty Module head. tail Input Module Output Module Data Structure Where is the queue? Menu Module 13 X 11
The OO Approach Queue Object head. tail Enqueue Module Restaurant Object Ref Queue Object head. tail Dequeue Module is. Empty Module Enqueue Module Input Module Output Module Menu Module Dequeue Module is. Empty Module Data Object Cust 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? 13 X 11
Goals • • Encapsulation Reusability Adaptability/Flexibility Decentralization/Distribution 13 X 11
OOP Terminology • • • Abstract Data Type Class Object Method Fields/Attributes References 13 X 11
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. . . 13 X 11
Java • • Toasters Smart cards Killer apps The wwweb 13 X 11
Java, the good news • • • Real Very powerful In demand Software engineering Universal 13 X 11
Java, the bad news • • • Real Very powerful Not an educational language Jack of all trades/Master of none Slow 13 X 11
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 13 X 11
Translation • Compilation – – – Fortran Cobol Pascal Algol C/C++ • Interpretation – Basic – Lisp – Scheme 13 X 11
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 13 X 11
The Java Approach • Compilation into Byte. Code Java Source Javac Compiler Byte Code 13 X 11
The Java Approach • Interpretation by the Java Virtual Machine Any Computer Byte Code Java Virtual Machine 13 X 11
Why is this cool? 13 X 11
The Internet Java Source ©Al Gore Do this once Javac Compiler Byte Code Your Computer Web Server Your Favorite Browser Java Virtual Machine 13 X 11
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 13 X 11
Sample Application We create a file (using an editor) called “Hello. World. java” public class Hello. World { public static void main(String argv[]) { System. out. println(“Hello World!”); } } We compile by typing (at the OS prompt): javac Hello. World. java Hello World! Which produces Hello. World. class Then we execute by typing: java Hello. World 13 X 11
Demo >javac Hello. World. java >java Hello. World Hello World! > 13 X 11
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!!! 13 X 11
A Final Word • 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 13 X 11
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. 13 X 11
Questions? 13 X 11
13 X 11