Lecture 3 January 14, 2002 CSC 204 -- Programming I Fall 2001.

Slides:



Advertisements
Similar presentations
What is a Computer Program? For a computer to be able to do anything (multiply, play a song, run a word processor), it must be given the instructions.
Advertisements

Designing a Program & the Java Programming Language
CSCE 145: Algorithmic Design I Chapter 1 Intro to Computers and Java Muhammad Nazmus Sakib.
Copyright © 2000 W. W. Norton & Company. All rights reserved. 1 Chapter 1: Getting Started Java Programming FROM THE BEGINNING Chapter 1 Getting Started.
Programming Types of Testing.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Introduction to Computers and Java Module 1. Objectives overview computer hardware and software introduce program design and object-oriented programming.
1 Java Basics. 2 Compiling A “compiler” is a program that translates from one language to another Typically from easy-to-read to fast-to-run e.g. from.
1 Fall 2008ACS-1903 Chapter 1 Topics Java History Java Programs Why Program? Computer Systems: Hardware and Software Programming Languages What Is a Program.
Lecture 1: Intro to Computers Yoni Fridman 6/28/01 6/28/01.
Introduction to Computers and Programming. Some definitions Algorithm: –A procedure for solving a problem –A sequence of discrete steps that defines such.
Introduction to Computer Programming CSC 1401: Introduction to Programming with Java Lecture 2 Wanda M. Kunkle.
1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor.
Slide 1 of 40. Lecture A The Java Programming Language Invented 1995 by James Gosling at Sun Microsystems. Based on previous languages: C, C++, Objective-C,
1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
Introduction to Computers and Programming. Some definitions Algorithm: Algorithm: A procedure for solving a problem A procedure for solving a problem.
Hello, world! Dissect HelloWorld.java Compile it Run it.
Introduction to Java.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Chapter 1: Getting Started Java Programming FROM THE BEGINNING 1 Chapter 1 Getting Started.
Java Workshop for Teachers May 6, 2005 A Brief Look at the Java Programming Language.
Topics Introduction Hardware and Software How Computers Store Data
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.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Programming Languages Machine.
Computer Programming 12 Mr. Jean March 19 th, 2013.
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
UCSC All rights reserved. No part of this material may be reproduced and sold. 1 IT1202-Fundamentals Of Programming (Using JAVA) Interacting with.
Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project.
Lesson 2: First Java Programs. Objectives: –Discuss why Java is an important programming language. –Explain the Java virtual machine and byte code. –Choose.
1 Chapter 1 Introduction to Java. 2 History of Java Java Originally for _________________________ devices Then used for creating Web pages with __________________________.
Chapter 1: Getting Started Java Programming FROM THE BEGINNING Copyright © 2000 W. W. Norton & Company. All rights reserved. 1 Chapter 1 Getting Started.
Introduction to Computer Systems and the Java Programming Language.
1 CSC204 – Programming I Lecture 2 Intro to OOP with Java.
© 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 means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
OOP with Java, David J. Barnes Bits, Bytes, and Java1 The Challenge Writing programs well is a challenge. –From coder to software engineer. We want programs.
CSC204 – Programming I Lecture 1 August 23, 2006.
Chapter 1: Getting Started Java Programming FROM THE BEGINNING Copyright © 2000 W. W. Norton & Company. All rights reserved. 1 Chapter 1 Getting Started.
CSC Programming I Lecture 6 September 4, 2002.
Copyright © Mohamed Nuzrath Java Programming :: Syllabus & Chapters :: Prepared & Presented By :: Mohamed Nuzrath [ Major In Programming ] NCC Programme.
CHAPTER 1 INTRODUCTION 2 nd Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
introductory lecture on java programming
Computer and Programming. Computer Basics: Outline Hardware and Memory Programs Programming Languages and Compilers.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Overview of Programming.
Chapter 1: Getting Started Java Programming FROM THE BEGINNING Copyright © 2000 W. W. Norton & Company. All rights reserved. 1 Chapter 1 Getting Started.
1 1 1 Introduction to Java. 2 History of Java Java – Originally for intelligent consumer-electronic devices – Then used for creating Web pages with dynamic.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Computers,
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Software Engineering Algorithms, Compilers, & Lifecycle.
Fundamental of Java Programming (630002) Unit – 1 Introduction to Java.
Lecture 1b- Introduction
Getting Started Chapter 1 Copyright © 2000 W. W. Norton & Company.
CSCI-235 Micro-Computer Applications
Text by: Lambert and Osborne
Getting Started Chapter 1 Copyright © 2000 W. W. Norton & Company.
Java programming lecture one
Getting Started Chapter 1 Copyright © 2000 W. W. Norton & Company.
Getting Started Chapter 1 Copyright © 2000 W. W. Norton & Company.
Topics Introduction Hardware and Software How Computers Store Data
Computer Programming-1 CSC 111
Presentation transcript:

Lecture 3 January 14, 2002 CSC Programming I Fall 2001

Start Toss a coin Draw an X is head? done? count Rare Draw an O MediumWell-done y n y n End more X’smore O’s as many

Temperature Conversion Algorithm w/ Variables Added 1. Display a message asking the user to enter a Fahrenheit temperature. 2. Obtain the input entered by the user and store it into userInput. 3. Convert userInput into numerical form and store the result into fahrenheit. 4. Calculate the equivalent Celsius temperature using the formula celsius = ( fahrenheit – 32)  (5 / 9) 5. Convert the value of celsius to character form and display the result.

1.4Storing Data Computer algorithms manipulate data. The term data refers to information, particularly information that’s stored in a uniform and systematic fashion. Items of data are identified by variables –Type: numeric, text, etc –Location: in the main memory where the variable is stored

Numeric Data Humans usually write numbers in decimal (base 10), using the digits 0 through 9. Computers store numbers in binary (base 2). –In the electronic logics, only 0 (low voltage) and 1 (high voltage) can be recognized In binary, numbers consist of bits (binary digits), each of which is either 0 or 1. $012350

Binary Representation Inside a computer, each number is represented by a fixed number of 0s and 1s. Typical representations of –97 and : –

Numeric Data The encoding scheme for integers is different from the one for non-integers. Numbers that contain a decimal point are often called floating-point numbers, because they’re stored in a form of scientific notation that allows the decimal point to “float.”

Character Data Characters are stored as numeric codes, 0’s and 1’s. There are several codes in common use; the one that Java uses is named Unicode. In Unicode, each character has a 16-bit code.

Character Data in Bit Format How “Susan Cole” would be stored in Unicode: S u s a n space C o l e

Type and Value The same 0-1 pattern can represent different values –Character a –Integer X X64 + 1X X16 + 0X 8 + 0X4 + 0X2 + 1X1 = 97

Bytes Most computers group bits into larger units called bytes, which usually contain eight bits. A number typically occupies four bytes (32 bits). A Unicode character occupies two bytes (16 bits).

Variables Locations that are used to store data within a program are known as variables. (King’s version) Variable -- An item of data named by an identifier. Each variable has a type (such as int, char or Object ), and a scope. (SUN’s version) Variables are given names (or identifiers) by the programmer.

Variable Names It’s best to choose a name that suggests what data the variable stores. Good names: fahrenheitTemperature fahrenheitTemp fahrenheit Poor names: fahr f a x temp

Variable Types Each variable stores a particular type of data. In the Fahrenheit-to-Celsius algorithm, the user’s input will be a sequence of characters. The Fahrenheit and Celsius temperatures will be numbers, possibly with digits after the decimal point.

1.5Programming Languages Creating programs requires that algorithms be expressed in a highly precise language that’s specifically designed for computers. Every computer comes with such a language, known as machine language. Each CPU has its own machine language. Machine language is extremely primitive, making it difficult to write even simple programs.

High-Level Languages Most programmers use high-level languages that aren’t tied to a particular computer. Common high-level languages: –Ada (named for Ada Lovelace) –BASIC (Beginner’s All-purpose Symbolic Instruction Code) –C –C++ –COBOL (COmmon Business-Oriented Language) –FORTRAN (FORmula TRANslation) –Pascal (named after Blaise Pascal)

