Thursday, August 14, 2014

200 LATEST TOP JAVA Interview Questions and Answers

Below are the list of Latest Java interview questions and answers for freshers beginners and experienced pdf free download.

JAVA Interview Questions and Answers

JAVA Interview Questions and Answers
JAVA Interview Questions and Answers
Q: What do you know about Java?
A: Java is a high-level programming language originally developed by Sun Microsystems and released in 1995. Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.

Q: What are the supported platforms by Java Programming Language?
A: Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX/Linux like HP-Unix, Sun Solaris, Redhat Linux, Ubuntu, CentOS, etc.

Q: List any five features of Java?
A: Some features include Object Oriented, Platform Independent, Robust, Interpreted, Multi-threaded

Q: Why is Java Architectural Neutral?
A: It’s compiler generates an architecture-neutral object file format, which makes the compiled code to be executable on many processors, with the presence of Java runtime system.

Q: How Java enabled High Performance?
A: Java uses Just-In-Time compiler to enable high performance. Just-In-Time compiler is a program that turns Java bytecode, which is a program that contains instructions that must be interpreted into instructions that can be sent directly to the processor.

Q: Why Java is considered dynamic?
A: It is designed to adapt to an evolving environment. Java programs can carry extensive amount of run-time information that can be used to verify and resolve accesses to objects on run-time.

Q: What is Java Virtual Machine and how it is considered in context of Java’s platform independent feature?
A: When Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by virtual Machine (JVM) on whichever platform it is being run.

Q: List two Java IDE’s?
A: Netbeans, Eclipse, etc.

Q: List some Java keywords(unlike C, C++ keywords)?
A: Some Java keywords are import, super, finally, etc.

Q: What do you mean by Object?
A: Object is a runtime entity and it’s state is stored in fields and behavior is shown via methods. Methods operate on an object's internal state and serve as the primary mechanism for object-to-object communication.

Q: Define class?
A: A class is a blue print from which individual objects are created. A class can contain fields and methods to describe the behavior of an object.

Q: What kind of variables a class can consist of?
A: A class consist of Local variable, instance variables and class variables.

Q: What is a Local Variable
A: Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and it will be destroyed when the method has completed.

Q: What is a Instance Variable
A: Instance variables are variables within a class but outside any method. These variables are instantiated when the class is loaded.

Q: What is a Class Variable
A: These are variables declared with in a class, outside any method, with the static keyword.

Q: What is Singleton class?
A: Singleton class control object creation, limiting the number to one but allowing the flexibility to create more objects if the situation changes.

Q: What do you mean by Constructor?
A: Constructor gets invoked when a new object is created. Every class has a constructor. If we do not explicitly write a constructor for a class the java compiler builds a default constructor for that class.

Q: List the three steps for creating an Object for a class?
A: An Object is first declared, then instantiated and then it is initialized.

Q: What is the default value of byte datatype in Java?
A: Default value of byte datatype is 0.

Q: What is the default value of float and double datatype in Java?
A: Default value of float and double datatype in different as compared to C/C++. For float its 0.0f and for double it’s 0.0d

Q: When a byte datatype is used?
A: This data type is used to save space in large arrays, mainly in place of integers, since a byte is four times smaller than an int.

Q: What is a static variable?
A: Class variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block.

Q: What do you mean by Access Modifier?
A: Java provides access modifiers to set access levels for classes, variables, methods and constructors. A member has package or default accessibility when no accessibility modifier is specified.

Q: What is protected access modifier?
A: Variables, methods and constructors which are declared protected in a superclass can be accessed only by the subclasses in other package or any class within the package of the protected members' class.

Q: What do you mean by synchronized Non Access Modifier?
A: Java provides these modifiers for providing functionalities other than Access Modifiers, synchronized used to indicate that a method can be accessed by only one thread at a time.

Q: According to Java Operator precedence, which operator is considered to be with highest precedence?
A: Postfix operators i.e () [] . is at the highest precedence.

Q: Variables used in a switch statement can be used with which datatypes?
A: Variables used in a switch statement can only be a byte, short, int, or char.

Q: When parseInt() method can be used?
A: This method is used to get the primitive data type of a certain String.

Q: Why is String class considered immutable?
A: The String class is immutable, so that once it is created a String object cannot be changed. Since String is immutable it can safely be shared between many threads ,which is considered very important for multithreaded programming.

Q: Why is StringBuffer called mutable?
A: The String class is considered as immutable, so that once it is created a String object cannot be changed. If there is a necessity to make alot of modifications to Strings of characters then StringBuffer should be used.

Q: What is the difference between StringBuffer and StringBuilder class?
A: Use StringBuilder whenever possible because it is faster than StringBuffer. But, if thread safety is necessary then use StringBuffer objects.

Q: Which package is used for pattern matching with regular expressions?
A: java.util.regex package is used for this purpose.

Q: java.util.regex consists of which classes?
A: java.util.regex consists of three classes: Pattern class, Matcher class and PatternSyntaxException class.

Q: What is finalize() method?
A: It is possible to define a method that will be called just before an object's final destruction by the garbage collector. This method is called finalize( ), and it can be used to ensure that an object terminates cleanly.

Q: What is an Exception?
A: An exception is a problem that arises during the execution of a program. Exceptions are caught by handlers positioned along the thread's method invocation stack.

Q: What do you mean by Checked Exceptions?
A: It is an exception that is typically a user error or a problem that cannot be foreseen by the programmer. For example, if a file is to be opened, but the file cannot be found, an exception occurs. These exceptions cannot simply be ignored at the time of compilation.

Q: Explain Runtime Exceptions?
A: It is an exception that occurs that probably could have been avoided by the programmer. As opposed to checked exceptions, runtime exceptions are ignored at the time of compliation.

Q: Which are the two subclasses under Exception class?
A: The Exception class has two main subclasses : IOException class and RuntimeException Class.

Q: When throws keyword is used?
A: If a method does not handle a checked exception, the method must declare it using the throwskeyword. The throws keyword appears at the end of a method's signature.

Q: When throw keyword is used?
A: An exception can be thrown, either a newly instantiated one or an exception that you just caught, by using throw keyword.

Q: How finally used under Exception Handling?
A: The finally keyword is used to create a block of code that follows a try block. A finally block of code always executes, whether or not an exception has occurred.

Q: What things should be kept in mind while creating your own exceptions in Java?
A: While creating your own exception:

All exceptions must be a child of Throwable.

If you want to write a checked exception that is automatically enforced by the Handle or Declare Rule, you need to extend the Exception class.

You want to write a runtime exception, you need to extend the RuntimeException class.

Q: Define Inheritance?
A: It is the process where one object acquires the properties of another. With the use of inheritance the information is made manageable in a hierarchical order.

Q: When super keyword is used?
A: If the method overrides one of its superclass's methods, overridden method can be invoked through the use of the keyword super. It can be also used to refer to a hidden field

Q: What is Polymorphism?
A: Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object.

Q: What is Abstraction?
A: It refers to the ability to make a class abstract in OOP. It helps to reduce the complexity and also improves the maintainability of the system.

