Introduction CSC 111.

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

Lecture 1: Overview of Computers & Programming
CSCE 145: Algorithmic Design I Chapter 1 Intro to Computers and Java Muhammad Nazmus Sakib.
Chapter 1: An Overview of Computers and Programming Languages J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program.
1 Fall 2008ACS-1903 Chapter 1 Topics Java History Java Programs Why Program? Computer Systems: Hardware and Software Programming Languages What Is a Program.
Introduction to Computer Programming CSC 1401: Introduction to Programming with Java Lecture 2 Wanda M. Kunkle.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
Introduction to Java.
Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 1 Introduction To Computers.
Java PAL.  Contains the development kit and the runtime environment ( aka the Java Virtual Machine )  Download Link:
CHAPTER 1 GC 101 Introduction to computers and programs.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 1 – Introduction to Computers, the Internet, and the Web Outline 1.1 Introduction 1.2 What Is a.
Computer Programming-1 CSC 111 Chapter 1 : Introduction.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
Chapter 1 An Overview of Computers and Programming Languages.
Introduction to Java Lecture # Java History Green Team started by Sun Microsystems. *7 Handheld controller for multiple entertainment systems.
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
What is a Computer? An, electrical machine, that can be programmed to accept data (input), process it into useful information (output) and store it away.
INTRODUCTION TO JAVA CHAPTER 1 1. WHAT IS JAVA ? Java is a programming language and computing platform first released by Sun Microsystems in The.
Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions.
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Object Oriented Programming Lecture 3. Introduction  In discussing Java, some items need to be clarified  The Java programming language  The Java virtual.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, D.S. Malik D.S. Malik.
CHAPTER 1 INTRODUCTION 1 st Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
CHAPTER 1 INTRODUCTION 1 st semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
CT1513 Introduction To java © A.AlOsaimi.
J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second Edition D.S. Malik D.S. Malik.
CHAPTER 1 INTRODUCTION 2 nd Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
CHAPTER 1 INTRODUCTION 2 nd Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
Chapter 1: An Overview of Computers and Programming Languages
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
CS2301:Computer Programming 2
A.Abhari CPS1251 Topic 1: Introduction to Computers Computer Hardware Computer components Connecting Computers Computer Software Operating System (OS)
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Chapter 1 Introduction. Components of a Computer CPU (central processing unit) Executing instructions –Carrying out arithmetic and logical operations.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Overview of Programming.
ITP 109 Week 2 Trina Gregory Introduction to Java.
Chapter 1 An Overview of Computers and Programming Languages.
Introduction to Computer Programming using Fortran 77.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages.
Introduction to 1. What is Java ? Sun Microsystems Java is a programming language and computing platform first released by Sun Microsystems in The.
CHAPTER 1 OVERVIEW OF COMPUTER AND PROGRAMMING 1.1 Electronic Computer Then and Now 1.2 Computer Hardware 1.3 Computer Software 1.4 The Software Development.
Chapter 1: Introduction to Computers and Programming
Chapter 1 Introduction 2nd Semester H
Java Programming: From the Ground Up
Lecture 1b- Introduction
Chapter 1 – Introduction to Computers, the Internet, and the Web
Key Ideas from day 1 slides
Lecture 1: Introduction to JAVA
DDC 1023 – Programming Technique
Introduction to.
Introduction
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Java programming lecture one
C++ Programming: From Problem Analysis to Program Design
Computer Science I CSC 135.
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Chapter 1 Introduction(1.1)
CMP 131 Introduction to Computer Programming
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
(Computer fundamental Lab)
Understand the interaction between computer hardware and software
Chap 1. Getting Started Objectives
Chap 4. Programming Fundamentals
Computer Programming-1 CSC 111
Chapter 1 Introduction to Programming
ICS103 Programming in C 1: Overview of Computers And Programming
Presentation transcript:

Introduction CSC 111

Outline 4.1 Java Program Compilation 4.2 Java Virtual Machine (JVM) 1. Computer Organization 2. Program Solving Cycle 3. Program Components - Examples 4. Program Compilation 4.1 Java Program Compilation 4.2 Java Virtual Machine (JVM) 5. Program Testing & Debugging

1. Computer Organization A computer consists of: Hardware: Physical devices of computer system Software: Programs that run on computers A program is a set of instructions written in a high programming language (such as C/C++ or Java) to do a specific task.

1. Computer Organization (cnt’d) The main components of a computer system are: 1. Input unit (mouse, keyboard) 2. Output unit (printer, monitor, audio speakers) 3. Memory unit (retains input data, calculated data and instructions) 4. Central processing unit (CPU) which consists of: 4.1 Control unit (supervises the operation of other devices) 4.2 Arithmetic and Logic unit (ALU) (performs calculations) 5. Secondary storage (hard drives, floppy drives)

Refer to figure in Slide 6 2. Program Solving Cycle Solving a program goes through the following main steps: 1. Analysis: Outline the solution requirements 2. Design an appropriate algorithm or a flowchart. 3. Code the solution in a high programming language (such as Java) 4. Compile the code into machine language. Verify that the program works: 4.1 If there is an error, correct it by going to step 3. 4.2 If there is no error, proceed to step 5. 5. Run the program. Verify the results: 5.1 If the output does not give the required results, go to step 1. 5.2 If the output matches the required result, you are done. Refer to figure in Slide 6

