LATEST UPDATES

Friday 18 November 2016

What is the difference between continue and break statement?



Break and continue are two important keywords used in Loops. When a break keyword is used in a loop, loop is broken instantly while when continue keyword is used, current iteration is broken and loop continues with next iteration.

In below example, Loop is broken when counter reaches 4.



for (counter=0;counter
System.out.println(counter);
 
if (counter==4) {
 
break;}
 
}



In the below example when counter reaches 4, loop jumps tonext iteration and any statements after the continue keyword are skipped for current iteration.



for (counter=0;counter
System.out.println(counter);
 
if (counter==4) {
 
continue;
 
}
 
System.outprintln("This will not get printed when counter is 4");
 
}
Java

1

for (counter=0;counter

What is a singleton class? Give a practical example of its usage.

A singleton class in java can have only one instance and hence all its methods and variables belong to just one instance. Singleton class concept is useful for the situations when there is a need to limit the number of objects for a class.
The best example of singleton usage scenario is when there is a limit of having only one connection to a database due to some driver limitations or because of any licensing issues.

What’s the purpose of Static methods and static variables?

When there is a requirement to share a method or a variable between multiple objects of a class instead of creating separate copies for each object, we use static keyword to make a method or variable shared for all objects.

What are the various access specifiers for Java classes?

1. Public : Class,Method,Field is accessible from anywhere.
2. Protected:Method,Field can be accessed from the same class to which they belong or from the sub-classes,and from the class of same package,but not from outside.
3. Default: Method,Field,class can be accessed only from the same package and not from outside of it’s native package.
4. Private: Method,Field can be accessed from the same class to which they belong.

What is the difference between an Inner Class and a Sub-Class?

An Inner class is a class which is nested within another class. An Inner class has access rights for the class which is nesting it and it can access all variables and methods defined in the outer class.
A sub-class is a class which inherits from another class called super class. Sub-class can access all public and protected methods and fields of its super class.

What is the difference between throw and throws ?

The throw keyword is used to explicitly raise a exception within the program.

The throws clause is used to indicate those exceptions that are not handled by a method.

Each method must explicitly specify which exceptions does not handle, so the callers of that method can guard against possible exceptions. 

Finally, multiple exceptions are separated by a comma.

What is the difference between HashSet and TreeSet ?


  • The HashSet is Implemented using a hash table.
  • Its elements are not ordered. 
  • The add, remove, and contains methods of a HashSet.
  • Time  complexity O(1). 



  •  TreeSet is implemented using a tree structure. 
  • The elements in a TreeSet are sorted.
  • The add, remove, and contains methods.
  • Time complexity  O(logn).

What is Comparable and Comparator interface ? List their differences.

Java provides the Comparableinterface, --> which contains only one method, called compareTo

  1. This method compares two objects, in order to impose an order between them. Specifically, it returns a negative integer, zero, or a positive integer to indicate that the input object is less than, equal or greater than the existing object. 



Java provides the Comparator interface, --> which contains two methods, called compare and equals


  1. The first method compares its two input arguments and imposes an order between them. It returns a negative integer, zero, or a positive integer to indicate that the first argument is less than, equal to, or greater than the second. 
  2. The second method requires an object as a parameter and aims to decide whether the input object is equal to the comparator. The method returns true, only if the specified object is also a comparator and it imposes the same ordering as the comparator.

What is difference between ArrayList and LinkedList ?


1) ArrayList internally uses dynamic array to store the elements.
LinkedList internally uses doubly linked list to store the elements.

2) Manipulation with ArrayList is slow because it internally uses array. If any element is removed from the array, all the bits are shifted in memory.
Manipulation with LinkedList is faster than ArrayList because it uses doubly linked list so no bit shifting is required in memory.

3) ArrayList class can act as a list only because it implements List only.
LinkedList class can act as a list and queue both because it implements List and Deque interfaces.


4) ArrayList is better for storing and accessing data.
LinkedList is better for manipulating data.