Q: What is Abstract class
A: These classes cannot be instantiated and are either partially implemented or not at all implemented. This class contains one or more abstract methods which are simply method declarations without a body.

Q: When Abstract methods are used?
A: If you want a class to contain a particular method but you want the actual implementation of that method to be determined by child classes, you can declare the method in the parent class as abstract.

Q: What is Encapsulation?
A: It is the technique of making the fields in a class private and providing access to the fields via public methods. If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class. Therefore encapsulation is also referred to as data hiding.

Q: What is the primary benefit of Encapsulation?
A: The main benefit of encapsulation is the ability to modify our implemented code without breaking the code of others who use our code. With this Encapsulation gives maintainability, flexibility and extensibility to our code.

Q: What is an Interface?
A: An interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.

Q: Give some features of Interface?
A: It includes:

Interface cannot be instantiated

An interface does not contain any constructors.

All of the methods in an interface are abstract.

Q: Define Packages in Java?
A: A Package can be defined as a grouping of related types(classes, interfaces, enumerations and annotations ) providing access protection and name space management.

Q: Why Packages are used?
A: Packages are used in Java in-order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations and annotations, etc., easier.

Q: What do you mean by Multithreaded program?
A: A multithreaded program contains two or more parts that can run concurrently. Each part of such a program is called a thread, and each thread defines a separate path of execution.

Q: What are the two ways in which Thread can be created?
A: Thread can be created by: implementing Runnable interface, extending the Thread class.

Q: What is an applet?
A: An applet is a Java program that runs in a Web browser. An applet can be a fully functional Java application because it has the entire Java API at its disposal.

Q: An applet extend which class?
A: An applet extends java.applet.Applet class.

Q: Explain garbage collection in Java?
A: It uses garbage collection to free the memory. By cleaning those objects that is no longer reference by any of the program.

Q: Define immutable object?
A: An immutable object can’t be changed once it is created.

Q: Explain the usage of this() with constructors?
A: It is used with variables or methods and used to call constructer of same class.

Q: Explain Set Interface?
A: It is a collection of element which cannot contain duplicate elements. The Set interface contains only methods inherited from Collection and adds the restriction that duplicate elements are prohibited.

Q: Explain TreeSet?
A: It is a Set implemented when we want elements in a sorted order.

Q: What is Comparable Interface?
A: It is used to sort collections and arrays of objects using the collections.sort() and java.utils. The objects of the class implementing the Comparable interface can be ordered.

Q: Difference between throw and throws?
A: It includes:

Throw is used to trigger an exception where as throws is used in declaration of exception.

Without throws, Checked exception cannot be handled where as checked exception can be propagated with throws.

Q: Explain the following line used under Java Program:
public static void main (String args[ ])

A: The following shows the explanation individually:

public: it is the access specifier.

static: it allows main() to be called without instantiating a particular instance of a class.

void: it affirns the compiler that no value is returned by main().

main(): this method is called at the beginning of a Java program.

String args[ ]: args parameter is an instance array of class String

Q: Define JRE i.e. Java Runtime Environment?
A: Java Runtime Environment is an implementation of the Java Virtual Machine which executes Java programs. It provides the minimum requirements for executing a Java application;

Q: What is JAR file?
A: JAR files is Java Archive fles and it aggregates many files into one. It holds Java classes in a library. JAR files are built on ZIP file format and have .jar file extension.

Q: What is a WAR file?
A: This is Web Archive File and used to store XML, java classes, and JavaServer pages. which is used to distribute a collection of JavaServer Pages, Java Servlets, Java classes, XML files, static Web pages etc.

Q: Define JIT compiler?
A: It improves the runtime performance of computer programs based on bytecode.

Q: What is the difference between object oriented programming language and object based programming language?
A: Object based programming languages follow all the features of OOPs except Inheritance. JavaScript is an example of object based programming languages

Q: What is the purpose of default constructor?
A: The java compiler creates a default constructor only if there is no constructor in the class.

Q: Can a constructor be made final?
A: No, this is not possible.

Q: What is static block?
A: It is used to initialize the static data member, It is excuted before main method at the time of classloading.

Q: Define composition?
A: Holding the reference of the other class within some other class is known as composition.

Q: What is function overloading?
A: If a class has multiple functions by same name but different parameters, it is known as Method Overloading.

Q: What is function overriding?
A: If a subclass provides a specific implementation of a method that is already provided by its parent class, it is known as Method Overriding.

Q: Difference between Overloading and Overriding?
A: Method overloading increases the readability of the program. Method overriding provides the specific implementation of the method that is already provided by its super class parameter must be different in case of overloading, parameter must be same in case of overriding.

Q: What is final class?
A: Final classes are created so the methods implemented by that class cannot be overridden. It can’t be inherited.

Q: What is NullPointerException?
A: A NullPointerException is thrown when calling the instance method of a null object, accessing or modifying the field of a null object etc.

Q: What are the ways in which a thread can enter the waiting state?
A: A thread can enter the waiting state by invoking its sleep() method, by blocking on IO, by unsuccessfully attempting to acquire an object's lock, or by invoking an object's wait() method. It can also enter the waiting state by invoking its (deprecated) suspend() method.

Q: How does multi-threading take place on a computer with a single CPU?
A: The operating system's task scheduler allocates execution time to multiple tasks. By quickly switching between executing tasks, it creates the impression that tasks execute sequentially.

Q: What invokes a thread's run() method?
A: After a thread is started, via its start() method of the Thread class, the JVM invokes the thread's run() method when the thread is initially executed.

Q: Does it matter in what order catch statements for FileNotFoundException and IOException are written?
A: Yes, it does. The FileNoFoundException is inherited from the IOException. Exception's subclasses have to be caught first.

Q: What is the difference between yielding and sleeping?
A: When a task invokes its yield() method, it returns to the ready state. When a task invokes its sleep() method, it returns to the waiting state.

Q: Why Vector class is used?
A: The Vector class provides the capability to implement a growable array of objects. Vector proves to be very useful if you don't know the size of the array in advance, or you just need one that can change sizes over the lifetime of a program.

Q: How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?
A: Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns.

Q: What are Wrapper classes?
A: These are classes that allow primitive types to be accessed as objects. Example: Integer, Character, Double, Boolean etc.

Q: What is the difference between a Window and a Frame?
A: The Frame class extends Window to define a main application window that can have a menu bar.

Q: Which package has light weight components?
A: javax.Swing package. All components in Swing, except JApplet, JDialog, JFrame and JWindow are lightweight components.

Q: What is the difference between the paint() and repaint() methods?
A: The paint() method supports painting via a Graphics object. The repaint() method is used to cause paint() to be invoked by the AWT painting thread.

Q: What is the purpose of File class?
A: It is used to create objects that provide access to the files and directories of a local file system.

Q: What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
A: The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.

Q: Which class should you use to obtain design information about an object?
A: The Class class is used to obtain information about an object's design and java.lang.Class class instance represent classes, interfaces in a running Java application.

Q: What is the difference between static and non-static variables?
A: A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance.

