1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor.

Slides:



Advertisements
Similar presentations
compilers and interpreters
Advertisements

Dr. Ken Hoganson, © August 2014 Programming in R COURSE NOTES 2 Hoganson Language Translation.
 Suppose for a moment that you were asked to perform a task and were given the following list of instructions to perform:
INTRODUCTION Chapter 1 1. Java CPSC 1100 University of Tennessee at Chattanooga 2  Difference between Visual Logic & Java  Lots  Visual Logic Flowcharts.
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. OBJECTIVES FOR THIS UNIT Upon completion of this unit, you should be able to: Explain the Java virtual machine.
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. GCOC – A.P. Computer Science A College Board Computer Science A Topics Covered Program Design - Read and understand.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Chapter 1: Introduction
Chapter 1 These slides for CSE 110 Sections are based in part on the textbook-authors’ slides, which are copyright by the authors. The authors state that.
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
CHAPTER 1 INTRODUCTION GOALS  To understand the activity of programming  To learn about the architecture of computers  To learn about machine code and.
©2004 Brooks/Cole Chapter 1: Getting Started Sections Covered: 1.1Introduction to Programming 1.2Constructing a Java Program 1.3The print() and println()
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
1 Data types, operations, and expressions Overview l Format of a Java Application l Primitive Data Types l Variable Declaration l Arithmetic Operations.
1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor.
1 Programming Languages Translation  Lecture Objectives:  Be able to list and explain five features of the Java programming language.  Be able to explain.
Lecture 2: Do you speak Java?. From Problem to Program Last Lecture we looked at modeling with objects! Steps to solving a business problem –Investigate.
Introduction to a Programming Environment
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
Chapter 1 - Introduction. Ch 1Goals To understand the activity of programming To learn about the architecture of computers To learn about machine code.
By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Introducing Java.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
A First Program Using C#
Chapter 2 How to Compile and Execute a Simple Program.
Topics Introduction Hardware and Software How Computers Store Data
COMP 110 Spring Announcements Computers in class on Friday: Lab Office Hours: Monday 12-2 New students see me after class Administrative Changes.
COMP 110: Introduction to Programming Tyler Johnson January 14, 2009 MWF 11:00AM-12:15PM Sitterson 014.
CS 106 Introduction to Computer Science I 01 / 25 / 2010 Instructor: Michael Eckmann.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Chapter One: Introduction.
Programming With C.
Introduction to Computer Systems and the Java Programming Language.
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Programming Concept Chapter I Introduction to Java Programming.
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Chapter 1 Section 1.1 Introduction to Java Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
Robert Crawford, MBA West Middle School.  Explain how the binary system is used by computers.  Describe how software is written and translated  Summarize.
CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture.
Fall 2006Slides adapted from Java Concepts companion slides1 Introduction Advanced Programming ICOM 4015 Lecture 1 Reading: Java Concepts Chapter 1.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs -
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
A Look at Java. Categorize Java Which paradigm? Which paradigm? Scripting? Scripting? Declarative or procedural? Declarative or procedural? Which generation?
1 WELCOME TO CIS 1068! Instructor: Alexander Yates.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Chapter 1 Introduction. Chapter Goals To understand the activity of programming To learn about the architecture of computers To learn about machine code.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Introducing Java Chapter 3 Review. Why Program in Java? Java, is an object-oriented programming language. OOP languages evolved out of the need to better.
CS 106 Introduction to Computer Science I 01 / 24 / 2007 Instructor: Michael Eckmann.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Chapter 1 – Introduction
Lecture 1b- Introduction
The need for Programming Languages
CSC201: Computer Programming
Topics Introduction Hardware and Software How Computers Store Data
CSCI-235 Micro-Computer Applications
Chapter 3 GC 101 Java Fundamentals.
Topics Introduction Hardware and Software How Computers Store Data
Introduction CSC 111.
Computer Programming-1 CSC 111
Instructor: Alexander Stoytchev
Week 1 - Friday COMP 1600.
Presentation transcript:

1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor chips. l High level programming languages. l Language translators (compilers.) l Language interpreters. l Java compiler, Java bytecode and Java virtual machine. l Format of a basic java program.

