Wednesday, August 15, 2018

Loop Statements in Java



Loop statement enables program to execute the code repeatedly until the condition satisfies.

There are 3 loop statement , that are

1) For loop
2) While loop
3) Do while loop

For loop :

The code in for loop will be executed from the start value until the condition is met.

Example :

public class Forloop
{
   public static void main(String[] args)
   {
      int i;
      for (i = 1; i <=10; i++)
         System.out.println("Testing Solutions");
   }
}

While loop :

The code in while loop will be executed at the time when the condition is true.

Example :

public class Whileloop
{
   public static void main(String[] args)
   {
      int i = 1;
      while (i <= 5)
      {
         System.out.println("Welcome to Testing Solutions");
         i++;
      }
   }
}

Do while loop :

The do while loop is like the while loop except that in do while loop, the block of code is at least executed one time although the condition is not true. The reason is that condition is checked at the bottom, not the top of the loop.

Example :

public class Dowhileloop
{
   public static void main(String[] args)
   {
      int i = 1;
      do
      {
         System.out.println("Testing Solutions");
         i++;
      } while (i <= 10);
   }
}

Thanks ,

A M Balaji

Conditional Statements in Java



The statement that programming language used to decide , which code has to be run when the condition is met.

There are 4 types of Conditional Statements ,  that are

1) if statement
2) if else statement
3) Nested if statement
4) Switch statement

if statement :

The if statement checks the condition and if the result is true , it runs the code.

Example :

public class Ifstatement
{
   public static void main(String[] args)
   {
      int i = 2;
      if (i%2 == 0)
         System.out.println("i is an even number");
   }
}

if else statement :

If the condition is true , then it will execute the "if statement" , else it will execute the "else statement".

Example :

public class Ifelsestatement
{
   public static void main(String[] args)
   {
      int i = 5;
      if (i%2==0)
         System.out.println(i+" is an even number.");
      else
         System.out.println(i+" is an odd number.");
   }
}

Nested if statement :

There will be many conditions in "nested if statement", where any condition can be satisfied.

Example :

public class Ifstatementnested
{
   public static void main(String[] args)
   {
      int i = 1;
      if (i > 0)
         System.out.println(i+" is Positive.");
      else
         if (i < 0)
            System.out.println (i+" is Negative.");
         else
            System.out.println (i+" is Zero.");
   }
}







 switch statement :



The switch statement takes a variable and then has a list of cases or actions to perform for each value that the variable obtains.It uses the word default to perform actions in which the conditions are not met and it uses the word break to stop performing actions.

Example :

public class Switchstatement
{
   public static void main(String[] args)
   {
      int i = 5;
      switch(i)
      {
            case 1:
                    System.out.println ("i is 1");
                    break;
            case 2:
                    System.out.println ("i is 2");
                    break;
            case 3:
                   System.out.println ("i is 3");
                    break;   
            case 4
                  System.out.println(“i is 4”);
                  break;
            case 5:
                  System.out.println(“i is 5”);
                  break;
            default:
                  System.out.println("Invalid value");
                  }
               }
            }

Thanks ,

A M Balaji

Monday, January 29, 2018

Try-Catch in Java



Java try block should be used inside the method and it is mainly used in code that might Throw Exception.

Note : Always Try block should be followed by either Catch block or Finally block.

Syntax of Try - Catch block and Try - Finally block is :

Try - Catch :

try {

        // Inside Code

} catch (Exception)
{

      // Catch Exception

}

Try - Finally :

try {

         //Inside Code
}finally (Exception)
{

     // Catch Exception

}

Java Catch block :

Catch block is used to Handle Exception which is thrown from the Try Block.

Here we can use many Catch block for a Try block.

What are all the problems we will get , while running the code with out Try - Catch block.

Code (Without Try-Catch):
  
public class Test{   
public static void main(String args[]){   
int data=50/0;//may throw exception   
System.out.println("rest of the code...");   
}
}  

Here the error will be "Exception in thread main java.lang.ArithmeticException:/ by zero".

But the Execution will stop at the same point , Where the error occurs . it will not continue execution and print the "rest of the code" line.

Code(With Try-Catch) :

