Core Java: Basic needs for automation tester

1. Java program :


  • Java program is written in an editor & it's saved with an extension ".java" .
  • Java files are called as Source file or java file.
  • Java Compiler is used to convert source file to class file.
  • Class file has an intermediate language is called as byte code which is generated by java compiler.
  • JRE is used to execute class file or byte code.
  • JRE converts byte code to machine level language and executes the code line by line.
  • Byte code is ready to run, when we execute bytecode immediately ,JRE interpreted and executes.
  • If there is no byte code then each time java file should check for syntax error and it should be compile and then it should be execute.this makes execution slow.
But still java is more preferred because of below:

  • It supports different operating system like windows,linux.
  • It's platform independent.
  • Without the java compiler the java program can be execute .
  • Java is case sensitive. 
2.Variable in Java:

  • It's a temporary place in memory which is used to store a data.
  • To identify each variable we should assign an unique identifier, as called as variable name.
  • Syntax:   data type  variableName;
3. Data type :
  • Two types of data type : (i) Primitive data type (Built-in) (ii) Derived type (Customize type)
  • Primitive type: 8 types of data type in java
  1. Byte
  2. short
  3. int
  4. long
  5. float
  6. double
  7. char
  8. boolean 
 Ex : int count;
double pi;

Initialization :

  • Syntax: Varname = data;
Ex : int count = 1;
       char c ='x';
       boolean b = true;

Program example:

package com.pack1;

public class Datatype {


public static void main(String[] args) {

System.out.println("Program starts");
int i= 10;
System.out.println(i);
System.out.println("Program Ends");

}

}

o/p :
Program starts
10
Program Ends

Note :

  • In java there is no garbage value.
  • Without initializing the value, the variable can't print.
Types of variable :

  • Based on the scope of the variables, they categories into 2 types.
  1. Local variable
  1. Global variable.

  • Local variables are declared within a method.
  • Variables are declared directly within a class(outside of all methods) is called as global variable.
Note:
  • In java local variables must be initialised before using.If not initialised then the timeof execution it will through error.
  • Initialization is mandatory for global variables
  • If programmer is not initialising global variable then java initialize global variables with default value
  • Within a scope the variable name must be unique.
Data types Default variables for global variables
byte 0
short 0
int 0
long 0
float 0
double 0
char                                                                       empty
boolean                                                                   FALSE



Copyright © 2017 qatoolsguide.blogspot.com || ALL RIGHTS RESERVED