Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Computer Programming CSC 1401: Introduction to Programming with Java Lecture 2 Wanda M. Kunkle.

Similar presentations


Presentation on theme: "Introduction to Computer Programming CSC 1401: Introduction to Programming with Java Lecture 2 Wanda M. Kunkle."— Presentation transcript:

1 Introduction to Computer Programming CSC 1401: Introduction to Programming with Java Lecture 2 Wanda M. Kunkle

2 2 Computer Programs Computers perform many different kinds of tasks. Computers perform many different kinds of tasks. In order to perform these tasks, they need to be provided with instructions. In order to perform these tasks, they need to be provided with instructions. These sets of instructions are called computer programs. These sets of instructions are called computer programs. Computer programs are written by people called computer programmers. Computer programs are written by people called computer programmers.

3 3 Types of Computer Programs There are two main types of computer programs (also called “software”): There are two main types of computer programs (also called “software”): System software System software Application software Application software

4 4 Types of Computer Programs System software System software Used by the computer to perform tasks Used by the computer to perform tasks Consists of two main types of programs: Consists of two main types of programs: Operating system Operating system Controls the way the computer works from the time it starts up until the time it shuts down Controls the way the computer works from the time it starts up until the time it shuts down Different operating systems include: Different operating systems include: Microsoft Windows Microsoft Windows Mac OS Mac OS UNIX UNIX Linux (UNIX-like OS) Linux (UNIX-like OS) Utility programs Utility programs Small programs that handle system management and maintenance Small programs that handle system management and maintenance Example: Disk defragmenter Example: Disk defragmenter

5 5 Types of Computer Programs Application software Application software Used by people to perform tasks Used by people to perform tasks General categories of application software include: General categories of application software include: Software development (e.g., jGRASP, MS Visual Studio) Software development (e.g., jGRASP, MS Visual Studio) Productivity (e.g., MS Word) Productivity (e.g., MS Word) Financial (e.g., Peachtree Accounting) Financial (e.g., Peachtree Accounting) Multimedia (e.g., Adobe Photoshop) Multimedia (e.g., Adobe Photoshop) Educational (e.g., MS Encarta) Educational (e.g., MS Encarta) Communication (e.g., Lotus Notes) Communication (e.g., Lotus Notes) Entertainment (e.g., computer games) Entertainment (e.g., computer games)

6 6 Computer Programming Languages Computer programmers write programs in a variety of programming languages. Computer programmers write programs in a variety of programming languages. These languages may be divided into three general types. In order of evolution, they are: These languages may be divided into three general types. In order of evolution, they are: Machine language Machine language Assembly language Assembly language High-level language High-level language

7 7 Computer Programming Languages Machine language Machine language The “natural language” of a particular computer The “natural language” of a particular computer Machine-dependent, i.e., defined by the hardware of a particular machine Machine-dependent, i.e., defined by the hardware of a particular machine Consists of strings of numbers ultimately reducible to 1s and 0s Consists of strings of numbers ultimately reducible to 1s and 0s Example: Example: 000000 10001 10010 01000 00000 100000

8 8 Computer Programming Languages Assembly language Assembly language A language that uses English-like abbreviations (symbols, or mnemonics) to represent the elementary operations of the computer A language that uses English-like abbreviations (symbols, or mnemonics) to represent the elementary operations of the computer Symbolic code is translated into machine code using a program called an assembler, hence the name “assembly language” Symbolic code is translated into machine code using a program called an assembler, hence the name “assembly language” Example: add $t0, $s1, $s2 Example: add $t0, $s1, $s2

9 9 Computer Programming Languages High-level language High-level language A language that uses English-like statements to accomplish multiple operations A language that uses English-like statements to accomplish multiple operations Portable, i.e., NOT machine-dependent Portable, i.e., NOT machine-dependent High-level language programs are translated into machine (or byte) code using programs called compilers High-level language programs are translated into machine (or byte) code using programs called compilers FORTRAN was the first high-level language FORTRAN was the first high-level language C, C++, Java, and Microsoft’s.NET languages (e.g., Visual Basic, C#) are currently among the most widely used high-level languages C, C++, Java, and Microsoft’s.NET languages (e.g., Visual Basic, C#) are currently among the most widely used high-level languages Example: t0 = s1 + s2 Example: t0 = s1 + s2

10 10 Brief History of the Java Programming Language Java was developed at Sun Microsystems in the early 1990’s as the result of a funded research project to develop intelligent consumer electronic devices. Java was developed at Sun Microsystems in the early 1990’s as the result of a funded research project to develop intelligent consumer electronic devices. It was created by James Gosling, who originally called it … ? (Your turn!) It was created by James Gosling, who originally called it … ? (Your turn!) Java is based on C++, a high-level language that evolved from the C language. Java is based on C++, a high-level language that evolved from the C language. Like C++, it provides support for object-oriented programming, a programming style in which reusable software components called “objects” are used to model items in the real world. Like C++, it provides support for object-oriented programming, a programming style in which reusable software components called “objects” are used to model items in the real world.

11 11 Brief History of the Java Programming Language Java is touted for its “portability,” which means that it is easier to write programs in Java that run on many different computers than it is to do so in other programming languages. Java is touted for its “portability,” which means that it is easier to write programs in Java that run on many different computers than it is to do so in other programming languages. Java is widely used to implement Internet- based applications and software for devices that communicate over a network (e.g., cell phones and PDAs). Java is widely used to implement Internet- based applications and software for devices that communicate over a network (e.g., cell phones and PDAs).

12 12 Developing a Java Program There are 5 phases in the development of a Java program: There are 5 phases in the development of a Java program: Edit Edit Compile Compile Load Load Verify Verify Execute Execute

13 13 Developing a Java Program 5 phases in the development of a Java program: 5 phases in the development of a Java program: Edit Edit The programmer uses an editor to create a source code file and saves it to disk. The programmer uses an editor to create a source code file and saves it to disk. Example: Using the text editor that comes with jGRASP to create Time.java Example: Using the text editor that comes with jGRASP to create Time.java Compile Compile The compiler translates the Java source code into bytecodes and saves the file to disk. The compiler translates the Java source code into bytecodes and saves the file to disk. Bytecodes are the “language” that the Java Virtual Machine (JVM) understands. (A virtual machine is a software application that simulates a real machine, i.e., computer.) Bytecodes are the “language” that the Java Virtual Machine (JVM) understands. (A virtual machine is a software application that simulates a real machine, i.e., computer.) Example: Time.class Example: Time.class Load Load The loader loads the.class file containing the bytecodes into the computer's memory. The loader loads the.class file containing the bytecodes into the computer's memory. Example: None. Example: None.

14 14 Developing a Java Program 5 phases in the development of a Java program: 5 phases in the development of a Java program: Verify Verify The bytecode verifier examines a.class file as it is being loaded to ensure that its bytecodes are valid and do not violate Java’s security restrictions. The bytecode verifier examines a.class file as it is being loaded to ensure that its bytecodes are valid and do not violate Java’s security restrictions. Example: None. Example: None. Execute Execute The JVM executes the program by reading the bytecodes and translating them into a language the computer can understand (i.e., machine language). The JVM executes the program by reading the bytecodes and translating them into a language the computer can understand (i.e., machine language). Example: None. Example: None.

15 15 Developing an Algorithm What is an "algorithm"? What is an "algorithm"? An algorithm is a series of actions (statements) executed in a specific order to solve a programming problem. An algorithm is a series of actions (statements) executed in a specific order to solve a programming problem. Let's develop an algorithm for a “time" program. Let's develop an algorithm for a “time" program. The problem: Write a Java program that prompts a user to enter a distance and a speed, then computes and prints the time it takes to travel that distance. The problem: Write a Java program that prompts a user to enter a distance and a speed, then computes and prints the time it takes to travel that distance.

16 16 Developing an Algorithm Let's develop an algorithm for a “time" program. Let's develop an algorithm for a “time" program. The algorithm: The algorithm: Set aside storage space for the input (distance, speed) and output (time) values. Set aside storage space for the input (distance, speed) and output (time) values. Prompt the user for the distance and the speed. Prompt the user for the distance and the speed. Read and store each of the values input by the user. Read and store each of the values input by the user. Calculate the time required to travel the given distance at the given speed. Calculate the time required to travel the given distance at the given speed. Display the time. Display the time.

17 17 Lab 1 Preview Before trying to solve the “time” problem, let’s first look at a simpler problem, the first programming problem in Lab 1: http://elvis.rowan.edu/~kunkle/SJU- Fall2007/LabProjects/csc1401lab01.html Before trying to solve the “time” problem, let’s first look at a simpler problem, the first programming problem in Lab 1: http://elvis.rowan.edu/~kunkle/SJU- Fall2007/LabProjects/csc1401lab01.html http://elvis.rowan.edu/~kunkle/SJU- Fall2007/LabProjects/csc1401lab01.html http://elvis.rowan.edu/~kunkle/SJU- Fall2007/LabProjects/csc1401lab01.html


Download ppt "Introduction to Computer Programming CSC 1401: Introduction to Programming with Java Lecture 2 Wanda M. Kunkle."

Similar presentations


Ads by Google