Designing a Program & the Java Programming Language

Slides:



Advertisements
Similar presentations
Chapter 1: Introduction
Advertisements

Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming.
COSC 120 Computer 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.
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.
Chapter 2: Input, Processing, and Output
Chapter 1: Introduction to Computers and Java
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.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Computer Science 101 Introduction to Programming.
CS102 Introduction to Computer Programming
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 Introduction to Computers and Programming 1.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
Introducing Java.
Introduction to Programming. Our Book in CS Why Program? Lets watch a video
Chapter 1.4 Programming languages Homework Due: Monday, August 11, 2014.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
Hello World 2 What does all that mean?.
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.
Chapter 1 Introduction to Computer and Java 1. Contents 1.Introduction 2.Why Program? 3.Computer Systems: Hardware and Software 4.Programming Languages.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
1 Chapter 2 First Java Programs Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Computer Science 101 Introduction to Programming.
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.
© 2006 Pearson Education 1 Obj: cont 1.3 and 1.4, to become familiar with identifiers and to understand how programming languages work HW: p.51 #1.8 –
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 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
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.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Programming Concept Chapter I Introduction to Java Programming.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second Edition D.S. Malik D.S. Malik.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
1 12/4/1435 h Lecture 2 Programs and Programming Languages.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Overview of Programming.
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
CHAPTER 1 Introduction to Computers and Java Copyright © 2016 Pearson Education, Ltd.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 1: Introduction to Computers and Programming.
Lecture 1b- Introduction
Working with Java.
CSCI-235 Micro-Computer Applications
Key Ideas from day 1 slides
Chapter 1: Introduction to Computers and Programming
Statements, Comments & Simple Arithmetic
Hello World 2 What does all that mean?.
Programming Vocabulary.
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
Introduction CSC 111.
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

Designing a Program & the Java Programming Language Mrs. Butera

What is a Program? A program is a set of instructions a computer follows in order to perform a task. A programming language is a special language used to write computer programs.

Machine Language

Modern Programming Languages

Examples of Programming Languages BASIC FORTRAN COBOL Pascal C C++ Java JavaScript Perl Python Ruby Visual Basic

History of Java Developed by Sun Microsystems in 1991 Goal: Develop a language that could be processed by all the devices it controlled – not dependent upon the processor each with its own machine language Used in: Stand-alone applications Applets for the Internet and devices

Security Can Java applets corrupt your computer? NO! Web browsers run Java applets in a secure environment within your computer's memory and do not allow them to access any of your computer's resources

BEFORE you write the Program, you conceive: The Algorithm & sometimes a Flowchart

The algorithm is conceived before the program is written. What is an Algorithm? The set of well-defined steps that are given to the computer to perform a task or solve a problem. The algorithm is conceived before the program is written.

Example: Gross Pay Algorithm Display: “How many hours did you work?” Allow user to input hours worked – store the number in memory Display: “How much do you get paid per hour?” Allow user to input pay per hour and store the number in memory Calculate Gross pay = Hours_Worked x Pay_Per_Hour Display the Gross Pay

Flowchart Symbols

Gross Pay Flowchart Start Input Hours Input Pay Per Hour Calculate Output Gross Pay Start

What is a Program Made of? Vocabulary – the set of all words and symbols in the language. Syntax – rules for combine words into sentences or statements. Semantics – define the rules for interpreting the meaning of statements

Program Enhancements White Space and Indentation – for readability Comments – for maintenance purposes /*comment area */ // entire line

Sample First Java Program “Hello World” // This is the classic first Java program class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } Save As: HelloWorld.java

Key Words/Reserved Words Every programming language has reserved words that cannot be used as variable names When you compile your program, an error will be returned if you use a reserved word incorrectly

Key Words/Reserved Words public class Payroll { public static void main(String[] args) Int hours = 40; double grossPay, payRate = 25.0; grossPay = hours * payRate; System.out.println(“Your gross pay is $” + grossPay); }

Some Java Vocabulary Type of Element Examples + - * / Arithmetic operators + - * / Assignment operator = Numeric literals 5.73 9 Programmer defined variable name name, pay_per_hour, gross_pay

Invalid Program Syntax Answer = (F - 32) * / 9; Answer = )F - 32 ( * 5 / 9; Answer = F – 32) * 5 / 9; Answer = (F - 32) * 5.0 / 9.0

Semantics Defines the rules for interpreting the meaning of statements Answer = (F - 32) * 5.0 / 9.0; Means “go into the parentheses first, subtract 32.0 from the variable quantity indicated by F, then multiply the result by 5.0, and finally divide the whole thing by 9.0” & store result in the variable (storage area) Answer

Programmer-Defined Names Variable are the names of memory locations that may hold data. public class Payroll { public static void main(String[] args) Int hours = 40; double grossPay, payRate = 25.0; grossPay = hours * payRate; System.out.println(“Your gross pay is $” + grossPay); }

Operators public class Payroll { public static void main(String[] args) Int hours = 40; double grossPay, payRate = 25.0; grossPay = hours * payRate; System.out.println(“Your gross pay is $” + grossPay); }

Syntax/Punctuation Marks the end of a complete sentence/statement. public class Payroll { public static void main(String[] args) Int hours = 40; double grossPay, payRate = 25.0; grossPay = hours * payRate; System.out.println(“Your gross pay is $” + grossPay); }

Programs are made up of lines and statements.

Lines A line is just a single line as it appears in the body of a program. public class Payroll { public static void main(String[] args) Int hours = 40; double grossPay, payRate = 25.0; grossPay = hours * payRate; System.out.println(“Your gross pay is $” + grossPay); }

Statements A statement is a complete instruction that causes the computer to perform some action. public class Payroll { public static void main(String[] args) Int hours = 40; double grossPay, payRate = 25.0; grossPay = hours * payRate; System.out.println(“Your gross pay is $” + grossPay); }

Variables A variable is a named storage location in the computer's memory. public class Payroll { public static void main(String[] args) Int hours = 40; double grossPay, payRate = 25.0; grossPay = hours * payRate; System.out.println(“Your gross pay is $” + grossPay); }

The Compiler and the Java Virtual Machine (JVM) Source Code = the program is typed in a text editor. Source file example: Payroll.java javac Payroll.java – compiles the program - (converts source code to byte code – 3b 00 8h 01 84 ff ......) syntax errors may be returned java Payroll - executes the program

The Compiler and the Java Virtual Machine (JVM)

Integrated Development Environments (IDE) Software package including: Text Editor Compiler Debugger Other utilities Examples: NetBeans Eclipse Komodo WinDev

The Programming Process Clearly define what the program is to do (requirements). Visualize the program running on the computer. Use design tools to create a model of the program (algorithm, flowchart). Check the model for logical errors.

The Programming Process continued: 5. Enter the code and compile it. 6. Correct any errors found during compilation. Repeat steps 5 & 6 as many times as necessary. 7. Run the program with test data for input (valid & invalid data). Have someone else test it. 8. Correct any runtime errors found while running the program. Repeat steps 5 & 6 as many times as necessary. 9. Validate the results of the program.