Q: What is Serialization and deserialization?
A: Serialization is the process of writing the state of an object to a byte stream. Deserialization is the process of restoring these objects.

Q: What are use cases?
A: It is part of the analysis of a program and describes a situation that a program might encounter and what behavior the program should exhibit in that circumstance.

Q: Explain the use of sublass in a Java program?
A: Sub class inherits all the public and protected methods and the implementation. It also inherits all the default modifier methods and their implementation.

Q: How to add menushortcut to menu item?
A: If there is a button instance called b1, you may add menu short cut by calling b1.setMnemonic('F'), so the user may be able to use Alt+F to click the button.

Q: Can you write a Java class that could be used both as an applet as well as an application?
A: Yes, just add a main() method to the applet.

Q: What is the difference between Swing and AWT components?
A: AWT components are heavy-weight, whereas Swing components are lightweight. Heavy weight components depend on the local windowing toolkit. For example, java.awt.Button is a heavy weight component, when it is running on the Java platform for Unix platform, it maps to a real Motif button.

Q: What's the difference between constructors and other methods?
A: Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times.

Q: Is there any limitation of using Inheritance?
A: Yes, since inheritance inherits everything from the super class and interface, it may make the subclass too clustering and sometimes error-prone when dynamic overriding or dynamic overloading in some situation.

Q: When is the ArrayStoreException thrown?
A: When copying elements between different arrays, if the source or destination arguments are not arrays or their types are not compatible, an ArrayStoreException will be thrown.

Q: Can you call one constructor from another if a class has multiple constructors?
A: Yes, use this() syntax.

Q: What's the difference between the methods sleep() and wait()?
A: The code sleep(2000); puts thread aside for exactly two seconds. The code wait(2000), causes a wait of up to two second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.

Q: When ArithmeticException is thrown?
A: The ArithmeticException is thrown when integer is divided by zero or taking the remainder of a number by zero. It is never thrown in floating-point operations.

Q: What is a transient variable?
A: A transient variable is a variable that may not be serialized during Serialization and which is initialized by its default value during de-serialization,

Q: What is synchronization?
A: Synchronization is the capability to control the access of multiple threads to shared resources. synchronized keyword in java provides locking which ensures mutual exclusive access of shared resource and prevent data race.

Q: What is the Collections API?
A: The Collections API is a set of classes and interfaces that support operations on collections of objects.

Q: Does garbage collection guarantee that a program will not run out of memory?
A: Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection.

Q: The immediate superclass of the Applet class?
A: Panel is the immediate superclass. A panel provides space in which an application can attach any other component, including other panels.

Q: Which Java operator is right associative?
A: The = operator is right associative.

Q: What is the difference between a break statement and a continue statement?
A: A break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement.

Q: If a variable is declared as private, where may the variable be accessed?
A: A private variable may only be accessed within the class in which it is declared.

Q: What is the purpose of the System class?
A: The purpose of the System class is to provide access to system resources.

Q: List primitive Java types?
A: The eight primitive types are byte, char, short, int, long, float, double, and boolean.

Q: What is the relationship between clipping and repainting under AWT?
A: When a window is repainted by the AWT painting thread, it sets the clipping regions to the area of the window that requires repainting.

Q: Which class is the immediate superclass of the Container class?
A: Component class is the immediate super class.

Q: What class of exceptions are generated by the Java run-time system?
A: The Java runtime system generates RuntimeException and Error exceptions.

Q: Under what conditions is an object's finalize() method invoked by the garbage collector?
A: The garbage collector invokes an object's finalize() method when it detects that the object has become unreachable.

Q: How can a dead thread be restarted?
A: A dead thread cannot be restarted.

Q: Which arithmetic operations can result in the throwing of an ArithmeticException?
A: Integer / and % can result in the throwing of an ArithmeticException.

Q: Variable of the boolean type is automatically initialized as?
A: The default value of the boolean type is false.

Q: Can try statements be nested?
A: Yes

Q: What are ClassLoaders?
A: A class loader is an object that is responsible for loading classes. The class ClassLoader is an abstract class.

Q: What is the difference between an Interface and an Abstract class?
A: An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation.

Q: What will happen if static modifier is removed from the signature of the main method?
A: Program throws "NoSuchMethodError" error at runtime .

Q: What is the default value of an object reference declared as an instance variable?
A: Null, unless it is defined explicitly.

Q: Can a top level class be private or protected?
A: No, a top level class can not be private or protected. It can have either "public" or no modifier.

Q: Why do we need wrapper classes?
A: We can pass them around as method parameters where a method expects an object. It also provides utility methods.

Q: What is the difference between error and an exception?
A: An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. Exceptions are conditions that occur because of bad input etc. e.g. FileNotFoundException will be thrown if the specified file does not exist.

Q: Is it necessary that each try block must be followed by a catch block?
A: It is not necessary that each try block must be followed by a catch block. It should be followed by either a catch block or a finally block.

Q: When a thread is created and started, what is its initial state?
A: A thread is in the ready state as initial state after it has been created and started.

Q: What is the Locale class?
A: The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.

Q: What are synchronized methods and synchronized statements?
A: Synchronized methods are methods that are used to control access to an object. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.

Q: What is runtime polymorphism or dynamic method dispatch?
A: Runtime polymorphism or dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time. In this process, an overridden method is called through the reference variable of a superclass.

Q: What is Dynamic Binding(late binding)?
A: Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at run-time.

Q: Can constructor be inherited?
A: No, constructor cannot be inherited.

Q: What are the advantages of ArrayList over arrays?
A: ArrayList can grow dynamically and provides more powerful insertion and search mechanisms than arrays.

Q: Why deletion in LinkedList is fast than ArrayList?
A: Deletion in linked list is fast because it involves only updating the next pointer in the node before the deleted node and updating the previous pointer in the node after the deleted node.

Q: How do you decide when to use ArrayList and LinkedList?
A: If you need to frequently add and remove elements from the middle of the list and only access the list elements sequentially, then LinkedList should be used. If you need to support random access, without inserting or removing elements from any place other than the end, then ArrayList should be used.

Q: What is a Values Collection View ?
A: It is a collection returned by the values() method of the Map Interface, It contains all the objects present as values in the map.

Q: What is dot operator?
A: The dot operator(.) is used to access the instance variables and methods of class objects.It is also used to access classes and sub-packages from a package.

Q: Where and how can you use a private constructor?
A: Private constructor is used if you do not want other classes to instantiate the object and to prevent subclassing.T

Q: What is type casting?
A: Type casting means treating a variable of one type as though it is another type.

Q: Describe life cycle of thread?
A: A thread is a execution in a program. The life cycle of a thread include:
  • Newborn state
  • Runnable state
  • Running state
  • Blocked state
  • Dead state
Q: What is the difference between the >> and >>> operators?
A: The >> operator carries the sign bit when shifting right. The >>> zero-fills bits that have been shifted out.

Q: Which method of the Component class is used to set the position and size of a component?
A: setBounds() method is used for this purpose.

Q: What is the range of the short type?
A: The range of the short type is -(2^15) to 2^15 - 1.

