You are on page 1of 12

Object Oriented Programming

(Java)
Module 4
Control Structures and Arrays
Arrays

4.2

Control Structures and Arrays


Learn to manage array elements using control structures
ARRAY

Ø An array is a structure that holds multiple


values of the same type.

Ø The length of an array is established when


the array is created (at runtime).

Ø After creation, an array is a fixed-length


structure.

Control Structures and Arrays


First index
0 1 2 3 4 5 6 7 8 9

Array length is 10

Element at index 8

Control Structures and Arrays


Array Declaration
Syntax:
type arrayName[ ] = new type[length];

Example:
String names[ ] = new String[5];
int [ ]grades = new int[15];
double[ ] grades;
grades = new double[2];

Control Structures and Arrays


Array Initialization
Syntax:
type arrayName[ ] = {value,value,…};

Example:
String names[ ] ={“maria”,”blanco”,”forever”};

Control Structures and Arrays


Storing Values in an Array
Syntax:
arrayName[index] = value;

Example:
names[0] = “John Doe”;
names[1] = “Jane Doe”;

Control Structures and Arrays


Multi-dimesional Array
Syntax:
type[ ][ ] = new type[row][column];

Example:
int[ ][ ] = new int[5][4];

Control Structures and Arrays


Backiel, A. (2015). Beginning Java Programming: The Object-oriented Approach. 1st Edition
Fain, Y. (2015). Java programming 24-hour trainer. John Wiley and Sons:Indianapolis, IN
Smith, J. (2015). Java programs to accompany Programming logic and design. Cengage Learning:Boston, MA
Yener, M (2015). Professional Java EE Design Patterns. John Wiley & Sons, Inc.
Gordon, S. (2017). Computer Graphics Programming in opengl with Java. Mercury Learning and Information
Butler, A (2017). Java. s.n
Lowe, D (2017). Java all-in-one for dummies. John Wiley and Sons
Saumont, P (2017). Functional Programming in Java: How Functional Techniques Improve Your Java Programs. 1st Edition
Heffelfinger, D. (2017). Java EE 8 Application Development. Packt Puublishing
Murach, J. (2017). Murach’s Java Programming. Mike Murach & Associates,Inc.
Burd, B. (2017). Beginning programming with Java for dummies. John Wiley & Sons, Inc.
Manelli, L. (2017). Developing java web application in a day. s.n.
Klausen, P. (2017). Java 5: Files and Java IO software development (e-book)
Klausen, P. (2017). Java 3 object-oriented programming software development (e-book)
Muller, M (2018). Practical JSF in Java EE 8. Apress

You might also like