23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

public static f<strong>in</strong>al <strong>in</strong>t SOPHOMORE = 2; // code for<br />

sophomore<br />

public static f<strong>in</strong>al <strong>in</strong>t JUNIOR = 3; // code for<br />

junior<br />

public static f<strong>in</strong>al <strong>in</strong>t SENIOR = 4; // code for<br />

senior<br />

// Instance variables, constructors, <strong>and</strong> method<br />

def<strong>in</strong>itions go here…<br />

}<br />

• Indent statement blocks. Typically programmers <strong>in</strong>dent each statement<br />

block by 4 spaces; <strong>in</strong> this book we typically use 2 spaces, however, to avoid<br />

hav<strong>in</strong>g our code overrun the book's marg<strong>in</strong>s.<br />

• Organize each class <strong>in</strong> the follow<strong>in</strong>g order:<br />

1. Constants<br />

2. Instance variables<br />

3. Constructors<br />

4. Methods.<br />

We note that some <strong>Java</strong> programmers prefer to put <strong>in</strong>stance variable def<strong>in</strong>itions<br />

last. We put them earlier so that we can read each class sequentially <strong>and</strong><br />

underst<strong>and</strong> the data each method is work<strong>in</strong>g with.<br />

• Use comments that add mean<strong>in</strong>g to a program <strong>and</strong> expla<strong>in</strong> ambiguous or<br />

confus<strong>in</strong>g constructs. In-l<strong>in</strong>e comments are good for quick explanations <strong>and</strong> do<br />

not need to be sentences. Block comments are good for expla<strong>in</strong><strong>in</strong>g the purpose<br />

of a method <strong>and</strong> complex code sections.<br />

1.9.4 Test<strong>in</strong>g <strong>and</strong> Debugg<strong>in</strong>g<br />

Test<strong>in</strong>g is the process of experimentally check<strong>in</strong>g the correctness of a program,<br />

while debugg<strong>in</strong>g is the process of track<strong>in</strong>g the execution of a program <strong>and</strong><br />

discover<strong>in</strong>g the errors <strong>in</strong> it. Test<strong>in</strong>g <strong>and</strong> debugg<strong>in</strong>g are often the most timeconsum<strong>in</strong>g<br />

activity <strong>in</strong> the development of a program.<br />

Test<strong>in</strong>g<br />

82

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!