Q: What is the immediate superclass of Menu?
A: MenuItem class

Q: Does Java allow Default Arguments?
A: No, Java does not allow Default Arguments.

Q: Which number is denoted by leading zero in java?
A: Octal Numbers are denoted by leading zero in java, example: 06

Q: Which number is denoted by leading 0x or 0X in java?
A: Hexadecimal Numbers are denoted by leading 0x or 0X in java, example: 0XF

Q: Break statement can be used as labels in Java?
A: Yes, an example can be break one;

Q: Where import statement is used in a Java program?
A: Import statement is allowed at the beginning of the program file after package statement.

Q: Explain suspend() method under Thread class>
A: It is used to pause or temporarily stop the execution of the thread.

Q: Explain isAlive() method under Thread class?
A: It is used to find out whether a thread is still running or not.

Q: What is currentThread()?
A: It is a public static method used to obtain a reference to the current thread.

Q: Explain main thread under Thread class execution?
A: The main thread is created automatically and it begins to execute immediately when a program starts. It ia thread from which all other child threads originate.

Q: Life cycle of an applet includes which steps?
A: Life cycle involves the following steps:
  • Initialization
  • Starting
  • Stopping
  • Destroying
  • Painting
Q: Why is the role of init() method under applets?
A: It initializes the applet and is the first method to be called.

Q: Which method is called by Applet class to load an image?
A: getImage(URL object, filename) is used for this purpose.

Q: Define code as an attribute of Applet?
A: It is used to specify the name of the applet class.

Q: Define canvas?
A: It is a simple drawing surface which are used for painting images or to perform other graphical operations.

Q: Define Network Programming?
A: It refers to writing programs that execute across multiple devices (computers), in which the devices are all connected to each other using a network.

Q: What is a Socket?
A: Sockets provide the communication mechanism between two computers using TCP. A client program creates a socket on its end of the communication and attempts to connect that socket to a server.

Q: Advantages of Java Sockets?
A: Sockets are flexible and sufficient. Efficient socket based programming can be easily implemented for general communications. It cause low network traffic.

Q: Disadvantages of Java Sockets?
A: Socket based communications allows only to send packets of raw data between applications. Both the client-side and server-side have to provide mechanisms to make the data useful in any way.

Q: Which class is used by server applications to obtain a port and listen for client requests?
A: java.net.ServerSocket class is used by server applications to obtain a port and listen for client requests

Q: Which class represents the socket that both the client and server use to communicate with each other?
A: java.net.Socket class represents the socket that both the client and server use to communicate with each other.

Q: Why Generics are used in Java?
A: Generics provide compile-time type safety that allows programmers to catch invalid types at compile time. Java Generic methods and generic classes enable programmers to specify, with a single method declaration, a set of related methods or, with a single class declaration, a set of related types.

Q: What environment variables do I need to set on my machine in order to be able to run Java programs?
A: CLASSPATH and PATH are the two variables.

Q: Is there any need to import java.lang package?
A: No, there is no need to import this package. It is by default loaded internally by the JVM.

Q: What is Nested top-level class?
A: If a class is declared within a class and specify the static modifier, the compiler treats the class just like any other top-level class. Nested top-level class is an Inner class.

Q: What is Externalizable interface?
A: Externalizable is an interface which contains two methods readExternal and writeExternal. These methods give you a control over the serialization mechanism.

Q: If System.exit (0); is written at the end of the try block, will the finally block still execute?
A: No in this case the finally block will not execute because when you say System.exit (0); the control immediately goes out of the program, and thus finally never executes.

Q: What is daemon thread?
A: Daemon thread is a low priority thread, which runs intermittently in the back ground doing the garbage collection operation for the java runtime system.

Q: Which method is used to create the daemon thread?
A: setDaemon method is used to create a daemon thread.

Q: Which method must be implemented by all threads?
A: All tasks must implement the run() method

Q: What is the GregorianCalendar class?
A: The GregorianCalendar provides support for traditional Western calendars

Q: What is the SimpleTimeZone class?
A: The SimpleTimeZone class provides support for a Gregorian calendar .

Q: What is the difference between the size and capacity of a Vector?
A: The size is the number of elements actually stored in the vector, while capacity is the maximum number of elements it can store at a given instance of time.

Q: Can a vector contain heterogenous objects?
A: Yes a Vector can contain heterogenous objects. Because a Vector stores everything in terms of Object.

Q: What is an enumeration?
A: An enumeration is an interface containing methods for accessing the underlying data structure from which the enumeration is obtained. It allows sequential access to all the elements stored in the collection.

Q: What is difference between Path and Classpath?
A: Path and Classpath are operating system level environment variales. Path is defines where the system can find the executables(.exe) files and classpath is used to specify the location of .class files.

Q: Can a class declared as private be accessed outside it's package?
A: No, it's not possible to accessed outside it's package.

Q: What are the restriction imposed on a static method or a static block of code?
A: A static method should not refer to instance variables without creating an instance and cannot use "this" operator to refer the instance.

Q: Can an Interface extend another Interface?
A: Yes an Interface can inherit another Interface, for that matter an Interface can extend more than one Interface.

Q: Which object oriented Concept is achieved by using overloading and overriding?
A: Polymorphism

Q: What is an object's lock and which object's have locks?
A: An object's lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object's lock.

Q: What is Downcasting?
A: It is the casting from a general to a more specific type, i.e. casting down the hierarchy.

Q: What are order of precedence and associativity and how are they used?
A: Order of precedence determines the order in which operators are evaluated in expressions. Associatity determines whether an expression is evaluated left-to-right or right-to-left.

Q: If a method is declared as protected, where may the method be accessed?
A: A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.

Q: What is the difference between inner class and nested class?
A: When a class is defined within a scope of another class, then it becomes inner class. If the access modifier of the inner class is static, then it becomes nested class.

Q: What restrictions are placed on method overriding?
A: Overridden methods must have the same name, argument list, and return type. The overriding method may not limit the access of the method it overrides.

Q: What is constructor chaining and how is it achieved in Java?
A: A child object constructor always first needs to construct its parent. In Java it is done via an implicit call to the no-args constructor as the first statement.

Q: Can a double value be cast to a byte?
A: Yes, a double value can be cast to a byte.

Q: How does a try statement determine which catch clause should be used to handle an exception?
A: When an exception is thrown within the body of a try statement, the catch clauses of the try statement are examined in the order in which they appear. The first catch clause that is capable of handling the exception is executed. The remaining catch clauses are ignored.

Q: What will be the default values of all the elements of an array defined as an instance variable?
A: If the array is an array of primitive types, then all the elements of the array will be initialized to the default value corresponding to that primitive type.

10 TOP Free JAVA Programing Books for beginners & Experienced

Below are the list of Latest JAVA Programing Books for freshers beginners and experienced pdf free download.

JAVA Programing Books for beginners & Experienced


