Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| ||||
Interview Questions and Answers for 'Infosys' - 97 question(s) found - Order By Newest | ||||
Very frequently asked. Among first few questions in almost all interviews. Among Top 5 frequently asked questions. Frequently asked in Indian service companies (HCL,TCS,Infosys,Capgemini etc based on multiple feedback ) and Epam Systems | ||||
| ||||
Ans. "equals" is the method of object class which is supposed to be overridden to check object equality, whereas "==" operator evaluate to see if the object handlers on the left and right are pointing to the same object in memory. x.equals(y) means the references x and y are holding objects that are equal. x==y means that the references x and y have same object. Sample code: String x = new String("str"); String y = new String("str"); System.out.println(x == y); // prints false System.out.println(x.equals(y)); // prints true | ||||
Sample Code for equals | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   string comparison   string   object class   ==   equals   object equality  operator   == vs equals   equals vs == Asked in 294 Companies basic   frequent | ||||
Try 6 Question(s) Test | ||||
Frequently asked to fresh graduates and less experienced developers. Among the first few questions in many interviews. | ||||
| ||||
Ans. Composition - has-a relationship between objects. Inheritance - is-a relationship between classes. Composition - Composing object holds a reference to composed objects and hence relationship is loosely bound. Inheritance - Derived object carries the base class definition in itself and hence its tightly bound. Composition - Used in Dependency Injection Inheritance - Used in Runtime Polymorphism Composition - Single class objects can be composed within multiple classes. Inheritance - Single class can only inherit 1 Class. Composition - Its the relationship between objects. Inheritance - Its the relationship between classes. | ||||
Sample Code for inheritance Sample Code for composition | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java concepts   inheritance  object oriented programming (oops)  oops concepts   composition  object oriented programming (oops)  oops concepts   inheritance  object oriented programming (oops)  inheritance vs composition  object oriented programming (oops)  oops concepts Asked in 29 Companies basic   frequent | ||||
Try 5 Question(s) Test | ||||
| ||||
Ans. OOPs or Object Oriented Programming is a Programming model which is organized around Objects instead of processes. Instead of a process calling series of processes, this model stresses on communication between objects. Objects that all self sustained, provide security by encapsulating it's members and providing abstracted interfaces over the functions it performs. OOP's facilitate the following features 1. Inheritance for Code Reuse 2. Abstraction for modularity, maintenance and agility 3. Encapsulation for security and protection 4. Polymorphism for flexibility and interfacing | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  oops  oops features Asked in 260 Companies basic   frequent | ||||
Frequently asked at Manhattan Associates ( Based on 2 feedback ) | ||||
| ||||
Ans. Its an anonymous method without any declaration. Lambda Expression are useful to write shorthand Code and hence saves the effort of writing lengthy Code. It promotes Developer productivity, Better Readable and Reliable code. | ||||
Sample Code for lambda | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java8   lambda expression   architecture Asked in 58 Companies expert   frequent | ||||
Try 1 Question(s) Test | ||||
Very frequently asked. Favorite question in Walk in Drive of many Indian service companies. Frequently asked in HCL Technologies, TCS and Accenture. | ||||
| ||||
Ans. final - constant variable, objects cannot be de-referenced, restricting method overriding, restricting class sub classing. finally - handles exception. The finally block is optional and provides a mechanism to clean up regardless of what happens within the try block. Use the finally block to close files or to release other system resources like database connections, statements etc. finalize() - method helps in garbage collection. A method that is invoked before an object is discarded by the garbage collector, allowing it to clean up its state. | ||||
Sample Code for final Sample Code for finally Sample Code for finalize | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   final   finally   finalize   final vs finally vs finalize Asked in 61 Companies basic   frequent | ||||
Try 4 Question(s) Test | ||||
Very frequently asked to Fresh graduates. | ||||
| ||||
Ans. 1.Abstraction solves the problem at design level while encapsulation solves the problem at implementation level 2.Abstraction is used for hiding the unwanted data and giving relevant data. while Encapsulation means hiding the code and data into a single unit to protect the data from outside world. 3. Abstraction lets you focus on what the object does instead of how it does it while Encapsulation means hiding the internal details or mechanics of how an object does something. 4.For example: Outer Look of a Television, like it has a display screen and channel buttons to change channel it explains Abstraction but Inner Implementation detail of a Television how CRT and Display Screen are connect with each other using different circuits , it explains Encapsulation. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   oops concepts   encapsulation  object oriented programming (oops)  oops concepts   abstraction   basic interview question   encapsulation vs abstraction Asked in 10 Companies basic   frequent | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. It means that the type of variables are checked at compile time in Java.The main advantage here is that all kinds of checking can be done by the compiler and hence will reduce bugs. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   statically typed language   variable declaration Asked in 7 Companies basic   frequent | ||||
Very frequently asked. Favorite question in Walk in Drive of many Indian service companies. | ||||
| ||||
Ans. Underlying data structure for ArrayList is Array whereas LinkedList is the linked list and hence have following differences - 1. ArrayList needs continuous memory locations and hence need to be moved to a bigger space if new elements are to be added to a filled array which is not required for LinkedList. 2. Removal and Insertion at specific place in ArrayList requires moving all elements and hence leads to O(n) insertions and removal whereas its constant O(1) for LinkedList. 3. Random access using index in ArrayList is faster than LinkedList which requires traversing the complete list through references. 4. Though Linear Search takes Similar Time for both, Binary Search using LinkedList requires creating new Model called Binary Search Tree which is slower but offers constant time insertion and deletion. 5. For a set of integers you want to sort using quicksort, it's probably faster to use an array; for a set of large structures you want to sort using selection sort, a linked list will be faster. | ||||
Sample Code for ArrayList Sample Code for LinkedList | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  collections   java   data structures   arraylist   linkedlist   arraylist vs linkedlist Asked in 61 Companies Basic   frequent | ||||
Try 1 Question(s) Test | ||||
Frequently asked in Infosys and HCL Technologies ( Based on 2 feedback ) | ||||
| ||||
Ans. Using new operator - new xyzClass() Using factory methods - xyzFactory.getInstance( ) Using newInstance( ) method - (Class.forName(xyzClass))emp.newInstance( ) By cloning an already available object - (xyzClass)obj1.clone( ) | ||||
Sample Code for object initialization using clone Sample Code for object initialization using getInstance | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   object creation   new operator   class.forname   cloning   ebay Asked in 9 Companies expert | ||||
Frequently asked question in companies using Hibernate. | ||||
| ||||
Ans. It's a feature to lazily initialize dependencies , relationship and associations from the Database. Any related references marked as @OneToMany or @ManyToMany are loaded lazily i.e when they are accessed and not when the parent is loaded. | ||||
Sample Code for Lazy Initialization | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hibernate   lazy loading hibernate   lazy initialization hibernate   architecture Asked in 77 Companies Basic   frequent | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. 1. Overriding method can not be more restrictive than the overridden method. reason : in case of polymorphism , at object creation jvm look for actual runtime object. jvm does not look for reference type and while calling methods it look for overridden method. If by means subclass were allowed to change the access modifier on the overriding method, then suddenly at runtime when the JVM invokes the true objects version of the method rather than the reference types version then it will be problematic 2. In case of subclass and superclass define in different package, we can override only those method which have public or protected access. 3. We can not override any private method because private methods can not be inherited and if method can not be inherited then method can not be overridden. | ||||
Sample Code for Overriding | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   overriding   access specifier   inheritence   oops   polymorphism  object oriented programming (oops)  oops concepts   runtime polymorphism  object oriented programming (oops)  oops concepts Asked in 4 Companies | ||||
Try 2 Question(s) Test | ||||
Very Frequently asked. Have been asked in HCL Technologies very frequently ( based on 3 feedback ). Among first few questions in many interviews. | ||||
| ||||
Ans. Abstract classes can have both abstract methods ( method declarations ) as well as concrete methods ( inherited to the derived classes ) whereas Interfaces can only have abstract methods ( method declarations ). A class can extend single abstract class whereas it can implement multiple interfaces. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   classes   abstract class   interfaces   abstract class vs interface   abstract classes vs interfaces Asked in 82 Companies basic   frequent | ||||
Basic and Very Frequently asked. | ||||
| ||||
Ans. Polymorphism means the condition of occurring in several different forms. Polymorphism in Java is achieved in two manners 1. Static polymorphism is the polymorphic resolution identified at compile time and is achieved through function overloading whereas 2. Dynamic polymorphism is the polymorphic resolution identified at runtime and is achieved through method overriding. | ||||
Sample Code for overloading Sample Code for overriding | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  polymorphism  object oriented programming (oops)  oops concepts  oops concepts Asked in 108 Companies Basic   frequent | ||||
Try 2 Question(s) Test | ||||
Frequently asked in Infosys India | ||||
| ||||
Ans. String pool (String intern pool) is a special storage area in Java heap. When a string is created and if the string already exists in the pool, the reference of the existing string will be returned, instead of creating a new object and returning its reference. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   string   string class   string pool   heap memory Asked in 31 Companies intermediate   frequent | ||||
Try 2 Question(s) Test | ||||
Very Frequently asked to fresh graduates and less experienced. Favorite question in Walk in drives. Frequently asked in Indian Services companies. | ||||
| ||||
Ans. Overloading - Similar Signature but different definition , like function overloading. Overriding - Overriding the Definition of base class in the derived class. | ||||
Sample Code for overloading Sample Code for overriding | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   overloading   overriding   oops concepts   basic interview question   overloading vs overriding Asked in 86 Companies basic   frequent | ||||
Try 1 Question(s) Test | ||||
Frequently asked in Cognizant (CTS) | ||||
| ||||
Ans. Storing the state of an object in a file or other medium is called serialization. Classes can communicate only if they are built together ( as they need Byte code for communication ). What if we need to enable communication between different applications ( i.e they have been built independently or even they reside at different locations ), We need a mechanism that will transfer the Bean state to a Medium than can be transferred to the receiving application. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   serialization Asked in 18 Companies basic   frequent | ||||
Try 1 Question(s) Test | ||||
Frequently asked in Cognizant ( Based on 2 feedback ) | ||||
| ||||
Ans. Inner join is the intersection of two tables on the condition defined by the where clause i.e will get records from both tables matched by a column. Outer join is the union of two tables i.e will get all records from both tables and will put null in the columns where related records are not present. Left Outer join is the left union of two tables i.e all records from the table on the left and values from the right table for related records else null for the columns from right table. Right Outer join is the right union of two tables i.e all records from the table on the right and values from the left table for related records else null for the columns from left table. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  sql  inner join  outer join  right join  left join Asked in 24 Companies basic   frequent | ||||
Very frequently asked across all types of companies. | ||||
| ||||
Ans. Hashtable is synchronized whereas HashMap is not.HashMap allows null values whereas Hashtable doesnt allow null values. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   hashmap   map   hashtable   hashmap vs hashtable Asked in 14 Companies basic   frequent | ||||
Try 2 Question(s) Test | ||||
Advanced level question usually asked in High end product companies. Have been asked in Google and Amazon (Based on 1 Feedback) | ||||
| ||||
Ans. The Java runtime environment deletes objects when it determines that they are no longer being used. This process is known as garbage collection. The Java runtime environment supports a garbage collector that periodically frees the memory used by objects that are no longer needed. The Java garbage collector is a mark-sweep garbage collector that scans Java dynamic memory areas for objects, marking those that are referenced. After all possible paths to objects are investigated, those objects that are not marked (i.e. are not referenced) are known to be garbage and are collected. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   garbage collection   java memory management   advanced Asked in 21 Companies intermediate   frequent | ||||
Try 4 Question(s) Test | ||||
Frequently asked question in companies using hibernate. | ||||
| ||||
Ans. 1. First level cache is enabled by default whereas Second level cache needs to be enabled explicitly. 2. First level Cache came with Hibernate 1.0 whereas Second level cache came with Hibernate 3.0. 3. First level Cache is Session specific whereas Second level cache is shared by sessions that is why First level cache is considered local and second level cache is considered global. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hibernate   orm   hibernate cache   architecture   technical lead   first level cache vs second level cache Asked in 18 Companies Intermediate   frequent | ||||
Very frequently asked. Favorite question in Walk in Drive of many Indian service companies. | ||||
| ||||
Ans. Its a method which cannot be overridden. Compiler throws an error if we try to override a method which has been declared final in the parent class. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   final   final method Asked in 30 Companies basic   frequent | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   data types   casting  type casting   basic interview question Asked in 8 Companies basic   frequent | ||||
Very frequently asked. Favorite question in Walk in Drive of many Indian service companies. | ||||
| ||||
Ans. They are different the way their elements are stored in memory. TreeMap stores the Keys in order whereas HashMap stores the key value pairs randomly. | ||||
Sample Code for treemap Sample Code for hashmap | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   map   treemap   hashmap   treemap vs hashmap Asked in 31 Companies basic   frequent | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. Session tracking is a mechanism that servlets use to maintain state about a series requests from the same user across some period of time. The methods used for session tracking are: User Authentication - occurs when a web server restricts access to some of its resources to only those clients that log in using a recognized username and password Hidden form fields - fields are added to an HTML form that are not displayed in the client's browser. When the form containing the fields is submitted, the fields are sent back to the server URL rewriting - every URL that the user clicks on is dynamically modified or rewritten to include extra information. The extra information can be in the form of extra path information, added parameters or some custom, server-specific URL change. Cookies - a bit of information that is sent by a web server to a browser and which can later be read back from that browser. HttpSession- places a limit on the number of sessions that can exist in memory. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  j2ee   servlets   session   session management   web applications   cookies   httpsession   url rewriting   architecture Asked in 1 Companies | ||||
Very frequently asked in companies using SOA. | ||||
| ||||
Ans. REST or Representational State Transfer is a flexible architecture style for creating web services that recommends the following guidelines - 1. http for client server communication, 2. XML / JSON as formatiing language , 3. Simple URI as address for the services and, 4. stateless communication. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   web services   rest   java   j2ee  architecture Asked in 14 Companies intermediate   frequent | ||||
Almost sure to be asked in every company using any Dependency Injection framework ( Spring, Guice etc ) | ||||
| ||||
Ans. It is a Design Pattern that facilitates loose coupling by sending the dependency information ( object references of dependent object ) while building the state of the object. Objects are designed in a manner where they receive instances of the objects from other pieces of code, instead of constructing them internally and hence provide better flexibility. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  design patterns   ioc ( Inversion of Control )  dependency injection Asked in 83 Companies intermediate   frequent | ||||
| ||||
Ans. JDK(Java Development kit) = Development Kit comprising of JVM , library and development tools for developers JRE (Java Run time Environment) - Comprise of JVM and set of libraries JVM(Java Virtual Machine) = Interpreter which reads the .class file line by line. When we install JDK, JRE also get installed so we can write,compile and excute our code. Used by developer. Without JDK we can only execute the program using JRE. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  jvm  jre  jdk  jvm vs jre vs jdk Asked in 4 Companies | ||||
Very frequently asked.Usually among first few questions. | ||||
| ||||
Ans. MVC is a Design Pattern that facilititates loose coupling by segregating responsibilities in a Web application 1. Controller receives the requests and handles overall control of the request 2. Model holds majority of the Business logic, and 3. View comprise of the view objects and GUI component | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  j2ee   mvc   mvc design pattern   design pattern   struts   spring   web application   web frameworks   ebay Asked in 60 Companies basic   frequent | ||||
Try 1 Question(s) Test | ||||
Frequently asked to fresh graduates and less experienced. | ||||
| ||||
Ans. Inheritance means a object inheriting reusable properties of the base class. Compositions means that an abject holds other objects. In Inheritance there is only one object in memory ( derived object ) whereas in Composition , parent object holds references of all composed objects. From Design perspective - Inheritance is "is a" relationship among objects whereas Composition is "has a" relationship among objects. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   oops concepts   inheritance  object oriented programming (oops)  oops concepts   composition  object oriented programming (oops)  oops concepts   difference between   basic interview question Asked in 12 Companies basic   frequent | ||||
Try 2 Question(s) Test | ||||
Very frequently asked. Usually asked in different variants like Diff between StringBuffer , String Builder ; Difference between StringBuilder and String class; Choice between these classes etc. | ||||
| ||||
Ans. A string buffer implements a mutable sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls. The String class represents character strings. All string literals in Java programs, such as "abc" are constant and implemented as instances of this class; their values cannot be changed after they are created. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   string   stringbuffer   frequently asked Asked in 18 Companies basic   frequent | ||||
Try 1 Question(s) Test | ||||