What is difference between Array and ArrayList ? When will you use Array over ArrayList ?

  • Arrays can contain primitive or objects, while an ArrayList can contain only objects.
  • Arrays have fixed size, while an ArrayList is dynamic.
  • An ArrayListprovides more methods and features, such as addAllremoveAlliterator, etc.
  • For a list of primitive data types, the collections use autoboxing to reduce the coding effort. However, this approach makes them slower when working on fixed size primitive data types.

Array
ArrayList
Arrays are data structures that can store elements of similar data type.
ArrayList is a collection that can store elements of similar data type as well as elements of different data type.
Along with objects, Arrays can also store elements of primitive data type.
ArrayList cannot store elements of primitive data type. ArrayList can store only objects.
Array size is fixed.
ArrayList is resizable. Its size is not fixed.
While declaring and creating the Array, the size is specified in square brackets []. For example,
int[] intArray = new int[10]
The above statement creates an integer array of size 10. After creating it, its size cannot be changed. It cannot hold more than 10 elements.
ArrayList has a special parameter called initialCapacity using which the initial size of the ArrayList is specified. Later on, the ArrayList can be resized.
Array cannot automatically grow or shrink in size.
ArrayList has the capability to automatically grow and shrink in size. When an element is removed from the ArrayList, its size is reduced by 1. When an element is added to the ArrayList and if its initial capacity is reached then the size is automatically increased by 1.
Array is not part of collection framework. Arrays are directly defined in java language as a basic data structure.
ArrayList is part of Collection framework.
Arrays inherit from java.lang.Object.
ArrayList implements List interface and inherits AbstractList class.
Generics cannot be used along with Arrays.
When elements of similar data type have to be stored in an ArrayList then the ArrayList will use generics.
Arrays can be single dimensional or multi dimensional.
ArrayList can only be single dimensional.
Arrays are present in java.lang package. However a customized array class is present in java.util package. This java.util.Arrays has the capability to perform binary search, copy of another array, fill, sort and much more using its predefined methods.
ArrayList is present in java.util package. ArrayList also has rich predefined methods such as add, addAll, remove, toArray, iterator, listiterator, sort, reverse and much more.
Arrays can be iterated through a simple for loop by iterating over its index.
ArrayList can be iterated using Iterator or ListIterator.
Arrays cannot be synchronized.
ArrayList can be synchronized.
Array elements are accessed using its index. The index ranges from 0 to array length-1.
ArrayList elements are accessed using get() and other specialized methods.

What differences exist between HashMap and Hashtable ?


    1. HashMap allows the existence of null keys and values, 
    2. Hashtable doesn’t allow neither null keys, nor null values.

    1. Hashtable is synchronized.
    2. while a HashMap is not.

    1.  HashMap is preferred in single-threaded environments.
    2.  Hashtable is suitable for multi-threaded environments.

    1. HashMap provides its set of keys and a Java application can iterate over them.
    2. Hashtable provides an Enumeration of its keys.

What is the importance of hashCode() and equals() methods ?


  • In Java, a HashMap uses the hashCode and equals methods to determine the index of the key-value pair and to detect duplicates.
  • More specifically, the hashCodemethod is used in order to determine where the specified key will be stored. 
  • Since different keys may produce the same hash value, the equals method is used, in order to determine whether the specified key actually exists in the collection or not.
  • Therefore, the implementation of both methods is crucial to the accuracy and efficiency of the HashMap.

How HashMap works in Java ?


  • The HashMap requires a hash function and uses hashCode and equals methods, in order to put and retrieve elements to and from the collection respectively. 
  • When the put method is invoked, the HashMap calculates the hash value of the key and stores the pair in the appropriate index inside the collection. 
  • If the key exists, its value is updated with the new value. 
  • Some important characteristics of a HashMap are its capacity, its load factor and the threshold resizing.

Java Collections

Java Collections Framework provides a well designed set of interfaces and classes that support operations on a collections of objects. The most basic interfaces that reside in the Java Collections Framework are:
  • Collection, which represents a group of objects known as its elements.
  • Set, which is a collection that cannot contain duplicate elements.
  • List, which is an ordered collection and can contain duplicate elements.
  • Map, which is an object that maps keys to values and cannot contain duplicate keys.

What is the difference between a synchronized method and a synchronized block ?

In Java programming, each object has a lock. 
A thread can acquire the lock for an object by using the synchronized keyword. 
The synchronized keyword can be applied in a method level  or block level of code.

Explain the available thread states in a high-level.

  • NEW: The thread becomes ready to run, but does not necessarily start running immediately.
  • RUNNABLE: The Java Virtual Machine (JVM) is actively executing the thread’s code.
  • BLOCKED: The thread is in a blocked state while waiting for a monitor lock.
  • WAITING: The thread waits for another thread to perform a particular action.
  • TIMED_WAITING: The thread waits for another thread to perform a particular action up to a specified waiting time.
  • TERMINATED: The thread has finished its execution.

Explain different ways of creating a thread. Which one would you prefer and why ?

There are three ways that can be used in order for a Thread to be created:
  • A class may extend the Thread class.
  • A class may implement the Runnable interface.
  • An application can use the Executor framework, in order to create a thread pool.
The Runnable interface is preferred, as it does not require an object to inherit the Thread class. 

What is the difference between an Interface and an Abstract class ?

Interface  v/s  Abstract class


  • All methods in an interface are implicitly abstract
  • Abstract class may contain both abstract and non-abstract methods.

  • A class may implement a number of Interfaces
  • Abstract class can extend only one abstract class


  • In order for a class to implement an interface, it must implement all its declared methods. However, a class may not implement all declared methods of an abstract class. Though, in this case, the sub-class must also be declared as abstract.
  • Abstract classes can implement interfaces without even providing the implementation of interface methods.

  • Variables declared in a Java interface is by default final.
  • An abstract class may contain non-final variables.

  • Members of a Java interface are public by default.
  • A member of an abstract class can either be private, protected or public.

Does Java support multiple inheritance ?

No, Java does not support multiple inheritance. Each class is able to extend only on one class, but is able to implement more than one interfaces.

Can you access non static variable in static context ?


  • A static variable in Java belongs to its class and its value remains the same for all its instances.
  • A static variable is initialized when the class is loaded by the JVM.
  • If your code tries to access a non-static variable, without any instance, the compiler will complain, because those variables are not created yet and they are not associated with any instance.

What does the “static” keyword mean ? Can you override private or static method in Java ?

The static keyword denotes that a member variable or method can be accessed, without requiring an instantiation of the class.


  • User cannot override static methods in Javabecause method overriding is based upon dynamic binding at run time.
  • Static methods are statically binded at compile time
  • A static method is not associated with any instance of a class so the concept is not applicable.

What is the Difference between JDK and JRE ?


  • The Java Runtime Environment (JRE) is
    •  Basically the Java Virtual Machine (JVM) 
    • Where your Java programs are being executed. 
    • It also includes browser plugins for applet execution. 
  • The Java Development Kit (JDK) is 
    • The full featured Software Development Kit for Java, including the JRE, the compilers and tools (like JavaDoc, and Java Debugger), in order for a user to develop, compile and execute Java applications.


Tuesday 12 April 2016

Java questions - part 10

1. How many objects are created in the following piece of code?
My class C1, C2, C3;
C1 = new Myclass ();
C2 = new Myclass ();

Exp:           Only 2 objects are created, C1 and C3. The reference C2 is only declared and not initialized.

2. Can a public class 'Myclass' be defined in a source file named 'Yourclass.java'?

Exp:           The source file name, if it contains a public class, must be the same as the public name itself with a  .java extension.

3. Can main() method be declared final?

Exp:           Yes, the main() method can be declared final, in addition to being public static.

4. What is HashMap and Map?