1. Data Structures and Algorithms with Object-Oriented Design Patterns in Java
Author : Bruno R. Preiss
Download : http://www.brpreiss.com/books/opus5/index.html
Description : Great book to learn data structure and algorithm in Java programming language. Filled with lots of simple but non trivial examples of implementing different data structures e.g. stack, queue, linked list in Java. Since data structure and algorithm are very very important for any Java programmer and quite a common topic in Java interview, it is absolutely must to have a strong command in both. If you are preparing for Java job interviews then you can also take a look at some of my favorite algorithm and data-structures questions, it may help in your preparation. If you like to read paperback edition, you can order it from Amazon as well.
FREE Java Programming Books
2. Java Application Development on Linux
Author : Carl Albing and Michael Schwarz
Download : http://javalinuxbook.com/
Description : A perfect Java book, if you are developing or running Java application on Linux environment, which is the case in most of the investment banks. You can download entire books as PDF, along with all example programs. Carl Albing and Michael Schwarz has done excellent job to to put everything needed to run and support a Java program in Linux environment including how to start, stop, or kill Java process, checking logs with some handy useful UNIX commands. Paperback edition of this book is also available here in Amazon.
Java Application Development on Linux

3.Core Servlets and JavaServer Pages
Author : by Marty Hall and Larry Brown
Download : http://pdf.coreservlets.com/
Description : Servlets and JSP are fundamental Java technologies for developing web applications in Java. Core Servlets and Java Server Pages, teaches you basics of these technologies. You can access all chapter of this book as FREE  PDF online, they are also available for download. Good thing about this Java books, is that source code and lecture notes are also available for FREE download. If you like to read paper book than you can also purchase, paperback edition of this book here

