Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 1 l Background information »important regardless of programming.

Slides:



Advertisements
Similar presentations
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Advertisements

Lecture 1: Overview of Computers & Programming
Copyright © 2002 W. A. Tucker1 Chapter 1 Lecture Notes Bill Tucker Austin Community College COSC 1315.
CSCE 145: Algorithmic Design I Chapter 1 Intro to Computers and Java Muhammad Nazmus Sakib.
Introduction to Computers and Java Module 1. Objectives overview computer hardware and software introduce program design and object-oriented programming.
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Introduction to Computers and Java Objects
1 Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
Lecture 1: Intro to Computers Yoni Fridman 6/28/01 6/28/01.
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition by Tony Gaddis, Judy Walters,
ICS 102 Computer Programming University of Hail College of Computer Science & Engineering Computer Science and Software Engineering Department.
Introduction Algorithms and Programming. Computer Programming  A form of problem solving  Or, more accurately, a way to solve problems  What we will.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 1 Introduction To Computers.
Introduction to Computers and Programming
1 I.Introduction to Algorithm and Programming Algoritma dan Pemrograman – Teknik Informatika UK Petra 2009.
CS102 Introduction to Computer Programming
Computer Programming-1 CSC 111 Chapter 1 : Introduction.
1 Chapter-01 Introduction to Computers and C++ Programming.
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 Coding Introduction.
1 Lecture 2 : Computer System and Programming. Computer? a programmable machine that  Receives input  Stores and manipulates data  Provides output.
Lecturer: Dr. AJ Bieszczad Chapter 1 COMP 150: Introduction to Object-Oriented Programming 1-1 l Background information »important regardless of programming.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
Topics Introduction Hardware and Software How Computers Store Data
Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 1 l Background information »important regardless of programming.
©Silberschatz, Korth and Sudarshan1.1 Chapter 1: Introduction to Computers and Java Objects Background information  hardware  software  computer languages.
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.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
111 © 2002, Cisco Systems, Inc. All rights reserved.
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
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 Computers and Java Chapter 1.3. A Sip of Java: Outline History of the Java Language Applets A First Java Program Compiling a Java Program.
Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Java Byte Code l The Java compiler generates Java Byte Code. (Most.
Visual C++ Programming: Concepts and Projects
Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 1 l Background information »important regardless of programming.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 1- 1 October 20, October 20, 2015October 20, 2015October 20,
1 Problem Solving with C++ The Object of Programming Walter Savitch Chapter 1 Introduction to Computers and C++ Programming Slides by David B. Teague,
Systems Software Operating Systems. What is software? Software is the term that we use for all the programs and data that we use with a computer system.
Chapter 1 Section 1.1 Introduction to Java Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
Introduction to Computers and Java Module 1. Objectives overview computer hardware and software introduce program design and object-oriented programming.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
1 Lecture 2 : Computer System and Programming. Computer? a programmable machine that  Receives input  Stores and manipulates data  Provides output.
Mrs. Ulshafer August, 2013 Java Programming Chapter 1.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Beginning Snapshots Chapter 0. C++ An Introduction to Computing, 3rd ed. 2 Objectives Give an overview of computer science Show its breadth Provide context.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Chapter 1 : Overview of Computer and Programming By Suraya Alias
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
A.Abhari CPS1251 Topic 1: Introduction to Computers Computer Hardware Computer components Connecting Computers Computer Software Operating System (OS)
Computer and Programming. Computer Basics: Outline Hardware and Memory Programs Programming Languages and Compilers.
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Software Engineering Algorithms, Compilers, & Lifecycle.
Introduction to Computers and Programming
Chapter 1 Coding Introduction.
Programming Language Hierarchy, Phases of a Java Program
Lecture 1: Introduction to JAVA
Introduction to Computers and Java
Java programming lecture one
Computers: Hardware and Software
Introduction CSC 111.
Presentation transcript:

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 1 l Background information »important regardless of programming language l Introduction to Java Introduction to Computers and Java Objects

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 2 Computer Basics l Computer system: hardware + software l Hardware: the physical components l Software: the instructions that tell the hardware what to do

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 3 Common Hardware Components l Processor (CPU) »Central Processing Unit »Interprets and executes the instructions l Memory »main & auxiliary »holds data and instructions l I nput device(s) »mouse, keyboard, etc. l O utput device(s) »video display, printer, etc. l CPU and memory are physically housed together Standard Hardware Organization Memory (main & auxiliary) Processor (CPU) Input Devices (such as mouse and keyboard) Output Devices (such as video display or printer)

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 4 Physical Organization l Keyboard l Monitor l Chassis »CPU »memory »disk drives »I/O connectors »etc.

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 5 Two Kinds of Memory l Main »working area »temporarily stores program and data (while program is executing) l Auxiliary »permanent (more or less) »saves program and results »includes floppy & hard disk drives, CDs, tape, etc.

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 6 Main Memory Organization l Bit = one binary digit »Binary digit can have only one of two values, 0 or 1 l Byte = 8 bits l “Byte Addressable” »Main memory is a list of numbered locations that contain one byte of data in each location l Number of bytes per data item may vary

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 7 Auxiliary Memory Organization

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 8 Running a Program Program Computer Data (input for the program) Output Program—a set of instructions for a computer to follow

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 9 Many Types of Programs l User-created applications l Existing applications »word-processor/editor »web browser »compiler or assembler »etc. l Operating System »DOS, Microsoft Windows, MacOS, Linux, UNIX, etc.

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 10 Various Types of User Interfaces l Command-line »type in key words and letters »DOS and UNIX l Menu »parts of DOS and Windows l GUI (Graphical User Interface) »click on icon »also called “event-driven” »MacOS, Windows

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 11 Programming Language Hierarchy

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 12 The highs and lows of programming languages... High-Level Language (HLL) »closest to natural language »words, numbers, and math symbols »not directly understood by hardware »“portable” source code (hardware independent) »Java, C, C++, COBOL, FORTRAN, BASIC, Lisp, Ada, etc. Machine Language (lowest level) »least natural language for humans, most natural language for hardware »just 0s and 1s »directly understood by hardware »not portable (hardware dependent)

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 13 Assembly Language (middle level) l a more or less human readable version of machine language l words, abbreviations, letters and numbers replace 0s and 1s l easily translated from human readable to machine executable code l like machine code, not portable (hardware dependent)

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 14 Getting from Source to Machine Code l “Compiling a program” translating from a high-level language source code to machine (object, or executable) code. l “Compiler” a program that translates HLL source code to machine (object, or executable) code. l “Assembly” translating from assemble language source code to machine (object, or executable) code. l “Assembler” a program that translates assembly source code to machine (object, or executable) code. l Compilers need to know the specific target hardware

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 15 Compilers vs. Assemblers vs. Interpreters l Compilers and Assemblers »translation is a separate user step »translation is “off-line,” i.e. not at run time l Interpreters - another way to translate source to object code »interpretation (from source to object code) is not a separate user step »translation is “on-line,” i.e. at run time Compiler, Assembler, or Interpreter Source Code Object Code

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 16 Algorithms l Algorithm - a set of instructions (steps) for solving a problem. »must be precise »must be complete l May be in a number of different formats »natural language (such as English) »a specific programming language »a diagram, such as a flow chart »pseudocode - a mix of natural and programming language

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 17 Example of an Algorithm Algorithm that determines the total cost of a list of items: 1. Write the number 0 on the blackboard. 2. Do the following for each item on the list: --Add the cost of the item to the number on the blackboard. --Replace the old number on the board by this sum. 3. Announce that the answer is the number written on the board

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 18 Reusable Components Advantages of using reusable components: l saves time and money l components that have been used before are often better tested and more reliable than new software Make your classes reusable: l encapsulation l general classes have a better chance of being reused than ad hoc classes

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 19 Program Design Process l Design, then code l Design process »define the problem clearly »design objects your program needs »develop algorithms for the methods of objects »describe the algorithms, usually in pseudocode »write the code »test the code »fix any errors and retest

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 20 Testing and Debugging l Even with careful programming, your code could still contain errors and must be thoroughly tested. l Bug—a mistake in a program l Debugging—fixing mistakes in a program

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 21 Types of Errors l Syntax l Run-Time l Logic

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 22 Syntax l The set of grammar rules for a programming language is called the syntax. l The compiler checks your program to make sure it is a valid Java program. l If your program is not a valid Java program, then the compiler outputs a message indicating a syntax error.

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 23 Syntax Errors l caught by compiler (“compiler-time error”) l automatically found, usually the easiest to fix l cannot run code until all syntax errors are fixed l error message may be misleading Example: Misspelling a command, for example “rturn” instead of “return”

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 24 Run-Time Errors l An execution error (during run-time) l Not always so easy to fix l Error message may or may not be helpful l Not detected by the compiler. Example: Division by zero - if your program attempts to divide by zero it automatically terminates and prints an error message.

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 25 Logic Errors Just because it compiles and runs without getting an error message does not mean the code is correct! l An error in the design (the algorithm) or its implementation »code compiles without errors »no run-time error messages »but incorrect action or data occurs during execution l Generally the most difficult to find and fix l Need to be alert and test thoroughly »think about test cases and predict results before executing the code

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 26 Logic Error Examples l Algorithm Error: »averageOfFiveScores = SumOfScores/2 (should divide by 5) l Implementation Error: »typed in wrong symbol in source code - sum = a - b; (should be sum = a + b; )

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 27 Finally! Now, a taste of Java! History l James Gosling, Sun Microsystems, Inc. l originally a language for programming home appliances l later (1994) used for World Wide Web applications (since byte code can be downloaded and run without compiling it) l eventually used as a general-purpose programming language (for the same reason as above plus it is object- oriented) l Why the name “Java”? Not sure - it may just be a name that came during a coffee break and it had not been copyrighted, yet.

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 28 Applets vs. Java Applications l Applets »Java programs intended to be downloaded via the WWW and run immediately »“little applications” »requires a web browser l Applications »Java programs intended to be installed then run »often larger applications l Slightly different programming for each, but both are easy to do

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 29 Compiling a Java Program Assuming the java compiler is already set up and all the files are in the same folder (subdirectory): l Each class used in a program should be in a separate file l The name of the file should be the same as the class except with “.java” added to it l We are using “NetBeans” for our IDE (Integraged Development Environment) to compile (“Build”) and run (“Execute”) our programs in this class.

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 30 Running a Java Program Only the class with public static void main(String[] args) can be run »the critical word to look for is main For Sun Microsystems’ JDK (Java Development Kit), type java » is the same name used in the original source file.java »use just ; do not use.java or.class l Note that you compile in a separate step and invoke the Java interpreter and linker when you run the program.

Chapter 1Java: an Introduction to Computer Science & Programming - Walter Savitch 31 Summary Part 1 l A computer’s main memory holds both the program that is currently running and its data. l Main memory is a series of numbered locations, each one containing a single byte. l Auxiliary memory is for more or less permanent storage. l A compiler is a program that translates a high-level language, like java, into a lower level format (“byte-code” for java). l Actual translation of Java byte-code to the hardware’s specific machine code occurs at run time (it is interpreted). l An algorithm is a set of instructions for solving a problem (it must be complete and precise).