Pages

Sunday, 22 February 2015

JAVA QUESTIONS

What is Immutable Object? Can you write Immutable Class?

Immutable classes are Java classes whose objects can not be modified once created. Any modification in Immutable object result in new object. For example String is immutable in Java. Mostly Immutable classes are also final in Java, in order to prevent sub classes from overriding methods, which can compromise Immutability. You can achieve same functionality by making member as non final but private and not modifying them except in constructor. Apart form obvious, you also need to make sure that, you should not expose internals of Immutable object, especially if it contains a mutable member. Similarly, when you accept value for mutable member from client e.g.java.util.Date, use clone() method keep separate copy for yourself, to prevent risk of malicious client modifying mutable reference after setting it. Same precaution needs to be taken while returning value for a mutable member, return another separate copy to client, never return original reference held by Immutable class

What is the difference between creating String as new() and literal?

When we create string with new() Operator, it’s created in heap and not added into string pool while String created using literal are created in String pool itself which exists in PermGen area of heap. For example, String str = new String("Test")does not put the object str in String pool , we need to call String.intern() method which is used to put them into String pool explicitly. its only when you create String object as String literal e.g. String s = "Test" Java automatically put that into String pool. By the way there is a catch here, Since we are passing arguments as "Test", which is a String literal, it will also create another object as "Test" on string pool.


Saturday, 21 February 2015

Testing Concepts

1. How do drivers and stubs relate to manual testing?

- Drivers and stubs are a part of incremental testing.
- The two approaches used in incremental testing are: the top down and the bottom up methods.
- Drivers are used for the bottom up approach.
- Drivers are the modules that run the components that are being tested.
- A stub is used for the top down approach.
- It is a replacement of sorts for a component which is used to test a component that it calls.

2. Explain the following mentioned testing types?

a.) Stress testing: 
- It checks the robustness of application.
- It verifies that application consistently provides satisfactory performance under unfavorable and extreme conditions. This includes - heavy user traffic, heavy process loads, irregular hardware clocking, and heavy utilization of resources.
 
- Stress testing is also useful in verifying the effectiveness of error handling under extreme conditions.
b.) Sanity testing:
- Sanity testing is used to ensure that multiple or conflicting functions or variables do not exist in the system.
- It verifies that the components of the application can be compiled without a problem.
- It is conducted on all parts of the application.
c.) Ad hoc testing:
- It is a type of testing that is performed without the use of planning and/or documentation.
- These tests are run only one time unless a defect is found.
 
- If defect is found, testing can be repeated.
 
- It is considered to be a part of exploratory testing.
d.) Smoke testing:
- Smoke testing covers all of the basic functionality of the application.
- It is considered as the main test for checking the functionality of the application.
- It does not test the finer details of the application.

JAVA QUESTIONS

What will happen if we put a key object in a HashMap which is already there?

If you put the same key again than it will replace the old mapping because HashMap doesn't allow duplicate keys. Same key will result in same hashcode and will end up at same position in bucket. Each bucket contains a linked list of Map.Entry object, which contains both Key and Value. Now Java will take Key object form each entry and compare with this new key using equals() method, if that return true then value object in that entry will be replaced by new value.


What is difference between StringBuffer and StringBuilder in Java ?

StringBuffer:

StringBuffer is mutable means one can change the value of the object . The object created through StringBuffer is stored in the heap .  StringBuffer  has the same methods as the StringBuilder , but each method in StringBuffer is synchronized that is StringBuffer is thread safe . Due to this it does not allow  two threads to simultaneously access the same method . Each method can be accessed by one thread at a time . But being thread safe has disadvantages too as the performance of the StringBuffer hits due to thread safe property . Thus  StringBuilder is faster than the StringBuffer when calling the same methods of each class.

String Buffer can be converted to the string by using  toString() method.

StringBuffer demo1 = new StringBuffer("Hello") ;

demo1=new StringBuffer("Bye");

StringBuilder:

StringBuilder  is same as the StringBuffer , that is it stores the object in heap and it can also be modified . The main difference between the StringBuffer and StringBuilder is that StringBuilder is also not thread safe.

StringBuilder is fast as it is not thread safe . 

StringBuilder demo2= new StringBuilder("Hello");


demo2=new StringBuilder("Bye"); 

Friday, 20 February 2015

Testing Concepts

3. Explain the following.

a.) Compatibility testing:
- It is a non-functional test performed on a software system or component for checking its compatibility with the other parts in the computing environment. 
- This environment covers the hardware, servers, operating system, web browsers, other software, etc.

b.) Integration testing:
- This test is performed to verify the interfaces between system components, interactions between the application and the hardware, file system, and other software. 
- A developer can also perform it.
- Ideally an integration testing team should perform it.

4. Explain the following.

a.) Code Complete:
- Phase of development where functionality is implemented in entirety with only bug fixes remaining.
- All functions from the functional specifications are already implemented.

b.) Code Coverage:
- This is an analysis method which determines which parts of the software have already been covered by the test case suite and which are remaining. 

c.) Code Inspection: 
- A formal testing technique where the programmer reviews source code with a group who ask questions analyzing the program logic, analyzing the code with respect to a checklist of historically common programming errors, and analyzing its compliance with coding standards.



Application Architectures

Application  Architectures
Applications are developed  to suport org in their business operations.Applications accept input,process the data based on business rules,and provide data as output. The functions performed by an application can be divided into three categories.They are
1.      User Services
2.      Business Services
3.      Data Services.
Each category is implemented as a layer in an application.
User Services :
            The user service layer constitutes the froent end of a solution.it is also called a presentation layer because it provides an interactive user interface.

Business Services :
            The business service layer controls the enforcement of business rules on the data of an org.
Data Services :
            The data service layer comprises the data and the functions for manipulating this data.

Types of  Application Architectures :
  1. Single-tier Architecture
  2. Two-tier Architecture
  3. Three-tier Architecture
  4. N-tier Architecture


Single-tier Architecture :
      In the case of single-tier architecture,a single executable file handles all functions relating to the user,business,and data services layers.Such an application is called a Monolithic application.Some of the very early COBOL programms performing extermely mission-critical opperations fall under this category.




 






Single-tier Architecture





Two-tier Architecture :
      The Two-tier architecture divides an application into following two components :
                  Client  : Implements the user interface.
                  Server : Stores Data.




 















Two-tier Architecture


In the case of two-tier architecture, the user and the data services are located separately,either on the same machine or on saperate machines.For Example  You might have an VB application ,Which provides the user interface and SQL Server 7.0 which manages data.
      In the two-tier archicturethe business service layer may be implemented in one of the following ways.
      By using FAT Client

      By Using FAT Sever

By Dividing the business services between the user services and the data services.
FAT Client :
                  In the case of fat clients the business service layer is combined with the user service layer.Clients execute the presentation logic and enforce business logic.The Server stores data and processes transactions.
     

FAT Sever :

                        In the two-tier archicture with a fat server, the business services layer is combined with the data services layer.As business services are  stored on theserver,most of the processing takes place on the server.



By Dividing the business services between the user services and the data services:
                  You can also implement a two-tier model in which the business services are distributed between the user sevices and data services.In this case the processing of business logic is distributed between the user and data services.

Three-tier Architecture :

                  In the case of three-tier architecture,all the three service layers reside separately,either on the same machine or on different machines.The user interface interacts with the business logic.The business logic validates the data sent by the interface and forwards it to the database if it conforms to the requirements. The froent-end only interacts with business logic,which inturn interacts with the database.

 







Three-tier Architecture


N-tier Architecture :
                  An n-tire application uses business objects for handling business rules and data access.It has multiple servers handling business services.This application architecture provides various advantages over other types of application architectures. Some of the advantage include extensibility,resilience to change,maintainability,and scalability of the application.



Tuesday, 10 February 2015

Types of Testing in Software Testing

Types of Testing in Software Testing

1.     Describe cyclomatic complexity with example.
Cyclomatic complexity is a software metric that measure the logical strength of the program. It was developed by Thomas J. McCabe. Cyclomatic complexity is calculated by using the control flow graph of the program. In the flow graph, nodes are represented by circle. Areas bounded by edges and nodes are called regions. When counting regions, we also include the area outside the graph as a region.
Complexity is computed in one of three ways:
The total number of regions of the flow graph.
By using the formula defined as:
V(G) = E - N + 2
Cyclomatic complexity, V(G), for a flow graph, G, is also defined as
V(G) = P + 1 ,where P is the number of predicate nodes contained in the flow graph G.
Note: Nodes that contain a condition is called a predicate node and is characterized by two or more edges originating from it.

Find out the Cyclomatic complexity V(G) of the given below flow graph.

Description: http://www.careerride.com/images/testing-interview-1.png
In the above flow graph there are total 9 nodes, 11 edges, and 4 regions.
1. The flow graph has four regions. 
2. V (G) = 11 edges- 9 nodes + 2 = 4.
 
3. V (G) = 3 predicate nodes + 1 = 4.

Control flow graph
Control flow graph enables developers to determine the independent execution paths and design the tests to validate these paths . Using this , the testers can assure that all the paths have been tested at least once in the white box testing .
Example :
 int check_age(int age)
   {
    if (age < 50)
       printf(“you are pretty young \n”);
Else
     {
      if (age <80 )
           printf( “you are old \n”);
      else
          printf(“you are really old \n”);
    }
Return 0;
  }
Here e=7, n=6 hence independent execution paths are 3.