public class Test{ 
public static void main(String args[]){ 
try{ 
int data=50/0; 
}catch(ArithmeticException e){System.out.println(e);} 
System.out.println("rest of the code..."); 

}


Here the error will be "Exception in thread main java.lang.ArithmeticException:/ by zero". 
With "rest of the code" line.







Thanks,

A M Balaji


   


Saturday, January 27, 2018

Java Data Types



Definition : Data type is the classification of the type of data , which can be used used in your programs as per the functionality .

Here java supports explicit declaration of data types , that is data type should be initialized before used as variable.

Syntax : data_type variable_name ;

data_type variable_name = value ;

Example :

int testing ;

int testing =100;

Here we have two types of data types ,

         1) Primitive Data Type
         2) Non primitive Data Type

Now we can see this in detail.

Primitive Data Type :

           1) Integer Types :

                     1)  byte - 8 bits(byte a = 100)
                     2)  short - 16 bits(short a = 100
                     3)  int - 32 bits(int a = 100)
                     4)  long - 64 bits(long a = 100000L)

           2) Rational Types :

                     1)  float - 32 bits(float a = 1.2)
                     2)  double - 64 bits(double a = 12.3456)

           3) Characters

                     1)  char -16 bits(char a = 'Z')

           4) Conditional

                     1) boolean - undefined (boolean a = true)

Non Primitive Data Type(Referenced Data Type):

             Objects and Arrays are the Non Primitive Data Types . And here Referenced
             Data Type are not "Passed by Value" and it is "Passed by Reference".

             Button b = new Button("OK")

Regards,

A M Balaji

Java Modifiers



Java Modifiers are used as keywords , which can be added to the definitions to change their meanings.

There are two types of modifiers which can be used in java .

       1) Access Modifiers
       2) Non Access Modifiers

First let us see about what are the Access Modifiers :

There are four types of access modifiers in java , which is used to control the classes, methods and variables .

       1) Private(private)
       2) Default(default)
       3) Protected(protected)
       4) Public(public)

Here we want to declare all the access modifiers in "Lowercase" letters as mentioned above in the bracket for all the modifiers.

Now lets as see the use of all the modifiers one by one .

private :

The private access modifier can be accessed only within the class

Example for the private modifier :

class test
{

private String testing = "testing";

}

default :

If there is no access modifier defined , then it will treated as default modifier.This can be accessible only with in the package .

Example for the default modifier :

class test
{

int testing =1;

}

protected :

The protected modifiers can is same as default modifier , can be accessed with in the package and other thing is , it can be accessed outside the package by using inheritance (Reuseability).

public :

This modifier can be accessible from everywhere.


Modifier
Within class
Within Package
Outside of the Package (by sub classes)
Outside of the Package
Private
Y
N
N
N
Default
Y
Y
N
N
Protected
Y
Y
Y
N
Public
Y
Y
Y
Y

Now let us see about Non access modifiers :

Here we have

       1) static
       2) final
       3) abstract

as Non access modifiers , which can be used in classes , methods and variables as per the functionality we have .

Thanks ,

A M Balaji



Thursday, December 7, 2017

Java Basic Programming with Eclipse IDE - 1



How to write a Java program and run in Eclipse IDE :

1) Download Eclipse in your machine . Click here to download.
2) Install Eclipse in your machine , before that ensure that JAVA is installed .
3) After installing both Java(To check Java is installed correctly ,
    refer "JMeter Introduction" Page) and Eclipse, Open the Eclipse by double clicking
    the eclipse icon.           
4) When Eclipse is Opened, it will ask for the WorkSpace ( it is nothing but where your
     projects will be stored), Create the WorkSpace by giving preferred name.


5) Once the Eclipse IDE is opened , you will be seeing 2 perspectives (Windows)

               1) Project Explorer -  where you can create packages , classes etc.
               2) Java Editor -  where you can write the Java coding .



6) Create a Java Project in Eclipse IDE(Hello World Project)

       1) Right Click in the Project Explorer and Select New > Java Project.
      2) Specify the name as "HelloWorld" in the Project Name and Click Finish.
      3) Then the project will be created in Project Explorer.



7) Create a Package in the Java Project

       1) Right Click in the "SRC" Folder and then Select New > Package.
      2) Give the Package Name as "com.HelloWorld" and Click Finish.
      3) Now you can see the "com.HelloWorld" Package in the Project Explorer.



8) Create a Class in the Java Project

       1) Right Click in the "com.HelloWorld" Package Name and Select New > Class.
      2) Give the Class Name as "HelloWorld" and Click Finish.
      3) Now you can see the "HelloWorld.class" is created in the "Project Explorer"
           and Default code is generated in the Java Editor.