Core Servlets and JavaServer Pages
4. The Java Language Specification, Java SE 7 Edition (Java Series)
Author : James Gosling, Bill Joy, Guy L. Steele Jr., Gilad Bracha, Alex Buckley (Author)
Download : http://docs.oracle.com/javase/specs/jls/se7/jls7.pdf
Description : Official Java language specification for Java SE 7 edition is available online to view as HTML and download as PDF. This is the best FREE resource in Java, as it's from source and contains most up-to-date details about Java Programming language. If you like paperback edition, you can also purchase this books from amazon here.
the Java Language Specification
5. The Java Virtual Machine Specification, Java SE 7 Edition
Author : Tim Lindholm, Frank Yellin, Gilad Bracha, Alex Buckley
Download : http://docs.oracle.com/javase/specs/jvms/se7/jvms7.pdf
Description : Knowledge of Java Virtual Machine is very important for experienced Java developers, to get maximum out of JVM and avoid unnecessary optimization, which can be effectively done by JIT and JVM. For a beginner, It's too much ask, to know more about JVM, but since it's a free Java book, you can always download PDF and read it. Paperback edition of this Java book is also available for purchase in Amazon, here.
Java Virtual Machine Specification
6. The Java Tutorial: A Short Course on the Basics (5th Edition)
Author : Sharon Biocca Zakhour, Sowmya Kannan, and Raymond Gallardo
Download : http://www.oracle.com/technetwork/java/javase/downloads/java-se-7-tutorial-2012-02-28-1536013.html
Description : This is the official Java tutorials from Oracle, which explains different Java concepts in form of short courses e.g. JDBC, JMX, JAXB. All tutorials are available online and you can also download them for free as eBook, available in both .mobi and .epub format, nice to read in iPhone and android phones. If you love paperback edition, you can also order it from Amazon. By the way, these tutorials are really good quality and great way to explore different features of Java Programming language.
Short Course on the Basics
7. Thinking in Java 3rd edition
Author : Bruce Eckel
Download : http://www.mindview.net/Books/TIJ/
Description : Thinking in Java is a Jolt Award winner and one of the classic book to learn Java programming. Third edition of this books is freely available for download and you can download them as PDF format for offline read. By the way, fourth edition of this book is also available which covers most of new Java 5 concepts in detail, but it's NOT FREE. you can purchase that from Amazon. One more thing, first six chapters of Thinking in Java 4th edition is also available in PDF format for free download.
Thinking in Java 3rd edition
8. Introduction to Programming Using Java, Sixth Edition
Author : David J. Eck
Download : http://math.hws.edu/javanotes/
Description : This is another free Java book, which is available in both PDF and HTML format and teaches programming basics using Java programming language. I liked there chapter on Linked Data structure and Recursion, which teaches some of the key programming concept with simple, non trivial Java examples. You can also purchase paperback edition of this book on Amazon .
Introduction to Programming Using Java
9. Processing XML with Java (A Guide to SAX, DOM, JDOM, JAXP, and TrAX
Author : Elliotte Rusty Harold
Download : http://www.cafeconleche.org/books/xmljava/
Description : XML is one of the most desirable skill along with Java. You often need to work with XML files in large projects, as it's one of the most widely used data transport format. This Java book is a comprehensive and up-to-date collection of various XML technology and how to use them with Java programming language. You will learn about different XML parsers e.g. SAX and DOM, JDOM, XPATH and XSLT etc. If your work involve, XML and Java, then this is the book you should read. This Java book is freely available for online read, and you can buy paperback edition from any book store including Amazon.
Processing XML with Java
10. Think Java (How to Think Like a Computer Scientist)
Author : by Allen B. Downey
Download : http://greenteapress.com/thinkapjava/
Description : Don't confuse this book with Thinking in Java, it's different one. This is another great Java book for beginners which is available for FREE. You can download it as PDF or read it online in there site. It covers programming basics, object oriented concepts, essential software development technique, debugging etc. It's actually tailored for students, who wants to give Computer Science advanced placement (AP) exam, but turn out be a great book for any beginner. If you just started learning Java, give it a try. Paperback edition of this book is available in Amazon here.
Think Java
That's all guys, these are some really useful FREE Java books. As we all love free resources, go download them as PDF or view online them as HTML. If you have slow Internet connection, then it's better to download PDF eBooks and read them offline. By the way, nothing can substitute a paperback book, eBooks are good but not for continuous reading. So don't forget to have a paperback edition of at least one Java book, when you start learning Java. If you are absolute beginner then buy Head First Java.

18 LATEST TOP JAVA DESIGN PATTERN Interview Questions and Answers

Below are the list of Latest Java Design Pattern interview questions and answers for freshers beginners and experienced pdf free download.

JAVA DESIGN PATTERN Interview Questions and Answers

JAVA DESIGN PATTERN Interview Questions
JAVA DESIGN PATTERN Interview Questions
1. When to use Strategy Design Pattern in Java?
Strategy pattern in quite useful for implementing set of related algorithms e.g. compression algorithms, filtering strategies etc. Strategy design pattern allows you to create Context classes, which uses Strategy implementation classes for applying business rules. This pattern follow open closed design principle and quite useful in Java. One example of Strategy pattern from JDK itself is a Collections.sort() method and Comparator interface, which is a strategy interface and defines strategy for comparing objects. Because of this pattern, we don't need to modify sort() method (closed for modification) to compare any object, at same time we can implement Comparator interface to define new comparing strategy (open for extension).

2. What is Observer design pattern in Java? When do you use Observer pattern in Java?
This is one of the most common Java design pattern interview question. Observer pattern is based upon notification, there are two kinds of object Subject and Observer. Whenever there is change on subject's state observer will receive notification. See What is Observer design pattern in Java with real life example for more details.

3. Difference between Strategy and State design Pattern in Java?
This is an interesting Java design pattern interview questions as both Strategy and State pattern has same structure. If you look at UML class diagram for both pattern they look exactly same, but there intent is totally different. State design pattern is used to define and mange state of object, while Strategy pattern is used to define a set of interchangeable algorithm and let's client to choose one of them. So Strategy pattern is a client driven pattern while Object can manage there state itself.

4. What is decorator pattern in Java? Can you give an example of Decorator pattern?
Decorator pattern is another popular java design pattern question which is common because of its heavy usage in java.io package. BufferedReader and BufferedWriter are good example of decorator pattern in Java. See How to use Decorator pattern in Java fore more details.

5. When to use Composite design Pattern in Java? Have you used previously in your project?
This design pattern question is asked on Java interview not just to check familiarity with Composite pattern but also, whether candidate has real life experience or not. Composite pattern is also a core Java design pattern, which allows you to treat both whole and part object to treat in similar way. Client code, which deals with Composite or individual object doesn't differentiate on them, it is possible because Composite class also implement same interface as there individual part. One of the good example of Composite pattern from JDK is JPanel class, which is both Component and Container.  When paint() method is called on JPanel, it internally called paint() method of individual components and let them draw themselves. On second part of this design pattern interview question, be truthful, if you have used then say yes, otherwise say that you are familiar with concept and used it by your own. By the way always remember, giving an example from your project creates better impression.

6. What is Singleton pattern in Java? 
Singleton pattern in Java is a pattern which allows only one instance of Singleton class available in whole application. java.lang.Runtime is good example of Singleton pattern in Java. There are lot's of follow up questions on Singleton pattern see 10 Java singleton interview question answers for those followups

7. Can you write thread-safe Singleton in Java?
There are multiple ways to write thread-safe singleton in Java e.g by writing singleton using double checked locking, by using static Singleton instance initialized during class loading. By the way using Java enum to create thread-safe singleton is most simple way. See Why Enum singleton is better in Java for more details.

8. When to use Template method design Pattern in Java?
Template pattern is another popular core Java design pattern interview question. I have seen it appear many times in real life project itself. Template pattern outlines an algorithm in form of template method and let subclass implement individual steps. Key point to mention, while answering this question is that template method should be final, so that subclass can not override and change steps of algorithm, but same time individual step should be abstract, so that child classes can implement them.

9. What is Factory pattern in Java? What is advantage of using static factory method to create object?
Factory pattern in Java is a creation Java design pattern and favorite on many Java interviews.Factory pattern used to create object by providing static factory methods. There are many advantage of providing factory methods e.g. caching immutable objects, easy to introduce new objects etc. See What is Factory pattern in Java and benefits for more details.

10. Difference between Decorator and Proxy pattern in Java?
Another tricky Java design pattern question and trick here is that both Decorator and Proxy implements interface of the object they decorate or encapsulate. As I said, many Java design pattern can have similar or exactly same structure but they differ in there intent. Decorator pattern is used to implement functionality on already created object, while Proxy pattern is used for controlling access to object. One more difference between Decorator and Proxy design pattern is that, Decorator doesn't create object, instead it get object in it's constructor, while Proxy actually creates objects.

11. When to use Setter and Constructor Injection in Dependency Injection pattern?
Use Setter injection to provide optional dependencies of an object, while use Constructor injection to provide mandatory dependency of an object, without which it can not work. This question is related to Dependency Injection design pattern and mostly asked in context of Spring framework, which is now become an standard for developing Java application. Since Spring provides IOC container, it also gives you way to specify dependencies either by using setter methods or constructors. You can also take a look my previous post on same topic.

12. What is difference between Factory and Abstract factory in Java
see  here to answer this Java design pattern interview question.

13. When to use Adapter pattern in Java? Have you used it before in your project?
Use Adapter pattern when you need to make two class work with incompatible interfaces. Adapter pattern can also be used to encapsulate third party code, so that your application only depends upon Adapter, which can adapt itself when third party code changes or you moved to a different third party library. By the way this Java design pattern question can also be asked by providing actual scenario.

14. Can you write code to implement producer consumer design pattern in Java?
Producer consumer design pattern is a concurrency design pattern in Java which can be implemented using multiple way. if you are working in Java 5 then its better to use Concurrency util to implement producer consumer pattern instead of plain old wait and notify in Java.  Here is a good example of implementing producer consumer problem using BlockingQueue in Java.

15. What is Open closed design principle in Java?
Open closed design principle is one of the SOLID principle defined by Robert C. Martin, popularly known as Uncle Bob. This principle advices that a code should be open for extension but close for modification. At first this may look conflicting but once you explore power of polymorphism, you will start finding patterns which can provide stability and flexibility of this principle. One of the key example of this is State and Strategy design pattern, where Context class is closed for modification and new functionality is provided by writing new code by implementing new state of strategy. See this article to know more about Open closed principle.

16. What is Builder design pattern in Java? When do you use Builder pattern ?
Builder pattern in Java is another creational design pattern in Java and often asked in Java interviews because of its specific use when you need to build an object which requires multiple properties some optional and some mandatory. See When to use Builder pattern in Java for more details


17. Can you give an example of  SOLID design principles in Java?
There are lots of SOLID design pattern which forms acronym SOLID, read this list of SOLID design principles for Java programmer  to answer this Java interview question.

18. What is difference between Abstraction and Encapsulation in Java?
I have already covered answer of this Java interview question in my previous post as Difference between encapsulation and abstraction in Java. See there to answer this question. 

52 LATEST TOP QTP Interview Questions and Answers

Below are the list of Latest QTP interview questions and answers for freshers beginners and experienced pdf free download.

QTP Interview Questions and Answers


QTP Interview Questions
QTP Interview Questions and Answers
1) Which environments are supported by QTP?

QTP supports the following environments

  •     Active X
  •     Delphi
  •     Java
  •     .Net
  •     Oracle
  •     People Soft
  •     Power Builder
  •     SAP
  •     Siebel
  •     Stingray
  •     Terminal Emulator
  •     Visual Basic
  •     Visual Age
  •     Web
  •     Web Services

To learn more about Add-ins and how to use them, watch this video tutorial.

2) What are the types object Repositories in QTP.

QTP Supports 2 types of Object Repository

1) Shared Object Repository (also called Global)

2) Per-Action Object Repository, (also called Local)

Per-Action Object Repository is used by default. The extension for Per-Action repository is ".mtr" .

Shared Object Repository is preferable while dealing with dynamic objects which are called in multiple tests. The extension is ".tsr"

3) Can we call QTP test from another test using scripting. Suppose there are 4 tests and I want to call these tests in a main script. Is this possible in QTP?

Yes.  You can call 4 or even more scripts in your tests.For this, first you will need to make the Actions in the corresponding scripts re-usable.Then from the destination script you can make calls to these re-usable actions.

4) What is action split and the purpose of using this in QTP?

