i) Java Basics for Selenium ( Variable, Data Types & Objects )

 Variable:

A Java variable is a piece of memory that can contain a data value during java program execution.

Variable Declaration:

To declare a variable, you must specify the data type & give the variable a unique name.

Ex., int a,b,c;


float pi;


double d;


char a;


Variable Initialization:

To initialize a variable, you must assign it a valid value.

Ex., int a=2,b=4,c=6;


float pi=3.14f;


double do=20.22d;


char a=’v’;


Types of variables

In Java, there are three types of variables:

  1. Local Variables

  2. Instance Variables

  3. Static Variables

1) Local Variables

Local Variables are a variable that are declared inside the body of a method.

2) Instance Variables

Instance variables are defined without the STATIC keyword .They are defined Outside a method declaration. They are Object specific and are known as instance variables.

3) Static Variables

Static variables are initialized only once, at the start of the program execution. These variables should be initialized first, before the initialization of any instance variables.

Example,


class Testdemo{

    static int a = 1; //static variable  

    int data = 99; //instance variable  

    void method() {

        int b = 90; //local variable  

    }

}

What is Data Types in Java?

Data Types in Java are defined as specifiers that allocate different sizes and types of values that can be stored in the variable or an identifier. Data types in Java can be divided into two parts :

  1. Primitive Data Types :- which include integer, character, boolean, and float

  2. Non-primitive Data Types :- which include classes, arrays and interfaces.
    There are eight primitive data types:

  1. byte (1 byte)

  2. short (2 bytes)

  3. int (4 bytes)

  4. long (8 bytes)

  5. float (4 bytes)

  6. double (8 bytes)

  7. char (2 bytes)

  8. boolean (1 byte)

What is Class in Java?

CLASS are a set of instructions to build a specific type of object. Class in Java determines how an object will behave and what the object will contain.

Syntax: 

class <class_name>{  

    field;  

    method;  

  } 

What is Object in Java?

OBJECT is an instance of a class.

Syntax: 

ClassName ReferenceVariable = new ClassName();

 


Comments

Popular posts from this blog

For Get Dynamic data & USe it into Postman Body parameters

API Automation Testing Script to check Response

Login through Data Driven Testing in selenium

Which dependencies needed in pom.xml while doing automation through selenium?

Download Java(JDK) & Eclipse IDE for selenium

What is data driven testing?

How to extract all the links in selenium?