Overview Object oriented programming How to run a simple program.

13
Overview Object oriented programming How to run a simple program

Transcript of Overview Object oriented programming How to run a simple program.

Page 1: Overview Object oriented programming How to run a simple program.

Overview

• Object oriented programming

• How to run a simple program

Page 2: Overview Object oriented programming How to run a simple program.

Programming languages

• Machine languages 1's and 0's; machine-dependent

• Assembly languages: English-like abbreviations; elementary operations

• High-level languages: single statements could be written to accomplish substantial tasks.

Page 3: Overview Object oriented programming How to run a simple program.

Example (Programming languages)

• Machine languages: +1300042774

+1400493419

+1200274027

• Assembly languages: LOAD BASEPAY

ADD OVERPAY

STORE GROSSPAY

• High-level languages:

grossPay = basePay +overTimePay

Page 4: Overview Object oriented programming How to run a simple program.

Objects

• An object has: – state - descriptive characteristics – behaviors - what it can do (or be done to it)

• For example, a particular bank account – has an account number – has a current balance – can be deposited into – can be withdrawn from

Page 5: Overview Object oriented programming How to run a simple program.

Bank account object example

tomsSaving int acountNumber = 123456789;

int currentBalance = 30000;

deposit(int x);

withdraw(int y);

Page 6: Overview Object oriented programming How to run a simple program.

Classes

• A class is a blueprint of an object

• It is the model or pattern from which objects are created

• A class defines the methods and types of data associated with an object

• Creating an object from a class is called instantiation; an object is an instance of a particular class

• For example, the Account class could describe many bank accounts, but toms_savings is a particular bank account with a particular balance.

Page 7: Overview Object oriented programming How to run a simple program.

Bank account class example

public class bankAccount{

int balance;

int accountNumber;

public BankAccount(){

}

public void withdraw(int x){

… …

}

public void deposit(int x){

… ...

}

}

Page 8: Overview Object oriented programming How to run a simple program.

Variables

• A variable is a container

• A variable has a type

• A variable has a value

• A variable can change its value

Page 9: Overview Object oriented programming How to run a simple program.

Assignment statement

• Example integer age = 25;

type name assignment symbol initial value

• “=” is not the equality symbol

Page 10: Overview Object oriented programming How to run a simple program.

Programming process

• Use an editor to type in the program

• Use a compiler to translate the program into machine code.

• Use Java Virtual Machine to run the program.

Page 11: Overview Object oriented programming How to run a simple program.

Programming process

ideas Program text, on paper or in head

Work done at the keyboard with a text editor

Program text, in a file such as Test.java

Compiler--a program for

translating programs

Program in Java byte code,

in the file Test.class

Java Virtual Machine JVM,executes the

program Test.class

Page 12: Overview Object oriented programming How to run a simple program.

IDE(Integrated Development Environment)

• IDE consists of:– a text editor (Notepad is fine too)– a compiler (the JDK's javac, where JDK is the Java

Development Kit)– a Java Virtual Machine (JVM)

• Java IDE Examples– Code Warrior– Visual Age Java(IBM)– Visual Café

Page 13: Overview Object oriented programming How to run a simple program.

Summary

• class, object

• identifier

• variable

• statement, assignment statement

• editor, compiler, JVM, IDE