Java Reference
In-Depth Information
Reference types are initialized to null by default. No object is constructed
without calling new . An “uninitialized reference variable” or NullPointer-
Exception indicates that you forgot to allocate the object.
4.
In Java, arrays are indexed from 0 to N-1 , where N is the array size. How-
ever, range checking is performed, so an out-of-bounds array access is
detected at run time.
5.
Two-dimensional arrays are indexed as A[i][j] , not A[i,j] .
6.
Checked exceptions must either be caught or explicitly allowed to propa-
gate with a throws clause.
7.
Use " " and not ' ' for outputting a blank.
8.
on the internet
Following are the available files for this chapter. Everything is self-contained,
and nothing is used later in the text.
RandomNumbers.java Contains the code for the example in Figure 2.4.
ReadStrings.java Contains the code for the example in Figures 2.6
and 2.7.
ReadStringsWithArrayList.java
Contains the code for the example in Figure 2.8.
MatrixDemo.java
Contains the code for the example in Figure 2.9.
Echo.java
Contains the code for the example in
Figure 2.10.
ForEachDemo.java
Illustrates the enhanced for loop.
DivideByTwo.java
Contains the code for the example in Figure 2.11.
MaxTest.java
Contains the code for the example in Figures 2.15-2.18.
ListFiles.java
Contains the code for the example in Figure 2.19.
DoubleSpace.java
Contains the code for the example in Figure 2.20.
exercises
IN SHORT
2.1
List the major differences between reference types and primitive
types.
List five operations that can be applied to a reference type.
2.2
What are the differences between an array and ArrayList ?
2.3
Describe how exceptions work in Java.
2.4
 
Search WWH ::




Custom Search