1 / 15

Programming HSPM J713 Programming languages and systems

Programming languages generally come with programming system. The language part of a programming language is the key words, symbols, and syntax used to write code. ...

Kelvin_Ajay
Download Presentation

Programming HSPM J713 Programming languages and systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming HSPM J713

  2. Programming languages and systems • Programming languages generally come with programming system • The language part of a programming language is the key words, symbols, and syntax used to write code. • The system part translates the written code into machine instructions that computer executes. Can be a compiler or an interpreter.

  3. Platform-specific • Language system works with specific hardware • The “IBM-compatible” PC or the Windows PC • All use the same: • Machine instructions (which depends on chip architecture) • Memory, screen

  4. Assembly language mov ax, 1234h mov bx, ax Directly translates into machine code (binary numbers) Compiler translates all instructions in program into machine code Low level – explicitly manipulates registers (places to hold data) on the CPU chip. Each chip has its own assembly language

  5. FORTRAN Do 10 j = 2 , 1000 B(j) = A(j-1) A(j-1)=j 10 continue Compiled into machine language and then run Used on mainframes since 1950’s. Designed for math

  6. BASIC Beginner's All-purpose Symbolic Instruction Code For students and general users Interpreted – One line at a time is translated into machine code and executed

  7. BASIC – unstructured, interpreted 10 INPUT "What is your name: ", U$ 20 PRINT "Hello "; U$ 30 INPUT "How many stars do you want: ", N 40 S$ = "" 50 FOR I = 1 TO N 60 S$ = S$ + "*" 70 NEXT I 80 PRINT S$ 90 INPUT "Do you want more stars? ", A$ 100 IF LEN(A$) = 0 THEN 90 110 A$ = LEFT$(A$, 1) 120 IF A$ = "Y" OR A$ = "y" THEN 30 130 PRINT "Goodbye ";U$ 140 END

  8. BASIC structured, compiled INPUT "What is your name: ", UserName$ PRINT "Hello "; UserName$ DO INPUT "How many stars do you want: ", NumStars Stars$ = STRING$(NumStars, "*") PRINT Stars$ DO INPUT "Do you want more stars? ", Answer$ LOOP UNTIL Answer$ <> "" Answer$ = LEFT$(Answer$, 1) LOOP WHILE UCASE$(Answer$) = "Y" PRINT "Goodbye "; UserName$

  9. C, C++ • This Hello world program uses the C++ standard library stream facility to write a message to standard output: #include <iostream> // provides std::cout int main() { std::cout << "Hello, world!\n"; } Uses “library” of code, callable with key words, to execute complex tasks Compiler for specific platform translates that into machine code.

  10. Java • Compiled code runs on Virtual Machine • A virtual machine is written for each platform. • The virtual machine for a platform translates virtual machine instructions into machine instructions for that platform • Java runs on PC virtual machine on PC’s, Macintosh virtual machine on Macs, for example. • So compiled Java code can run on many platforms. Good for web applications.

  11. Java resembles C in syntax Class HelloWorld { public static void main (String[] arguments) { System.out.println(“Hello World!”); } } Compiled using Java Development Kit

  12. Java uses objects import java.applet.*; import java.awt.*; public class TextEntry extends Applet { TextField Reply; TextField Entry; public void init() { setBackground(Color.white); add("EntryLabel", new Label("Type your number in the small box and press Enter:")); add("Entry", Entry = new TextField("", 5)); add("Reply", Reply = new TextField("My reply will appear here.", 60)); Reply.setEditable(false); } public void compute() { int value; try { value = Integer.valueOf(Entry.getText().trim()).intValue(); if (value == 15) { Reply.setText("Correct! 15 is right!"); } else { if (value > 15) Reply.setText(Entry.getText()+" is too high."); if (value < 15) Reply.setText(Entry.getText()+" is too low."); } } catch(NumberFormatException e) { Reply.setText(Entry.getText() + " is not a number."); } } public boolean action(Event e, Object dummy) { compute(); return(true); } } Textentry example

  13. Java uses objects import java.applet.*; import java.awt.*; public class TextEntry extends Applet { TextField Reply; TextField Entry; … }

  14. Java uses objects … public class TextEntry extends Applet { TextField Reply; TextField Entry; public void init() { setBackground(Color.white); add("EntryLabel", new Label("Type your number in the small box and press Enter:")); add("Entry", Entry = new TextField("", 5)); add("Reply", Reply = new TextField("My reply will appear here.", 60)); Reply.setEditable(false); } … }

  15. Java uses objects … public void compute() { int value; try { value = Integer.valueOf(Entry.getText().trim()).intValue(); if (value == 15) { Reply.setText("Correct! 15 is right!"); } else { if (value > 15) Reply.setText(Entry.getText()+" is too high."); if (value < 15) Reply.setText(Entry.getText()+" is too low."); } } catch(NumberFormatException e) { Reply.setText(Entry.getText() + " is not a number.");} } public boolean action(Event e, Object dummy) { compute(); return(true); } }

More Related