Overview • Object oriented programming How to run a simple program

advertisement
Overview
• Object oriented programming
• How to run a simple program
Programming languages
• Machine languages 1's and 0's; machinedependent
• Assembly languages: English-like
abbreviations; elementary operations
• High-level languages: single statements
could be written to accomplish substantial
tasks.
Example (Programming languages)
• Machine languages:
+1300042774
+1400493419
+1200274027
• Assembly languages:
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
• High-level languages:
grossPay = basePay +overTimePay
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
Bank account object example
tomsSaving
int acountNumber = 123456789;
int currentBalance = 30000;
deposit(int x);
withdraw(int y);
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.
Bank account class example
public class bankAccount{
int balance;
int accountNumber;
public BankAccount(){
}
public void withdraw(int x){
……
}
Variables
• A variable is a container
• A variable has a type
• A variable has a value
• A variable can change its value
Assignment statement
• Example
integer age = 25;
type name assignment symbol initial value
• “=” is not the equality symbol
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.
Programming process
ideas
Program in
Java byte code,
in the file
Test.class
Program text,
on paper or in
head
Compiler-a program for
translating
programs
Java Virtual
Machine JVM,
executes the
program Test.class
Work done at
the keyboard
with a text
editor
Program text,
in a file such
as Test.java
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é
Summary
•
•
•
•
•
class, object
identifier
variable
statement, assignment statement
editor, compiler, JVM, IDE
Download