Primitives vs Non Primitives:

  • primitive data types: lowercase

    • boolean
    • integers
    • doubles
    • float
    • character
  • non primitive data types: uppercase

    • wrapper class - string
    • arrays

If/Else Statements:

The if/else statement executes a block of code if a specified condition is true. If the condition is false, another block of code can be executed.

int time = 20; //set variable
if (time < 18) { //the program decides whether this is true or not
  System.out.println("Good day."); //if it is then print this line
} else {
  System.out.println("Good evening."); //if it is not then print this
}

De Morgan's Law:

The complement of the union of two sets is the intersection of their complements and the complement of the intersection of two sets is the union of their complements.

|| means "or" and the && means "and"

boolean blue = true;
boolean red = true;

if (!(blue && red)){
    System.out.println("I do not like blue or red");
}
else{
    System.out.println("My favorite colors are blue and red");
}
My favorite colors are blue and red

Switch Case in Java:

The switch statement is a multi-way branch statement. In simple words, the Java switch statement executes one statement from multiple conditions.

int x = 1; // the integer given in the variable is 20
String output;
switch (x) { 
    case 1:
        output = x + " > 0";
        break;
    case 2:
        output = x + " > 2";
        break;
    case 3:
        output = x + " > 3";
        break;
    case 4:
        output = x + " > 4";
        break;
}
System.out.println(output)