2 Machine Operations & Machine Language l When a program is running on a computer, the processor is constantly performing very detailed electronic operations. E.g: »Reading a byte of data from main memory into a part of the processor. »Testing if one of the bits in the byte is a "1" bit. l Most processors can perform several hundred types of small operations like these. l A large number of these small operations can add up to a large and useful action. l This is similar to what happens with a car. A "big operation" such as "accelerate", involves the valves on the engine's cylinders opening and closing 24,000 times per minute. l Each tiny electronic operation that a processor can perform is called a machine operation. A processor (a "machine") performs these one at a time, but millions of them in a second.

3 Machine Operations & Machine Language l A machine instruction consists of several bytes in main memory that tells the processor to perform one machine operation. l The electronics of the computer system is designed so that the processor looks at machine instructions in main memory one after another, and performs a machine operation for each machine instruction. l The collection of machine instructions in main memory is called a machine language program or (more commonly) an executable program. l Luckily for us, with a programming language like Java, we can program a computer without knowing any of these electronic details. Point-to-PointShared Line

4 Example of Machine Language l Let us assume that an electric toothbrush has a processor and main memory. l Suppose the processor can perform the following operations which for which the corresponding machine instruction are defined: l A machine language program to rotate the toothbrush until the switch is turned off could be as follows: Machine InstructionMachine Operation 0000 Stop Rotate bristle left Rotate bristle right Go back to start Skip next instruction is switch is off AddressMachine Instruction

5 Different Processors l There are many types of processors used in computer systems. Examples: » Intel processors (486, Pentium, Pentium II & III) »The processors used in Apple computers. l A computer system is designed around its processor.. l The fundamental difference between (say) an Apple Power Macintosh and a Dell Corporation computer is their processors l Different processors have different machine operations. A machine program for a Dell computer (with a Pentium processor) would make no sense to an Apple computer.

6 High Level Programming Languages l It is very rare for programmers to write programs in machine language. l The executable files for most applications contain hundreds of thousands of (if not millions) of machine language instructions. l Most programs are created using a high level programming language such as Java, C, C++, or BASIC. --- Why are they called High Level? l With a high level language, a programmer creates a program using powerful, "big" operations which will later be converted into many little machine operations. l For example, here is a line from a program in the language "C": int sum = 0; l The machine operations that correspond to this line will set up a small part of main memory to hold a number, store the number zero there, and arrange things so other parts of the program can use it. l It might take a hundred machine operations to do all this. Clearly, it is easier for a programmer to ask for all these operations using "C".

7 Source Program l Programmers create programs by writing commands in a high level language. l A high level language program consists of lines of text that have been created with a text editor and are kept in a file on the hard disk. l For example, here is a complete program in "C" (Java will be discussed later): #include main(){ int sum = 0; sum = 2 + 2; printf( "%d\n", sum ); } l This program could be saved on the hard disk in a file called addup.c. Like all files, it consists of a sequence of bytes. l However, since it is a text file, these bytes contain character data and not machine instructions. l If the bytes are copied into main memory, they cannot run as a program without some extra work. l Thus, A source program (or source file) is a text file that contains instructions written in a high level language.

8 Compilers/Interpreters l An application program called a translator or Compiler takes a source file as input and produces an executable program (machine language program) as output. l For example, the "C" program addup.c could be translated into an executable program. The executable program might be called addup.exe and can be saved on the hard disk. Now this executable version of the program can be copied into main memory and executed. Here is a picture that shows what usually happens with programs written in "C“. l The above is what goes on with most languages: Ada, Pascal, C, C++, FORTRAN and others. Java adds a few more steps, which will be discussed next.

9 Portability l Ideally, only one program needs to be written in the high level language. l The source file can then be translated into several executable files, each containing the correct machine instructions for its intended processor. l This idea is called software portability. l Unfortunately, things do not work out that nicely. It takes a substantial amount of human effort to get a program running on a new system. l One of the big advantages of Java is that it is automatically portable between computer systems that have Java support. No human effort is involved at all. l To understand how Java achieved this, we need to understand one more thing, an Interpreter or a Virtual machine.