2.     Describe Condition testing in brief.
Condition testing works on logical conditions contained in a program module. A simple condition is a Boolean variable or a relational expression. A relational expression takes the form
E1 <relational-operator>E2
For Example Where E1 and E2 are arithmetic expressions and <relational-operator> is one of the following: <, ≤, =, ≠ (not equal to), >, or ≥. A compound condition is created by using two or more simple conditions, Boolean operators, and parentheses. Conditional error is generated if Boolean variable, relational operator or Boolean operator is incorrectly used.
The purpose of condition testing is to detect errors in the conditions of a program.
3.     What are white-box, black-box and gray-box testing?
Whit-box Testing: It refers to the testing a system with full knowledge and access to all source code and other architecture documents. This testing enables to reveal bugs and vulnerabilities quickly in comparison with trial and error method. More complete testing coverage is ensured by exactly knowing what to test.
Ø  Statement Coverage.
Ø  Try to cover 100% of statement coverage of the code.
Ø  Testing the every possible statement in the code is executed atleast once.
Ø  Cantata++ tool is used to test this coverage.
Ø  Decision Coverage.
Ø  Try to cover 100% of statement coverage of the code.
Ø  Testing the every possible decision conditions like for loop and other conditional loops in the code is executed at least once.       
Ø  TCAT-PATH is used to test this coverage.
Ø  Condition Coverage.
Ø  Try to cover 100% Condition coverage of the code.
Ø  Testing the every possible conditions in the code is executed at least once.
Black-box Testing: It refers to testing a system without knowledge of specification to the internal workings of the system, access to the source code, and knowledge of the architecture. Essentially this approach mimics in a close approach, how an attacker typically follows approach to the application. However, the uncovering of issues or vulnerabilities could be further longer, because of lacking internal application knowledge.
Gray-box Testing: It refers to a testing system by knowing limited information about the internals of the system. The knowledge is always limited for detailed design documents and architecture diagrams. In concise, it is a good blend of black and white box testing, which leverage the strengths of each.
4.     What is Big-bang testing?
Big bang waterfall model delivers the complete solution once and in one go. That’s why it’s termed Big Bang.
Following is the approach:
  • Customer provides complete overall requirements.
  • Design follows
  • The design is built / developed.
  • The development work is tested.
  • The system is implemented.
One should go with Big bang waterfall model if:
  • Contract of work is completely defined and accurate.
  • Requirement and acceptance criteria is completely defined and accurate
  • It is feasible to finish the work within given constraints.
  • No change in requirements is expected.
  • Problem and proposed solution both are clearly understood by all stakeholders.
  • No mistakes can occur in requirements, design phases.
5.     Difference between Verification and Validation?
Verification - is to determine the right thing, which involves the testing the implementation of right process. Ex: Are we building the product right?
Validation - is to perform the things in right direction, like checking the developed software adheres the requirements of the client. Ex: right product was built
6.     Difference between Pilot and Beta Testing.
Pilot testing involves having a group of end users try the system prior to its full deployment in order to give feedback on its performance.
Beta testing is testing of the product in the user environment.
From the definitions, it is evident that beta testing comes at last in development cycle; whereas pilot testing takes place before deployment of the system. Also, beta testing takes place in real time user environment and pilot testing in development environment. A selected group of users do pilot testing whereas beta testing is carried by all users.

 

 

7.     What is Equivalence Partitioning?
Equivalence Partitioning (EP) is the process of methodically reducing the huge set of possible test cases into a much smaller but still equally effective set. The goal of EP is to reduce the set of possible test cases into a smaller, manageable set that still adequately tests the software. Since we are choosing not to test everything, we are taking on risk. So we need to be careful how to choose classes. Also note that EP is a set of test cases that test the same thing or reveal the same bug.
Example: If a student’s Mark Sheet s/w takes numbers only from 0 to 100, we need to check that the system takes all the numbers between 0 and 100 (including both) and it does not take any other number. Now if we have to verify this, ideally we need to make sure system accepts all numbers from 0 to 100 and it does not accept any number <0 and > 100. Testing all these numbers is practically impossible because we can’t test for all number from 0 to -8 and from 101 to +8. So we could partition the i/p data into 2 classes: Valid and Invalid. Where valid class would include all the numbers between 0 to 100 (including both) and invalid class would include numbers <0 and > 100. Thus, we can test for few entries from both the classes and safely say that the s/w works for all the numbers.
8.     Explain Structure-based testing techniques
- Structure-based testing techniques are also termed as white-box testing techniques.
- These are dynamic techniques. 
- They use the internal structure of the software to derive test cases. 
- They are usually termed as 'white-box' or 'glass-box' techniques 
- They need you to have knowledge of how the software is implemented and how it works.
9.     Explain component testing.
- Component testing is also termed as unit, module or program testing. 
- It looks for defects in the software and verifies its functioning. 
- It can be done in isolation from rest of the system depending on the context of the development life cycle and the system. 
- Mostly stubs and drivers are used to replace the missing software and simulate the interface between the software components in a simple manner.
- The stub is called from the software component to be tested while a driver calls a component to be tested.




    10. Explain exploratory testing.

