0% found this document useful (0 votes)
2 views

AutomationTesting_Java_8

The document outlines the Java installation procedure, including checking the Java version, downloading, and setting the Java path. It also covers Eclipse IDE installation and provides examples of Java programming concepts such as variables, data types, methods, control statements, and constructors. The document includes code snippets to illustrate these concepts and their usage in Java programming.

Uploaded by

vikas bisen
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

AutomationTesting_Java_8

The document outlines the Java installation procedure, including checking the Java version, downloading, and setting the Java path. It also covers Eclipse IDE installation and provides examples of Java programming concepts such as variables, data types, methods, control statements, and constructors. The document includes code snippets to illustrate these concepts and their usage in Java programming.

Uploaded by

vikas bisen
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 23

Java installation procedure:

Step1: Command to check java version: java -version

step2: check operating system:

Step2: how to download java


search download java version-->click on oracle.com-->Java SE Development Kit -->
click on 32/64 related file to download java

Step3: install downloaded java file

Step4: Copy java path


open C drive-->program files-->java-->jdk/jre(jdk prefered)-->bin folder-->copy bin
folder path

Step5: Set java path


right click on This Pc/my computer-->properties-->advanced system setting--
>envirnment variable-->user variable--> check for "path" variable

--Case1: already path variable exist -->click on path variable-->edit-->new-->ctrl+


V(Paste) --> ok--ok
--Case2: no path variable--> click on new --> enter variable name i.e. -"path"-->
variable value -ctrl+ V(Paste)--> ok-->ok

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---

Diff versions eclipse IDE:


versions:
oxygen
neon
marsh
photon

eclipse installation procedure:

--search download eclipse oxygen-->click on https://www.eclipse.org/-->MORE


DOWNLOADS-->Eclipse version-->Eclipse IDE for Java and DSL Developers-->Windows
x86_64--> eclipse.zip file

--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;

public class demo2


{
//class body

public static void main(String [] args)


{
//main method body

System.out.println("Good morning"); //printing statement


System.out.println("Hi.....");
}
}

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
1.Variables:
Variables are nothing but piece of memory use to store information.
one variable can store 1 information at a time.

Variables also used in information reusability.

To utilise variables in java programing language we need to follow below


steps:

1. Variable declaration (Allocating/Reserving memory)


2. Variable Initialization(Assigning or Inserting value)
3. Usage

Note:- According to all programming language dealing with information directly is


not a good practice
to overcome this variables are introduced.