10 Interpreter/Virtual Machine l Another way to make a source program to run on a computer is through the use of an interpreter l An interpreter is a program that acts like a processor that can directly execute a high level language. l In this figure, the source program "program.bas" has been written in BASIC. l It is being interpreted by the BASIC interpreter, which is running on the processor. The BASIC interpreter will read each command in the source program and do what it says.

11 Interpreter/Virtual Machine –Contd. l From the perspective of the BASIC program, it looks like the commands in BASIC are being directly executed by some sort of machine. l Here is the figure, modified to show this: l The word "virtual" is used in situations where software has been used to make something look like the real thing. In this case it looks like we have a machine that can directly execute BASIC, so we can say that we have a BASIC virtual machine.

12 Java Virtual Machine l The following is a simple Java program (Saved in a file, Hello.java). It consists of a class called Hello which contains one method called main. class Hello { public static void main (String[] args) { System.out.println("Hello World!"); } l To get the sample program running, it is first translated into bytecodes, a machine instruction for a Java processor chip using the Java Compiler. ‘

13 Java Virtual Machine - Contd. l The important idea introduced by Java is that the Java compiler will produce exactly the same bytecodes no matter what computer system is used. l The Java bytecode interpreter (or Virtual machine) executes the bytecode file. l Notice that each type of computer system has its own Java interpreter that can run on that system. l This is how Java achieved Compatibility. It does not matter on what computer system a Java program is compiled, provided the target computer has a Java Virtual machine.

14 Java Applets and Application l Java can be used to create two types of programs: Applications and Applet Application: An application is a program that runs on your computer just like any other programs created with C or C++. Applet: An applet is an application designed to be transmitted over the internet and executed by the java compatible web browsers. This ability of java to create applets makes it more important than any other programming language. In the next slide you will be seeing the format of a java application. The format of an applet you will see when we start with applets in Lecture 9.

15 Format of a Java Application l A Java application consists of one or more classes A Java class consists of one ore more methods (functions) one of which must be the main method l A method is a collection of instructions (statements) describing how to carry out a particular task.. The following is a simple Java application to print the the message "Hello World!“ on the screen. public class Hello { public static void main ( String[] args ) { System.out.println("Hello World!"); }

16 Format of a Java Application – Contd. The Statement: public class Hello starts a new class named Hello public means the class is accessible to all other objects, we shall encounter private later. The class containing the main method must be declared as public l It is up to you to give names to your classes provided you follow the following simple rules and conventions. A class name »must be one word (no spaces) »must start with a letter »must not contain special characters (+, &, etc) »should start with capital letter »If a class name contains more than one English words, each word should start with a capital letter (e.g. MyFirstClass ) »It should reflect the function of the class A Java file must be saved with the name of the class it contains with the extension.java If it contains more than one class, the name of the class containing the main method must be used.

17 Format of a Java Application – Contd. The Statement: public static void main starts the main method. Again the main method must always be declared as public. The main method must always be declared as static, to be explained later - most methods are not static The parameter (String[],args) is required for the main method. It is used to pass command line arguments l Naming a method follow the same rule as naming a class, however, by convention, we shall always start a method with a small letter to differentiate it with a class. If a method contains more than one English word, the subsequent words should start with a capital letter. E.g. myFirstMethod The Statement: System.out.println(“Hello world”); prints a line of text “Hello world” on the standard output (the screen)

18 Format of a Java Application – Contd. l The standard output is represented by an object called out contained in the class System and referred to as System.out. l println is a method of the System.out object and can be used to print strings and numbers. e.g. System.out.println(3+4); displays 7 l When ever you use a method in Java, you must specify three items: »The object containing the method - System.out »The name of the method -. println »A pair of parenthesis which may contain any other information needed by the method (e.g. “Hello world”) l The println method prints the contents of its argument and move to the next line. E.g. the following prints two lines. System.out.println(“ICS Department”); Syetem.out.println(“KFUPM”); l Another method of the System.out object is print. This prints its argument but does not move to the next line. The following statements prints one line. System.out.print(“ICS Department”); Syetem.out.print(“KFUPM”);