Introduction to Computer Systems and the Java Programming Language.

Slides:



Advertisements
Similar presentations
 The central processing unit (CPU) interprets and executes instructions.  The “brains” of the computer.  The speed of the processor is how fast it.
Advertisements

IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Chapter 1: An Overview of Computers and Programming Languages J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Wednesday, 9/4/02, Slide #1 1 CS 106 Intro to CS 1 Wednesday, 9/4/02  Today: Introduction, course information, and basic ideas of computers and programming.
Lecture 1: Intro to Computers Yoni Fridman 6/28/01 6/28/01.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Introduction to Computers and Programming. Some definitions Algorithm: –A procedure for solving a problem –A sequence of discrete steps that defines such.
COMP 14 Introduction to Programming
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
1 Introduction to Computers Prof. Sokol Computer and Information Science Brooklyn College.
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.
Hello, world! Dissect HelloWorld.java Compile it Run it.
COMP Computer Basics Yi Hong May 13, 2015.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Chapter 1: An Introduction to Computers and Programming Prelude to Programming Concepts and Design Copyright © 2001 Scott/Jones, Inc.. All rights reserved.
Why Program? Computer – programmable machine designed to follow instructions Program – instructions in computer memory to make it do something Programmer.
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.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Chapter 1 An Overview of Computers and Programming Languages.
Topics Introduction Hardware and Software How Computers Store Data
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.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
An Introduction to Computers August 12, 2008 Mrs. C. Furman.
Introduction to Computers
1 Introduction to Computers Prof. Sokol Computer and Information Science Brooklyn College.
Copyright © 2003 by Prentice Hall Module 5 Central Processing Unit 1. Binary representation of data 2. The components of the CPU 3. CPU and Instruction.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 1 Introduction to Computers and Programming.
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.
Computer Parts. Two Basic Parts Hardware & Software.
Intro to Computers Computer Apps 1.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
Mrs. Ulshafer August, 2013 Java Programming Chapter 1.
1 Programming Fundamentals How to Program in C++ How to Program in C++
CompSci Today’s topics Parsing Java Programming Notes from Tammy Bailey Reading Great Ideas, Chapter 3 & 4.
Computer Organization. The digital computer is a digital system that performs various computational tasks Digital computer use binary number system which.
Scott Marino MSMIS Kean University MSAS5104 Introduction to Programming with Data Structures and Algorithms Week 2 Scott Marino.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
The Computer System CS 103: Computers and Application Software.
Computer Systems. Bits Computers represent information as patterns of bits A bit (binary digit) is either 0 or 1 –binary  “two states” true and false,
Computer and Programming. Computer Basics: Outline Hardware and Memory Programs Programming Languages and Compilers.
Chapter 1 An Overview of Computers and Programming Languages.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Introduction To Computer Programming – 1A Computer Parts, Words, and Definition Herriman High School.
Java Programming: From the Ground Up
HelloWorld.java import java.awt.*; public class HelloWorld extends
Chapter 1: An Overview of Computers and Programming Languages
Topics Introduction Hardware and Software How Computers Store Data
Chapter 1: An Overview of Computers and Programming Languages
The Central Processing Unit
Chapter 1: An Overview of Computers and Programming Languages
CSCI 161: Introduction to Programming
Introduction to Computers
Computer Electronic device Accepts data - input
Computer Electronic device Accepts data - input
Introduction to Computers
Topics Introduction Hardware and Software How Computers Store Data
Computer Electronic device Accepts data - input
ICS103 Programming in C 1: Overview of Computers And Programming
Computer components.
Presentation transcript:

Introduction to Computer Systems and the Java Programming Language

Computer systems  A computer is a system made up of components  Two categories of components: –hardware: electronic and mechanical parts –software: programs and data  Main hardware components of a computer system –Processor (CPU) –Main memory –Secondary memory –Input devices (keyboard, mouse) –Output devices (monitor, printer)

Processor  Central processing unit (CPU), processor chip  “Brain” of the computer  Contains the logic circuitry controlling the interpretation and execution of machine instructions –programmed instructions –arithmetic and logical operations on data –controls input/output functions  Instructions –electronic operations –executed one at a time –millions per second –collection of instructions  executable program

Computer memory  Holds data and programs  Main memory –temporary memory –stores programs and data when the processor is actively using them –random access memory (RAM)  Secondary memory –permanent –stores (saves) programs and data on a long-term basis –hard disk, floppy disks

Binary  In both main and secondary memory, information is stored as patterns of bits  Binary  “Two states” –1 and 0 –true and false –on and off  Binary devices –can be in just one of two possible states at a time  A single binary value is called a bit –binary digit

Example  A light switch is a binary device –holds one bit of information –can be in one of two states: on or off –can not be in any other possible state  A light dimmer is not a binary device –can be on, off, or some state in-between –difficult to characterize in-between states how to turn a light exactly 50% or “half” on? how to tell “how much” a light is on?

