# Intro to Computer Programming

• The essence of a Computer

• The computer is a man-made machine that can carry out a specific sequence of instructions (that is provided by a computer programmer)

• The computer is in fact the best slave to mankind:

• It carries out the instructions very precisely (in fact, the computer cannot contemplate whether the instruction makes sense, or whether the action is moral, etc... all it does is executes the instruction...)

• Using a computer: the communication gap...

• OK, a computer can carry out the instructions that you provide it...

• Before the computer can carry out your instructions, you must first communicate the instructions to the computer...

• This task is easier said than done, because it is not practical (economically) to construct a machine that can understand human language... (e.g., English)

Also, it is infeasible to make a machine that is capable of doing every that a human can do...

• What people end up making is a machine (computer) that has limited capabilities - i.e., the computer can execute a limited instruction set

• Typical computer instructions include:

• Get the content of memory location 40
• Get the value 25
• Subtract two numbers
• If the first value is greater than the second value, continue with the instruction that is stored in memory location 240.

• To further simplify the machine, the language that the computer recognizes is not English or any human language, but a code:

Computer instructions are represented by a unique number

• Examples: 1 for ADD, 2 for SUBTRACT, 21 for get the content of memory location, 16 for get the value, etc...

• Concrete examples: The following codes are used by the "Java Virtual Machine":

• 21 40 = Get the contents of memory location 40.
• 16 100 = Load the value 100.
• 163 240 = If the first value is greater than the second value, continue with the instruction that is stored in memory location 240.

• Bridging the communication gap...

• The problem:

The computer uses a different "language" than humans do (for economical reasons - we can make a computer that can understand English, but it would be very expensive)

• The solution:

• Simple: a translator !!!

• Computer science research has produced a rich set of techniques to solve very complex problems with a computer.

One of the area of research was designing good programming languages and another important area of research is translating instructions written in programming languages into machine language

• Human friendly programming languages are called high level programming languages (e.g., Java, which we will learn in this course)

• Compiler: is a program that translates instructions written in a "high level language" to computer instructions

• Self-Check

• What is the code for the Java virtual machine instruction "Load the contents of memory location 100"?

21 100

• Does a person who uses a computer for office work ever run a compiler?

No - a compiler is intended for programmers, to translate high-level programming instructions into machine code.

THE JAVA PROGRAMMING LANGUAGE

• The Java Programming Language

• Simple
• Safe
• Platform-independent (write once, run anywhere)
• Rich library
• Designed for the Internet (applets)

• Applets on a Web Page

• An applet is a Java program that can be downloaded from a website and run in your web-browser.

And the program runs inside your webbrowser.

Because you may download viruses from websites, applets (that run inside webbrowser) are restricted in their ability to use resources - e.g., applets cannot update files...

• Self-Check

• What are the two most important benefits of the Java language?

• Safety
• Portability

• How long does it take to learn the entire Java library?

Too long... and you don't want to learn the entire library... (most of the stuff you will not use)