Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

1 A Review

2 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.

3 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).

4 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).

5 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)

6 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[ ]) {

7 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.

8 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)

9 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)

10 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.

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

12 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

13 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 = 5000.00F; DON’T USE $ OR, IN DATA! float totalExpense = $5,000.00F; Correct: float totalExpense = 5000.00F;

14 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 }

15 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;

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

17 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 }

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

19 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!


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

Similar presentations


Ads by Google