Documente Academic
Documente Profesional
Documente Cultură
PROGRAMMING PARADIGMS
Object Oriented Programming using Java
Arrays
Arrays
● an array is a collection of similar type of elements that have a contiguous
memory location.
● Data Structure – organizing , storing and retrieving.
Array ( Cond…)
Advantages
● Code Optimization: It makes the code optimized, we can retrieve or sort the
data efficiently.
● Random access: We can get any data located at an index position.
Disadvantages
● Size Limit: We can store only the fixed size of elements in the array. It
doesn't grow its size at runtime. To solve this problem, collection framework is
used in Java which grows automatically.
arrayName []
ArrayName[][]
ArrayName[][][]
ArrayName[][][][]
Example
class Testarray{
public static void main(String args[]){
int a[]=new int[5]; //declaration and instantiation
a[0]=10;//initialization
a[1]=20;
a[2]=70;
a[3]=40;
a[4]=50;
//traversing array
for(int i=0;i<a.length; i++)//length is the property of array
System.out.println(a[i]);
}}
● byte Array[];
● short Array[];
● boolean Array[];
● long Array[];
● float Array[];
● double Array[];
● char Array[];
● int a[]={33,3,4,5};
● A[0] = 33;
● A[1] = 3;
● A[2] = 4;
● A[3] = 5;
Comments in Java
/* This is a
multi line
comment
*/
System.out.println("Hi World");
}
}
Documentation Comment
● begin with /** and terminate with */ and that spans multiple lines.
/**
This is a documentation comment.
Why ?
/**
* The HelloWorld program implements an application that
* simply displays "Hello World!" to the standard output.
*
* @author Zara Ali
* @version 1.0
* @since 2014-03-31
*/
●
@versio Adds a "Version" subheading with the @version version-
n specified version-text to the generated text
docs when the -version option is used.
Example
@see Adds a "See Also" heading with a link or text @see reference
entry that points to reference.