Java Program Structure
Java plan construction / Java Syntax
> Download Java Software (JDK) too Install
> Set Environment (Path) Variable to access Java Run -time Environment from whatever directory inwards C drive.
> Download Eclipse software
C:\Program Files\Java\jdk1.8.0_40\bin - Java path
C:\Users\G C Reddy\Desktop\eclipse -Eclipse
How Eclipse communicates amongst Java Run-time Environment
Using Path Environment variable
---------------------------------------------
Java Programming
Java Project
-> Packages
-> Classes, Interfaces etc...
> Create Java Project inwards Eclipse
> Create a package
> Create a Class
--------------------------------
Sample Java Program
1) Package Declaration statement
Ex:
package abcd;
----------------------
2) Import Statements
We tin import built inwards too User defined Libraries using import keyword.
Examples for Built inwards packages
io, jxl, sql etc...
import java.io.Console;
import java.lang.*;
import is coffee keyword to import Libraries
java - Project
io - package
Console - Class
lang.* - all classes from lang package
-----------------------------
3) Class annunciation statement
Ex:
public class Sample {
public - Access Modifier
class - coffee keyword to declare a class
Sample - Name of the class
---------------------------------
4) Comments section
// This is a Sample Java Program
5) principal method statement - Program execution starts from principal method
(* It is the mandatory contestation inwards every Java program)
public static void principal (String [] args){
public - Access Modifier
static - operate principal method without invoking whatever object
void - returns nothing
main method name
6) Declarations
We tin declare variables too constants
---------------------
System.out.println ("Addition of a, b, c is: "+ (a+b+c));
System - Class
out - Object
println - method
"Addition of a, b, c is: " - Message / Details
+ - Concatenation
a, b, c, d -Variables
Conditional statements
Loop statements
Built inwards too user defined methodsOperators etc....
------------------------------
Writing Normal statements - every contestation should halt amongst ;
Writing blocks - Statements of the block enclosed {}
----------------------------------------
Java Program Example:
package abcd;
import java.io.Console;
import java.lang.*;
public class Sample {
// This is a Sample Java Program
public static void principal (String [] args){
int a = 10, b, c; // Declartion of Variables
b= 20; // Initialization
System.out.println (a+b);
a = 50;
lastly int MONEY = 100; // declaring constant
// MONEY = 200;
System.out.println ("Addition of a, b, is: "+ (a+b));
if (b > a){
System.out.println ("B is a Big Number");
}
else
{
System.out.println ("A is a Big Number");
}
for (c=1; c <= 10; c++){
System.out.println (c);
}
}
}
--------------------------------------------
Java Comments
Comments are English linguistic communication word, tin live 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 describe of piece of occupation comment
Use /*....
......
.....
*/ for multiple lines comment
--------------
Ex:
int a = 10, b, c; // Declaration of Variables
// world static void principal (String [] args){
----------
/* if (b > a){
System.out.println ("B is a Big Number");
}
else
{
System.out.println ("A is a Big Number");
}
*/
Usage of Comments inwards Test Automation:
a) To write Test headers
b) To write method headers
c) To explicate complex logic
d) To explicate resources usage
Etc...
--------------------------------
Java Data Types
What is Data Type?
Data type is a classification of the type of information that a variable or object tin concur inwards estimator programming.
Ex: character, integer, float etc....
> Java supports explicit annunciation of Data types.
(we ask to specify the information type earlier declaring the Variable)
Syntax:data_type variable_name;
data_type variable_name = value;
Example:int a;
int a = 100;
----------------------
Two types of Data types inwards java
a) Primitive Data types
b) Non-primitive Data types / Reference Data types
-----------------------------------
a) Primitive Data types8 primitive information types
Integer types
1) byte (8 bits)
Ex:
byte a =100;
2) brusk (16 bits)
short a = 10000;
3) int (32 bits)
int a = 100000;
4) long (64 bits)
long a = 100000L
------------------
Rational types (Numbers amongst decimal places)
5) float (32 bits)
float a = 1.2;
6) double (64 bits)
ex:
double a = 19.3456;
---------------------
Characters
7) char (16 bits)
Ex:
char a ='Z'
------------------------
Conditional
8) boolean (undefined, depends on JVM)
Ex:
boolean a = true
---------------------------------
b) Non-primitive / Reference information types
Non-primitive information types inwards Java are Objects too Arrays.
Note:
Reference types are non passed value, passed yesteryear reference
Ex:
Button a = novel Button("OK")
-----------------------------------------------
Java Variables
1) What is Variable?
A named retentivity location to shop or concur the data.
Two types of retentivity inwards Computer environment:
i) Primary retentivity -RAM
ii) Secondary retentivity -ROM
Ex: CD, DVD, HDD etc...
-------------------------
2) Declaration of Variables
Java Supports explicit annunciation of variables
Syntax:
dataType VariableName;
Ex:
int a;
---------------
dataType variable1, variable2, variable3;
Ex:
int a, b, c;
------------------------
dataType VariableName = value;
Ex:
int a =100;
--------------------------
3) Assigning values to variables
a) Initialization
int a;
a=10; // Initialization
--------------
int a=10; // Initialization
----------------
b) Reading
using Input devices
from files(text/excel)
from databases
from Application objects
-------------------------
4) Types of Variables
a) Instance Variable
A variable that is declared within the class only exterior the method
b) Local variable
A variable that is declared within the method
c) Static variables
A Variable that is declared equally static, It cannot live local.
----------------------
5) Naming Conventions
> Java Variables are example sensitive, monkey is non the equally Monkey or MONKEY.
char monkey, Monkey, MONKEY
> Java variable refer must commencement amongst a alphabetic lineament or $ or _
Ex:
myvar
MYVAR
$myvar
_myvar
myvar1
myvar_1
----------
1myvar - invalid
----------------------
> Variable names cannot live equal to coffee reserved words
Ex:
int
for
import
> Must live unique inwards the reach of declaration.
----------------------------------------
Sumber http://www.gcreddy.com/
Java plan construction / Java Syntax
> Download Java Software (JDK) too Install
> Set Environment (Path) Variable to access Java Run -time Environment from whatever directory inwards C drive.
> Download Eclipse software
C:\Program Files\Java\jdk1.8.0_40\bin - Java path
C:\Users\G C Reddy\Desktop\eclipse -Eclipse
How Eclipse communicates amongst Java Run-time Environment
Using Path Environment variable
---------------------------------------------
Java Programming
Java Project
-> Packages
-> Classes, Interfaces etc...
> Create Java Project inwards Eclipse
> Create a package
> Create a Class
--------------------------------
Sample Java Program
1) Package Declaration statement
Ex:
package abcd;
----------------------
2) Import Statements
We tin import built inwards too User defined Libraries using import keyword.
Examples for Built inwards packages
io, jxl, sql etc...
import java.io.Console;
import java.lang.*;
import is coffee keyword to import Libraries
java - Project
io - package
Console - Class
lang.* - all classes from lang package
-----------------------------
3) Class annunciation statement
Ex:
public class Sample {
public - Access Modifier
class - coffee keyword to declare a class
Sample - Name of the class
---------------------------------
4) Comments section
// This is a Sample Java Program
5) principal method statement - Program execution starts from principal method
(* It is the mandatory contestation inwards every Java program)
public static void principal (String [] args){
public - Access Modifier
static - operate principal method without invoking whatever object
void - returns nothing
main method name
6) Declarations
We tin declare variables too constants
---------------------
System.out.println ("Addition of a, b, c is: "+ (a+b+c));
System - Class
out - Object
println - method
"Addition of a, b, c is: " - Message / Details
+ - Concatenation
a, b, c, d -Variables
Conditional statements
Loop statements
Built inwards too user defined methodsOperators etc....
------------------------------
Writing Normal statements - every contestation should halt amongst ;
Writing blocks - Statements of the block enclosed {}
----------------------------------------
Java Program Example:
package abcd;
import java.io.Console;
import java.lang.*;
public class Sample {
// This is a Sample Java Program
public static void principal (String [] args){
int a = 10, b, c; // Declartion of Variables
b= 20; // Initialization
System.out.println (a+b);
a = 50;
lastly int MONEY = 100; // declaring constant
// MONEY = 200;
System.out.println ("Addition of a, b, is: "+ (a+b));
if (b > a){
System.out.println ("B is a Big Number");
}
else
{
System.out.println ("A is a Big Number");
}
for (c=1; c <= 10; c++){
System.out.println (c);
}
}
}
--------------------------------------------
Java Comments
Comments are English linguistic communication word, tin live 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 describe of piece of occupation comment
Use /*....
......
.....
*/ for multiple lines comment
--------------
Ex:
int a = 10, b, c; // Declaration of Variables
// world static void principal (String [] args){
----------
/* if (b > a){
System.out.println ("B is a Big Number");
}
else
{
System.out.println ("A is a Big Number");
}
*/
Usage of Comments inwards Test Automation:
a) To write Test headers
b) To write method headers
c) To explicate complex logic
d) To explicate resources usage
Etc...
--------------------------------
Java Data Types
What is Data Type?
Data type is a classification of the type of information that a variable or object tin concur inwards estimator programming.
Ex: character, integer, float etc....
> Java supports explicit annunciation of Data types.
(we ask to specify the information type earlier declaring the Variable)
Syntax:data_type variable_name;
data_type variable_name = value;
Example:int a;
int a = 100;
----------------------
Two types of Data types inwards java
a) Primitive Data types
b) Non-primitive Data types / Reference Data types
-----------------------------------
a) Primitive Data types8 primitive information types
Integer types
1) byte (8 bits)
Ex:
byte a =100;
2) brusk (16 bits)
short a = 10000;
3) int (32 bits)
int a = 100000;
4) long (64 bits)
long a = 100000L
------------------
Rational types (Numbers amongst decimal places)
5) float (32 bits)
float a = 1.2;
6) double (64 bits)
ex:
double a = 19.3456;
---------------------
Characters
7) char (16 bits)
Ex:
char a ='Z'
------------------------
Conditional
8) boolean (undefined, depends on JVM)
Ex:
boolean a = true
---------------------------------
b) Non-primitive / Reference information types
Non-primitive information types inwards Java are Objects too Arrays.
Note:
Reference types are non passed value, passed yesteryear reference
Ex:
Button a = novel Button("OK")
-----------------------------------------------
Java Variables
1) What is Variable?
A named retentivity location to shop or concur the data.
Two types of retentivity inwards Computer environment:
i) Primary retentivity -RAM
ii) Secondary retentivity -ROM
Ex: CD, DVD, HDD etc...
-------------------------
2) Declaration of Variables
Java Supports explicit annunciation of variables
Syntax:
dataType VariableName;
Ex:
int a;
---------------
dataType variable1, variable2, variable3;
Ex:
int a, b, c;
------------------------
dataType VariableName = value;
Ex:
int a =100;
--------------------------
3) Assigning values to variables
a) Initialization
int a;
a=10; // Initialization
--------------
int a=10; // Initialization
----------------
b) Reading
using Input devices
from files(text/excel)
from databases
from Application objects
-------------------------
4) Types of Variables
a) Instance Variable
A variable that is declared within the class only exterior the method
b) Local variable
A variable that is declared within the method
c) Static variables
A Variable that is declared equally static, It cannot live local.
----------------------
5) Naming Conventions
> Java Variables are example sensitive, monkey is non the equally Monkey or MONKEY.
char monkey, Monkey, MONKEY
> Java variable refer must commencement amongst a alphabetic lineament or $ or _
Ex:
myvar
MYVAR
$myvar
_myvar
myvar1
myvar_1
----------
1myvar - invalid
----------------------
> Variable names cannot live equal to coffee reserved words
Ex:
int
for
import
> Must live unique inwards the reach of declaration.
----------------------------------------