Few weeks back i started reading Java™ How to Program, Sixth Edition By H. M. Deitel - Deitel & Associates, Inc., P. J. Deitel - Deitel & Associates, Inc.
Nice book written By H. M. Deitel - Deitel & Associates, Inc., P. J. Deitel - Deitel & Associates, Inc.
I wanted to share few quotations found the book from the 7th chapter.
1) Arrays are data structures consisting of related data items of the same type. Arrays are fixed-length entitiesthey remain the same length once they are created, although an array variable may be reassigned the reference of a new array of a different length.
2) An array is a group of variables (called elements or components) containing values that all have the same type. Arrays are objects, so they are considered reference types. The elements of an array can be either primitive types or reference types (including arrays).
3) To refer to a particular element in an array, we specify the name of the reference to the array and the index (subscript) of the element in the array.
4) A program refers to any one of an array's elements with an array-access expression that includes the name of the array followed by the index of the particular element in square brackets ([]).
5) The first element in every array has index zero and is sometimes called the zeroth element.
6) An index must be a nonnegative integer. A program can use an expression as an index.
7) Every array object knows its own length and maintains this information in a length field. The expression array.length accesses array's length field to determine the length of the array.
8) To create an array object, the programmer specifies the type of the array elements and the number of elements as part of an array-creation expression that uses keyword new. The following array-creation expression creates an array of 100 int values:
int b[] = new int[ 100 ];
9) When an array is created, each element of the array receives a default valuezero for numeric primitive-type elements, false for boolean elements and null for references (any nonprimitive type).
10) When an array is declared, the type of the array and the square brackets can be combined at the beginning of the declaration to indicate that all the identifiers in the declaration are array variables, as in
double[] array1, array2;
11) A program can declare arrays of any type. Every element of a primitive-type array contains a variable of the array's declared type. Similarly, in an array of a reference type, every element is a reference to an object of the array's declared type.
12) A program can create an array and initialize its elements with an array initializer (i.e., an initializer list enclosed in braces).
13) Constant variables (also called named constants or read-only variables) must be initialized before they are used and cannot be modified thereafter.
14) When a Java program executes, the JVM checks array indices to ensure that they are valid (i.e., they must be greater than or equal to 0 and less than the length of the array). If a program uses an invalid index, Java generates a so-called exception to indicate that an error occurred in the program at execution time.
15) The enhanced for statement allows programmers to iterate through the elements of an array or a collection without using a counter. The syntax of an enhanced for statement is:
for ( parameter : arrayName )
statement
where parameter has two partsa type and an identifier (e.g., int number), and arrayName is the array through which to iterate.
16) The enhanced for statement cannot be used to modify elements in an array. If a program needs to modify elements, use the traditional counter-controlled for statement.
17) When an argument is passed by value, a copy of the argument's value is made and passed to the called method. The called method works exclusively with the copy.
18) When an argument is passed by reference, the called method can access the argument's value in the caller directly and possibly modify it.
19) Java does not allow programmers to choose between pass-by-value and pass-by-referenceall arguments are passed by value. A method call can pass two types of values to a methodcopies of primitive values (e.g., values of type int and double) and copies of references to objects. Although an object's reference is passed by value, a method can still interact with the referenced object by calling its public methods using the copy of the object's reference.
20) To pass an object reference to a method, simply specify in the method call the name of the variable that refers to the object.
21) When an argument to a method is an entire array or an individual array element of a reference type, the called method receives a copy of the array or element's reference. When an argument to a method is an individual array element of a primitive type, the called method receives a copy of the element's value.
22) To pass an individual array element to a method, use the indexed name of the array as an argument in the method call.
23) Multidimensional arrays with two dimensions are often used to represent tables of values consisting of information arranged in rows and columns.
24) Arrays that require two indices to identify a particular element are called two-dimensional arrays. An array with m rows and n columns is called an m-by-n array. A two-dimensional array can be initialized with an array initializer of the form
arrayType arrayName[][] = { { row1 initializer }, { row2 initializer }, ... };
25) Multidimensional arrays are maintained as arrays of separate one-dimensional arrays. As a result, the lengths of the rows in a two-dimensional array are not required to be the same.
26) A multidimensional array with the same number of columns in every row can be created with an array-creation expression of the form
arrayType arrayName[][] = new arrayType[ numRows ][ numColumns ];
27) An argument type followed by an ellipsis (...) in a method's parameter list indicates that the method receives a variable number of arguments of that particular type. The ellipsis can occur only once in a method's parameter list and it must be at the end of the parameter list.
28) A variable-length argument list is treated as an array within the method body. The number of arguments in the array can be obtained using the array's length field.
29) Passing arguments to main in a Java application from the command line is achieved by including a parameter of type String[] in the parameter list of main. By convention, main's parameter is named args.
30) Java passes the command-line arguments that appear after the class name in the java command to the application's main method as Strings in the array args. The number of arguments passed in from the command line is obtained by accessing the array's length attribute.
31) The static method parseInt of class Integer converts its String argument to an int.
About the Authors
Dr. Harvey M. Deitel, Chairman and Chief Strategy Officer of Deitel & Associates, Inc., has 43 years experience in the computing field, including extensive industry and academic experience. Dr. Deitel earned B.S. and M.S. degrees from the Massachusetts Institute of Technology and a Ph.D. from Boston University. He worked on the pioneering virtual-memory operating-systems projects at IBM and MIT that developed techniques now widely implemented in systems such as UNIX, Linux and Windows XP. He has 20 years of college teaching experience, including earning tenure and serving as the Chairman of the Computer Science Department at Boston College before founding Deitel & Associates, Inc., with his son, Paul J. Deitel. He and Paul are the co-authors of several dozen books and multimedia packages and they are writing many more. With translations published in Japanese, German, Russian, Spanish, Traditional Chinese, Simplified Chinese, Korean, French, Polish, Italian, Portuguese, Greek, Urdu and Turkish, the Deitels' texts have earned international recognition. Dr. Deitel has delivered hundreds of professional seminars to major corporations, academic institutions, government organizations and the military.
Paul J. Deitel, CEO and Chief Technical Officer of Deitel & Associates, Inc., is a graduate of the MIT's Sloan School of Management, where he studied Information Technology. Through Deitel & Associates, Inc., he has delivered Java, C, C++, Internet and World Wide Web courses to industry clients, including IBM, Sun Microsystems, Dell, Lucent Technologies, Fidelity, NASA at the Kennedy Space Center, the National Severe Storm Laboratory, Compaq, White Sands Missile Range, Rogue Wave Software, Boeing, Stratus, Cambridge Technology Partners, Open Environment Corporation, One Wave, Hyperion Software, Adra Systems, Entergy, CableData Systems and many other organizations. Paul is one of the most experienced Java corporate trainers having taught about 100 professional Java training courses. He has also lectured on C++ and Java for the Boston Chapter of the Association for Computing Machinery. He and his father, Dr. Harvey M. Deitel, are the world's best-selling Computer Science textbook authors.
Wednesday, 4 February 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment