Chapter 1 Introduction to Programming and the Java Language.

Slides:



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

Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
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.
OBJECT ORIENTED PROGRAMMING I LECTURE 2 GEORGE KOUTSOGIANNAKIS
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
1 Fall 2008ACS-1903 Chapter 1 Topics Java History Java Programs Why Program? Computer Systems: Hardware and Software Programming Languages What Is a Program.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
Introduction to Computers and Programming. Some definitions Algorithm: –A procedure for solving a problem –A sequence of discrete steps that defines such.
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
Topic 1: Introduction to Computers and Programming
Introduction to Computers and Programming. Some definitions Algorithm: Algorithm: A procedure for solving a problem A procedure for solving a problem.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Chapter 1 - Introduction. Ch 1Goals To understand the activity of programming To learn about the architecture of computers To learn about machine code.
COMP Computer Basics Yi Hong May 13, 2015.
CS102 Introduction to Computer Programming
Chapter Introduction to Computers and Programming 1.
Chapter 1 Introduction to Programming and the Java Language.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
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.
1. Fundamentals of Computer Systems Define a computer system Computer Systems in the modern world Professional standards for computer systems Ethical,
COMPUTER SOFTWARE Section 2 “System Software: Computer System Management ” CHAPTER 4 Lecture-6/ T. Nouf Almujally 1.
Topics Introduction Hardware and Software How Computers Store Data
Computer Hardware and Software Chapter 1. Overview Brief History of Computers Hardware of a Computer Binary and Hexadecimal Numbers Compiling vs. Interpreting.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
CISC105 General Computer Science Class 1 – 6/5/2006.
An Introduction to Computers August 12, 2008 Mrs. C. Furman.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 1 Introduction to Computers and Programming.
Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions.
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.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
CHAPTER 1 Introduction to Computers and Java Copyright © 2016 Pearson Education, Inc., Hoboken NJ.
Chapter 1: An Overview of Computers and Programming Languages
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
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.
An Object-Oriented Approach to Programming Logic and Design Chapter 1 An Overview of Computers and Logic.
Development of Computers. Hardware 1. Original concept: Charles Babbage 1840’s 2. 4 basic components of a computer system: input store mill output (Now:
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 : Overview of Computer and Programming By Suraya Alias
Computer and Programming. Computer Basics: Outline Hardware and Memory Programs Programming Languages and Compilers.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
Chapter 1: Introduction to Computers and Java 1-2 Chapter Topics Chapter 1 discusses the following main topics: –Introduction –Why Program? –Computer.
COMPUTER SYSTEM A computer system is define as combination of components designed to process data and store files. A computer system consists of four.
Chapter 1 An Overview of Computers and Programming Languages.
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. Introduction to Computers and Computing.
CHAPTER 1 Introduction to Computers and Java Copyright © 2016 Pearson Education, Ltd.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Java Programming: From the Ground Up
Lecture 1 Introduction Richard Gesick.
Topics Introduction Hardware and Software How Computers Store Data
CSCI-235 Micro-Computer Applications
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Java programming lecture one
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design
Topics Introduction Hardware and Software How Computers Store Data
Introduction CSC 111.
ICS103 Programming in C 1: Overview of Computers And Programming
Presentation transcript:

Chapter 1 Introduction to Programming and the Java Language

CHAPTER TOPICS What is Programming? Basic Computer Concepts Data Representation Introduction to Programming Languages Introduction to Programming –Programming Basics –Program Design with Pseudocode –Developing a Java Application

What is Programming? Creating an application such as a ticketing kiosk, a game, a restaurant ordering system or another business application Programming is a science –Many techniques have been developed for accomplishing basic programming tasks –Software engineering practices insure that the program is correct and maintainable Programming is also creative –We get to solve problems

Basic Computer Concepts Hardware –Central Processing Unit –Memory and Storage Devices Operating Systems Application Software Computer Networks and the Internet

Typical Computer Hardware CPU –executes the instructions of the program Hard disk and CD-ROM –store instructions and data so program can be loaded into memory and executed Main memory –stores the program instructions and data while executing Keyboard and mouse –used for data input Monitor –used to display output from a program Other accessories, such as a printer

A Typical Design of a Personal Computer

Central Processing Unit (CPU) Arithmetic Logic Unit –performs integer arithmetic and logical operations Floating-point Unit –performs floating-point operations Hardware registers –store data and memory addresses Instruction Pointer –keeps track of next instruction to execute Examples of CPUs: –Intel Core 2 Duo™, AMD Turion™ 64, Sun Microsystems SPARC, Hewlett-Packard PA-RISC, IBM POWER processor

CPU Instructions Move data from one location to another Perform a calculation Compare data Change the sequence of instructions to execute (the flow of control)

CPU Speed Rated in MHz or GHz In one clock cycle, a CPU: –fetches an instruction from memory –decodes the instruction –executes the instruction Pipelining allows overlap of operations to improve performance 2-Ghz CPU can execute 2 billion instructions per second

Memory or Storage Devices Memory consists of cells that hold one bit. A bit's value can be 0 or 1 A byte is 8 binary digits (bits) Storage capacity is expressed as: –Kilobytes (1,024 bytes) –Megabytes (1,048,576 bytes) –Gigabytes (1,073,741,824 bytes)

Operating System (OS) Software OS boots when computer is turned on, and runs continuously Controls the peripheral devices (disks, keyboard, mouse, etc.) Supports multitasking (multiple programs executing simultaneously) Allocates memory to each program Prevents one program from damaging another program OS Examples: Microsoft Windows, Linux

Application Software Written to perform specific tasks Runs "on top of" the operating system Examples: word processor, spreadsheet, database management system, games, Internet browser, etc.

Computer Networks Networks connect two or more computers so they can share files or devices Local Area Network (LAN) –computers located geographically close to one another Servers provide services –access to database –downloading of files – delivery Clients use these services –Most desktop computers are clients

The Internet A network of networks –Evolved from the ARPANET military research project Web servers deliver Internet content (web pages) to clients via a browser Web pages are identified using a URL (Uniform Resource Locator) Domain Name Servers (DNS) –translate a URL to an Internet Protocol (IP) address

Data Representation Binary Numbers –Expressed in base 2 system (two values are 0 and 1) Hexadecimal Numbers –Base-16 system used as shorthand for representing binary numbers The Unicode Character Set –Used to represent characters

Binary Equivalents of Decimal Numbers Decimal Binary Equivalent

Powers of 2 Decimal Decimal , , , , , ,768

Decimal (base 10) numbers A decimal number can be represented as the sum of powers of 10 (the base) with coefficients in the base 10 alphabet (0 - 9) For example: 2485 = = 2 * * * * = 2 * * * * 10 0

Converting From Decimal to Binary Just as a decimal number can be represented as a sum of powers of 10 (the base) with coefficients in the base 10 alphabet (0 to 9) A decimal number can be represented as the sum of powers of 2 (the base of the binary system) with coefficients in the base 2 alphabet (0 and 1) So we need an algorithm to do that

Converting From Decimal to Binary 1.Find the largest power of 2 that is smaller than or equal to the decimal number 2.Subtract that number from the decimal number 3.Insert 1 in binary number for position equivalent to that power of 2 4.Repeat 1 - 3, until you reach 0

Example: Convert 359 to Binary 1.Largest power of 2 that is smaller than 359 is 256 (2 8 ) = 103 so 359 = 2 8 * Largest power of 2 that is smaller than 103 is 64 (2 6 ) = 39 so 359 = 2 8 * * (continued on next slide)

Example: Convert 359 to Binary 1.Largest power of 2 that is smaller than 39 is 32 (2 5 ) = 7 so 359 = 2 8 * * * Largest power of 2 that is smaller than 7 is 4 (2 2 ) = 3 so 359 = 2 8 * * * * (continued on next slide)

Example: Convert 359 to Binary 1.Largest power of 2 that is smaller than 3 is 2 (2 1 ) = 1 so 359 = 2 8 * * * * * Largest power of 2 that is smaller than or equal to 1 is 1 (2 0 ) = 0, so we are finished

Our Results Insert a coefficient of 0 for any missing powers of 2 Thus, 359 = 2 8 * * * * * * * * * 1 Removing powers of 2, we get: or

Hexadecimal Numbers Base-16 number system Uses digits and letters A - F One hexadecimal digit can express values from 0 to 15 –For example: C represents 12 Thus, one hexadecimal digit can represent 4 bits

Hexadecimal - Binary Equivalents Hex Binary A B C D E F 1111

Examples Binary number: Hex equivalent: 1 A F 9 Binary number: Hex equivalent: B 3 B E

The Unicode Character Set Each character is stored as 16-bits Maximum number of characters that can be represented: 65,536 (2 16 ) ASCII character set (used by many programming languages) stores each character as 7 bits (maximum number of characters is 128) For compatibility, first 128 characters of Unicode set represent the ASCII characters

Some Unicode Characters Character Decimal Value Hex Value *42002A A B a b } D