-------------------------------------------------------------------------
-
package Variables; -
-
public class sample2 -
{ -
public static void main(String[] args) {

//1. Variable declaration


String sname; //dataType variableName
int rollnum;
char grade;
float per;

//2. Variable Initialization(Assigning or Inserting value)


sname = "Kanchan"; //variableName = "variable value"
rollnum = 100; //variableName = variable value
grade = 'A'; //variableName = 'variable value'
per = 65.5f; //variableName = variablevalue f

//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) {

//1. Variable declaration


String sname; //dataType variableName
int rollnum;
char grade;
float per;

//2. Variable Initialization(Assigning or Inserting value)


sname = "Kanchan"; //variableName = "variable value"
rollnum = 100; //variableName = variable value
grade = 'A'; //variableName = 'variable value'
per = 65.5f; //variableName = variablevalue f

//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.

In java programming it is mandatory to declare datatype before declaration


of variable.

In java datatypes are classified into two types :


1. Primitive datatype.
2. Non-primitive datatype.

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:

Note:- keyword starts with lower case

syntax: datatype variablename;

1.(Numeric + Non-decimal):-
Ex: 80,85,10,..etc

Data Type Size


1. byte 1 byte
2. short 2 bytes
3. int 4 bytes
4. long 8 bytes

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.

Note: Identifier starts with capital letter.

e.g. String, className


-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-

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.

without main method we can't run any java program.

2. Regular method

1. static regular method


1. static method call from same class --> methodname();
2. static method call from diffrent/another class --
>className.methodname();
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-

package Methods;

public class demo1 {

//1. static regular method call from same class --> methodname();

public static void main(String[] args) //main method-->manager


{
System.out.println("main method started");

m1(); // methodname(); //static regular method call from same


class
m2();

System.out.println("main method ended");


}

// static ->regular method


public static void m1() //regular method-->emp
{
System.out.println("running static regular method from same class:
m1");
}

public static void m2() {


System.out.println("running static regular method from same class:
m2");
}

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------

package Methods;

public class demo2 {

//2. static method call from diffrent/another class --


>className.methodname()
public static void main(String[] args) {

System.out.println("main method started");

demo3.m3(); // className.methodname(); //static method call from


diff class

demo3.m4();

System.out.println("main method ended");


}
}
-----------------------------------------------------------------------------------
-----------

package Methods;

public class demo3 {

// static ->regular method


public static void m3()
{
System.out.println("running static regular method from diff class:
m3");
}

// static ->regular method


public static void m4()
{
System.out.println("running static regular method from diff class:
m4");
}

}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--

2. non- static regular method


3. non-static method call from same class --> create object of same class
4. non-static method call from diffrent/another class --> create object of
diff class

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.

regular methods can be called multiple times.


-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
package Methods;

public class demo4 {


//3. non-static method call from same class --> create object of same
class

public static void main(String[] args)


{
System.out.println("main method started");

//classname objectName = new classname();


demo4 d = new demo4(); //object creation
d.m5(); //objectName.methodname();
d.m6();

System.out.println("main method ended");


}

//non-static regular method


public void m5()
{
System.out.println("running non-static regular method from same class:
m5");
}

//non-static regular method


public void m6()
{
System.out.println("running non-static regular method from same class:
m6");
}
}

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-

package Methods;

public class demo5


{
//4. non-static method call from diffrent/another class --> create object of
diff class

public static void main(String[] args)


{
System.out.println("main method started");

//classname objectName = new classname();


demo6 d6=new demo6(); //object creation
d6.m7();
d6.m8();

System.out.println("main method ended");


}

}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-

package Methods;

public class demo6 {

//non-static regular method


public void m7()
{
System.out.println("running non-static regular method from diff class:
m7");
}

//non-static regular method


public void m8()
{
System.out.println("running non-static regular method from diff class:
m8");
}

}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
package Methods;

public class demo7


{

//5. method without/zero parameter

public static void main(String[] args)


{
System.out.println("main method started");

addition();

System.out.println("main method ended");


}

//static regular method


//method without/zero parameter
public static void addition()
{
int a=10;
int b=20;
int c=a+b;
System.out.println(c);
}
}
-----------------------------------------------------------------------------------
-------------------------------------------------------

package Methods;

public class demo9 {

// 6. method with parameter

public static void main(String[] args) {


System.out.println("main method started");

studentName();
studentName("Anil");
studentName("Sunil");
System.out.println("main method ended");
}

//static regular method


//method without parameter --
public static void studentName()
{
String sname="Ajay";
System.out.println(sname);
}

//static regular method


//method with parameter --String parameter
public static void studentName(String sname)
{
System.out.println(sname);
}
}
-----------------------------------------------------------------------------------
---------------------------------------------------------------------------------

package Methods;

public class demo10


{
public static void main(String[] args) {

System.out.println("main method started");


//studentInfo();
studentInfo("abc",200, 'C', 85.2f);
System.out.println("------------------");
studentInfo("xyz",300, 'A', 60.2f);

System.out.println("main method ended");


}

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);
}

//public static void studentInfo()


//{
// String StudentName;
// int StudentRollNum;
// char StudentGrade;
// float StudentPer;
//
// StudentName ="abc";
// StudentRollNum = 100;
// StudentGrade ='B';
// StudentPer = 76.6f;
//
// System.out.println(StudentName);
// System.out.println(StudentRollNum);
// System.out.println(StudentGrade);
// System.out.println(StudentPer);
//}

}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
package Control_Statements;

public class example1_IF_Statement {


public static void main(String[] args) {

int marks= 20;

//20>=35
if(marks>=35)
{
System.out.println("Pass");
}

// if(condition)
// {
//
// }

}
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-

package Control_Statements;

public class example2_IF_Else_Statement {


public static void main(String[] args) {

int marks = 35;

// 35>=35
if(marks>=35)
{
System.out.println("Pass");
}
else
{
System.out.println("Fail");
}

}
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
package Control_Statements;

public class example3_else_If_Stement {


public static void main(String[] args) {
int marks = 40;

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;

public class example4_nested_IF


{
public static void main(String[] args)
{
String UN="abc";
String PWD="xyz";

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;

public class example5_Switch {


public static void main(String[] args) {
int day=15;

switch (day)
{
case 1: System.out.println("Today is mon");
break;

case 2: System.out.println("Today is Tue");


break;

case 3: System.out.println("Today is Wed");


break;

case 4: System.out.println("Today is Thr");


break;

case 5: System.out.println("Today is Fri");


break;

case 6: System.out.println("Today is Sat");


break;

case 7: System.out.println("Today is Sun");


break;

default: System.out.println("invalid input");


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.

At the time of constructor declaration below points need to folow:


1. Constructor name should be same as class name
2. you should not declare any return type for the constrictor(like
void).
3. Any no of constructor can be declared in a java class but
constructor name should be same as class name,
but arguments/parameter should be diffrent.

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

2. User defined Constructor


If programer is declaring constructor in java class then it is
considered to be as User defined constructor.
User defined Constructor are classified into 2 types
1. Without/zero parameter constructor
// example-without parameter constructor --eg. addition
2. With parameter constructor
// example-with parameter constructor- only 1 constructor
-- eg. addidtion
// example-with parameter constructor- multiple constructor
-- eg. addition
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
package Contructor;

public class sample1


{

//example of default constructor

//constructor --> default constructor privided by compiler


// use1: use to copy all the members of class into object
// sample1()
// {
//
// }

public static void main(String[] args)


{
sample1 s1=new sample1();
s1.addition();

//sample1 --> classname-->dataType


//s1 --> objectName/reference variable
// new --> keyword --> blank object
//sample1() --> classname(); --> constructor

sample2 s2=new sample2();


s2.mul();

//non-static regular from same class


public void addition()
{
int a=10;
int b=20;
int sum=a+b;
System.out.println(sum);
}

}
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------------
package Contructor;

public class sample2


{

//example of default constructor

//default condtictor--> provided by compiler


// use1: use to copy all the members of class into object
// sample2()
// {
//
// }

//non-static regular from diff class


public void mul()
{
int a=10;
int b=20;
int mul=a*b;
System.out.println(mul);
}

}
-----------------------------------------------------------------------------------
---------------------------------------------------------------------------------

package Contructor;

public class sample3


{
//example of user defined contructor
//Step1: declaration
int a; //50
int b; //60

//contructor--> user defined


// use1: use to copy all the members of class into object
// use2. To initialize data member/variable

//step2: initialization
sample3()
{
a=50;
b=60;
}

public static void main(String[] args)


{

sample3 s3=new sample3();


s3.addition();
s3.mul();

System.out.println("------------------");

sample4 s4 =new sample4();


s4.div();
}

//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;

public class sample4


{

//example of user defined 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;

public class sample5


{

//example with parameter -->single constructor

//step1: declaration
int num1; //10, 15
int num2;

//step2: initialization

//constructor --> user defined --> only 1 constructor

//use1: copy all members of class into object


//use2: to perform initialization

sample5(int a, int b) // int , int parameter constructor a=10, b=15


{
num1 = a;
num2 = b;
}

public void addition()


{
int c= num1+num2;
System.out.println(c);
}

public static void main(String[] args)


{

sample5 s5=new sample5(30,40);


s5.addition();

sample5 s55=new sample5(5,6);


s55.addition();

}
-----------------------------------------------------------------------------------
----------------------------------------------------------------------------------

package Contructor;

public class sample8


{

//example with parametr -->multiple constructor

int num1;
int num2;
String sname;

//user defined -->without parameter


sample8()
{
num1=20;
num2=30;
}

//user defined -->with parameter(2 int parameter)


sample8(int a,int b)
{
num1=a; //10
num2=b; //15
}

//user defined -->with parameter(String parameter)


sample8(String str)
{
sname=str;
}

public void addition()


{
int sum = num1 + num2;
System.out.println(sum);
}

public void studentName()


{
System.out.println(sname);
}

}
-----------------------------------------------------------------------------------
----------------------------------------------------------------------------------

package Contructor;

public class sample7 {


public static void main(String[] args) {

//example with parameter -->multiple constructor

sample8 s8 =new sample8(); //create object of without parameter constructor


s8.addition(); //50

System.out.println("----------------");

sample8 s9=new sample8(10, 15);


s9.addition();

System.out.println("----------------");
sample8 s10=new sample8("abc");
s10.studentName();

}
}
-----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
------------------------------------------------------
Object-Oriented Programming System(OOPS)

Java programming language is very popular in software industry because of OOPS


concept.

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.

The class from where properties are acquiring/inheriting is called


super/base/parent class.

The class too where properties are inherited/delivered is called sub/child


class.

Inheritance takes place between 2 or more than 2 classes.

Inheritance is classified into 4 types:


1. Singlelevel Inheritance
2. Multilevel Inheritance
3. Multiple Inheritance
4. hirarchicle
1. Singlelevel Inheritance:
It is a operation where inheritance takes place between 2 classes.
To perform singlelevel inheritance only 2 classes are mandatory.

2. Multilevel Inheritance:
Multilevel Inheritance takes place between 3 or more than 3 classes.

In Multilevel Inheritance 1 sub class acquires properties of another super


class &
that class acquires properties of its another super class & phenomenon
continuous.

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.

By using interface we can achieve Multiple Inheritance.

4. Hirarchicle Inheritance:
multiple sub classes can acquire properties of 1 super class is known as
hirarchicle Inheritance.
-----------------------------------------------------------------------------------
---------------------------------------------------------------------------------
package Inheritance;

// super/base/parent class

public class father


{
public void car()
{
System.out.println("Car: kia seltos");
}

public void money()


{
System.out.println("money: 2L");
}

public void home()


{
System.out.println("home: 2BHK");
}
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------

package Inheritance;

//sub / child class


public class son extends father
{
public void mobile()
{
System.out.println("mobile: samsung A50");
}

// public void car()


// {
// System.out.println("Car: kia seltos");
// }
//
// public void money()
// {
// System.out.println("money: 2L");
// }
//
// public void home()
// {
// System.out.println("home: 2BHK");
// }

}
-----------------------------------------------------------------------------------
----------------------------------------------------------------------------------

package Inheritance;

public class SingleLevel_Inheritance {


public static void main(String[] args) {

son s=new son();


s.mobile();
s.car();
s.money();
s.home();
}
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
package Inheritance;

//Multilevel Example

public class whatsAppV1


{
public void textMsg()
{
System.out.println("text Msg");
}
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------

package Inheritance;

public class whatsAppV2 extends whatsAppV1


{

public void audioCalling()


{
System.out.println("audio Calling");
}

// public void textMsg()


// {
// System.out.println("text Msg");
// }
}

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------

package Inheritance;

public class whatsAppV3 extends whatsAppV2


{
public void videoCalling()
{
System.out.println("video Calling");
}

// public void audioCalling()


// {
// System.out.println("audio Calling");
// }

// public void textMsg()


// {
// System.out.println("text Msg");
// }

}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-

package Inheritance;

public class MultiLevel_Inheritance


{
public static void main(String[] args) {

whatsAppV3 v3=new whatsAppV3();


v3.textMsg();
v3.audioCalling();
v3.videoCalling();

}
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
package Inheritance;

// super/base/parent class
public class father
{
public void car()
{
System.out.println("Car: kia seltos");
}

public void money()


{
System.out.println("money: 2L");
}

public void home()


{
System.out.println("home: 2BHK");
}
}
-----------------------------------------------------------------------------------
----------------------------------------------------------------------------------

package Inheritance;

public class son1 extends father


{

public void mobile()


{
System.out.println("mobile");
}

}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------

package Inheritance;

public class son2 extends father


{

public void laptop()


{
System.out.println("laptop");
}

}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------

package Inheritance;

public class son3 extends father


{

public void PC()


{
System.out.println("PC");
}
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------

package Inheritance;

public class Hirarchicle_Inheritance {


public static void main(String[] args) {

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();
}
}
-----------------------------------------------------------------------------------
-----------------------------

You might also like