9) How to Run and Print the "Hello World " in the Console

      1) Use "System.out.println("Hello World");" to Print the Hello World as the
           Output in the Console.
      2) Then Right Click in the Project and Select Run As > Java Application.
      3) Then "Hello World " Output can be seen in the Console.



10) HelloWorld Program

              package com.HelloWorld;

              public class HelloWorld {

      public static void main(String[] args) {

System.out.println("Hello World");

       }

               }

Thanks ,

A M Balaji

Monday, December 4, 2017

Appium Introduction



Mobile software application(Native/Hybrid) is increasing day by day and now software companies are converting their Web Applications to Mobile Applications.To test the functionality of the application , we need some tool and to stay connected with new technology . Appium(Automation) tool is currently trending in Mobile Automation Industry which is used to do mobile automation testing.

Appium is similar to selenium web driver(Used for Web Application Automation).It will be easy to learn Appium if he/she has the knowledge of how selenium web driver works and Basics of Java Programming .

Here we are going to see about What is Appium and Why is Appium?

 1) Appium tool is used to automate Mobile Web Applications , Native Applications and
     Hybrid applications.
2) It is a open source automation tool which is used to automate both Android(Windows)
    and IOS(MAC) Applications.
3) Appium is a "cross platform" automation tool , Which enables you to reuse large
    amount of codes(If it uses same API).
4) Appium supports test automation on both emulator and physical devices(Preferred:
    Based on the execution speed).
5) Appium supports many programing languages like Java(Prefered),PHP and C# etc..
6) Appium supports many platforms like Android ,IOS and FirefoxOS.
7) No source code is needed to test the app , can test directly with the App itself.
8) Can use Built in apps like camera , calendar etc , if your test script needs.

Limitations of Appium :

1) For Android , No Support for API level < 17. (Prefered Selendroid for API < 17).
2) Script execution is slow in IOS.
3) Gestures support is limited.
4) No support for Toast Messages.

Thanks,

A M Balaji

Tuesday, November 28, 2017

JMeter – Server Performance Metrics Collector




JMeter has many listeners which provides information such as Response Time,Error Percentage,Throughput and etc.

But Server Performance Metrics Collector is used to collect server performance like CPU Utilization,Memory Utilization etc..

Here we will see the steps one by one to Configure Server Performance Metrics Collector.

Step 1: Install Server Agent in Server Machine

   1) Download the latest Server Agent from JMeter Website.
   2) Unzip the file and move  in some folder in the server
       (Java should be installed in the server).
   3) Then Open the port 4444(Default) on the server machine.
   4) To Start the Server Agent use startAgent.bat(Windows) / startAgent.sh(Linux).
   5) 5) startAgent.bat -tcp-port 5555(Use this command for different port).

Step 2: PerfMon Metrics Collector

    1) This is the separate listener ,which can be downloaded from JMeter
         (Standard Set Plugins).
    2) Unzip the plugin folder and copy the files to that and paste in "JMeter/lib/ext" folder.
    3) Otherwise use Plugin Manager in the JMeter to download the plugins.
    4) Then Restart JMeter .
    5) Now in listeners , PerfMon Metrics Collector can be seen.

Step 3: How it Works

    1) Open JMeter , Create JMeter Project with basic elements .
    2) Then add PerfMon Metrics Collector in the JMeter Test Plan.
    3) Before adding any stuff in PerfMon , Make sure Server Agent is running in the
        Server Machine.
    4) Then add a Server IP , Port and Metrics to Collect in the as given in the
        image below.
    5) Thats it , Start the JMeter Test Now.



Thanks,

A M Balaji

Saturday, October 21, 2017

How to Perform Distributed Testing Using JMeter




JMeter is having some limitations while running the load testing from the single machine. So that we are using "Distributed Testing" for Load/Performance Testing . i.e) Master(Controller) and Slave (Load Generator) configuration.Here we can add many slaves and can generate more .



Note: If configuration is not done properly , then it may give wrong results or may not run properly.

There are some prerequisites should be done before starting distributed load testing.

1) Firewalls on the master and slave systems should be turned off.
2) The systems should be in the same subnet.
3) Make sure JMeter can access the servers.
4) Same version of JMeter should be installed in master and slave systems.

Now do the steps to start the Distributed load testing .

Step 1: Go to jmeter.properties > Open it.
Step 2: Search for "remote_hosts" in that file .
Step 3: Add the Slave IP's in that remote_hosts.



After that start the jmeter-server.bat in all the master and slave machines.

