Find out number of Objects created for a class in Java

Hi Guys,

In this post we shall look at a Java program to find out number of objects created for a class.

Whenever any object is created, Constructor for the class will be called. We can create one static counter variable and increment it whenever constructor runs. Count of objects can be obtained by reading the counter value.

Below is the source code for working Java program and it is tested in Windows environment.

package javaExploration;

public class NumberOfObjects {

static int count;

static {
count = 0;
}

public static void main(String[] args) {
// TODO Auto-generated method stub

System.out.println(“Inside Main Method”);

NumberOfObjects objectsCount = new NumberOfObjects();
NumberOfObjects objectsCount_1 = new NumberOfObjects();
System.out.println(“Number of objects created: “+count);

}

public NumberOfObjects(){
count++;
}

}

Output generated will be :

Inside Main Method
Number of objects created: 2

This is one of the way in which count of objects can be obtained. Please comment if you have any other best way to solve this.

As usual suggestions are always welcome.

Seneca Global Interview Experience

Seneca Global is a Software development and Technical advisory firm and provides services to it’s clients.

Following are the interview questions for QA engineer at Seneca Global Hyderabad.

First Round:

  1. What is a Static keyword in Java.
  2. What are grep and find commands in Shell scripting and difference between them.
  3. SQL query about inner joins.
  4. Correlation in Jmeter.
  5. Describe yourself.
  6. What is the new thing you have learned in last 3 months?
  7. What is the test procedure you follow in software development life cycle?
  8. What are the performance metrics for a tester?
  9. What is the new project you have worked on?
  10. Any experience on API testing and Web services testing?

Second Round:

  1. Give two appropriate reasons because of which we might not take you for Seneca Global?
  2. What are the two best defects you have found till date?
  3. If you are made lead to a team for your current project, what would like to change?
  4. Write different possible test cases for Amazon site? (Write different ones)
  5. If given time what would you like to learn in the coming 6 months?
  6. Why are you willing to change?
  7. What are the things you felt difficult to answer in First round?
  8. What are the things you could not answer in First round? (Be honest for these two questions)
  9. What are the things you have missed in system test?
  10. How did first round of interview happen?
  11. You might have to extend yourself till late night, are you ready? Why?
  12. What is your notice period? Is it negotiable? If yes, why do you think it is negotiable.
  13. Any experience on Backend testing?
  14. Any experience on No sql db ?

These are the sample questions indicating the process they might follow during the interview.

In addition to the two rounds, an Automation test round might also be conducted.

Hope these questions help you in cracking the interview. As always, please comment for any feedback. Subscribe to blog to get latest updates.

How to detect OS in Java

In previous post, we have seen couple of ways to determine Operating system using Python -> Determine Operating System using Python

In this post we will try to do that using Java.

One of the system properties, os.name can help us in achieving that.

This code can detect Windows, Mac, Unix, Solaris.

