Save
Computer Programming
Save
Share
Learn
Content
Leaderboard
Learn
Created by
Chame
Visit profile
Subdecks (2)
Comprog 3
Computer Programming
48 cards
Comprog 2
Computer Programming
45 cards
Cards (120)
Object which contains
elements
of a
similar
data
type
Arrays
Index-based, the
first
element
of the array is stored at the
0th
index,
2nd
element
is
stored
on
1st
index and so on
Arrays in Java
Types of
Arrays
in Java
Single Dimensional
Array/
One
Dimensional Array,
Two Dimensional
and
Multi
Dimensional
Considered as the "List if
variables
of
similar
data
types
"
Single Dimensional Array
or
One Dimensional Array
Single Dimensional
or
One Dimensional Array
valid declarations
int
[
]
a
; and int
b
[
]
;
int[]
number
= new int[
5
];
Initialize
an
array
named 'number' with the element of
5
Array of
arrays
where data is
organized
into
rows
and
columns
(like an Excel file)
Two Dimensional Array
Two Dimensional Array valid declaration
int a[]
[
]
; ,
int[
]
[] b; and int[]
c
[
]
;
Multiple
declaration of array variable
int[
]
a
[
]
,
b[
]
; ,
int[
]
[
]
e, f[]; and int[]
g[
]
,
h[
]
;
Ways to print an array in Java
Java for
loop
Java
for-each loop
,
Java
Arrays.toString()
method
Java
Arrays.deepToString()
method
Java
Arrays.asList()
method
Java
Iterator Interface
Java
Stream API
Used to
execute
a set of statements
repeatedly
until a particular
condition
is satisfied
Java for
Loop
Java for Loop syntax
for(initialization; condition; increment/decrement
){
//
statement
}
Example of
For Loop
public
class Main{
public static void main(String[] args){
int
a[
]
=
new
int
[4];
a
[0] = 10;
Used to
pass
through
an
array
or collection.
Returns
the elements one by one in a
define
variable
Java for-each loop
Java
for-each loop
syntax
for
(
Type var
:array)
Name
assign
to a
storage
area that the program can
manipulate
Variable
A variable type determines the
size
and layout of the variable's
memory
Three places where variables you can declare variable programming language
Inside a
function
or a block:
Local
Variable
Outside of all function:
Global
Variables
Definition of function parameters:
Formal
Parameters
Local
variable
is declared
inside
a function whereas Global variable provides
data
sharing
Created when the function has started
execution
and is lost when the function
terminates
Local
Variables
Variable that provides
data
sharing
Global
Variables
Stored
on the
stack
Local
Variable
Stored
on a
fixed
location decided by the
compiler
Local Variables
Parameters
passing is required for
local
variable where as it is not necessary for the
global
variable
Defined as a
type
of
variable
declared
within
programming block or subroutines
Local Variable
Local
variable
public
int
add()
{
int a = 4;
int b = 5;
return
a+
b;
}
Global
Variable
int a = 4;
int b = 5;
public
int
add()
{
return
a+b;
}
See all 120 cards