another simple use of an array in the following code fragmentwhich counts the number of times certain number appears in an array/*counts the number of times an integer appears in an array *public static int findcount(int[aint kint count for (int ea/note the use of the "foreachloop if ( = /check if the current element equals count++return countout of bounds errors it is dangerous mistake to attempt to index into an array using number outside the range from to length &minus such reference is said to be out of bounds out of bounds references have been exploited numerous times by hackers using method called the buffer overflow attack to compromise the security of computer systems written in languages other than java as safety featurearray indices are always checked in java to see if they are ever out of bounds if an array index is out of boundsthe run-time java environment signals an error condition the name of this condition is the arrayindexoutofboundsexception this check helps java avoid number of security problems (including buffer overflow attacksthat other languages must cope with we can avoid out-of-bounds errors by making sure that we alway index into an arrayausing an integer value between and length one shorthand way we can do this is by carefully using the early termination feature of boolean operations in java for examplea statement like the following will never generate an index out-of-bounds errorif (( > &( [ ]