Presentation is loading. Please wait.

Presentation is loading. Please wait.

What is a Computer Program? For a computer to be able to do anything (multiply, play a song, run a word processor), it must be given the instructions.

Similar presentations


Presentation on theme: "What is a Computer Program? For a computer to be able to do anything (multiply, play a song, run a word processor), it must be given the instructions."— Presentation transcript:

1

2 What is a Computer Program? For a computer to be able to do anything (multiply, play a song, run a word processor), it must be given the instructions to do so. A program is a set of instructions written by humans for computers to perform tasks. The instructions are written in programming languages such as C, C++, Java, etc.

3 Programming Languages Machine Language Assembly Language High-Level Language Machine language is a set of primitive instructions built into every computer. The instructions are in the form of binary code, so you have to enter binary codes for various instructions. Program with native machine language is a tedious process. Moreover the programs are highly difficult to read and modify. For example, to add two numbers, you might write an instruction in binary like this: 1101101010011010

4 Programming Languages Machine Language Assembly Language High-Level Language Assembly languages were developed to make programming easy. Since the computer cannot understand assembly language, however, a program called assembler is used to convert assembly language programs into machine code. For example, to add two numbers, you might write an instruction in assembly code like this: ADDF3 R1, R2, R3

5 Programming Languages Machine Language Assembly Language High-Level Language The high-level languages are English-like and easy to learn and program. For example, the following is a high-level language statement that computes the area of a circle with radius 5: area = 5 * 5 * 3.1415;

6 Popular High-Level Languages COBOL (COmmon Business Oriented Language) FORTRAN (FORmula TRANslation) BASIC (Beginner All-purpose Symbolic Instructional Code) Pascal (named for Blaise Pascal) Ada (named for Ada Lovelace) C (whose developer designed B first) Visual Basic (Basic-like visual language developed by Microsoft) Delphi (Pascal-like visual language developed by Borland) C++ (an object-oriented language, based on C) Java (We use it in this class)

7 Compiling Programs Computers do not understand the languages (C++, Java, etc) that programs are written in. Programs must first be compiled (converted) into machine code that the computer can run. A compiler is a program that translates a programming language into machine code.

8 Running Programs All programs follow a simple format: Input Execution Output Inputs can be from users, files, or other computer programs Outputs can take on many forms: numbers, text, graphics, sound, or commands to other programs

9 Multiple Compilers Because different operating systems (Windows, Macs, Unix) require different machine code, you must compile most programming languages separately for each platform. program compiler Win MAC Unix

10 Java is a little different. Java compiler produces bytecode not machine code. Bytecode can be run on any computer with the Java interpreter installed. Java Program compiler Java Bytecode Win MAC Unix Interpreter Java Interpreter

11 Advantages and Disadvantages of Java Advantages: Java is platform independent. Once it's compiled, you can run the bytecode on any machine with a Java interpreter. You do not have to recompile for each platform. Java is safe. Certain common programming bugs and dangerous operations are prevented by the language and compiler. Java standardizes many useful operations like managing network connections and providing graphical user interfaces. Disadvantages: Running bytecode through the interpreter is not as fast as running machine code, which is specific to that platform. Because it is platform independent, it is difficult to use platform specific features (e.g., Windows taskbar, quick launch) in Java. Java interpreter must be installed on the computer in order to run Java programs.

12 Javas Compiler + Interpreter Editor Hello.java Compiler Hello.class Interpreter Hello, World ! Interpreter

13 Java Virtual Machine Must Run on Any Architecture Program in Java Java Compiler Java Bytecode Java Virtual Machine WRITE ONCE, RUN ANYWHERE! pretty portable

14 Why Bytecodes? Platform-independent Load from the Internet faster than source code Interpreter is faster and smaller than it would be for Java source Source code is not revealed to end users Interpreter performs additional security checks, screens out malicious code

15 Types of Programs Console applications GUI applications Applets

16 Java on the Web: Java Applets Clients download applets via Web browser Browser runs applet in a Java Virtual Machine (JVM) Interactive web, security, and client consistency Slow to download, inconsistent VMs (besides, flash won this war) Applet Client Server

17 Java on the Web: J2EE Thin clients (minimize download) Java all server side Client Server JSPsServletsEJBJDBC

18 Console Applications C:\javamethods\Ch02> path=%PATH%;C:\Program Files\Java\jdk 1.5.0_07\bin C:\javamethods\Ch02> javac Greetings2.java C:\javamethods\Ch02> java Greetings2 Enter your first name: Josephine Enter your last name: Jaworski Hello, Josephine Jaworski Press any key to continue... Simple text dialog: prompt input, prompt input... result

19 GUI Applications Menus Buttons Clickable panel Slider

20 OOP Object-Oriented Programming An OOP program models a world of active objects. An object may have its own memory, which may contain other objects. An object has a set of methods that can process messages of certain types.

21 OOP (contd) A method can change the objects state, send messages to other objects, and create new objects. An object belongs to a particular class, and the functionality of each object is determined by its class. A programmer creates an OOP application by defining classes.

22 Inheritance A programmer can define hierarchies of classes More general classes are closer to the top Person ChildAdult BabyToddlerTeen

23 OOP Benefits Facilitates team development Easier to reuse software components and write reusable software Easier GUI (Graphical User Interface) and multimedia programming


Download ppt "What is a Computer Program? For a computer to be able to do anything (multiply, play a song, run a word processor), it must be given the instructions."

Similar presentations


Ads by Google