Then run the JMeter , by clicking the jmeter.bat(or)ApacheJMeter.jar file and goto Run > Remote Start.Where you can see the Slaves IP Address.



Thanks ,

A M Balaji

Tuesday, September 26, 2017

How to generate Report Dashboard in JMeter





Steps to Create Report Dashboard in JMeter

1) Create a JMeter(.jmx) file as per the requirement , if it has large number of users ,then go for Non GUI Mode as discussed in the previous post ,otherwise run it from the JMeter GUI Mode Itself.
2) While Creating add a Listeners in the JMX File.
3) After completing the Load / Performance Test , go to the Listeners and Save the data as .csv file , if the Load / Performance Test is done from the GUI Mode.
4) If it is ran from the Non GUI Mode , then open the same JMX File in JMeter and Add Listeners in that.
5) Then Browse the JTL from the Listeners and the data will be shown in the JMeter.
6) Save that as .csv File by clicking "Save Table Data".
7) Then open reportgenerator.properties from JMeter > Bin Folder , Copy all the content from the properties file.
8) Open user.properties from the same path as mentioned above and Paste all the content and then "Save".
9) Now run the below mentioned command in the command prompt.
10) jmeter -g "Path of .csv file" -o "Path for Reports"(Dont Create as "ReportD"),
as it will be automatically created from JMeter itself ).
11) Finally Reports will be generated in the "Path for Reports/ReportD".

Next Topic will be followed in up coming posts😊😊😊.


Thanks

A M Balaji



How to Solve "Out of Memory Error" in JMeter


                



There are 2 ways to solve this issue
1) Increasing Heap Size.
2) Running JMeter in Non GUI Mode.

How to increase Heap Size in JMeter

1) Open jmeter.bat File(JMeter > Bin ), Search for "Heap" in the File.
2) You will be finding some thing as "HEAP=-Xms512m -Xmx512m".
3) In this , change the second part as -Xmx1024m(Depends on your system RAM,can be given upto 80% of the RAM Size).
4) Then start JMeter by double clicking the jmeter.bat file .

Running JMeter in Non GUI Mode

1) Before running JMeter in Non GUI Mode , Make sure you have not added any "Samplers" in JMeter
2) Do all the stuffs in JMeter to do Load / Performance Testing , Such as Recording HTTP Requests, Threads(Users) as per the requirement .
3) Save the JMeter File in JMeter > Bin Folder  .
4) Open the Command Prompt and Navigate to JMeter > Bin Folder
5) Then type the command as "jmeter -n -t YourFile.jmx -l YourFile.jtl"
Where, -n indicates Non GUI Mode
             -t indicates JMX File
            -l indicates Log File(JTL File)

Next Topic will be followed in up coming posts😊😊😊.


Thanks

A M Balaji

Friday, September 15, 2017

Basic Elements required to do Load/Performance Testing in JMeter



                    



Below mentioned elements are required for JMeter Basic Load / Performance Testing.

1) Test Plan
2) Threads Group > Recordings
3) Workbench > Http(s) Test Script Recorder
4) Basic Listeners
1) View Result Tree
2) Summary Report

Here Test Plan and Workbench will be Shown when the JMeter is freshly opened (Open JMeter using jmeter.bat for Windows in JMeter > Bin Folder) and (for Linux jmeter.sh).

User can add above mentioned elements manually one by one (or) Click the "Templates" which is located in the Menu Bar,Which will create all Basic Elements of JMeter to do Load / Performance   Testing.

Test Plan : A test plan is the top level body of JMeter, explains sequence of steps execute at run  time.

Threads Group: The name,Thread Groups represent a group of Threads. Under this group, each   thread simulates one real user requests to the server.

Thread Group will be having 3 Properties :

       1) Number of threads - the number of users you are going to test.
   2) Ramp-up time -  The time set by the users to execute the no. of threads.
   3) Loop count - How many times the test should be looped.
   
Recordings : Here the script will be recorded automatically , when user records the Request from Mobile(Look at the Post 2 and 3) for Automatic Recording.

Workbench > Http(s) Test Script Recorder : From Here only user will start the JMeter Proxy to record the Script under "Recordings" ( Look at the Earlier Post).

View Result Tree : Here user can see the request and responses for each and every  Http Requests which is recorded.

Summary Report : Here user can see the Min,Max and Avg Response time , Errors and such other information for each and every request.



Next Topic will be followed in up coming posts😊😊😊.

Thanks

