Tuesday, 28 October 2008

Java Concepts By Cay Horstmann - Part3

Today i started reading Java Concepts 5th Edition By Cay Horstmann.

Nice book written by Cay Horstmann.

I wanted to share few quotations from the next two (5-6) chapters.

1) The if statement lets a program carry out different actions depending on a condition.

2) A block statement groups several statements together.

3) The Selection Operator Java has a selection operator of the form

condition ? value1 : value2

The value of that expression is either value1 if the condition is true or value2 if it is false. For example, we can compute the absolute value as


y = x >= 0 ? x : -x;



which is a convenient shorthand for


if (x >= 0)
y = x;
else
y = -x;


The selection operator is similar to the if/else statement, but it works on a different syntactical level. The selection operator combines values and yields another value. The if/else statement combines statements and yields another statement.

For example, it would be an error to write


y = if (x < 0) x; else -x; // Error



The if/else construct is a statement, not a value, and you cannot assign it to a variable.We don't use the selection operator in this book, but it is a convenient and legitimate construct that you will find in many Java programs.

4) Relational operators compare values. The == operator tests for equality.

5) When comparing floating-point numbers, don't test for equality. Instead, check whether they are close enough.

6) Do not use the == operator to compare strings. Use the equals method instead.

7) The compareTo method compares strings in dictionary order.

8) The == operator tests whether two object references are identical. To compare the contents of objects, you need to use the equals method.

9) The null reference refers to no object.

10) Multiple conditions can be combined to evaluate complex decisions. The correct arrangement depends on the logic of the problem to be solved.

11) The boolean type has two values: true and false.

12) You can form complex tests with the Boolean operators && (and), | | (or), and ! (not).

13) De Morgan's law shows how to simplify expressions in which the not operator (!) is applied to terms joined by the && or | | operators.

14) You can store the outcome of a condition in a Boolean variable.

De Morgan's Law

De Morgan's law shows how to simplify expressions in which the not operator (!) is applied to terms joined by the && or | | operators.


if (!(0 > amount && amount > 1000)) . . .



This test is a little bit complicated, and you have to think carefully through the logic. "When it is not true that 0 < amount and amount < 1000 ..." Huh? It is not true that some people won't be confused by this code.
The computer doesn't care, but humans generally have a hard time comprehending logical conditions with not operators applied to and/or expressions. De Morgan's law, named after the mathematician Augustus de
Morgan (1806-1871), can be used to simplify these Boolean expressions. De Morgan's law has two forms: one for the negation of an and expression and one for the negation of an or expression:


!(A && B) is the same as !A || !B



15) Black-box testing describes a testing method that does not take the structure of the implementation into account.

16) White-box testing uses information about the structure of a program.

17) Test coverage is a measure of how many parts of a program have been tested.

18) Boundary test cases are test cases that are at the boundary of acceptable inputs.

19) Logging messages can be deactivated when testing is complete.

20) A while statement executes a block of code repeatedly. A condition controls how often the loop is executed.

21) You use a for loop when a variable runs from a starting to an ending value with a constant increment or decrement.

22) Loops can be nested. A typical example of nested loops is printing a table with rows and columns.

23) Sometimes, the termination condition of a loop can only be evaluated in the middle of a loop. You can introduce a Boolean variable to control such a loop.

24) A debugger is a program that you can use to execute another program and analyze its run-time behavior.

25) You can make effective use of a debugger by mastering just three concepts: breakpoints, single-stepping, and inspecting variables.

26) When a debugger executes a program, the execution is suspended whenever a breakpoint is reached.

27) The single-step command executes the program one line at a time.

28) A debugger can be used only to analyze the presence of bugs, not to show that a program is bug-free.

29) During debugging, compare the actual contents of variables against the values you know they should have.

About the Author

Cay Horstmann grew up in Northern Germany and attended the Christian-Albrechts-Universität in Kiel,a harbor town at the Baltic sea. I received a M.S. in computer science from Syracuse University , and a Ph.D. in mathematics from the University of Michigan in Ann Arbor. I now teach computer science at San Jose State University . In my copious spare time I write books and articles on Java and consult on internet programming.

No comments: