Lecture 5

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

15.

561
Information Technology Essentials

Session 5
Programming Languages

Acknowledgments:
Copyright © 2005 Thomas Malone, Stuart Madnick Slides marked “SM” are adapted from Stuart Madnick, MIT.
Outline

• Types of software

• Types of programming languages

• Examples
– Java
– Y2K
Types of software

• System software
– Operating systems
– Programming languages
– Database systems

• Application software
– General office tasks (word processing, etc.)
– Accounting
– Design
– Factory automation
– …
Programming languages

• Machine language

• Assembly language

• High-level languages

• Fourth-generation languages
A sample LMC program

1 ASSEMBLY LANG 2 MACHINE LANG.


(Source Program) (Object Program)
INSTRUCTIONS
STEP INSTRUCTION LOC INSTRUCTION
op-
code symbolic 00 get 00 901
01 store w 01 398
000 stop 02 get 02 901
1xx add 03 store b 03 399
2xx subtract 04 load w 04 598
3xx store 05 add b 05 199
5xx load 06 put 06 902
901 get 07 stop 07 000
902 put

Source: S. Madnick, MIT


Machine language

• Binary

• Machine dependent

• Stored in the computer when the program is running

• Example:
01110110001010010010 ….
Assembly language

• Mnemonic

• Symbolic addressing

• One-to-one correspondence with machine language

• Example:
Get X
Add Y
Store Z
Automatically translating assembly
language to machine language

Get X 11001000100
Add Y 01100100011
Store Z Assembler 10001011001
... ...

Assembly Machine
language language
program program
(“source code”) (“object code”)
High-level languages

• Closer to how people think about their problems

• No one-to-one correspondence to machine language

• General purpose

• Example:
Z=X+Y
High-level languages - Examples

• Fortran

• Basic

• Visual Basic

•C

• C++

• Java
Example 1 – Basic

!    L QF L OQF X  L   G O F X    H OX R  V W L R OX R  OU  D P V  H
K G
 QF X O �X R Q G O  V L  I O Y Q OJ QF H OX R  O    L  OV J OQF X  L   G OD V W O F X   E
 QF X O �X R  V W L R O X R  O U  D P V  H OX D  O? ? ? OX V OQF H QK X  OX R  O F H OV J OH X E
 QF X
G W I Z 
K V W F X   OZ 
 QF X O�  G  O F X   O OF W I P   E
QF W X OF W I P  
H V OY R Q  O F W I P   O ` O ? ? ?
G W I Z G W I � F W I P  
K V W F X   Z K V W F X   � 6
 QF X O�  G  O F X   OX R  OF  ' X OF W I P   E
QF W X OF W I P  
V V
   L  Z G W I +K V W F X  
 Q F X O �X R  O    L  O V J O X R  O F W I P   O Q G E2O    L 
 F H
Example 2 – C++
++O    L QF L OQF X  L   G O F X    H OX R  V W L R OX R  OU  D P V  H

( 5 *$ 9 / � � O ` 5 0 : ) 8 � . <  , 
< . 5 *O 1 O 
3O
90 . )O.  � 8 . ; � 2
5 *) */ <  � 8 � O $ 0 / *) � 8 O Z O  2O O 5 *) : / < O Z O  2
$ 0 / ) ` ` O �X R Q G O  V L  I O Y Q O J Q F H O X R  O    L  O V J O Q F X  L   G O D V W O  F X   O *E2
$ 0 / ) ` ` O �X R  V W L R O X R  O U  D P V  H  O X D  O ? ? ? O X V O Q F H Q K X  O  F H O V J O H X  O *E2
$ 0 / ) ` ` O�  G  O F X   O OF W I P   E2
$ 5 * O */ <  � 8 2
 , 5 9 � O 1 */ <  � 8 O % Z ? ? ? 
3
: / < O Z : / < O � O */ <  � 8 2
$ 0 / *) � 8 � � 2
$ 0 / ) ` ` O �*  G   F X   O X R  O F  ' X O F W I P   E2
$ 5* */ <  � 8 2
&
.  � 8 . ; � O Z O : / < O + O $ 0 / *) � 8 2
$ 0 / ) ` ` O �*X R     L  O V J O X R  O F W I P   G O Q G O �` ` O .  � 8 . ; � 2
&
Example 3 – Java
{
import java.io.*; BufferedReader in = new BufferedReader(new
import java.lang.*; InputStreamReader(System.in));
/** String cin = "0";
** Prompts user for list of numbers and outputs average System.out.println("Please enter a number.");
**/ while (!(cin=in.readLine()).equals("999"))
{
class AverageNumbers { sum = sum + Integer.parseInt(cin);
public static void main (String[] args) { counter = counter + 1;
float sum = 0; System.out.println("Please enter another
float average = 0; number.");
int counter = 0; }
in.close();
System.out.println("THIS PROGRAM WILL FIND THE average = sum/counter;
AVERAGE OF THE INTEGERS YOU ENTER System.out.println("The average of the numbers is :
THROUGH THE KEYBOARD. TYPE 999 TO "+average);
INDICATE END OF DATA."); }
catch (IOException e)
try {
System.out.println("Ooops..");
}
}
}
Automatically translating high-level
language to machine language

Z=X+Y 11001000100
... 01100100011
Compiler 10001011001
...

High-level Machine
language language
program program
(“source code”) (“object code”)
“Interpreting” high level languages

Z=X+Y
...
Interpreter

High-level
language
program
(“source code”)
Interpreting high level languages

• Advantages
– Can give machine independence
» (e.g., one machine can “look” like another)
– Can be easier to debug and modify
– Can give more flexibility at “run time”

• Disadvantages
– Slower
“Fourth-generation” languages

• Even closer to how people think about their problems

• Special purpose

• Examples:
– Scripting languages
» FIND ALL RECORDS WHERE NAME IS “SMITH”
– Spreadsheet formulas?
Object-oriented programming

• A special kind of high-level language

• Can increase programming efficiency and software


re-use

• Combines procedures and data into “objects”

• Arranges objects in “class hierarchies”

• “Inherits” properties of objects in this hierarchy


Class inheritance in
object-oriented programming
Credit card account
Owner
Balance
Credit limit
----­
Open
Deposit
Bank account
Withdrawal
Owner
Authorize charge
Balance
----­
Open Checking account Joe’s checking account
Deposit Owner Owner: Joe
Withdrawal Balance Balance: $400
Minimum balance: $100 Minimum balance: $100
----­ ----­
Open Open
Deposit Deposit
Withdrawal Withdrawal
What’s good about Java?
• Highly interactive
– Traditional Web - application software runs on server
– Java applets dynamically downloaded and run on client
(e.g., input data validation)
• “Nice” programming language
– Simpler than C/C++
– Object-oriented
• Secure programming environment
– “Sandbox” approach
• Portable (“write once, run anywhere”)
– Based on Java byte-code interpreter
SM
Java Operation Servers

S
D
Internet
J
Sun/UNIX

• Static pages (S)


• Dynamic pages (D)
• Java applets (J)
Windows 2000 Mac OS

HTML
page
Java
applet
HTML
page
Java
applet } same

Windows XP HTML Java HTML Java

}
Interpreter interpreter Interpreter interpreter

Netscape (Win 2000) Netscape (Mac OS) different


Windows 2000 OS Mac OS
PC Hardware PowerMac Hardware

Client environments SM
Java reality check

• Highly interactive or too slow (interpretive)

• “Nice” programming language or too limited

• Secure environment or (1) not secure enough or


(2) too secure (restrictive)

• Portable only if consistent Java interpreter availabl


(Java “dialects”)
SM
What will happen with Java?
Y2K problem

• Why was this a hard problem?

• Was money wasted?

You might also like