Problem of the Day  Why are manhole covers round?

Slides:



Advertisements
Similar presentations
Prof. Matthew Hertz WTC 207D /
Advertisements

Debugging Introduction to Computing Science and Programming I.
10-Jun-15 Fibonacci Numbers A simple example of program design.
Nov 10, Fall 2006IAT 8001 Debugging. Nov 10, Fall 2006IAT 8002 How do I know my program is broken?  Compiler Errors –easy to fix!  Runtime Exceptions.
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
Java Review 2 – Errors, Exceptions, Debugging Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
COMP 110 Introduction to Programming Mr. Joshua Stough September 10, 2007.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
CSC 107 – Programming For Science. Science Means Solving Problems  Physics – How does an atom work?
JS Arrays, Functions, Events Week 5 INFM 603. Agenda Arrays Functions Event-Driven Programming.
11 Values and References Chapter Objectives You will be able to: Describe and compare value types and reference types. Write programs that use variables.
1 Web Based Programming Section 6 James King 12 August 2003.
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage  Weekly assignments.
Prof. Matthew Hertz SH 1029F /
Simple Programs from Chapter 2 Putting the Building Blocks All Together (corresponds with Chapter 2)
Java: Chapter 1 Computer Systems Computer Programming II.
CSC 107 – Programming For Science. Announcements  Tutors available MTWR in WTC206/WTC208  Special lab (with Macs) & not in the Tutoring Center  Can.
CS 106 Introduction to Computer Science I 01 / 25 / 2010 Instructor: Michael Eckmann.
CIT 590 Examples Debugging. Agenda This class is an experiment in letting students learn by just doing things as opposed to me talking all the time! So.
CSC 107 – Programming For Science. Spacing in a Program  C++ ignores spaces in a program  This also means where newlines placed ignored  #define &
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage.
JAVA BASICS: Variables and References SYNTAX, ERRORS, AND DEBUGGING.
Board Activity Find your seat on the seating chart Login – Remember your login is your first initial your last name and the last three numbers of your.
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
CSC 107 – Programming For Science. History of C  Dennis Ritchie developed C from 1969 – 1973  Based upon B (& other) earlier languages  Since its creation,
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Debugging in Java. Common Bugs Compilation or syntactical errors are the first that you will encounter and the easiest to debug They are usually the result.
1 Debugging. 2 A Lot of Time is Spent Debugging Programs Debugging. Cyclic process of editing, compiling, and fixing errors. n Always a logical explanation.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Problem of the Day  Why are manhole covers round?
Chapter 2: Java Fundamentals
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage  Weekly assignments.
CSC 107 – Programming For Science. Announcements.
Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent!
CSC 107 – Programming For Science. The Week’s Goal.
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
CSC 107 – Programming For Science. Announcements  Locations of Macs to use outside of lab time  Can find on Library ground floor (6) & main floor (6)
CSC 107 – Programming For Science. History of C  Dennis Ritchie developed C from 1969 – 1973  While at Bell Labs, created language to develop Unix 
CSC 212 – Data Structures Prof. Matthew Hertz WTC 207D /
Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent!
Introduction Chapter 1 8/31 & 9/1 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
CSC 213 – Large Scale Programming Prof. Matthew Hertz WTC 207D /
CSC 212 – Data Structures Lecture 2: Primitives, References, & Classes.
CSC Programming for Science Lecture 10: Boolean Expressions & More If ­ Else Statements.
CSC 107 – Programming For Science. Science Means Solving Problems  Physics – How does an atom work?
Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent!
PHY 107 – Programming For Science. Announcements no magic formulas exist  Need to learn concepts: no magic formulas exist  Single solution not useful;
CSC 107 – Programming For Science. Final Exams Dec. 16, 8AM – 10AM in OM221  Exam for CSC107: Dec. 16, 8AM – 10AM in OM221  Will be done using paper.
CS 106 Introduction to Computer Science I 09 / 10 / 2007 Instructor: Michael Eckmann.
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
Chapter 2 Wrap Up 2/18/16 & 2/22/16. Topics Review for Exam I DecimalFormat More Style Conventions Debugging using eclipse The Java API.
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.
Programming for Interactivity Professor Bill Tomlinson Tuesday & Wednesday 6:00-7:50pm Fall 2005.
CS 106 Introduction to Computer Science I 01 / 24 / 2007 Instructor: Michael Eckmann.
Problem of the Day  Why are manhole covers round?
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.
Testing and Debugging UCT Department of Computer Science Computer Science 1015F Hussein Suleman March 2009.
Values vs. References Lecture 13.
Eclipse Navigation & Usage.
Testing and Debugging.
CompSci 230 Software Construction
Building Java Programs
Chapter 2 Programming Basics.
LCC 6310 Computation as an Expressive Medium
Corresponds with Chapter 5
Presentation transcript:

Problem of the Day  Why are manhole covers round?

Problem of the Day  Why are manhole covers round? No matter how circle rotated, radius is constant so… …only shape that could not fall into the hole

Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage  Weekly assignments problems due before class  Remove rust from summer and get back into coding  During lectures will also add some new ideas

Style Guide  Good style helps when writing code  Program logic becomes easier to follow  Easier to read and fix errors  Starting & stopping work on project is far easier  Prevents  Prevents many common errors  Style includes two parts:  Formatting  Documentation

Indentation  Traditionally indent code within set of braces ({})  Be consistent with indentation size (I use 2 spaces)

Indentation  Traditionally indent code within set of braces ({})  Be consistent with indentation size (I use 2 spaces)  Nothing is

Indentation  Traditionally indent code within set of braces ({})  Be consistent with indentation size (I use 2 spaces)  Nothing is more

Indentation  Traditionally indent code within set of braces ({})  Be consistent with indentation size (I use 2 spaces)  Nothing is more annoying

Indentation  Traditionally indent code within set of braces ({})  Be consistent with indentation size (I use 2 spaces)  Nothing is more annoying than

Indentation  Traditionally indent code within set of braces ({})  Be consistent with indentation size (I use 2 spaces)  Nothing is more annoying than looking for the next line.

Indentation char _ [3141 ],__3141[3141];_314159[31415],_3141[31415];main(){register char* _3_141,*_3_1415, *_3__1415; register int _314,_31415,__31415,*_31, _3_14159,__3_1415;*_ =__31415=2,_ [0][_ ]=1[__3141]=5;__3_1415=1;do{_3_14159=_314=0,__ ;for( _31415 =0;_31415<(3,14-4)*__31415;_ )_31415[_3141]=_314159[_31415]= - 1;_3141[*_314159=_3_14159]=_314;_3_141=_ __3_1415;_3_1415= __3_1415 +__3141;for(_31415 = __3_1415 ;_31415;_ ,_3_141 ++,_3_1415++){_314 +=_314<<2 ;_314<<=1;_314+= *_3_1415;_31 =_ _314; if(!(*_31+1) )* _31 =_314 / __31415,_314 [_3141]=_314 % __31415 ;* ( _3__1415=_3_141 )+= *_3_1415 = *_31;while(* _3__1415 >= 31415/3141 ) * _3__1415+= - 10,(*--_3__1415 )++;_314=_314 [_3141]; if ( ! _3_14159 && * _3_1415)_3_14159 =1,__3_1415 = 3141-_31415;}if( _314+(__31415 >>1)>=__31415 ) while ( ++ * _3_141==3141/314 )*_3_141--=0 ;}while(_3_14159 ) ; { char * __3_14= "3.1415"; write((3,1) (--*__3_14,__3_14 ),(_3_ ,++_3_14159)) ; } for ( _31415 = 1; _31415< ;_ )write( 31415% 314-( 3,14),_ [ _31415 ] + " ","314" [ 3]+1)-_314; puts((*_ =0,_ )) ;_314= *" ";}

Braces  Always use braces:  Always use braces: for (int i = 0; i < n; i++); sum = sum + i; sumSquare = sumSquare + (i*i);

Braces  Always use braces:  Always use braces: for (int i = 0; i < n; i++); sum = sum + i; sumSquare = sumSquare + (i*i);  Using braces vs. fixing a bug 10 seconds 30 minutes

Increment/Decrement Operators  Only use ++ & -- on own line (or for loops) // What is result of each line? while (++k < n) { a[i++] = (2 * i) + 6; b[j] = (j++ * j) - 1; c[j] = a[j] +++ b[j]; }

Statements  Use variables to break up complex ideas // What is this computing? return ( (year % 4 == 0) && (year % 100 != 0)) || ( (year % 100 == 0) && (year % 400 == 0));

Statements  Use variables to break up complex ideas divisibleBy4 = ((year % 4) == 0); divisible100 = ((year % 100) == 0); divisible400 = ((year % 400) == 0); return (divisible4 && !divisible100) || (divisible100 && divisible400);

Comments  We program using “code”  Not easy to read even simple projects  Review your CSC 111 projects  (even better, review a friend’s CSC 111 project)  Comments break up this code  Provide simple English descriptions  State assumptions and preconditions  Describe the outcome of a section