2. Program Solving Cycle (cnt’d) Syntax Error Logical or Run-time Error

3. Program Components A program consists of the following: Input: Data to begin with to solve the program. Output: The target of the problem. This is the expected result. Nouns in the problem statement suggest input and output data. Processing: This is the set of instructions that drive from the input to the output. Verbs in the problem suggest the processing steps. Input Data Output Data Processing

Example 1 - Area and Perimeter of a Rectangle Write a program that calculates the area and the perimeter of a rectangle of width and length 5 cm and 3 cm respectively. Input Width = 5 cm Length = 3 cm Output Area = ? Perimeter = ? Processing (Input  Output) Area = length*width = 5 * 3 = 15 cm2 Perimeter = 2*( length + width) = 2*(3 + 5) = 16 cm If the values of the input data are not given in the problem statement, they may be read from the user through the keyboard.

Example 2 - Area and Perimeter of a Circle Calculate the area and the perimeter of a circle of radius = 2.5 cm. Input Radius = 2.5 cm PI = 3.14 Output Area = ? Perimeter = ? Processing (Input  Output) Area = PI * Radius * Radius = 3.14*6.25 = 19.625 cm2 Perimeter = 2 * PI * Radius = 2*3.14*2.5 = 15.7 cm If the values of the input data are not given in the problem statement, they may be read from the user through the keyboard.

Example 3 - Sum and Average of 5 Numbers Calculate the sum and the average of the numbers 10, 20, 30, 40 and 50. Input Five numbers = x1, x2, x3, x4, x5 Output Sum = ? Average = ? Processing (Input  Output) Sum = x1+x2+x3+x4+x5 =10+20+30+40+50= 150 Average = Sum/5 = 150/5 = 30 If the values of the input data are not given in the problem statement, they may be read from the user through the keyboard.

4. Program Compilation Computers do not understand programs written in high programming languages (source code) such as C++ and Java Therefore, programs must be converted into machine code that the computer can understand and execute A software that translates a source code from a high-level programming language into machine code is called a compiler Source Code Machine Code Compiler

4.1 What is Java ? Java is a programming language and computing platform first released by Sun Microsystems in 1995.  The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. The Java language is accompanied by a library of extra software that we can use when developing programs. The library provides the ability to create graphics, communicate over networks, and interact with databases. The set of supporting libraries is huge.

4.2 Java applications and applets Applications – standalone Java programs Applets – Java programs that run inside web browsers Java is the first programming language to deliberately embrace the concept of writing programs that can be executed on the Web.

4. Program Compilation (cnt’d) The compiler is a software that checks the correctness of the source code according to the language rules. If the compiler produces an error, this is called a syntax error. Translates the source code into a machine code if no errors were found. Machine code depends on the computer hardware: we say that the compiled version is platform-dependent. For example, a program compiled on a machine that works under the Windows operating system, cannot run on another machine that works under the MAC operating system. In this case, the program should be re-compiled under the MAC operating system. However, Java is characterized by being platform-independent. In other words, a Java program that is compiled under the Windows OS can run under the MAC OS without being re-compiled. Refer to figure in Slide 13 -16

4. Program Compilation (cnt’d) Platform-Dependent Compilation

4.1 Java Programs Compilation (cnt’d) The Java compiler translates the source code (with extension “.java”) into a bytecode (with extension “.class”) rather than machine code. Then, a bytecode is converted into machine code using a Java Interpreter. Source Code Bytecode Java VM or JVM = Java Virtual Machine

4.1 Java Programs Compilation The same bytecode is run on any computer installed with a Java Interpreter. “Hello.java” “Hello.class”

4.1 Java Programs Compilation (cnt’d) JVM = Java Virtual Machine

Hello world JAVA program // import section public class MyFirstprogram { // main method public static void main( String args[] ){ System.out.println(“Hello World”); } // end main } // end class

Compiling a Java program : Call the Java compiler javac . Saving a Java program : A file having a name same as the class name should be used to save the program. The extension of this file is ”.java”. “MyFirstprogram.java”. Compiling a Java program : Call the Java compiler javac . The Java compiler generates a file called ” MyFirstprogram.class” (the bytecode). Running a Java program Call the Java Virtual Machine java: java MyFirstprogram.class

4.2 Java Virtual Machine (JVM) Java Virtual Machine (JVM): A hypothetical computer developed to make Java programs machine independent (i.e. run on many different types of computer platforms). A JVM consists of the following components: The class loader: stores the bytecodes into the computer memory Bytecode verifier: ensures that the bytecodes do not violate security requirements Bytecode interpreter: translates the bytecode into machine language Refer to figure in Slide 18

5. Program Testing and Debugging After program compilation, the programmer needs to make sure that the output of the program matches the expected results. Two types of errors may be encountered Logical Errors: The program runs but provides wrong output. Runtime errors: The program stops running suddenly. This happens when the program asks the OS to execute a non-accepted statement (such as division by zero). Debugging When an error is encountered, it should be found, understood, and corrected.