Exp:           Map is an interface and Hashmap is the class that implements Map.

5. Difference between HashMap and HashTable?

Exp:           The HashMap class is roughly equivalent to HashTable, except that it is unsynchronised and permits nulls. (HashMap allows null values as key and value whereas HashTable doesnot allow).
          HashMap does not guarantee that the order of the Map will remain constant over time. HashMap is unsynchronised and HashTable is synchronised.

6. Difference between Vector and ArrayList?

Exp:           Vector is synchronised whereas ArrayList is not.

7. Difference between Swing and Awt?

Exp:           Awt are heavy-weight components. Swings are light-weight components. Hence Swing works faster than Awt.

8. What will be the default values of all the elements of an array defined as an instance variable?

Exp:           If the array is an array of primitive types, then all the elements of the array will be initialised to the default value corresponding to that primitive type.           Example: All the elements of an array of Int will be initialised to 0 (zero), while that of booleab type will be initialised to false. Whereas if the array is an array of reference (of any type), all the elements will be initialised to null. 

Thursday 31 March 2016

SDLC INTERVIEW QUESTIONS--1

1. What is SDLC?
Exp:          The various activities which are undertaken when developing software are commonly modelled as a software development life cycle.
The software development life cycle begins with the identification of a requirement for software and ends with the format verification of the developed software against that requirement.

2. what is the " software life cycle"?
Exp:          The life cycle begins when an application is first concieved and ends when it is no longer in use.

3. Is it necessary to use SDLC for software development?
Exp:          Because software can be very difficult and complex. Without SDLC you may end up producing low quality product, you may take more time to complete the project against the actual time to deliver the product, you may go over budget. SDLC provides well-defined, disciplined, efficient, approach in solving business and information technology problems. You can also calculate budget, and appropriate time to deliver the product.
It provides control/monitor over the process of application development, what all steps to be followed, defines and focus on roles and responsibilities provides a predefined level of precision to facilitate a complete, correct and predictable solution, enforces planning and control.

4. Different phases of SDLC.
Exp:          Requirement, Analysis, Designing, coding and unit testing, testingk, UAT, maintenance.

5. Requirement Phase
Exp:          By Interacting with the customer, we establish the service that the customer requires from a system and the constraints under which it operate are developed. How the system should react to particular inputs and how the system should behave in a particular situation. Definition of the function or entity. Description of inputs and where they come from. Descriptions of outputs and where they go to, Inter dependency of the functions. Pre and post conditions. The side effects (if any) of the function.  Business Analist (BA)/Domain Expert - usually MBA with atleast 8-10 years of domain specific experience who will understand the requirement or the business needs of the organisations. Specific what type of a project it is, whether it is a complete new project, or to rewrite the existing systems, or it is Maintenance project. Defines the type of the task the system should do. What type of SDLC to follow.

6. Who is Business Analyst?
Exp:          He is the one who collects the data from the stake holder, where in the raw requirements are processed into functional objectivers. The documentation of the requirement is done or a use can document, a prototype is developed, He uses some data flow diagrams to establish the requirement specification. Because just by natural langusre the developer doesn't understand the actual requirements and may not be able to develop the product. Estimation of the project is done.

7. Analysis phase
Exp:          In this phase decisions on a technology for software development based on several factors --- Cost, existing licences on software, licencing cost, scalability of the application, etc., out come of this phase is technology and software, Software Architecture Document (SAD) SAD is prepared by Architect - BE/MTech/MCA with atleast 15+ experience, will be having high level knowledge on all the technology for eg. COM, DCOM in .NET, Springs, hibernate in J2EE, ABAP in SAP, etc.,

8. Software Architecture Document
Exp:          SAD is not a design document. It sets some specifications like how it should be done. It provides some means of tracability between the requirements and the final system design to be implemented. The purpose of the SAD is provide
  1. An outline description of the software Architecture, including major software components and their interactions.
  2. A common understanding of the architectural principles used during design and implementation.
  3. A description of the hardware and software platforms on which the system is built and deployed.
  4. Explicit justification of how the architecture meets the non-functional requirements.

