If Statement

     

    If Statement


    I. Java if statement



    Syntax
    if(condition){  
    //code to be executed  
    }
    Example

    public class IfStatementExample {
        public static void main(String[] args) {
            int x, y;
            x = 10;
            y = 20;
            if (x < y) {
                System.out.println("x is less than y");
            }
            x = x * 2;
            if (x == y) {
                System.out.println("x now equal to y");
            }
            x = x * 2;
            if (x > y) {
                System.out.println("x now greater than y");
            }
            // this won't display anything
            if (x == y)
                System.out.println("you won't see this");
        }
    }
    Output:
    x is less than y
    x now equal to y
    x now greater than y

    II. Java if-else statement

    Syntax
    if(condition){  
         statement 1; //code if condition is true  
    }else{  
         statement 2; //code if condition is false  
    }  
    Example
    public class IfElseDemo {
        public static void main(String[] args) {
    
            int testscore = 76;
            char grade;
    
            if (testscore >= 90) {
                grade = 'A';
            } else if (testscore >= 80) {
                grade = 'B';
            } else if (testscore >= 70) {
                grade = 'C';
            } else if (testscore >= 60) {
                grade = 'D';
            } else {
                grade = 'F';
            }
            System.out.println("Grade = " + grade);
        }
    }
    Output:
    Grade = C

    III. Java if-else-if statement


    Syntax
    Syntax:
    
    if(condition1){  
    //code to be executed if condition1 is true  
    }else if(condition2){  
    //code to be executed if condition2 is true  
    }  
    else if(condition3){  
    //code to be executed if condition3 is true  
    }  
    ...  
    else{  
    //code to be executed if all the conditions are false  
    }  
    Example
    public class IfElseIfStatementExample {
        public static void main(String args[]) {
            int month = 4; // April
            String season;
            if (month == 12 || month == 1 || month == 2)
                season = "Winter";
            else if (month == 3 || month == 4 || month == 5)
                season = "Spring";
            else if (month == 6 || month == 7 || month == 8)
                season = "Summer";
            else if (month == 9 || month == 10 || month == 11)
                season = "Autumn";
            else
                season = "Bogus Month";
            System.out.println("April is in the " + season + ".");
        }
    }
    Output:
    April is in the Spring.


    Arithmetic Operators

     

    Arithmetic Operators

    1. The Arithmetic Operators



    public class BasicMath {
        public static void main(String args[]) {
            // arithmetic using integers
            System.out.println("Integer Arithmetic");
            int a = 1 + 1;
            int b = a * 3;
            int c = b / 4;
            int d = c - a;
            int e = -d;
            System.out.println("a = " + a);
            System.out.println("b = " + b);
            System.out.println("c = " + c);
            System.out.println("d = " + d);
            System.out.println("e = " + e);
            // arithmetic using doubles
            System.out.println("\nFloating Point Arithmetic");
            double da = 1 + 1;
            double db = da * 3;
            double dc = db / 4;
            double dd = dc - a;
            double de = -dd;
            System.out.println("da = " + da);
            System.out.println("db = " + db);
            System.out.println("dc = " + dc);
            System.out.println("dd = " + dd);
            System.out.println("de = " + de);
        }
    }
    Output:
    Integer Arithmetic
    a = 2
    b = 6
    c = 1
    d = -1
    e = 1
    
    Floating Point Arithmetic
    da = 2.0
    db = 6.0
    dc = 1.5
    dd = -0.5
    de = 0.5

    2. The Modulus Operator

     returns the remainder of a division operation
    public class Modulus {
        public static void main(String args[]) {
            int x = 42;
            double y = 42.25;
            System.out.println("x mod 10 = " + x % 10);
            System.out.println("y mod 10 = " + y % 10);
        }
    }
    Output:
    x mod 10 = 2
    y mod 10 = 2.25

    3. Increment and Decrement

    x = x + 1; or x++;
    x = x - 1; or x--;

    4. Arithmetic Assignment Operators

    public class OpEquals {
        public static void main(String args[]) {
            int a = 1;
            int b = 2;
            int c = 3;
            a += 5;
            b *= 4;
            c += a * b;
            c %= 6;
            System.out.println("a = " + a);
            System.out.println("b = " + b);
            System.out.println("c = " + c);
        }
    }
    Output:
    a = 6
    b = 8
    c = 3

    Modifier

       MODIFIER

      · Modifier

      · private/ default/ protected/ public

      · Non modifier

      · final/ static/ abstract

      · transient/ volatile/ native/ synchronized



      I. Class Modifier

      •  A class (A) can access to other class (B) :
      • Create a new object of class B
      •  Extend class B
      • Access to method/ property in class B

      Default Access

      • Do not use public keyword when create a new class.
      • Can be accessed by other classes in same package
      • Can not be accessed by other class if not in same package

      · 

      Public Access

      •  Use public keyword when create a new class
      •  Allow all class from other packages access and create new object


      Final Class

      • Can not be extended
      •  Other class can access via create new object

      Abstract Class

      • Do not allow initialize an object if it's abstract class
      • Can be used via extend

      II. Method/ Property Modifier




      Data Types in Java

         

            Data Types in Java

        There are 2 different types in java. They are shown below. You don't need to remember detail, just simplify know that. Then code as much as you can ^_^

        I. Primitive data types



        II. Non-primitive data types







        Variables in Java

           

          Variables in Java




          I. What is variable in Java?

          A variable is nothing but a name given to a storage area that our programs can manipulate..Each variable has a specific type. Data type determines size and layout of the variable's memory

          II. Declaring a variable

          type variable_name = value;
          Ex: 
          int a, b, c;
          int d = 35, e, f = 55;
          byte z = 22; // initializes z.
          double pi = 3.14159; // declares an approximation of pi.
          char x = 'x'; // the variable x has the value 'x'.
          String name = "Your name";\

          III. Type of variables

          1. Local Variables
          .A variable declared inside the body of the method is called local variable. You can use this variable only within that method and the other methods in the class do not know that the variable exists.

          A local variable cannot be defined with "static" keyword.




          public class LocalVariableExample {
              public int sum(int n) {
                  int sum = 0;
                  for (int i = 0; i < n; i++) {
                      sum = sum + i;
                  }
                  return sum;
              }
          
              public static void main(String[] args) {
                  LocalVariableExample localVariableExample = new LocalVariableExample();
                  int sum = localVariableExample.sum(10);
                  System.out.println("Sum of first 10 numbers -> " + sum);
              }
          }

          Output:
          Sum of first 10 numbers -> 45
           2. Instance Variables (Non-Static Fields)
          - Declared in class but outside methods, constructor or block code

          - Be created when an object is created. Then this variable is destroyed when that object is destroyed

          – có thể được khai báo trong lớp trước hoặc sau khi sử dụng nó.

          –  Use access modifier for instance variables. If we do not specify any access specifier, then the default access modifier will be used.

          – thông thường thì local variable sẽ visible với tất cả các method, constructor và block trong class.

          – Have Initialization  value . number is 0, boolean is false, object is null.

          public class InstanceVariableExample {
              public static void main(String[] args) {
                  Employee employee = new Employee();
          
                  // Before assigning values to employee object
                  System.out.println(employee.empName);
                  System.out.println(employee.id);
                  System.out.println(employee.age);
          
                  employee.empName = "Ramesh";
                  employee.id = 100;
                  employee.age = 28;
          
                  // After assigning values to employee object
                  System.out.println(employee.empName);
                  System.out.println(employee.id);
                  System.out.println(employee.age);
              }
          
          }
          
          class Employee {
          
              // instance variable employee id
              public int id;
          
              // instance variable employee name
              public String empName;
          
              // instance variable employee age
              public int age;
          }
          Output:
          null
          0
          0
          Ramesh
          100
          28

          3. Static variable
          A variable that is declared as static is called a static variable

          class Student {
              private int rollNo;
              private String name;
              private static String college = "ABC"; // static variable
              public Student(int rollNo, String name) {
                  super();
                  this.rollNo = rollNo;
                  this.name = name;
              }
              @Override
              public String toString() {
                  return "Student [rollNo=" + rollNo + ", name=" + name + ", college=" + college + "]";
              }
          }


          JAVA FOR BEGINNER

                   JAVA FOR BEGINNER


            I. GETTING STARTED

            1. Variable in java

            2. Data type in Java

            3. Modifiers

            4. Arithmetic Operators

            5. If Statement

            6. Switch case statement




            TEST CASES FOR SEARCH FIELD

             

            TEST CASES FOR SEARCH FIELD

              A search field is the common field of any website. Hope below some test cases are helpful for you !

            1.   Check the name of search field is correct

            2.   Check whether the the search field can be clicked or not.

            3.   Check whether it is able to type or enter in the search field or not.

            4.   Check placeholder is added to the search field.

            5.   Check the cursor appears after clicking the search icon.

            6.   Check that when the user pastes or copy in the search field.

            7.   Check that when the user can type any alphanumeric, special characters in the search field.

            8.   Check the search function return correct results for the valid keywords.

            9.   Enter any one character in the search field and click on the Search button/press Enter key.

            10.   Enter string more than the max length in search field.

            11.   Enter a string in the search field with spaces (before the string, after the string, and in between) and verify the results.

            12.   Without entering character in the search field then click on the Search button.

            13.   Click in the search field and press Enter key.

            14.   Check the time systems return search results.

            15.   Check the search results are in the correct order as requirement.

            16.   Check if suggestions are shown when adding keywords to the search field.

            17.   Try to drag and drop images, videos or another file in the search field and check the result