A M Balaji



Record Scripts from IOS Native Mobile Apps using JMeter

                                                             

                     


Step 1: Both Laptop and IOS Device should be same network, i.e) Both should be in same WIFI

Step 2: Check the IP of the Laptop,by typing IPCONFIG in the command prompt.   

Step 3: In IOS Device, goto Settings > WIFI , then Tab on the connected WIFI.

Step 4: After that tap on the "Manual" Option.

Step 5: Next give the IP Address in the "Server"(Which is taken from the Laptop Using IPCONFIG) and "Port" as 8888(Default Port for JMeter).

Step 6: Next open the JMeter 

    1) Click on the Templates in the Menu bar and then select "Recording"(default)
        and select OK

    2) Then select http(s) Test Script Recorder from the Workbench and Check the port , 
         it should be 8888 

    3) Then click on the Start Button to record the script for the specified App.

    4) Check whether the script in recording by clicking on the
        Thread > Recording Controller.

    5) If it is not recording , then restart both the Device and JMeter.

    Note : When user clicks on the Start Button in http(s) Test Script Recorder ,
               new popup will open with the certificate(Valid for 7 days) which will be seen in
               JMeter > Bin folder.

 

                            For IOS Mobile Configuration Check the Below Mentioned Image

                                                          

                                        


        Next Topic will be followed in up coming posts😊😊😊😊😊

     

      Thanks

      A M Balaji

Wednesday, September 13, 2017

Record Scripts from Android Native Mobile Apps using JMeter

                                                             

                    

Step 1: Both Laptop and Android Device should be same network, i.e) Both should be in same WIFI. 

Step 2: Check the IP of the Laptop,by typing IPCONFIG in the command prompt.   

Step 3: In Android Device, goto Settings > WIFI , then Long Press on the connected WIFI, then select the "Modify Network" Option in that.

Step 4: After that tap on the "Advanced Options" , then select the Proxy as "Manual".

Step 5: Next give the IP Address in the "Proxy hostname"(Which is taken from the Laptop Using IPCONFIG) and "Port" as 8888(Default Port for JMeter) and then Save it.

Step 6: Next open the JMeter 

    1) Click on the Templates in the Menu bar and then select
        "Recording"(default) and select OK

    2) Then select http(s) Test Script Recorder from the Workbench and Check the port , 
         it should be 8888 

    3) Then click on the Start Button to record the script for the specified App.

    4) Check whether the script in recording by clicking on the
        Thread > Recording Controller.

    5) If it is not recording , then restart both the Device and JMeter.

    Note : When user clicks on the Start Button in http(s) Test Script Recorder ,
               new popup will open with the certificate(Valid for 7 days) which will be seen in
               JMeter >  Bin folder.
 
   The above mentioned steps(from Step 6 > Step 3) will work if the Android App is
   "HTTP". If the Testing App is with "HTTPS", Then install the Generated Certificate
    in the mobile device (Certificate will  be seen in the JMeter > Bin folder).

                       For Android Mobile Configuration Check the Below Mentioned Image


                                        


        Next Topic will be followed in up coming posts😊😊😊😊😊

    

      Thanks

      A M Balaji

Tuesday, September 12, 2017

JMeter Introduction




Introduction


JMeter is an Open Source testing software. It is 100% pure Java application for load and performance testing. JMeter is designed to cover categories of tests like load, functional, performance, regression, etc., and it requires JDK 6 or higher. This tutorial will give you great understanding on JMeter framework needed to test an enterprise level application to deliver it with robustness and reliability.

                                                 

  Prerequisites


Before Installing JMeter , Java to be installed in the machine where JMeter is going to be Installed.

How to Install Java in the Machine.

1) If the Machine is 32 Bit , Download 32 bit Java and install in the Machine and then set the environment variables for java . Set JAVA_HOME in Environment Variables
2) Command to verify the java installation in the machine , type the below command in the command prompt. Link to download Java is Click Here
                         1) java -version
                         2) java -d32 -version or java -d64 -version

The second  command is to verify whether installed java version in 32 bit or 64 bit.

3) Then download JMeter ,to download Click Here.

4) After Downloading , extract the ZIP File in Drive(Preferably C: , Because Java will be installed in C Drive by default).

5) After extracting , go to bin folder , double click ApacheJMeter.jar or jmeter.bat file for windows and jmeter.sh for linux to start JMeter.


Next Topic will be followed in up coming posts😊😊😊.

Thanks

A M Balaji