Computer Programming

Subdecks (2)

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
    1. Java for loop
    2. Java for-each loop,
    3. Java Arrays.toString() method
    4. Java Arrays.deepToString() method
    5. Java Arrays.asList() method
    6. Java Iterator Interface
    7. 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;
    }