History of Java Java was first designed as a language (under the name Oak) to develop software for consumer electronics, by James Gosling at Sun Microsystems. The more-marketable name Java (which means “hot”) in January Java was officially announced in May The first official release of Java occurred in February 1996, when Sun made available version 1.0 of the Java Development Kit (JDK).

Writing and Executing a Program Writing a program in a high-level language requires creating a file containing source code. Source code is not executable—there is no direct way for a computer to follow the commands that it contains. Executing (or running) the program requires special software. Approaches to executing a program: –Compilation –Interpretation

Compilation The program’s source code is given to a program called a compiler. The compiler checks that the source code is valid (obeys the rules of the language) and translates it to machine instructions for a particular CPU. The compiled program is stored in a file, and it can be run as many times as desired.

Compilation & Execution Compiled File (a.out) Source Code (xxx.c) text file saved on disk editor compile edit compiler Instructions in machine language CPU specific saved on disk Memory CPU load Execution Compilation

Interpretation The program’s source code is given to a program known as an interpreter. The interpreter executes the program without first translating it to machine instructions. The interpreter itself is normally a compiled program, so it can execute machine instructions corresponding to the source code.

Interpretation & Execution Internal file Source Code (xxx.c) text file editor interpret edit interpreter Instructions in machine language CPU specific CPU Execution Compilation & Memory

Java’s Approach Java employs a combination of compilation and interpretation. The Java compiler translates the original program into bytecode instructions for a computer called the Java Virtual Machine. The resulting bytecode program is then executed by an interpreter. One advantage of Java’s approach is that programs don’t need a particular CPU or operating system.

Bytecode program (xxx.class) Source Code (xxx.java) text file saved on disk editor compile edit Compiler (javac) Instructions in bytecode saved on disk CPU load Execution Compilation Bytecode and JVM Memory JVM interpret

1.6Why Java? Simple Object-oriented Distributed Robust Architecture-neutral Portable Interpreted Multithreaded

1.7The Programming Process 1.Write a specification for the program. 2.Design the program. 3.Choose algorithms and decide how data will be stored. 4.Write the program. 5.Compile the program. 6.Execute the program. 7.Debug the program.

Program Maintenance Most of the time, there’s an additional step in the programming process: maintenance. Reasons for maintenance: –Fix bugs –Add enhancements –Adapt to changes in the program’s specification Maintenance is often the costliest step in the programming process.

1.8What You Need to Know A file is a collection of related data. In many operating systems, a file name includes an extension that indicates the type of the file. Common Windows file extensions:.exe (executable program).doc (document).gif,.jpg (image) Java file extensions you need to know for now.java (Java source code).class (bytecode program)

File Operations Basic file operations: –Edit –Create –Copy –Rename –Delete A file can be created or edited by using an editor or word processor. An editor is a program that can create or modify a file containing text (ordinary characters). A word processor has the added ability to format text.

Directories A directory is a place where files can be kept. Directories are also known as folders. Directories are normally organized in a tree-like fashion, with a “root” directory that contains other directories as well as files. Basic directory operations: –Create a directory –Move from one directory to another –List the files in a directory

Edit Source Code on a PC Open Windows Explorer –Start|Programs|Windows Explorer Create a new folder (or directory) –Give it a name, e.g. myJavaCode Open an text editor (e.g. notepad ) –Start|Programs|Accessories|notepad Type in a Java program and save it as –C:\myJavaCode\HelloWorld.java

A Hello, World! Program public class HelloWorld { public static void main( String[] args ) { System.out.println( "Hello, World!" ); }

Executing Programs In a GUI environment, a program is executed (or launched) by clicking on an icon or by choosing the program from a menu. In a text-based environment, a program is executed by typing its name. A program that isn’t in the current directory can still be executed as long as the operating system knows where to look for the program.

Compile & Execute in DOS Open a DOS command prompt –Start|MS-DOS Prompt Change your working directory –C:\WINDOWS>cd c:\myJavaCode Compile Java code from command line –C:\myJavaCode>javac HelloWorld.java Set the classpath if necessary –C:\myJavaCode>set classpath=%calsspath%;. Execute the Java bytecode program –C:\myJavaCode>java HelloWorld