Programming Languages Machine language Assembly language High-level languages

Machine and Assembly Languages Machine language –Written using CPU instruction set –Difficult to write and not portable Assembly language –Written using mnemonics for instructions and symbolic names for variables –Assembler converts code to machine language –Easier to write, but still not portable

High-Level Languages Examples: Fortran, Perl, COBOL, C++, Java Highly symbolic Portable among CPU architectures Languages can be designed for specific uses: –Perl: Internet applications –Fortran: scientific applications –COBOL: business applications

High-Level Languages Compiled –Compiler converts source code (instructions and data) into machine language, then program is executed Interpreted –Interpreter converts instructions into machine language at run time as instructions are executed –Usually executes more slowly than compiled program

Java Combination of compiler and interpreter Compiler converts source code into byte codes (an instruction set for a virtual, machine-independent processor) At run time, the Java Virtual Machine (JVM) interprets the byte codes and converts them into the machine language for the platform on which the program is running.

Object-Oriented Programming (OOP) Class –tool for encapsulating data and operations (methods) into one unit –defines a template, or model, for creating and manipulating objects Objects –data created using the class and its methods –an object is an instance of the class –creating an object is called instantiation

OOP Advantage: Reuse Well-written classes can be reused in new applications Shortens development time because programmers don't need to write that code Programs are more robust because the class code is already tested

