Chapter 1 Introduction to Computers, Programs, and Java

Slides:



Advertisements
Similar presentations
L1:CSC © Dr. Basheer M. Nasef Lecture #1 By Dr. Basheer M. Nasef.
Advertisements

Chapter 1: Computer Systems
The Java Programming Language
Outline Java program structure Basic program elements
1 Chapter 1 Introduction to Computers, Programs, and Java.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 1 Introduction.
Chapter 1 Introduction. © 2004 Pearson Addison-Wesley. All rights reserved1-2 Outline Computer Processing Hardware Components Networks The Java Programming.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Chapter 1 Introduction.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Java: Chapter 1 Computer Systems Computer Programming II Aug
Chapter 1 Introduction to Computers, Programs, and Java
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 1 Introduction to Computers, Programs, and Python.
Chapter 1 Introduction to Computers, Programs, and Python 1.
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 1 Introduction to Computers, Programs, and C++
Chapter 1 Introduction to Computers, Programs, and Java
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computer Science.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Computer and Operating System.
© 2006 Pearson Education Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition.
Chapter 1.4 Programming languages Homework Due: Monday, August 11, 2014.
Java: Chapter 1 Computer Systems Computer Programming II.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Programming Languages Machine.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Computers,
CPCS  Problem Solving in Everyday Life  Types of Problems  Problem Solving with Computers  Difficulties with Problem Solving 0-3.
1 Chapter 1 Introduction to Computers, Programs, and Java.
Java Language and SW Dev’t
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Programs,
Chapter 1 Introduction to Java 10/8/2015 Lecture 1 1.
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 1 Introduction.
The Java Programming Language
ECOM 2314 Computer Programming I
Introduction. Objectives An overview of object-oriented concepts. Programming and programming languages An introduction to Java 1-2.
Chapter 1 Introduction to Computers, Programs, and Java 1.
Chapter 1: Introduction to Programs, and Java 1. Objectives To review programs (§ ). To understand the relationship between Java and the World Wide.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved What is a Computer? A computer.
Object Oriented Rabie A. Ramadan, PhD Slides are exerted from different sources.
Liang, Introduction to C++ Programming, (c) Chapter 1 Introduction to Computers, Programs, and C++
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
1 Chapter 1 Introduction to Computers, Programs, and Java.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Computers,
CHAPTER 1 INTRODUCTION TO COMPUTERS, PROGRAMS, AND PYTHON 1.
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
Chapter 1 Introduction to Computers, Programs, and Python
Chapter 1 Introduction to Computers, Programs, and C++
Working with Java.
Objectives To review computer basics, programs, and operating systems (§ ). (Optional) To represent numbers in binary, decimal, and hexadecimal (§1.5.
Chapter 1 Introduction to Computers, Programs, and Java
Chapter 1 Introduction to Computers, Programs, and Java
GC101 Introduction to computer and program
Chapter 1 Introduction to Computers, Programs, and C++
Chapter 1 Introduction to Computers, Programs, and Java
Chapter 1 Introduction to Computers, Programs, and Java
Java programming lecture one
Chapter 1 Introduction to Computers, Programs, and Java
Chapter 1 Introduction to Computers, Programs, and Java
Chapter 1: Computer Systems
Units with – James tedder
Chapter 1 Introduction to Computers, Programs, and C++
Focus of the Course Object-Oriented Software Development
Computer and Operating System slides extended from Liang’s Java Programming textbook by Professor Parson for CSC 352.
Introduction to Computers, Programs, and Java
Presentation transcript:

Chapter 1 Introduction to Computers, Programs, and Java

Objectives To review computer basics, programs, and operating systems To understand programs and programming languages To know Java To know Java JDK and popular IDEs To write a simple Java program To know error types To Know basic syntax of a Java program

What is a Computer? A computer consists of a CPU, memory, hard disk, floppy disk, monitor, printer, and communication devices.

CPU The central processing unit (CPU) is the brain of a computer. It retrieves instructions from memory and executes them. The CPU speed is measured in megahertz (MHz), with 1 megahertz equaling 1 million pulses per second. The speed of the CPU has been improved continuously. If you buy a PC now, you can get an Intel Pentium 4 Processor at 3 gigahertz (1 gigahertz is 1000 megahertz).

Memory Memory is to store data and program instructions for CPU to execute. A memory unit is an ordered sequence of bytes, each holds eight bits. A program and its data must be brought to memory before they can be executed. A memory byte is never empty, but its initial content may be meaningless to your program. The current content of a memory byte is lost whenever new information is placed in it.

How Data is Stored? Data of various kinds, such as numbers, characters, and strings, are encoded as a series of bits (zeros and ones). The zeros and ones represent the Binary System. For example, character ‘J’ is represented by 01001010 in one byte. A small number such as three can be stored in a single byte. For a large number that cannot fit into a single byte, the computer uses a number of adjacent bytes. No two data can share or split a same byte. A byte is the minimum storage unit.

Storage Devices Memory is volatile, because information is lost when the power is off. Programs and data are permanently stored on storage devices and are moved to memory when the computer actually uses them. There are three main types of storage devices: Disk drives (hard disks and floppy disks), CD drives (CD-R and CD-RW), and Tape drives.

Output Devices: Monitor The monitor displays information (text and graphics). The resolution and dot pitch (the amount of space between pixels) determine the quality of the display.

Monitor Resolution and Dot Pitch The resolution specifies the number of pixels per square inch. Pixels (short for “picture elements”) are tiny dots that form an image on the screen. The resolution can be set manually. The higher the resolution, the sharper and clearer the image is. However, the image may be very small if you set high resolution on a small screen monitor. PC monitors are usually 15-inch, 17-inch, 19-inch, or 21-inch. For a 15-inch monitor, a comfortable resolution setting would be 640480 (307,200 pixels). dot pitch The dot pitch is the amount of space between pixels. The smaller the dot pitch, the better the display.

Communication Devices A regular modem uses a phone line and can transfer data in a speed up to 56,000 bps (bits per second). A DSL (digital subscriber line) also uses a phone line and can transfer data in a speed 20 times faster than a regular modem. A cable modem uses the TV cable line maintained by the cable company. A cable modem is as fast as a DSL. Network interface card (NIC) is a device to connect a computer to a local area network (LAN). The LAN is commonly used in business, universities, and government organizations. A typical type of NIC, called 10BaseT, can transfer data at 10 mbps (million bits per second).

Programs Computer programs, known as software, are instructions to the computer. They tell the computer what to do through programs. Computers do not understand human languages, so you need to use computer languages to communicate with them. Programs are written using programming languages.

Programming Languages Machine Language Assembly Language High-Level Language Machine language is a set of primitive instructions built into every computer. The instructions are in the form of binary code. Programming with native machine language is a tedious process. The programs are highly difficult to read and modify. For example, to add two numbers, you might write an instruction in binary like this:   1101101010011010

Programming Languages Machine Language Assembly Language High-Level Language Assembly languages were developed to make programming a bit easier than using machine language. Since the computer cannot understand assembly language, however, a program called assembler is used to convert assembly language programs into machine code. For example, to add two numbers, you might write an instruction in assembly code like this: ADD R1, R2, R3

Programming Languages Machine Language Assembly Language High-Level Language The high-level languages are English-like and easy to learn and program. For example, the following is a high-level language statement that computes the area of a circle with radius 5 (A = r2PI): area = 5 * 5 * 3.1415; print ("The area = ", area);

Popular High-Level Languages COBOL (COmmon Business Oriented Language) FORTRAN (FORmula TRANslation) BASIC (Beginner All-purpose Symbolic Instructional Code) Pascal (named for Blaise Pascal) Ada (named for Ada Lovelace) C (whose developer designed B first) Visual Basic (Basic-like visual language developed by Microsoft) Delphi (Pascal-like visual language developed by Borland) C++ (an object-oriented language, based on C) C# (a Java-like language developed by Microsoft) Java (We use in this course and textbook)

Compiling Source Code A program written in a high-level language is called a source program. Since a computer cannot understand a source program. Program called a compiler is used to translate the source program into a machine language program called an object program (byte code). The object program is often then linked with other supporting library code before the object can be executed on the machine. JVM then converts byte code to machine code.

Operating Systems The operating system (OS) is a program that manages and controls a computer’s hardware activities. For example, Windows 98, NT, 2000, XP, or ME. Application programs such as an Internet browser and a word processor cannot run without an operating system.

Why Java? The answer is that Java enables users to develop and deploy applications on the Internet for servers, desktop computers, and small hand-held devices. The future of computing is being profoundly influenced by the Internet, and Java promises to remain a big part of that future. Java is the Internet programming language. Java is a general purpose programming language. Java is the Internet programming language. Java is portable (machine-independent) 18

Java, Web, and Beyond Java can be used to develop Web applications Java Supports Applets Java can also be used to develop applications for hand-held devices such as Palm and cell phones Developed by James Gosling at Sun Microsystems (May 20, 1995) 19

JDK Versions JDK 1.02 (1995) (Java Development Kit) JDK 1.1 (1996) JDK 1.5 (2004) a. k. a. JDK 5 or Java 5 JDK 1.6 (2006) a. k. a. JDK 6 or Java 6 JDK 1.7 (2010) a. k. a. JDK 7 or Java 7 JDK 1.8 (2014) a. k. a. JDK 8 or Java 8 20

JDK Editions Java Standard Edition (J2SE) - J2SE can be used to develop client-side standalone applications or applets. (2 refers to Java 2 platform) Java Enterprise Edition (J2EE) - J2EE can be used to develop server-side applications such as Java servlets and Java ServerPages. Java Micro Edition (J2ME). - J2ME can be used to develop applications for mobile devices such as cell phones. The textbook uses J2SE to introduce Java programming. 21

Popular Java IDEs NetBeans Open Source by Sun Eclipse Open Source by IBM JBuilder by Borland MetroWerks CodeWarrior BlueJ jGRASP (we'll use this IDE in this course, download it from http://www.jgrasp.org/) 22

A Simple Java Program Listing 1.1: Welcome.java //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) System.out.println("Welcome to Java!"); } 23

Syntax and Semantics The syntax rules of a language define how we can put together symbols, reserved words, and identifiers to make a valid program The semantics of program statements define the meaning/logic of the statements (program). A program that is syntactically correct is not necessarily logically (semantically) correct A program will always do what we tell it to do, not what we meant to tell it to do 24

Errors A program can have three types of errors The compiler will find syntax errors and other basic problems (compile-time errors or syntax errors) - If compile-time errors exist, an executable version of the program is not created A problem can occur during program execution, such as trying to divide by zero, which causes a program to terminate abnormally (run-time errors) A program may run, but produce incorrect results, perhaps using an incorrect formula (logical errors) 25

Syntax Errors Did you make any mistakes when you typed in the examples? If you use the wrong case it won’t work > math.abs(-3)  Error: Undefined class 'math‘ If you misspell something it won’t work > Mat.abs(-3)  Error: Undefined class 'Mat' > Math.ab(-3)  Error: No 'ab' method in 'java.lang.Math' 26

Basic Program Development Syntax errors Run-time errors Logical errors Type, edit, and save program Compile program Execute program and evaluate results 27

Anatomy of a Java Program Class name Main method Statements Statement terminator Reserved words Comments Blocks 28

Class Name Every Java program must have at least one class. Each class has a name. By convention, class names start with an uppercase letter. In this example, the class name is Welcome. // This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } 29

Main Method Line 2 defines the main method. In order to run a class, the class must contain a method named main. The program is executed from the main method. A program/class will not run without a main method! // This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } 30

Statement A statement represents an action or a sequence of actions. The statement System.out.println("Welcome to Java!") in the program in Listing 1.1 is a statement to display the greeting "Welcome to Java!". // This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } 31

Statement Terminator Every statement in Java ends with a semicolon (;). // This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); System.out.println("Again, welcome to Java!"); } 32

Reserved Words Reserved words or keywords are words that have a specific meaning to the compiler and cannot be used for other purposes in the program. For example, when the compiler sees the word class, it understands that the word after class is the name for the class. // This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } 33

Reserved Words Java reserved words: abstract assert boolean break byte case catch char class const continue default do double else enum extends false final finally float for goto if implements import instanceof int interface long native new null package private protected public return short static strictfp super switch synchronized this throw throws transient true try void volatile while 34

Blocks A pair of braces in a program forms a block that groups components of a program. 35

Special Symbols 36

{ … } // This program prints Welcome to Java! public class Welcome { { … } // This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } 37

( … ) // This program prints Welcome to Java! public class Welcome { ( … ) // This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } 38

; // This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } 39

// … // This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } 40

" … " // This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } 41

Programming Style and Documentation Appropriate Comments Naming Conventions Proper Indentation and Spacing Lines Block Styles 42

Appropriate Comments Include a summary at the beginning of the program to explain what the program does, its key features, its supporting data structures, and any unique techniques it uses. Include your name, class section, instructor, date, and a brief description at the beginning of the program. 43

Naming Conventions Choose meaningful and descriptive names. Class names: Capitalize the first letter of each word in the name. For example, the class name ComputeExpression. Method names: Lowercase name (one word) or capitalize the first letter of every other word in the name. For example, method main(String[] args) method computeAvegrateGarde(int[] grades) 44

Proper Indentation and Spacing Indent two spaces. Note: JGrasp has a function that does indentation automatically (called CSD style). Spacing Use blank line to separate segments of the code. 45

Block Styles Use either style, just be consistent! 46

End of Chapter 1 47