Comments private static void compileResults(String server, String handle) throws IOException { for (Experiment e : Experiment.values()) { Benchmark[] benches = e.getResults(); File newFile = getOutFile(server, e.name(), handle); newFile.createNewFile(); PrintStream out = new PrintStream(newFile); Double[] baselines = computeBaselineMeans(server, e.getResults(), handle, BASELINE, benches); for (Build b : Build.values()) { File[] files = new File[benches.length]; Scanner[] scanners = new Scanner[benches.length]; for (int i = 0; i < files.length; i++) { files[i] = getInFile(server, benches[i], b, handle); scanners[i] = new Scanner(files[i]); } String[] lines = new String[scanners.length]; int heapSize = 0; while (scanners[0].hasNextLine()) { out.print(b.name() + "\t"); for (int i = 0; i < scanners.length; i++) { lines[i] = scanners[i].nextLine(); out.print(lines[i] + "\t"); }

Ever Have A Bug?  At some point, everyone must fix bug in code  What should you do first after discovering the bug?

Ever Have A Bug?  At some point, everyone must fix bug in code  What should you do first after discovering the bug?

Ever Have A Bug?  At some point, everyone must fix bug in code  What should you do first after discovering the bug?

Ever Have A Bug?  At some point, everyone must fix bug in code  What should you do first after discovering the bug?

Ever Have A Bug?  At some point, everyone must fix bug in code  What should you do first second after discovering it?

Fixing Bugs  Three common ways students fix bugs:  Guess where error is and make random change  Use Eclipse debugger to run program & find source  Get out your pencil & paper and draw a memory trace

Normal Method of Debugging  Also called "debugging-via-drunken-walk" SMALL  Can work for SMALL programs with limited choices  Guessing for millions of lines of code harder  Not at all effective at actually fixing errors  Entire point is to avoid understanding bug's cause  "Fix" may cause other errors later on in program  Cannot prevent future errors using this approach

Better Method of Debugging  Could use Eclipse debugger to find and fix bug  Set breakpoints to stop program where bug likely  Use step filters to walk through the program bit by bit  Spend a few hours learning how to make it work  Can get to root of problem once it is executed  But requires executing entire program to trigger bug  Cannot work backward to try and understand why

Best Method of Debugging  Generating memory trace has many benefits  Could check algorithm – don’t need any code to try  Can make up situations and just trace a method  Look back through trace to see root cause of bug  Trace code by running it like you were computer  DON’T SKIP STEPS  DON’T SKIP STEPS – easy to (wrongly) assume things  As you go along update variables’ values  GIGO effects limit tracing’s effectiveness

Best Method of Debugging  Generating memory trace has many benefits  Could check algorithm – don’t need any code to try  Can make up situations and just trace a method  Look back through trace to see root cause of bug  Trace code by running it like you were computer  DON’T SKIP STEPS  DON’T SKIP STEPS – easy to (wrongly) assume things  As you go along update variables’ values  GIGO effects limit tracing’s effectiveness

Benefits of Memory Traces  Draw what actually occurs in memory  Pictures used to debug rather than bare text  Much easier to understand what a method does  Excellent way to learn new programming topics  Past studies found improves student grades  Debugging time decreased greatly at same time  Greater support for these traces in Eclipse  Drawing of static trace integrated with debugger  Over this term should see tools improve

Starting a Memory Trace  Paper holds 3 areas separated by vertical lines  Program stack drawn on left part of page  Right side of page holds the program heap  Program output shown outside the stack & heap  Objects allocated during run drawn in the heap  Will discuss how this is done next week  Draw frame on top of stack each method call  Fancy name for box labeled with method name  Each parameter & local variable needs space in box

Data Types  8+1 primitive data types  Examples: boolean, byte, char, int, double, String *  Only types that work with Java operators  Operators include: +, -, %, &&, ||, >=, <, !  Primitives used natively by computers  Means using them is very quick  Implies greater support within the language

Primitive Types  Primitive variables are simple to use  Each variable is “xerox” holding a value  Assignment copies value  Update assigned variable only; changes not reflected

Starting a Memory Trace public static void main(String[] args) { String s = “”; for (int i = 0; i < 5; i+=2) { s = s + i; System.out.println(s); } }

Writing a Memory Trace public static int fibber(int i, int j) { return i + j; } public static void main(String[] args) { int f = 0; int s = 1; for (int i = 0; i < 5; i+=4) { int oldF = f; f = s; s = fibber(oldF, f); } }

Your Turn  Get into groups and complete activity

For Next Lecture  Reading AF Chapter 3 & 7.13 for Friday  Continues Java review & looks at references  Introduces enum s – first really new concept of term  Use language template to take notes on enum s!  There is weekly assignment problem on Angel  Due before Friday’s lecture (via )  Get back into the swing of writing Java code