A Review. a review of lessons learned so far… ( 2 steps forward - 1 step back) Software Development Cycle: design, implement, test, debug, document Large.

Slides:



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

COSC 120 Computer Programming
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
Outline Java program structure Basic program elements
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
JavaScript, Third Edition
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
2440: 211 Interactive Web Programming Expressions & Operators.
Computer Science 101 Introduction to Programming.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Input, Output, and Processing
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
What does a computer program look like: a general overview.
Boolean expressions, part 2: Logical operators. Previously discussed Recall that there are 2 types of operators that return a boolean result (true or.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Java Programming: From Problem Analysis to Program Design, 5e Chapter 2 Basic Elements of Java.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
C++ for Engineers and Scientists Second Edition
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Boolean expressions, part 1: Compare operators. Compare operators Compare operators compare 2 numerical values and return a Boolean (logical) value A.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Unit 1 Review By: Mr. Jacobs.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
CompSci 230 S Programming Techniques
Topics Designing a Program Input, Processing, and Output
BASIC ELEMENTS OF A COMPUTER PROGRAM
Completing the Problem-Solving Process
Java programming lecture one
Java Programming: From Problem Analysis to Program Design, 4e
2.1 Parts of a C++ Program.
Introduction to C++ Programming
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Chapter 2 Edited by JJ Shepherd
Chapter 2: Basic Elements of Java
Chapter 1: Computer Systems
Chapter 2: Java Fundamentals
CS 200 Primitives and Expressions
elementary programming
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Primitive Types and Expressions
Chapter 2 Primitive Data Types and Operations
DATA TYPES There are four basic data types associated with variables:
Presentation transcript:

A Review

a review of lessons learned so far… ( 2 steps forward - 1 step back) Software Development Cycle: design, implement, test, debug, document Large Problems are broken down into smaller modules to be solved using flowcharting or pseudo-code, then coded, & re-assembled to solve the complete problem. High-level languages require a compiler to translate source code into machine code ( or byte code in the case of Java). Byte code is interpreted by the Java Virtual Machine and run.

a review of lessons learned so far… ( 2 steps forward - 1 step back) Program command execution is linear, thus, programming statements must be written in order (linear) as well. Programming languages contain keywords/reserved words that can only be used as their intended purpose as determined by the language. Languages utilize a specific syntax & punctuation. Primitive data types are “built in” to the language, and allow for data storage & retrieval. Storage space must be allocated for data, before it can be used to store data. Programming languages allow for user defined “identifiers” of storage space (variables & constants), methods, and classes (in object-oriented languages like Java).

a review of lessons learned so far… ( 2 steps forward - 1 step back) The API extends/expands the language with a library of classes/methods for common programming tasks. Common Mathematical Operators are: +, -, *, /, %, ++ (increment), -- (decrement) & - (unary minus) = (The Assignment Operater, assigns the rval to the the lval ) Mathematical Expressions are processed with operator precedence & associativity. Programmers use comments to note explanation of coding methods & identifier purposes for future reference. Good Programming Practice is to write “readable by humans” code (indent, ws, comments).

You mean there are more than one? Compile-Time: syntax errors caught by the compiler Run-Time: errors caused by exceptions resulting in the program terminating abnormally (ex. attempting to divide by zero (0) - undefined command - program crashes) Logic: program compiles & runs, but, produces inaccurate results (always test program with data to verify accurate results)

Compiler Gotcha: Mismatched braces, quotation marks, or parenthesis Possible Error Message: Errors.java:13: reached end of file while parsing public class Errors { Enter them in pairs & label closing Enter them in pairs & label closing } //closing class header } //closing main method //body of method public static void main(String args[ ]) {

Compiler Gotcha: misspelling a keyword Error Message: Errors.java:6: cannot find symbol Type Accurately. Remember keywords are l.c. Type Accurately. Remember keywords are l.c.

Compiler Gotcha: Using a keyword as a variable name Errors.java:6: not a statement Errors.java:6: ';' expected Errors.java:6: not a statement Sampling of most commonly accidently used keywords (and replacement choice): class (use group) final ( use endResult) return (use returnValue) false ( use negative) true (use affirmative) new (use newValue) null ( use emptyValue) Sampling of most commonly accidently used keywords (and replacement choice): class (use group) final ( use endResult) return (use returnValue) false ( use negative) true (use affirmative) new (use newValue) null ( use emptyValue)

Compiler Gotcha: misspelling variable names & switching use of l.c. & u.c. Errors.java:7: cannot find symbol Be consistent. Follow convention when naming variables. List all variable declarations at the beginning of a method - FIRST! (then you can refer to them as a list when you need to use them, and… you will not improperly use or accidently reuse a variable name) Be consistent. Follow convention when naming variables. List all variable declarations at the beginning of a method - FIRST! (then you can refer to them as a list when you need to use them, and… you will not improperly use or accidently reuse a variable name)

Compiler Gotcha: putting blank space in a multi-word variable name Error Messages: Errors.java:6: ';' expected Errors.java:6: not a statement Just Don’t Do It! To reinforce this habit, never use blank spaces when you name any computer file. Just Don’t Do It! To reinforce this habit, never use blank spaces when you name any computer file.

Compiler Gotcha: forgetting to end the statement? Error Message: Errors.java:6: ';' expected Use it! ; (semi-colon) Use it! ; (semi-colon)

Compiler Gotcha: mis-matched data types & literals Error Message: Errors.java:6: possible loss of precision Remember float literals are treated as double values. float total = 5.0; // wrong float total = 5.0F; // correct Remember float literals are treated as double values. float total = 5.0; // wrong float total = 5.0F; // correct

Compiler Gotcha: using commas (,) or currency ($) symbols in numeric data types Error Message: Errors.java:6: ';' expected DON’T USE $ OR, IN DATA! float totalExpense = $5,000.00F; Correct: float totalExpense = F; DON’T USE $ OR, IN DATA! float totalExpense = $5,000.00F; Correct: float totalExpense = F;

unintentionally performing integer division (loss of remainder) Error Message: NONE! Watch out for this one! public class Errors { public static void main(String args[ ]) { int x =5; int y =2; int z; z= x/y; System.out.println(z); //output: 2 } //closing main method }

forgetting the rules for operator precedence Error Message: NONE! Watch out for this one! When operators within an expression have the same precedence, sharing an operand, they work according to their associativity. When in doubt, use (parenthesis)! Highest Precedence - (unary) * / % Lowest Precedence + - x = 2+5*4; // x = 22 x = (2+5)*4; // x = 28 y = 7-2+3; // y = 8; y = 7 – (2+3); // y = 2;

Compiler Gotcha: placing a space between combined operators Error Message: Errors.java:9: illegal start of expression z + = y; //Don’t z += y; //Do

Compiler Gotcha: incompatible data types public class Errors { public static void main(String args[ ]) { float y =2.75F; int z =1; z+= y; //Don’t (z:3) } //closing main method } public class Errors { public static void main(String args[ ]) { float y =2.75F; float z =1.0F; //Do z+= y; //(z:3.75) } //closing main method }

Compiler Gotcha: forgetting to terminate a multi-line comment Error Message: Errors.java:3: unclosed comment /* start multi-line comment blah, blah, blah… */

Compiler Gotcha: forgetting to use the import statement Errors.java:11: cannot find symbol import java.util.Scanner; public class Errors { public static void main(String args[ ]) { Scanner keyboard = new Scanner(System.in); } //closing main method } //closing class definition For this statemnt to work… You must import the Scanner Object!