The Java Language Created by Sun Microsystems in 1995 Syntax is based on C++ Object-oriented Supports Internet applications Provides an extensive library of prewritten classes Is portable among platforms Has built-in networking

Java Programs Applets –Small programs designed to add interactivity to websites –Downloaded with the web page and launched by the Internet browser Servlets –Run by web server on the server –Typically generate web content Applications –Programs that run standalone on a client

An Introduction to Programming Programming Basics Program Design with Pseudocode Developing a Java Application

Programming Basics Programming is translating a problem into ordered steps consisting of operations a computer can perform: –Input –Perform calculations –Compare values –Move data –Output The order of execution of instructions is called flow of control

Program Design with Pseudocode Pronounced sue-dough-code English-like language for specifying the design of a program Programmer can concentrate on design of program without worrying about Java language rules (syntax) Programmer then converts pseudocode into Java code

Four Types of Flow of Control Sequential Processing –Execute instructions in order Method Call –Jump to code in method, then return Selection –Choose code to execute based on data value Looping or Iteration –Repeat operations for multiple data values

Sequential Processing The pseudocode for calculating the sum of two numbers would look like this: read first number read second number set total to (first number + second number) output total

Method Call Calling the method executes the method Methods can take arguments (data to use) and return values Here is pseudocode for calculating the square root of an integer: read an integer call the square root method, passing the integer and receiving the square root output the square root

Selection The pseudocode for determining if a number is positive or negative is: read a number if the number is greater than or equal to 0 write "Number is positive." else write "Number is negative."

Looping The pseudocode for finding the sum of a set of numbers is: set total to 0 read a number while there was a number to read, add number to total read the next number write total

Developing a Java Application 1.Write the source code Using an Integrated Development Environment (IDE) or text editor Save in a.java file 2.Compile the source code: javac ClassName.java The compiler creates a.class file 3.Execute the application: java ClassName The Java Virtual Machine runs the code

A First Application 1 // First program in Java 2 // FirstProgram.java 3 4 public class FirstProgram 5 { 6 public static void main( String [] args ) 7 { 8 System.out.println( "Programming is not " 9 + " a spectator sport!" ); 10 System.exit( 0 ); 11 } 12 }

Java is case-sensitive. The source file must be saved with the same name as the class name with a.java extension. The class name and the source filename must match exactly, including capitalization. Common Error Trap

Types of Program Errors Compiler errors –Found by the compiler –Usually caused by incorrect syntax or spelling Run-time errors –Reported by the JVM –Usually caused by incorrect use of prewritten classes or invalid data Logic errors –Found by testing the program –Incorrect program design or incorrect execution of the design