- In exploratory testing approach testers are involved in minimum planning and maximum test execution.
- The planning includes creation of a test charter, a short declaration of the scope of a short time-boxed test effort, the objectives and possible approaches to be used. 
- The test design and test execution are performed parallelly without any formal documentation of test conditions, test cases or test scripts. However, this does not imply that other more formal testing techniques will not be used.

   11. Differentiate between re-testing and regression testing

Regressions testing: 
- It means testing new bug fixes to ensure that they don’t cause problems to occur involving problems fixed earlier. 
- The process here involves running a suite of tests. 
Re-testing: 
- It means testing a single defect that was just fixed. Only one test is performed here. 
- The target is to ensure that the defect that was just fixed was actually fixed properly. 

 


Multithreading in Java

Multithreading in Java
Multithreading is a process of running two parts of the same program to run concurrently or simultaneously . It is a technique that allows a program or a process to execute many tasks concurrently (at the same time and parallel). It allows a process to run its tasks in parallel mode on a single processor system 
In the multithreading concept, several multiple lightweight processes are run in a single process/task or program by a single processor. For Example, When you use a word processor you perform a many different tasks such as printing, spell checking and so on. Multithreaded software treats each process as a separate program.
In Java, the Java Virtual Machine (JVM) allows an application to have multiple threads of execution running concurrently. It allows a program to be more responsible to the user. When a program contains multiple threads then the CPU can switch between the two threads to execute them at the same time.

Types of Multitasking:
          1. Process Based
          2. Thread Based
A Process Based multitasking is the feature that allows the computer to run 2 or more programs concurrently. Process-based multitasking has a larger overhead than thread-based multitasking. In process-based multitasking, each process requires its own address space in memory. The operating system requires a significant amount of CPU time to switch from one process to another process. Programmers call this context switching, where each process (program) is a context. Additional resources are needed for each process to communicate with each other.
In a Thread Based multitasking environment, the thread is the smallest unit of dispatch able code. A single program can perform 2 or more tasks simultaneously.  the threads in thread-based multitasking share the same address space in memory because they share the same program. This also has an impact on context switching, because switching from one part of the program to another happens within the same address space in memory. Likewise, communication among parts of the program happens within the same memory location.
Multithreading enables to write very efficient programs that make maximum use of the CPU.
States of a Thread:
1.     New Born or Ready to run
2.     Runnable
3.     Blocked
4.     Resumed
5.     Terminated
Thread Priorities:
A thread can voluntarily relinquish control- examine all threads & the highest priority thread is given to the CPU.
A thread can be preempted by a higher-priority thread- When the higher-priority thread wants to run, it is executed.
Java priorities are in the range between MIN_PRIORITY (a constant of 1) and MAX_PRIORITY (a constant of 10). By default, every thread is given priority NORM_PRIORITY (a constant of 5).
 Creating a Thread
1.     Create a class that implements Runnable Interface
2.     Create a class as a  subclass of Thread
Creating a thread using runnable interface:
The easiest way to create a thread is to create a class that implements the Runnable interface. while implementing Runnable, a class need to  implement only a single method called run( ), which is declared like this:
Syntax:
Class classname implements Runnable{
Public void run(){
//Body of the thread code
}}
After creating a class that implements Runnable, we will instantiate an object of type Thread from within that class. Thread defines several constructors.
The one that we will use is shown here:
Thread(Runnable threadObject, String threadName);
Here threadObject  is an instance of a class that implements the Runnable interface and the name of the new thread is specified by threadName.
After the new thread is created, it will not start running until we call its start( ) method, which is declared within Thread.
The start( ) method is shown here:
void start( );
Creating a thread using Thread Class:
The  another  way to create a thread is to create a class that extends  the  Thread class.
Syntax:
Class classname extends Thread{
Public void run(){
//Body of the thread code
}}

Simple Thread Example:
class MyThread extends Thread {
    private String name, msg;
    public MyThread(String name, String msg) {
        this.name = name;
        this.msg = msg;
    }
    public void run() {
        System.out.println(name + " starts its execution");
        for (int i = 0; i < 5; i++) {
            System.out.println(name + " says: " + msg);
            try {  Thread.sleep(500); } catch (InterruptedException ie) {}
        }
        System.out.println(name + " finished execution");
    }}
public class Threadprogram {
  public static void main(String[] args) {
    MyThread mt1 = new MyThread("thread1", "ping");
    MyThread mt2 = new MyThread("thread2", "pong");
     mt1.start();
    mt2.start();
  for(int k=1;k<=10;k++)
  System.out.println("ok");
  }
}

Visit : www.sssedu.in\