public class DetermineOS {

public static String OS = System.getProperty(“os.name”).toLowerCase();

public static void main(String[] args){

System.out.println(OS);

if(OS.contains(“win”)){

System.out.println(“Windows Environment”);

}else if(OS.contains(“mac”) {

System.out.println(“Mac Environment”);

}else if(OS.contains(“sunos”)){

System.out.println(“This is Solaris”);

}else if(OS.contains(“nix”) || OS.contains(“nux”) || OS.contains(“aix”)){

System.out.println(“This is Unix environment”);

}else {

System.out.println(“Your OS is not supported”);

}

}

}

Please comment if you are aware of any other ways to determine Operating system.

Copy files from Windows to Linux

While working on an application which is compatible across different platforms, we might face this challenge of setting up application on Linux systems. This requires copying setup files between Windows and Linux systems.

We can’t use Ctrl+C, Ctrl+V operations as Linux usually doesn’t have UI to operate on. Tools like CygWin, WinSCP, PSCP can be used for this task.

We will see how to copy files using PSCP in this article.

PSCP stands for Putty Secure Copy Client. It can be downloaded here. Choose Windows Installer, download it and add the location to PATH environment variable.

Use the following syntax from Command Prompt:
pscp filename username@hostname or ip address:folder

pscp abcd.txt root@1.1.1.1:/opt/

It prompts for Password, enter it.

Then you can see copied files in /opt folder of Linux file system.

Determine Operating System using Python

Usually while running an automation script in different environments, test cases might fail because of keyword not being supported by OS.

To handle this situation we can determine Operating system version and decide to run respective keywords for different operating system versions.

Following are the three ways in which we can do that by using methods in Python. These examples can be handy when you are using Python based automation framework like Robot Framework.

Use below code in Python IDLE or Command prompt:

#import platform and sys modules
import platform;
import sys;

#Print output to console
print(platform.system());
print(platform.platform(1,1));

print(sys.platform);

Following output can be observed by running above code:

Windows
Windows-10
win32

Possible values for the methods used are:

platform.system() – Windows for windows, Darwin for Mac.

platform.platform(1,1) – Windows-version for windows, Darwin-version for Mac. You can play with values for platform() method to obtain desired values.

sys.platform – win32 for windows, darwin for Mac.

Using these methods in Robot framework:

*** Settings ***
Library           Selenium2Library
Library           OperatingSystem
Library           String
Library           BuiltIn
Library           Process

*** Test Cases ***
DetermineOperatingSystem
    [Documentation]    This Test case finds out Operating System on which Python 
is running.
    ${OS1}=    Evaluate    platform.system()    platform
    log    ${OS1}
    Run Keyword If    '${OS1}'=='Windows'    log    Windows environment
    ...    ELSE IF    '${OS1}'='Darwin'    log    Mac environment
    ${OS2}=    Evaluate    platform.platform(1,1)    platform
    log    ${OS2}
    ${OS3}=    Evaluate    sys.platform    sys
    log    ${OS3}

 

Suggestions are always welcome. Please comment for any queries or suggestions.

We will see how to determine Operating system using Java in next post.

Technovert Interview Experience for manual QA positions

Technovert is a Product development company and is a Microsoft solution provider. Here are a set of Interview questions for QA positions in Technovert.

Questions were mainly focused on Manual skills and automation was not stressed upon.

1.Test cases for Login page functionality.
2.Test cases for Search functionality.
3.What is the difference between Verification and Validation.
4.What is the difference between Defect and Bug.
5.What does Severity and Priority mean.
6.Give examples for High Severity, Low Priority situation.
7.Explain defect life cycle.
8.Explain Software development life cycle.
9.Explain about Agile methodology.
10.What are the levels of testing starting from product development.
11.What is Regression testing and it’s role in Product development.
12.What is a Test plan and what does it mainly contain.

Oracle Interview Experience – QA

Hi all,

Set of interview questions for QA positions in Oracle.

1. How to abort a shell script while it is running.
2. Is it possible to use echo command in place of ls command ?
3. How to remove one line from a text file using unix commands.
4. Provide logic to replace M with F and F with M in Employees table using single command without any temp table.
5. How to pick nth maximum salary from employees table.
6. Difference between two constraints – Primary key and Unique Key.
7. What are various DML, DDL and DCL commands in SQL.
8. What is the next number in the sequence 9, 18, 21, 25, 20 ?
9. One aptitude question – If a monkey climbs 6 metres and descends 3 metres in 1 min. What is the time monkey takes to climb 60 metres ?
10. Explain different steps in SDLC model.
11. What is Agile methodology and what are the benefits of it.
12. What is difference between Web application and Desktop application.
13. What is the best bug you have found till date.
14. What is the difference between Defect and Bug.
15. Write a Java program to generate Random numbers from 1 to 10.
16. Write Selenium webdriver code to login to an application and check the validity of one element in the resulting page.
17. What are the conditions you follow to pick test cases for Automation ?
18. What are the conditions you follow to not select test cases for Automation ?
19. What is xpath and where is it used.
20. What is the difference between // and / in xpath?
21. What are different types of waits in Webdriver ?
22. Difference between Explicit and Implicit wait in webdriver.
23. Give an example for High priority and Low severity scenario.

 

How to run Webdriver scripts in Chrome Browser ?

To run scripts on Chrome browser, we require Chrome Driver in local machine.

A driver is a Webdriver implementation which controls the browser running on local machine.

First Method:

1. Download Chrome driver.
2. Add driver location to ‘PATH’ environment variable.
3. Instantiate Chrome driver class in scripts.

Web driver code:

package seleniumTutorials;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class LaunchChromeBrowser {

public static void main(String[] args) {
// TODO Auto-generated method stub

WebDriver driver = null;

driver = new ChromeDriver();

driver.get(“www.google.com”);

}

}

Second Method:

1. Download Chrome driver.
2. Set driver location as a property in scripts.

Web driver code:

package seleniumTutorials;

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebDriver;

public class LaunchChromeBrowserWithProperty {

public static void main(String[] args) {
// TODO Auto-generated method stub

WebDriver driver = null;

String driverPath = “G:\\Chrome Driver\\chromedriver.exe”;

System.setProperty(“webdriver.chrome.driver”,driverPath);

driver = new ChromeDriver();

driver.get(“www.google.com”);

}

}

These are the two methods through which Web driver scripts can be run in Chrome browser.

GainSight Interview Experience – Round 2

Following the previous post for Gainsight Interview experience. GainSight Interview Experience

Below is the experience for Round 2.

1. Experience on Database testing using Selenium Webdriver.
2. Experience on API testing using Selenium Webdriver.
3. How to run Tests using TestNG framework. Parameters used in the framework.
4. Write use cases for Login page.
5. Why do you want to switch to a new job ?
6. What are your expectations from GainSight ?

GainSight Interview Experience

GainSight is a Big data and Data analytics startup. Interview process is a good experience.

Following are a set of interview questions for QA positions.

1.What is Regression Testing ? It’s role in Software development process ?

2. List out SQL commands which you are aware of.

3. List out Shell scripting commands which you are aware of.

4. How to know status of recently used command in shell scripting ? and how to assign permissions using chmod command ?

5. What is the best bug you have found till date ? what is the fix for that bug ?

6.Write Performance, Security, Functional test cases for Photo sharing website.

7. How to select nth matching element for a xpath in a web page using selenium webdriver ?

8. Write FizzBuzz program.

9. What does System.out.println mean in Java ?

10. Few basic questions about HTTP protocol.

Also have a look at another set of Interview questions for Gainsight in an other post. GainSight Interview Experience – Round 2