Action split is to divide an existing action into two parts.The purpose is to divide actions based on their functionality to improve code re-use.

5) How will you handle Java tree in QTP ?

Foremost you will select Java Add - In and launch QTP. Next step record operations on the Java Tree. If you face an issue while recording, you can select Tools > Object Identification > Java, tree object and make changes in mandatory and assistive properties to enable identification.

Tip: You can base you answer on similar lines for any other object of any environment. For example : If the question is how will check SAP checkbox , You say , first I will select SAP Add in ... and so on.

6) Explain how QTP identifies object ?

QTP identifies any GUI Object based on its corresponding properties.  While recording, QTP will identify and store peculiar properties (as defined in the Object Identification settings) in the object repository of the GUI object . At run-time, QTP will compare the stored property values with the on-screen properties, to uniquely identify the GUI object.

Learn more about Object Identification

7) How many types of recording modes in QTP? Which will be used when ?

QTP supports 3 types of recording modes

1. Normal mode also called Contextual

2. Low-level recording mode

3.Analog mode

Normal Mode: It is the default recording mode and takes full advantage of QTP's Test Object Model. It recognizes objects regardless of their position on -screen. This is the preferred mode of recoding and is used for most of the automation activities.

Low-level recording mode: This mode records the exact x,y co-ordinates of your mouse operations. It is helpful in testing hashmaps. It is useful for recording objects not identified by normal mode of QTP.

Analog mode: This mode records exact mouse and keyboard "movements" you perform in relation to the screen / application window. This mode is useful for the operation such as drawing a picture, recording signature., drag and drop operations.

Learn more about Recording Modes in QTP

8) How will you  call from one action to another action ?

We can call an action in 2 ways

1) Call to copy of Action. - In this ,the Action Object Repository , Script and Datable will be copied to the destination Test Script.
2) Call to Existing Action. - In this,  Object Repository , Script and Datable  will NOT be copied but a call (reference) would be made to the Action in the source script.

9) What are Virtual Objects?

Your application may contain objects that behave like standard objects but are not recognized by QTP. You can define these objects as virtual objects and map them to standard classes, such as a button or a check box. QTP emulates the user's action on the virtual object during the run session. In the test results, the virtual object is displayed as though it is a standard class object.

For example, suppose you want to record a test on a Web page containing a bitmap that the user clicks. The bitmap contains several different hyperlink areas, and each area opens a different destination page. When you record a test, the Web site matches the coordinates of the click on the bitmap and opens the destination page.

To enable QTP to click at the required coordinates during a run session, you can define a virtual object for an area of the bitmap, which includes those coordinates, and map it to the button class. When you run a test, QTP clicks the bitmap in the area defined as a virtual object so that the Web site opens the correct destination page.

10) How to perform Cross platform testing and Cross browser testing using QTP? Can u explain giving some example?

You will need to create separate Actions which take care of different OS and Browsers

Cross Platform Testing:

Using the Built in Environment Variable you can dig up the OS information.

Eg. Platform = Environment("OS"). Then based on the Platform you need to call the actions which you recorded on that particular platform.

Cross Browser Testing:

Using this code  Eg. Browser("Core Values").GetROProperty("version") you can extract the Browser and its correspondin version. Ex: Internet Explorer 6 or Netscape 5. Based on this value you call the actions which are relevant to that browser.

11) What is logical name of the object?

Logical name is a name  given by  QTP while creating an object in the repository to uniquely identify it from other objects in the application. This name would be used by the QTP to map the object name in script with its corresponding description in the object repository. Ex: Browser("Browser").Page("Guru99") Here Guru99 is the logical name of the object.

12) What is descriptive programming?

Typically ,an object and its properties must be recorded in the Object Repository to enable QTP to perform action s on it.

Using descriptive programming , you do not store the object and its property values in the Object repository but mention the property value pair directly in the script.

The idea behind descriptive programming is not bypass the object repository but help recogonize dynamic objects.

Learn more about Descriptive Programming

13)What are the properties you would use for identifying a browser & page when using descriptive programming ?

You can use the name property

ex: Browser("name:="xxx"").page("name:="xxxx"").....

OR

We can also use the property "micClass".
ex: Browser("micClass:=browser").page("micClass:=page")....

14)Can we record an application running on a remote machine using QTP ?

Yes .you can record remote application provided you are accessing application through the local browser not via remoter like citrix.

If you are still unable to record it is advisable install QTP and application, on the same machine

15) Explain the keyword CreateObject with an example.

Creates and returns a reference to an Automation object

SYNTAX: CreateObject(servername.typename [, location])

Arguments
servername: Required. The name of the application providing the object.
typename :  Required. The type or class of the object to create.
location :  Optional. The name of the network server where the object is to be created.


Example : Set IE = CreateObject("InternetExplorer.Application")

16) Can you switch between Per-Action and Shared Object Repository ? If yes how ?

Yes .We can switch. Go to Test--->Settings--->Resources. Here  you have an option to choose repositories.

17) What is Object Spy ? How to Use it ?

Object Spy helps in determining the run & test time object properties & methods of the application under test.

You can access object spy directly from the toolbar or from the Object Repository Dialog Box.

It is very useful during Descriptive Programming

Learn more about Object Spy

18) When ordinal identifiers alone can make an object unique then why they are not given top priority? Why it is first mandatory and next assistive. Why we cannot go for ordinal identifiers directly?

Consider the following -

a) If two objects are overlapped on each other than location based object recognition will fail.

b) If only index based recognition is used your script will work but script execution time will increase.

Hence mandatory and assistive properties are used.

19) What is the file extension of the code file in QTP?

Code file extension is script.mts

20) Explain in brief about the QTP Automation Object Model.

QTP Automation Object model deals with Automation of QTP itself. Almost all configuration and functionality provided by QTP is represented by QTP's Automation Object Model . Almost all dialog boxes in QTP have a corresponding automation object which can set or retrieved using the corresponding properties or methods in the Automation Object Model.QTP Automation Objects can be used along with standard VB programming elements like iterative loops or conditional statements to help you design a script of choice.

21) What is the use of Text output value in QTP?

Text Output values enable you to capture text appearing on the application under test during run-time.

If parameterized, text output values will capture values appearing in each iteration which would be stored in the run-time data table for further analysis.

22) What is Step Generator?

Step Generator enables use to Add Test Steps in your script. Using step generator you can add steps to your script without actually recording it.

23) How to make QTP understand the difference amongst the  same type of objects .Suppose there are 5 check boxes in a page and I have to choose the 2nd one, how to do that through script?

You can use ordinal identifiers like index along with a little descriptive programming for object recognition.

Watch a video of this example.

24) What is Test Fusion Report ?.

Test Fusion Report , displays all aspects of a test run and is organized in a Tree format.

It gives details of each step executed for all iterations.

It also gives Run-time data table, Screen shots and movie of the test run if opted.

25) How can you handle exceptions in QTP?

In QTP Exceptional handling is done by using

a. Recovery Scenarios.
b. Using “On Error” statement

In Recovery scenario you have to define.
1. Triggered Events.
2. Recovery steps.
3. Post Recovery Test-Run.

At Script Level you can use the On Error Resume Next and On Error Go to 0 statement.

26) What are the types of environment variables in QTP ?

Environment variables in QTP are of three types:

1) Built-in (Read only)

2) User-defined Internal (Read only)

3) User-defined External (Read/Write)

You Set the Environment Variable  using the following syntax

Environment.Value( "name") = "Guru99"

You can Retrieve the Environment Variable using following syntax

Environment.Value("name") -- This will retrun name as Guru99

Environment.Value("OS")  -- This will return your system OS

27) What is the Difference between Bitmap Check point & Image Check point?
Bitmap checkpoint does a pixel to pixel comparison of an image or part of an image.

Image checkpoint does do a pixel to pixel comparison but instead compare image properties like alt text , destination url etc.

28) What is the difference between functions and actions in QTP?

Actions have their own Object Repository & Data Table. Actions help make your Test modular and increase reuse. Example: You can divide your script into Actions based on functionality like Login, Logout etc.

Functions is a VB Script programming concept and do not have their own Object Repository or Data Table. Functions help in re-use of your code. Ex:  You can create a Function in your script to concatenate two strings.

29) What is keyword view and Expert view in QTP? 

Keyword View is an icon based view which shows test steps in tabular format. It also automatically generates documentation for the test steps.

Expert View gives the corresponding VB Script statement for every test step in the Keyword view.

30)  Explain QTP Testing process? -

Quick Test testing process consists of 6 main phases:

1)  Create your test plan - This is preparatory phase where you identify the exact test steps, test data and expected results for you automated test. You also identify the environment and system configurations required to create and run your QTP Tests.

2) Recording a session on your application - During this phase , you will execute test steps one by one on your AUT ,and QTP will automatically record corresponding VB script statements for each step performed.

3) Enhancing your test - In this stage you will insert checkpoints , output values , parameterization , programming logic like if…else loops to enhance the logic of your test script.

4) Replay & Debug - After enhancements you will replay the script to check whether its working properly and debug if necessary.

5) Run your Tests - In this phase you will perform the actual execution of your Test Script.

6) Analyzing the test results - Once test run is complete, you will analyze the results in the Test Fusion report generated.

7) Reporting defects - Any incidents identified needs to be reported. If you are using Quality Center , defects can be automatically raised for failed tests in QTP.

31) What are the different types of Test Automation Frameworks ?

The types of Automation Frameworks are -

1) Linear Scripting - Record & Playback

2) The Test Library Architecture Framework.

3)The Data-Driven Testing Framework.

4)The Keyword-Driven or Table-Driven Testing Framework.

Learn more about Test Automation Frameworks.

32) How will you check a web application for broken links using QTP?

You can use the Page Checkpoint which gives a count of valid/invalid links on a page.

33) What is a Run-Time Data Table? Where can I find and view this table?

Data like parameterized output , checkpoint values , output values  are stored in the Run-time Table. It is an xls file which is stored in the Test Results Folder.  It can also be accessed in the Test Fusion Report.

34) What is the difference between check point and output value.

Check point is a verification point that compares a current value for a specified property with the expected value for that property. Based on this comparison, it will generate a PASS or FAIL status.

An output value is a value captured during the test run and can be stored in a specified location like the  Datable or even a variable. Unlike Checkpoints, no PASS/FAIL status is generated.

35) How would you connect to database using vbscript ?

To connect to the database you must know

a) connection string of your server

b) username

c) password

d) DNS name

You can code the database connectivity command directly or you can use the SQL Query tool provided by QTP.

36) What is QTP batch testing tool?

 You can use the Batch testing tool to run multiple scripts. Once the scripts are added in the tool , it  will automatically open the scripts and start executing them one after the other.

37) What are the drawbacks of QTP?

As of QTP version 10

1) Huge Tests in QTP consume lots of memory and increase CPU utilization.

2) Since QTP stores results in HTML file (and not txt) the result folder sometimes becomes big.

38) What is an Optional Step ?

A step when declared optional is not mandatory to be executed. If the corresponding GUI object is present, QTP performs the operation on it. If the GUI object is not present, QTP bypasses the optional step and proceeds to execute the next step.

39) What  is Reporter.ReportEvent ?

Reporter.Reportvent is standard method provided by QTP to send custom messages to the test results window.

Syntax

Reporter.ReportEvent EventStatus, ReportStepName, Details [, ImageFilePath]

where  

EventStatus = 0 or micPass

                    1 or micFail

                    2 or micDone

                    3 or micWarning

 Results can assume any status like Pass , Fail , Warning etc. You can also send screenshot to the test results window.

40) How will you  declare a variable in QTP ?

You declare using a DIM keyword. You assign value to the variable using the SET keyword.

Ex.

Dim temp 'Will declare the temp variable

Set  temp = 20 ' Will assign a value 20 to temp.

41) What is GetRoProperty ?

 GetRoProperty is a standard method provided by QTP to fetch property values of a run -time object.

42) What is smart Identification?

Typically, if even one of the on-screen object property does not match the recorded object property. The test fails.

In smart identification, QTP does not give an error if the property values do not match, but uses Base filter and Optional Filter properties to uniquely identify an object. In Smart identification, if a property value does not match the script does not fail but it proceeds ahead to compare the next property. Smart identification can be enabled in Object Identification Dialog box.

Learn more about SMART Identification

43) How would you export a Script from one PC to another in QTP ?

We can make use of the "Generate Script" function available in Object Identification, Test Settings and Tools/Options tab to create a zip of the script at the source computer. These zip files then can be imported into QTP at the destination computer.

44) Can launch two instances of QTP on the same machine ?

No. You can work with only single instance of QTP on the same machine. But QTP itself can work on multiple instances of the Application Under Test (AUT). Ex:  QTP can handle multiple IE browser windows.

45) Give the syntax to import/export xls into QTP.

DataTable.ImportSheet "..\..\TestData\Input.xls",1,dtGlobalSheet

DataTable.ExportSheet "..\..\Results\Output.xls","Global"

46) What is SetToProperty ?

SetToProperty changes property of an object stored in the Object Repository. However these changes are not permanent.

47) What is the standard timing delay for web based application in QTP ?

The standard delay is 60 seconds. This is can be changed in Test Settigns.

48) What is the Action Conversion Tool ?

It is an in-built tool provided by QTP to convert Actions into Business Process Components.

49) What is the extension for a function library ?

The extension is  '.QFL'

50) If the Global Data sheet contains no data and the Local Datasheet contains two rows of data, how many times will the test iterate?

The test will iterate only once - global iteration.

51)  What factors affect bitmap checkpoints ?

Bitmap checkpoints are affected by screen resolution and image size.

52)  What is Accessibility Checkpoint?

World Wide Web Consortium (W3C) came up with some instructions and guidelines for Web-based technology and information systems to make it easy for the disabled to access the web. For example the standards make it mandatory to have an 'alt text' for an image. So a blind person who is accessing the website, will use text - to -speech converters and atleast understand what the image is about if not see it. All these standards are checked by Accessibility Checkpoints.