AutomationTesting_Java_8
AutomationTesting_Java_8
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---
--open downloads folder --> unzip eclipse file ---> open eclipse folder--> double
click on eclipse application file (blue colour icon)--> it should ask for workspace
path--> keep as it is(default path)-->select checkbox-->launch--> welcome page
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--
package Sample1;
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
1.Variables:
Variables are nothing but piece of memory use to store information.
one variable can store 1 information at a time.
-------------------------------------------------------------------------
-
package Variables; -
-
public class sample2 -
{ -
public static void main(String[] args) {
//3. Usage
System.out.println(sname);
System.out.println(rollnum);
System.out.println(grade);
System.out.println(per);
-
} -
} -
-
-------------------------------------------------------------------------
package Variables;
public class sample2
{
public static void main(String[] args) {
//3. Usage
System.out.println("Student name: "+sname);
System.out.println("student rollNum: "+rollnum);
System.out.println("student grade: "+grade);
System.out.println("student percentage: "+ per +" %");
}
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
Data Types:
Data type are used to represent type of data or information which we are
going to use in our java program.
1.Primitive datatype:
There are 8 type of primitive datatypes.
all the primitive datatypes are keywords.
* Memory size of primitive datatype are fix.
The types of primitive datatype are:
1.(Numeric + Non-decimal):-
Ex: 80,85,10,..etc
2.(Numeric + decimal):-
Ex: 22.5,22.8,6.4....
5. float 4 byte
6. double 8 byte
3.Character :-
Ex: A,B,X,Z.
7. char 2 byte
---------------------------------------
4.Conditional:-
Ex: true,false.
8. boolean 1 bit
---------------------------------------------------------
2. Non-primitive datatype:
There are 2 types of non primitive datatypes .
all the Non primitive datatypes are identifiers.
* Memory size of non primitive datatype is not defined or not fix.
Methods:
A method is a block of code which only runs when it is called.
You can pass data, known as parameters, into a method.
Methods are used to perform certain actions, and they are also known as
functions.
Why use methods? To reuse code: define the code once, and use it many
times.
1. main method
In any Java program, the main() method is the starting point from where
compiler starts program execution.
So, the compiler needs to call the main() method.
2. Regular method
package Methods;
//1. static regular method call from same class --> methodname();
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
package Methods;
demo3.m4();
package Methods;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--
Note: At the time of program execution main method is going to get executed
automatically,
where as regular methods are not going to get executed automatically.
At the time of program execution priority is sceduled for main method only.
To call a regular method we need to make call method call from main method,
until unless if the method call is not made regular method will not get
executed.
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
package Methods;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
package Methods;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
package Methods;
addition();
package Methods;
studentName();
studentName("Anil");
studentName("Sunil");
System.out.println("main method ended");
}
package Methods;
public static void studentInfo(String sname, int sRollNum, char sGrade, float sper)
{
System.out.println(sname);
System.out.println(sRollNum);
System.out.println(sGrade);
System.out.println(sper);
}
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
package Control_Statements;
//20>=35
if(marks>=35)
{
System.out.println("Pass");
}
// if(condition)
// {
//
// }
}
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
package Control_Statements;
// 35>=35
if(marks>=35)
{
System.out.println("Pass");
}
else
{
System.out.println("Fail");
}
}
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
package Control_Statements;
if(marks>=65)
{
System.out.println("distinction");
}
else if (marks>=60)
{
System.out.println("1st class");
}
else if (marks>=55)
{
System.out.println("higher 2nd class");
}
else if (marks>=50)
{
System.out.println("2nd class");
}
else if (marks>=35)
{
System.out.println("Pass");
}
else
{
System.out.println("Fail");
}
}
}
-----------------------------------------------------------------------------------
---------------------------------------------------------------------------
package Control_Statements;
if("ab"==UN)
{
System.out.println("Correct UN");
System.out.println("Enter your password");
if("xyz"==PWD)
{
System.out.println("Correct PWD--> Login Scuccessful");
}
else
{
System.out.println("Wrong PWD--> Login Failed");
}
}
else
{
System.out.println("Wrong UN --> Login Failed");
}
}
}
-----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
package Control_Statements;
switch (day)
{
case 1: System.out.println("Today is mon");
break;
}
}
}
-----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
Constructor:
A constructor in Java is a special method that is used to initialize
objects/variables.
The constructor is called when an object of a class is created.
Use of Constructor
1. To copy/load all members of class into object --> when we create
object of class
2. To initialize data member/variable
Types of Constructor
1. Default Constructor
2. User defined Constructor
1. Default Constructor
If Constructor is not declared in java class then at the time of
compilation compiler will provide Constructor for the class
If programer has declared the constructor in the class then compiler
will not provided default Constructor.
The Constructor provided by compiler at the time of compilation is
known as Default Constructor
}
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------------
package Contructor;
}
-----------------------------------------------------------------------------------
---------------------------------------------------------------------------------
package Contructor;
//step2: initialization
sample3()
{
a=50;
b=60;
}
System.out.println("------------------");
//step3: usage
public void addition()
{
int sum=a+b;
System.out.println(sum);
}
//step3: usage
public void mul()
{
int mul=a*b;
System.out.println(mul);
}
}
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------------
package Contructor;
//step1: declaration
int a;
int b;
//constructor--> user defined
// use1: use to copy all the members of class into object
// use2. To initialize data member/variable/objects
//step2: initialization
sample4()
{
a=10;
b=5;
}
//step3: usage
public void div()
{
int divValue= a/b;
System.out.println(divValue);
}
}
-----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
package Contructor;
//step1: declaration
int num1; //10, 15
int num2;
//step2: initialization
}
-----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
package Contructor;
int num1;
int num2;
String sname;
}
-----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
package Contructor;
System.out.println("----------------");
System.out.println("----------------");
sample8 s10=new sample8("abc");
s10.studentName();
}
}
-----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
------------------------------------------------------
Object-Oriented Programming System(OOPS)
OOps concept provides 5 important pillers/principles for the language they are
1. Inheritance
2. Polymorphism
3. Encapsulation
4. Abstraction
-----------------------------------------------------------------------------------
---------------------
Inheritance:
It is one of the Oops principle where one class acquires properties of
another class with the help of 'extends' keywords is called Inheritance.
2. Multilevel Inheritance:
Multilevel Inheritance takes place between 3 or more than 3 classes.
3. Multiple Inheritance:
1 subclass acquiring properties of 2 super classes at the same time is known
as Multiple Inheritance.
Java doesn't support Multiple Inheritance using class because of "dimond
ambiguity" problem.
4. Hirarchicle Inheritance:
multiple sub classes can acquire properties of 1 super class is known as
hirarchicle Inheritance.
-----------------------------------------------------------------------------------
---------------------------------------------------------------------------------
package Inheritance;
// super/base/parent class
package Inheritance;
}
-----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
package Inheritance;
//Multilevel Example
package Inheritance;
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
package Inheritance;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
package Inheritance;
}
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
package Inheritance;
// super/base/parent class
public class father
{
public void car()
{
System.out.println("Car: kia seltos");
}
package Inheritance;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
package Inheritance;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
package Inheritance;
package Inheritance;
System.out.println("---properties of son1---");
son1 s1 =new son1();
s1.mobile();
s1.car();
s1.home();
s1.money();
System.out.println("---properties of son2---");
son2 s2=new son2();
s2.laptop();
s2.car();
s2.home();
s2.money();
System.out.println("---properties of son3---");
son3 s3=new son3();
s3.PC();
s3.car();
s3.home();
s3.money();
}
}
-----------------------------------------------------------------------------------
-----------------------------