# 0.3 Learning objects for arrays in java  (Page 4/5)

 Page 4 / 5
• Initially, the variable fib of type integer array is allocated. As part of the same statement, the array object is created with its seven fields having the values in the initializer; the reference to the object is returned and stored in the variable fib .
• A reference to the array is passed as a parameter to the method first . The formal parameter a contains a reference to the same array pointed to by the actual parameter fib .
• A new array b of the same type as the parameter a but half the length is declared and allocated.
• Each iteration of the for-loop moves one element from the first half of a to the corresponding element in the array b .
• The reference to array b is returned. Although array referenced by b was allocated within the method call, it still exists after returning.
• There are no references to the original array so it is inaccessible. Jeliot does not visualize garbage collection so the arrayremains visualized in the Instance and Array Area until the end of the program.

Exercise Modify the program so that the original array remains accessible in a different field.

## Two-dimensional arrays

Concept A matrix can be stored in a two-dimensional array. The syntax is int[][] with two indices, the first for rows and the second for columns. To access an element of the array, expressions for the twoindices must be givien.

Program: Array06.java

// Learning Object Array06 //     two-dimensional arrayspublic class Array06 {     static int addElements(int[][] a) {        int sum = 0;         for (int i = 0; i < a.length; i++)             for (int j = 0; j < a[i].length; j++)                sum = sum + a[i][j];         return sum;    }      public static void main(/*String[] args*/) {        int[][] matrix = new int[2][2];         for (int i = 0; i < matrix.length; i++)             for (int j = 0; j < matrix[i].length; j++)                matrix[i][j] = i*matrix.length + j;         int sum = addElements(matrix);    } }

This program creates a $2×2$ matrix and computes the sum of its elements.

• A two-dimensional array is allocated, the reference to it is assigned to the variable matrix . The variable matrix contains one reference for each row, and the rows are allocated as separate objects.Note that Jeliot displays each row from top to bottom as it does for all objects!
• The elements of the array are initialized to (0,1,2,3) in a nested for-loop.The outside loop iterates over the rows and the inner loop iterates over the columns within an array.
• matrix.length is used to get the number of rows and matrix[i].length to get the number of columns in row i , which is the same for all rows in this program.
• The reference to the array is passed as a parameter to the method addElements , which adds the values of all the elements.
• The sum is returned from the method and assigned to the variable sum .

Exercise Modify the program perform the same computation on a $2×3$ matrix and on a $3×2$ matrix.

## Arrays of arrays

Concept A two-dimensional array is really an array of arrays; that is, each element of the array contains a reference to another array. Therefore, byusing only one index a one-dimensional array is obtained.

where we get a research paper on Nano chemistry....?
what are the products of Nano chemistry?
There are lots of products of nano chemistry... Like nano coatings.....carbon fiber.. And lots of others..
learn
Even nanotechnology is pretty much all about chemistry... Its the chemistry on quantum or atomic level
learn
da
no nanotechnology is also a part of physics and maths it requires angle formulas and some pressure regarding concepts
Bhagvanji
Preparation and Applications of Nanomaterial for Drug Delivery
revolt
da
Application of nanotechnology in medicine
what is variations in raman spectra for nanomaterials
I only see partial conversation and what's the question here!
what about nanotechnology for water purification
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
Damian
yes that's correct
Professor
I think
Professor
Nasa has use it in the 60's, copper as water purification in the moon travel.
Alexandre
nanocopper obvius
Alexandre
what is the stm
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
if virus is killing to make ARTIFICIAL DNA OF GRAPHENE FOR KILLED THE VIRUS .THIS IS OUR ASSUMPTION
Anam
analytical skills graphene is prepared to kill any type viruses .
Anam
Any one who tell me about Preparation and application of Nanomaterial for drug Delivery
Hafiz
what is Nano technology ?
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
why we need to study biomolecules, molecular biology in nanotechnology?
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
why?
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
how did you get the value of 2000N.What calculations are needed to arrive at it
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!