CS2_11_Debugging - CS2 Module 11 Category Elements of Java...

Info icon This preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
CS2 Module 11 Category: Elements of Java Topic: Coding Style/Debugging Objectives Emphasize key aspects of coding style Introduce basic debugging concepts
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CS 2 Introduction to Object Oriented Programming Module 11 Elements of Java Debugging
Image of page 2
Coding Style Use a consistent clear coding style Java identifiers typically do not contain underscores. Instead words are together with successive words capitalized Class names should be capitalized class Queue class CountingQueue class LinkedList class ThreeBlindMice
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Coding Style Method and variable names should not have their first letter capitalized. Names should suggest what they do or hold calcAverage() printMenu() getChoice() int count; float maxPressure; boolean isBad; // Note: not goodOrBad
Image of page 4
Coding Style Methods should generally not be longer than one screenful of code. Extremely long methods are often difficult to understand and usually indicate poor abstraction thus suggesting further abstraction (i.e. write more methods) is needed Methods that fit on one screen can use simple variable names: Queue q = new Queue(); Stack s = new Stack(); s.push(q.dequeue());
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Coding Style Comment closing braces to indicate which block is closing particularly when blocks are nested while(forever) { if(someBoolean) { for() { ... } // end for } // end if...then else { // whatever } // end else } // while forever
Image of page 6
Coding Style Use a consistent indentation style while(forever) { if(someBoolean) { for() { ... } // end for } // end if...then else { // whatever } // end else } // while forever
Image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Coding Style Use a consistent indentation style while(forever) { if(someBoolean) { for() { ... } // end for } // end if...then else { // whatever } // end else } // while forever
Image of page 8
Debugging
Image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Debugging Strategies Incremental programming System.out.println Use of toString method Debug constant Debugging mains Command line arguments Understanding errors
Image of page 10
Incremental Programming: The Idea : Find and repair bugs “in the small” before you have a program with several components. The hardest thing is finding the errors. So, find them as you create each class. Thus, do not : write your entire program, then type in your entire program, then attempt to test your entire program Instead: design your program at high level, then focus on one class at a time, for each class, write and test before going on to the next one, this means write a main method for every class!
Image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern