12/24/15

Java Exercises for Selenium



public class Calculation {

     int a;
     int b;
    
     public Calculation()  // Default constructor
     {
          a=10;
          b=20;
     }
    
    
     public Calculation(int a, int b)  // parameterized
     {
          this.a=a;
          this.b=b;
     }
    
    
    
     public void addition()
     {
          System.out.println(a+b);
         
     }
    
    
    
}

************************************************************************

public class calculatormain {

     public static void main(String[] args)
    
     {
          //Calculation cal=new Calculation(); // Invoked default constructor

          Calculation cal=new Calculation(100,50);  // Invoked parameterized constructor
         
          cal.addition(); // calling method
     }

}

************************************************************************

public class datatypes {

     public static void main(String[] args) {
         
          int i=10;  // interger varaible
          long l=10000;
          double d=12324.6777;
          char c='A';
          String s="welcome";
          boolean b=true;
         
          System.out.println(" integer value is" +"  " + i);
          System.out.println(" long value is" +"  " + l);
          System.out.println(" double value is" +"  " + d);
          System.out.println(" char value is" +"  " + c);
          System.out.println(" string value is" +"  " + s);
          System.out.println(" boolean value is" +"  " + b);
    
     }

}

************************************************************************

public class Emp {
    
     int empid;
     String ename;
     int salary;
     final static int deptno=10;
    
     final String desg="Engineer";
    
    
     public void display()
     {
          System.out.println(empid +" "+ ename+"  " + salary+"  "+deptno);
     }

}

************************************************************************

public class Employee {
     int empid;
     String ename;
     int salary;
     int deptno;
    
    
     public void getempdata(int empid,String ename,int sal,int dno) // getting the emp data from main method
     {
          this.empid=empid;
          this.ename=ename;
          salary=sal;
          deptno=dno;
         
     }
    
     public void displayempdata()  // displaying emp details
     {
          System.out.println(empid);
          System.out.println(ename);
          System.out.println(salary);
          System.out.println(deptno);
    
     }
    
     public int diaplaydeptno()
     {
          return deptno;
     }
    

}

************************************************************************

public class Empmain {

     public static void main(String[] args) {
         
          Employee e1=new Employee();
         
          /*e1.empid=1234;
          e1.ename="ABC";
          e1.salary=20000;
          e1.deptno=10;*/
         
          e1.getempdata(1234, "ABC",30000,20);
          e1.displayempdata();   // calling method from object e1
         
          //int d=e1.diaplaydeptno();
         
          System.out.println(e1.diaplaydeptno());
         
         
              
          /*Employee e2=new Employee();
         
          e2.empid=4321;
          e2.ename="xyz";
          e2.salary=20000;
          e2.deptno=10;
          e2.displayempdata();   // calling method from object e2   */
         
         
     }

}

************************************************************************

public class firstjavaprogram
{

    
    
public static void main(String args[])
{
     System.out.println("this is my first program");
}



}

************************************************************************

public class flowcontrolstatements {

     public static void main(String[] args) {
         
     /*   for(int count=0;count<=10;count++)
          {
              if(count==6)
              {
                   break;
              }
             
              System.out.println("count value is:"+ count);
          }
         
          System.out.println("Exited from loop");
     }*/
         
    
          for(int count=0;count<=5;count++)
          {
              if(count==3)
              {
                   continue;
              }
              System.out.println("count value is:"+ count);
          }
    
              
     }   
         

}

************************************************************************

public class ifelsestatement {

     public static void main(String[] args) {
         
         
          String sday="monday";
         
          if(sday.equals("sunday"))
          {
                        System.out.println("today is sunday");
          }
          else
          {
                        System.out.println("today is NOT sunday");
          }   
         

     }

}

************************************************************************

public class ifstatement {

     public static void main(String[] args) {
         
          String day="SUNDAY"// string variable
          //int iday=7;
         
         
          /*if(iday==7)
          {
              System.out.println("today is sunday");
          }*/
         
         
     /*   if(day.equals("sunday"))
          {
              System.out.println("today is sunday");
             
          }*/
         
         
          /*if(day.equalsIgnoreCase("sunday"))
          {
              System.out.println("today is sunday");
          }*/
         
         
          /*if(day.contains("U"))
          {
              System.out.println("today is sunday");
          }*/
         
          if(day=="SUNDAY")
          {
              System.out.println("today is sunday");
          }

     }

}

************************************************************************
class A
{
     int a;
     int b;
    
     void sum()
     {
          System.out.println(a+b);
     }
}

class B extends A
{
     int p;
     int q;
    
     void sub()
     {
     System.out.println(p-q);
     }
    
}


class C extends B
{
     int x;
     int y;
    
     void mul()
     {
          System.out.println(x*y);
     }
}



public class InheritanceEx
{
     public static void main(String args[])
     {
     /*   A a_obj=new A();
         
          a_obj.a=10;
          a_obj.b=20;
          a_obj.sum();*/
         
          /*B b_obj=new B();
         
          b_obj.p=100;
          b_obj.q=50;
          b_obj.sub();
         
          b_obj.a=100;
          b_obj.b=50;
         
          b_obj.sum();*/
         
         
          C c_obj=new C();
         
          c_obj.a=100;
          c_obj.b=200;
          c_obj.sum();
         
          c_obj.p=500;
          c_obj.q=100;
          c_obj.sub();
         
          c_obj.x=10;
          c_obj.y=20;
          c_obj.mul();
         
         
         
         
     }

}


************************************************************************
interface Myinterface
{
     int a=20;
     static final int b=10;
    
     public void printsum();
     public void printsub();
}

class xyz implements Myinterface
{
     public void printsum()
     {
          System.out.println(a+b);
         
     }
     public void printsub()
     {
          System.out.println(a-b);
     }
}


public class InterfaceEx
{
public static void main(String args[])
{
     xyz obj=new xyz();
    
     obj.printsum();
     obj.printsub();
    
    
     Myinterface mi=new xyz();
    
     mi.printsub();
     mi.printsum();
    
    
}
}

************************************************************************

public class loopingstatements {

     public static void main(String[] args) {
         
          //int i=0;
         
          /*while(i<20 span="">
          {
              System.out.println("i value is:" + i);
              i+=2;   // i=i+1
          }*/
         
         
          /*do
          {
              i++;
              System.out.println("i value is:" + i);
          } while(i<20 span="">
         
         
         
          for(int i=20;i>0;i--)
          {
              System.out.println("i value is:" + i);
          }
             
          System.out.println("Exited from while loop");
         
              
     }

}



************************************************************************

public class maintest {

     public static void main(String[] args)
     {
          test t1=new test();  // object creation
         
          t1.a=20;
          t1.b=10;
         
    
          t1.m1();
          t1.m2();
              

     }

}



************************************************************************
interface printable
{
     void print();
}


interface showable
{
     void show();
}


public class MultipleInheritance implements printable,showable
{

     public void print()
     {
          System.out.println("Hello");
     }
    
    
     public void show()
     {
          System.out.println("Welcome");
     }
    
     public static void main(String args[])
     {
          MultipleInheritance obj=new MultipleInheritance();
         
          //printable obj1=new MultipleInheritance ();
         
         
          obj.print();
          obj.show();
         
     }
    
}


************************************************************************

public class nestedifelsestatement {

     public static void main(String[] args) {
         
          String day="Friday";
         
          if(day.equals("Sunday"))
          {
              System.out.println("today is sunday");
          }
         
          else if(day.equals("Monday"))
          {
              System.out.println("today is Monday");
          }
         
          else if(day.equals("Tuesday"))
          {
              System.out.println("today is Tuesday");
          }
         
          else
          {
              System.out.println(" Today is NOT sunday,monday,Tuesday");
          }

     }

}


************************************************************************

public class objectclasswithsingledimarray {

     public static void main(String[] args) {
         
          //int a[]=new int[3];
          //char c[]=new char[3];
          //String s[]=new String[3];
         
          Object x[]={10,"welcome",123.66,true,'C'};
         
         
          /*Object x[]=new Object[4];    // Object class
         
          x[0]=10;
          x[1]="welcome";
          x[2]=1234.677;
          x[3]=true; */
         
          System.out.println(x.length);
         
          for(int i=0;i<x.length;i++)
          {
              System.out.println(x[i]);
          }
         
         

     }

}


************************************************************************

public class objectclasswithtwodimarray {

     public static void main(String[] args) {
         
         
          Object a[][]=new Object[2][2];
         
          a[0][0]=10;
          a[0][1]="welcome";
          a[1][0]='C';
          a[1][1]=false;
         
         
          for(int i=0;i<a.length;i++)
          {
              for(int j=0;j<a[i].length;j++)
              {
                   System.out.print(a[i][j]);
                  
              }
              System.out.println();
          }
         
     }

}

************************************************************************

public class operators {

     public static void main(String[] args) {
    
         
         
          int a=10;
          int b=20;
         
         
          System.out.println(" Arithmetic operators");
          System.out.println("-----------------------------");
          // Arithmetic operators

          System.out.println("addition is:" +(a+b));
          System.out.println("addition is:" +(b-a));
          System.out.println("addition is:" +(a*b));
          System.out.println("addition is:" +(a/b));
          System.out.println("addition is:" +(a%b));
         
          System.out.println(" relational operators");
          System.out.println("-----------------------------");
          // Relational operators returns boolean type
         
          System.out.println(a<b);  // true
          System.out.println(a>b);
          System.out.println(a<=b);
          System.out.println(a>=b);
          System.out.println(a!=b);
          System.out.println(a==b);
         
          System.out.println(" logical operators");
          System.out.println("-----------------------------");
          //Logical operators
         
          boolean x=true;
          boolean y=false;
         
          System.out.println(x && y);   // AND operator
          System.out.println ((a<b) && (a>b)); // false
         
          System.out.println(x || y);   // true
          System.out.println ((a<b) || (a>b)); // true
         
          System.out.println(!x); //false
         
          System.out.println(!(a<b));  //false
         
     }

}

************************************************************************

public class operators2 {

     public static void main(String[] args) {
         
          int a=10;
         
          //Assignment operators
          //a=a+2;
          //a+=2;
         
          a=a-5;
          a-=5;
         
          //Increment/decrement operators
         
          int x=10;
         
          //x++ ; // increment operator x+=1   , x=x+1;
         
          //x--; //decrement operator x-=1 ,    x=x-1;
         
         
          x-=5;
          System.out.println("x values is:" + x);
         
              
     }

}



************************************************************************

public class OverlaodingMethods {
    
     public void sum(int a, int b)
     {
          System.out.println("Addition of 2 numbers:" +(a+b));
     }
    
     public void sum(int a, int b, int c)
     {
          System.out.println("Addition of 3 numbers:" + (a+b));
     }
    
     public void sum(double a, char b)
     {
          System.out.println("Addition of 2 numbers:" + a+b);
     }
    
}


************************************************************************

public class Overloadmaintest {

     public static void main(String[] args)
     {
         
          OverlaodingMethods ol=new OverlaodingMethods();
         
          ol.sum(10, 20);
         
          ol.sum(100, 200,3000);

          ol.sum(123.4566,'A');
         
     }

}

************************************************************************
class Bank
{
     int getROI()
     {
          return 0;
     }
}


class SBI extends Bank
{
     int getROI()
     {
          return 7;
     }
}

class ICICI extends Bank
{
     int getROI()
     {
          return 8;
     }
}

class AXIS extends Bank
{
     int getROI()
     {
          return 9;
     }
}


public class OverridingEx {

public static void main(String args[])
{
     SBI s=new SBI();
     System.out.println(s.getROI());
    
     ICICI i=new ICICI();
     System.out.println(i.getROI());
    
     AXIS x=new AXIS();
     System.out.println(x.getROI());
    
}
    
}


************************************************************************
import java.util.Scanner;


public class Scannertest {

     public static void main(String args[])
     {
         
          Scanner s=new Scanner(System.in);
                  
          System.out.print("Ente u r name:" );
          String name=s.nextLine();
          System.out.println(name);
         
         
             
     }

    
}


************************************************************************

public class singledimarray {

     public static void main(String[] args) {
    
          int a[]={10,20,30};     // declaration, instantiation, initiation
         
         
     /*   int a[]=new int[3];   // declaration, instantiation
         
          a[0]=10;
          a[1]=20;
          a[2]=30;*/
         
         
          /*for(int i=0;i
          {
              System.out.println(a[i]);
          }*/
         
         
         
          for(int x:a)
          {
              System.out.println(x);
          }

     }

}


************************************************************************

public class singledimarraywithenhancedforloop {

     public static void main(String[] args) {
         
          String d[]={"MON","TUE","WED","THU","FRI","SAT"};
         
          /*for(int i=0;i
          {
              System.out.println(d[i]);
          }*/

         
          //enhanced for loop
          for(String day:d)
          {
              System.out.println(day);
          }
         
     }

}


************************************************************************

public class staticTest {

    
     int x;      // Non static
     static int y;      // static
    
         
     public static void main(String[] args// static method
     {
          // static methods can directly access static stuff
          y=10;
          putdata();
         
          // static methods can access Non-static stuff through Object
          staticTest st=new staticTest();
          st.x=20;
          st.getdata();
          st.testdata();
    
     }

     static public void main()
     {
          System.out.println(" thsi is second main method");
     }
    
    
         
     public void getdata()        // Non-static
     {
          x=100;  // non static
          y=200;   // static
         
          putdata();  // static method
          testdata();  // non static  
         
     }
    
     public static void putdata() // static method
     {
          System.out.println("This is test put method and it is  static");
     }
    
     public void testdata()       // non static
     {
          System.out.println("This is test data method and it is non static");
     }
    
}


************************************************************************

public class stringexamle {

     public static void main(String[] args) {
    
          /*declaring strings
         
          //String s="welcome";
         
          String s=new String("welcome");
         
          char c[]={'w','e','l','c','o','m','e'};
          s=new String(c);  */
         
         
          String s1="selenium automation framework";
          String s2="java training";
         
          //concatenate
         
          System.out.println(s1.concat(s2));
          System.out.println(s1+s2);
         
          // equality
         
          System.out.println(s1.equals(s2));
          System.out.println(s1.equalsIgnoreCase(s2));
         
          // contains
         
          System.out.println(s1.contains("automation"));
         
          //Substring
         
          String st="Welcome";
         
          System.out.println(st.substring(4)); // starting position
          System.out.println(st.substring(2,4));  // 2 - begining index  4- number of letters
         
          //split method
                  
          String a[]=s1.split(" ");
         
          System.out.println(a[0]);
          System.out.println(a[1]);
          System.out.println(a[2]);
     }

}


************************************************************************

public class Student {
    
     int sid;
     String sname;
     int age;
     char rank;
    
     public Student()   // Default Constructor
     {
          sid=10;
          sname="ABC";
          age=15;
          rank='A';
     }
    
    
     public void printdata()
     {
          System.out.println(sid);
          System.out.println(sname);
          System.out.println(age);
          System.out.println(rank);
         
     }

}

************************************************************************

public class Studentmain {

     public static void main(String[] args)
     {
         
          Student stu=new Student();
         
          stu.printdata();
     }

}

************************************************************************

public class switchcasestatement {

     public static void main(String[] args) {
         
          String day="Monday";
         
          switch(day)
          {
          case "Monday":
                             System.out.println("Today is Monday");
                             break;
         
          case "Tuesday":
                             System.out.println("Today is Tuesday");
                             break;
                            
          case "Wednesday":
              System.out.println("Today is Wednesday");
              break;
             
          case "Thurday":
              System.out.println("Today is Thurday");
              break;
             
          case "Friday":
              System.out.println("Today is Friday");
              break;
             
          case "Saturday":
              System.out.println("Today is saturday");
              break;
         
          default: System.out.println("Today is SUNDAY"); break;
             
          }
         
         

     }

}

************************************************************************

public class test {
    
      int a;
      int b;
    
     public void m1()
     {
     System.out.println("this is method1");
     System.out.println("sum:" +(a+b));
     }
    
     public void m2()
     {
          System.out.println("this is method2");
          System.out.println("sum:" +(a-b));
         
     }

}

************************************************************************

public class twodimarray {

     public static void main(String[] args) {
    
         
         
          int a[][]={{10,20,30},{40,50,60}};
         
         
          /*int a[][]=new int[2][3];
          a[0][0]=10;
          a[0][1]=20;
          a[0][2]=30;
          a[1][0]=40;
          a[1][1]=50;
          a[1][2]=60;*/
         
         
         
     /*   for(int i=0;i
          {
              for(int j=0;j
              {
                   System.out.print(a[i][j]); //10  //20  //30
              }
             
              System.out.println();
          }    */
         
         
     //Enhanced for loop
         
         
          for(int x[]:a)
          {
              for(int i:x)
              {
              System.out.print(i);
              }
             
              System.out.println();
          }
             
         
     }

}

************************************************************************

public class varaiblesClass {

     public static void main(String[] args) {
          // TODO Auto-generated method stub

     }

}




0 comments:

Post a Comment