Java Program Structure too Java Syntax
i) Java Program Structure
ii) H5N1 Sample Java Program
iii) Comments inwards Java
iv) Java Data Types
-----------------------------------------
Java Environment Setup
> Download Java (JDK) Software too Install
> Set Environment Variable (Path variable)
> Download Eclipse IDE too Extract.
--------------------------
Create Java project
> Create Java Package
Create Java Class /Program
-----------------------------------------
i) Java Program Structure
1) Documentation Section
2) Package proclamation Statement
Ex: bundle xyza;
3) Import Statements
We import built inwards too User defined libraries using import keyword
Ex:
import java.io.Console;
import java.lang.*;
import - It is a Java keyword to import Libraries.
java -Project
io -Package
Console - Class
lang.*; - import all classes from lang package.
--------------------------------------
4) Class proclamation Statement
public flat Sample {
}
public - Access Modifier
class - Java keyword to declare a class
Sample - it is the Class elevate (You tin dismiss purpose whatever meaningful name)
----------------------------------------------
5) chief Method (Java Program execution starts from chief method)
(* It is the mandatory contestation inwards every Java program)
public static void chief (String [] args) {
}
public - Access Modifier
static - Non-Access Modifier (use chief method without invoking whatever object)
void - Returns nothing
main- method name
-----------------------------------
6) Declarations
We tin dismiss Declare Variables too Constants.
Other Statements
System.out.println("Hello Selenium");
System - Class (Pre-defined)
out - Object
println - method
"Hello Selenium" - Message
--------------------------------
7) Code blocks
Condition blocks
Loop blocks
Method blocks (method proclamation earlier the chief method, simply nosotros access methods afterward chief method)
etc...
-------------------------------------
> Every normal statement/step ends amongst semi colon
> Every code block enclosed amongst {}
-----------------------------------------
ii) H5N1 Sample Java Program
//Documentation
package xyza;
import java.io.Console;
import java.lang.*;
public flat Sample {
//Create a Method(User defined)
public int multiply(int a, int b, int c){
int consequence = a * b * c;
return result;
}
public static void chief (String [] args){
// This is a sample Program
int a = 10, b, c; //Variables Declaration
b = 20; c = 30; //Initialization
final int coin =100;//Constant Declaration
System.out.println("Addition of a, b is " + (a + b));//Addition of a, b is 30
System.out.println(money);//100
System.out.println(c);//30
//Condition Block
if (a > b){
System.out.println("A is a Big Number");
}
else
{
System.out.println("B is a Big Nuber");
}
//Loop block
for (int d=1; d <=10; d++){
System.out.println(d);
}
//Create Object too access Methods
Sample obj = novel Sample();
int x = obj.multiply(10, 25, 50);
System.out.println(x);
}
}
-----------------------------------------
iii) Comments inwards Java
Comments are English linguistic communication words used for Code documentation.
Purpose of Comments
a) To brand the code Readable
b) To brand the code disable from execution
------------------------
Comments Syntax inwards Java
Use // for Single business comment
Use /* ......
...........
..............
*/ for multiple lines comment
Example:
package xyza;
public flat Sample2 {
public static void chief (String [] args){
//This is a Sample Program
int a, b, c; //Declaration of variables
a=10; b=20;c=30;
/*if (a > b){
System.out.println("A is a Big Number");
}
else {
System.out.println("B is a Big Number");
}*/
System.out.println(c);
}
}
------------------------------------
Usage of Comments inwards Test Automation
a) To write Test Case header
b) To write Method header
c) To explicate complex logic etc...
-----------------------------------------
iv) Java Data Types
Data Type is a classification of the type of information that variable or Constant or object tin dismiss concord inwards reckoner programming.
Ex: character, integer, float, boolean etc...
Java Supports Explicit Declaration of Data Types.
(we involve to specify the information type earlier declaring the a Variable or constant etc....)
Syntax:
dataType variableName;
dataType variableName =value;
dataType variable1Name, variable2Name, variable3Name;
Example:
int a;
char b ='A';
int a, b, c;
-----------------------------
Two Types of information Types inwards Java
a) Primitive Data Types
b) Non-primitive Data Types / Reference Data Types
--------------------------------
a) Primitive Data Types (8 information types)
i) Integer Types
----------------
1) byte (8 bits)
byte a =10;
2) curt (16 bits)
short a =10000;
3) integer(32 bits)
int a = 100000;
4) long (64 bits)
long a =100000000000000;
------------------------
ii) Relational types (Numbers amongst decimal places)
5) float (32 bits)
float a = 1.23;
6) double (64 bits)
double a =123.345654322;
-------------------------------
iii) Characters
7) character
char a ='Z'
----------------------------
iv) Conditional
8) Boolean
boolean a = true;
------------------------------
b) Non-primitive Data Types / Reference Data Types
Non-primitive or Reference information types inwards Java are Objects too Arrays.
ex:
Button a = novel Button("OK")
---------------------------------------------------
i) Java Program Structure
ii) H5N1 Sample Java Program
iii) Comments inwards Java
iv) Java Data Types
-----------------------------------------
Java Environment Setup
> Download Java (JDK) Software too Install
> Set Environment Variable (Path variable)
> Download Eclipse IDE too Extract.
--------------------------
Create Java project
> Create Java Package
Create Java Class /Program
-----------------------------------------
i) Java Program Structure
1) Documentation Section
2) Package proclamation Statement
Ex: bundle xyza;
3) Import Statements
We import built inwards too User defined libraries using import keyword
Ex:
import java.io.Console;
import java.lang.*;
import - It is a Java keyword to import Libraries.
java -Project
io -Package
Console - Class
lang.*; - import all classes from lang package.
--------------------------------------
4) Class proclamation Statement
public flat Sample {
}
public - Access Modifier
class - Java keyword to declare a class
Sample - it is the Class elevate (You tin dismiss purpose whatever meaningful name)
----------------------------------------------
5) chief Method (Java Program execution starts from chief method)
(* It is the mandatory contestation inwards every Java program)
public static void chief (String [] args) {
}
public - Access Modifier
static - Non-Access Modifier (use chief method without invoking whatever object)
void - Returns nothing
main- method name
-----------------------------------
6) Declarations
We tin dismiss Declare Variables too Constants.
Other Statements
System.out.println("Hello Selenium");
System - Class (Pre-defined)
out - Object
println - method
"Hello Selenium" - Message
--------------------------------
7) Code blocks
Condition blocks
Loop blocks
Method blocks (method proclamation earlier the chief method, simply nosotros access methods afterward chief method)
etc...
-------------------------------------
> Every normal statement/step ends amongst semi colon
> Every code block enclosed amongst {}
-----------------------------------------
ii) H5N1 Sample Java Program
//Documentation
package xyza;
import java.io.Console;
import java.lang.*;
public flat Sample {
//Create a Method(User defined)
public int multiply(int a, int b, int c){
int consequence = a * b * c;
return result;
}
public static void chief (String [] args){
// This is a sample Program
int a = 10, b, c; //Variables Declaration
b = 20; c = 30; //Initialization
final int coin =100;//Constant Declaration
System.out.println("Addition of a, b is " + (a + b));//Addition of a, b is 30
System.out.println(money);//100
System.out.println(c);//30
//Condition Block
if (a > b){
System.out.println("A is a Big Number");
}
else
{
System.out.println("B is a Big Nuber");
}
//Loop block
for (int d=1; d <=10; d++){
System.out.println(d);
}
//Create Object too access Methods
Sample obj = novel Sample();
int x = obj.multiply(10, 25, 50);
System.out.println(x);
}
}
-----------------------------------------
iii) Comments inwards Java
Comments are English linguistic communication words used for Code documentation.
Purpose of Comments
a) To brand the code Readable
b) To brand the code disable from execution
------------------------
Comments Syntax inwards Java
Use // for Single business comment
Use /* ......
...........
..............
*/ for multiple lines comment
Example:
package xyza;
public flat Sample2 {
public static void chief (String [] args){
//This is a Sample Program
int a, b, c; //Declaration of variables
a=10; b=20;c=30;
/*if (a > b){
System.out.println("A is a Big Number");
}
else {
System.out.println("B is a Big Number");
}*/
System.out.println(c);
}
}
------------------------------------
Usage of Comments inwards Test Automation
a) To write Test Case header
b) To write Method header
c) To explicate complex logic etc...
-----------------------------------------
iv) Java Data Types
Data Type is a classification of the type of information that variable or Constant or object tin dismiss concord inwards reckoner programming.
Ex: character, integer, float, boolean etc...
Java Supports Explicit Declaration of Data Types.
(we involve to specify the information type earlier declaring the a Variable or constant etc....)
Syntax:
dataType variableName;
dataType variableName =value;
dataType variable1Name, variable2Name, variable3Name;
Example:
int a;
char b ='A';
int a, b, c;
-----------------------------
Two Types of information Types inwards Java
a) Primitive Data Types
b) Non-primitive Data Types / Reference Data Types
--------------------------------
a) Primitive Data Types (8 information types)
i) Integer Types
----------------
1) byte (8 bits)
byte a =10;
2) curt (16 bits)
short a =10000;
3) integer(32 bits)
int a = 100000;
4) long (64 bits)
long a =100000000000000;
------------------------
ii) Relational types (Numbers amongst decimal places)
5) float (32 bits)
float a = 1.23;
6) double (64 bits)
double a =123.345654322;
-------------------------------
iii) Characters
7) character
char a ='Z'
----------------------------
iv) Conditional
8) Boolean
boolean a = true;
------------------------------
b) Non-primitive Data Types / Reference Data Types
Non-primitive or Reference information types inwards Java are Objects too Arrays.
ex:
Button a = novel Button("OK")
---------------------------------------------------