9. Design phase
Exp:          High level design: Designers (BE/MTech/MCA) with 10+ years experience in a particular technology.
  • First they describe what the system is (whether it is a distributed or client-server etc.,)
  • What platforms the system will run on .....
  • The major inputs and output
  • What uses interfaces the system will have and in what form (Web, Windows GUI, etc.,)
  • High level design/software architecture document is given to the client, framework, database schema of the application is described.
  • Design patterns are established.

Low level design :-- Designers (BE/MTech/MCA) with 10+ years of experience in a particular technology.
  • Class diagram and Sequence diagram
  • Low level design document containing class diagram sequence diagrams given to the developers.
  • DB is designed, cvs is configured and base version is put into it.

10. What is project planning?
Exp:         Project planning defines in detail the project activities and the product that will be produced, and describes how the project activities will be accomplished. Project planning defines all major tasks, estimates the size of the project, the scope of the effort, the resources required to complete the project, if any new technology is required and those technical experts are not their then you got appoint them, as well as steps to produce a project schedule, identify, assess and manage risks and negotiate commitments.
  • Risks is probability that some adverse circumstances will occur ........ risks like risks that affect the schedule or resources are not available.

11. Implementation (coding and unit testing)
Exp:          A team with TL, CL are appointed who do the coding part to develop the software .......                     *developers (BE/MTech/MCA) with 0-6 years of experience come into picture .....................

12. How do you assign tasks to the team
Exp:          First of all you got to know the technical ability of a programmer, for this purpose you got to do is ask some general technical questions or assign some task depending on the technology. By doing so you come to know their technical ability and then accordingly you can divide the tasks among the team.

13. Why customer developer partnership is important
Exp:          The success of any product depends on the customer satisfaction and remarks. Customer is constantly involved from the start of the project till delivery of the product he has to be kept informed about the progress of the project. When ever you develop and module you got to cross verify with the customer whether it meets the business goals.

14. What are the roles of  TL and CL?
Exp:          TL is concerned with getting the work done on scheduled time, motivate the team members, conduct meetings with the team members, hr maintains an excel sheet of the project progress states, if any project member faces any problems he has to give solutions to them...........
CL would first create cvs repository and corresponding login, would check in the base version. He has to take care that check in is conducted properly on a daily basis. Once check in is done he would take a fresh check out and would take build of it and if any error found then on which module and who has done it, would ask him to correct it and once every thing is fine then next day everybody can check out blindly.

15. How were the issues being handled
Exp:          If there is any issue that needs to be taken care of then you mention it in a excel sheet, the TL would conduct a meeting and get the issue resolved depending on the type of a issue whether  it is a db related or prototype or technical, correspondingly the meeting is conducted and get the issue resolved.

16. What is code review
Exp:          Once the module or coding is completed you perform a code review the reviewer would check the module whether documentation is done or not if any errors in a program, if exception handling is not then would specify the status as fatal in excel sheet and so on.

17. Testing phase
Exp:          A testing team would conduct number of testing on the application. In generally the types of testings are 
Defect testing :- To discover faults or defects in the software where its behavior is incorrect or not in sync with specification.
Component testing :- In the module wise testing test cases are written for the module and run against module. Choose inputs that force the system to generate all error messages. Design inputs that cause buffer to overflow and so on.
Performance and reliability test :- A series of tests are done where in the load is steadily increased until the system performance becomes unacceptable.
Stress testing :- In the sense system should not fail catastrophically, loss of series of data.
Black box testing :- Its also said as release test or functionality test. Testing to find defects int he system, first for such and such a input this should be the output, for invalid inputs this should be the output and so on.

18. User Acceptance testing:-
Exp:          Client performs the test before accepting the product.


E-Mail : shanth73@gmail.com
Designed By Blogger Templates