Binary representation  Bits can be used to represent patterns  Specifically, any system or set of symbols can be translated into bit patterns –patterns of ones and zeros –  Example: characters from any language alphabet  Require enough bits so that all symbols have a unique bit pattern to represent them –How many bits are needed to represent the English alphabet?  Require set of symbols is finite

Bits and Bytes  Bit –single binary or 0/1 value  One bit of information is so little that usually computer memory is organized into groups of eight bits  Byte: group of eight bits –kilobyte (KB): 2 10 = 1024 bytes –megabyte (MB): 2 20 = 1,048,576 bytes 1MB = 2 10 KB –gigabyte (GB): 2 30 = 1,073,741,824 bytes 1GB = 2 10 MB

High-level programming languages  Most programs are created using a high level programming language –closer to human language than machine language (low-level) –Java, C, C++, Pascal, FORTRAN –easier to read, write, and maintain  Source programs are translated to executable (machine language) programs by a compiler  Different programming languages require different compilers  Language can have many compilers –computer type, software package

Source program  Executable program  Create source program using a text editor –written (typed) instructions in a high-level language  Save source program on disk  Compile source program –compiler translates source program to executable program –source program remains unchanged –a new executable program is created –executable program is saved on disk  Run executable program –copied into main memory and run by processor

HelloWorld.java import java.awt.*; public class HelloWorld extends java.applet.Applet { TextField t; public void init() { t = new TextField(50); t.setText(“Hello World!"); add(t); }

Java programs  Java programs are created as text files using a text editor (like emacs!)  Save to disk with.java file extension HelloWorld.java  The file contains characters (stored as bytes) –file can be printed, displayed on monitor, or edited –file cannot be directly executed (run) by the computer system  Java must first translate the program into bytecodes before it can be run

Bytecodes  Java bytecode –machine instruction for the Java processor  Java compiler javac translates the source program into bytecodes  Bytecode file has same name as the source program with a with.class file extension HelloWorld.class HelloWorld.javajavacHelloWorld.class source program Java compiler Java bytecodes

Java Virtual Machine (JVM)  Bytecode (class) file will contain exactly the same bytecodes no matter what computer system is used  Bytecode file is executed by a Java bytecode interpreter –processor specific executable program  Each type of computer system has its own Java interpreter that can run on that system.  Any computer system can execute Java bytecode programs if it has a Java interpreter  Computers with Java interpreters are called Java Virtual Machines –a “computer” with a Java processor that can run Java bytecodes

Java applets  An applet is a Java bytecode program that runs on a Web browser  Most newer Web browsers have Java interpreters  Web pages on the Internet contain instructions that send Java bytecodes to your computer  Web browser runs the Java applet with its built-in interpreter

Data Types  Computer memory stores arbitrary bit patterns  Meaning of a bit pattern depends its use  The particular pattern used for a particular string of bits is a data type. –uses bits to represent values –values are any kind of data a computer can process –all values are represented using some data type  Example: What does the following pattern of 16 bits represent?  No way to know without more information  If data type is short (a Java type) it represents 103

Java data types  Primitive –types of data that are so fundamental ways to represent them are built into Java  Reference –reference to (an address of) the value or set of values represented by the variable

Primitive data types  Primitive data values use fixed number of bytes  There are exactly eight primitive data types: byte, short, int, long, float, double, char, boolean  A programmer can not create new primitive data types  Any data type you invent will be a type of object

Java primitive data types Primitive TypeDescriptionRange byte 8-bit integer-128 to 127 short 16-bit integer to int 32-bit integer to long 64-bit integer-2 63 to float 32-bit floating point to double 64-bit floating point to char Unicode character boolean Boolean variable false and true

Declaration and initialization  Declaration: type ; type = ;  Variable names –any combination of letters, numbers, and the underscore character –may not start with number –may not be reserved word ( int, return ) –may not be same as method name –case-sensitive ( num and Num are different)

Examples  int x, y, z;  int sum = 0;  float f;  double pi = 3.14;  char first = ‘T’, middle = ‘L’, last = ‘B’;  char first = ‘T’; char middle = ‘L’; char last = ‘B’;

Basic operators OperatorJavaDescription Assignment = assigns rhs to lhs Arithmetic +,-,*,/,% addition, subtraction, multiplication, division, remainder Unary -,++,-- negative, auto increment, auto decrement Equality ==, != equals to, not equals to Relational,>= less than, less than or equals to, greater than, greater than or equals to Logical &&,||,! AND, OR, NOT

Conditional statements  if-else if ( expression ) { … statements … } else { … statements … }

Conditional statements  while while ( expression ) { … statements … }  for for ( initialization ; test ; update ) { … statements … }

Java methods int sum_between(int x, int y) { int k, sum = 0; for(k = x; k <= y; k++) { sum = sum+k; } return sum; }