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 'Cognizant (cts)' - 88 question(s) found - Order By Newest | ||||
Advanced level question. Frequently asked in High end product companies. Frequently asked in Google , Cognizant and Deloitte ( Based on 2 feedback ) | ||||
| ||||
Ans. 1. String Pool - When a string is created and if it exists in the pool, the reference of the existing string will be returned instead of creating a new object. If string is not immutable, changing the string with one reference will lead to the wrong value for the other references. Example - String str1 = "String1"; String str2 = "String1"; // It doesn't create a new String and rather reuses the string literal from pool // Now both str1 and str2 pointing to same string object in pool, changing str1 will change it for str2 too 2. To Cache its Hashcode - If string is not immutable, One can change its hashcode and hence it's not fit to be cached. 3. Security - String is widely used as parameter for many java classes, e.g. network connection, opening files, etc. Making it mutable might possess threats due to interception by the other code segment. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   string   string class   immutable  immutability   advanced Asked in 39 Companies expert   frequent | ||||
Try 4 Question(s) Test | ||||
Very frequently asked in different variations. Frequently asked in Deloitte ( 2 feedback ) , HCL Tech ( 3 feedback ), TCS and Coginizant (CTS) | ||||
| ||||
Ans. If the Object value will not change, use String Class because a String object is immutable. If the Object value can change and will only be modified from a single thread, use StringBuilder because StringBuilder is unsynchronized(means faster). If the Object value may change, and can be modified by multiple threads, use a StringBuffer because StringBuffer is thread safe(synchronized). | ||||
Sample Code for String Sample Code for StringBuffer Sample Code for StringBuilder | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   string class   string   stringbuilder   stringbuffer   String vs StringBuffer   String vs StringBuilder   String vs StringBuilder vs StringBuffer   StringBuffer vs stringBuilder Asked in 29 Companies basic   frequent | ||||
Try 3 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 | ||||
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. 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 | ||||
| ||||
Ans. By putting code within static method. With Java 6 and earlier versions, even static block can be used. | ||||
Sample Code for static block | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   static   static method   static block Asked in 3 Companies basic   frequent | ||||
Try 1 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 | ||||
Frequently asked in all types of companies especially Indian Services companies. Frequently asked in CTS (Based on 2 feedback) | ||||
| ||||
Ans. Hashcode is used for bucketing in Hash implementations like HashMap, HashTable, HashSet etc. The value received from hashcode() is used as bucket number for storing elements. This bucket number is the address of the element inside the set/map. when you do contains() then it will take the hashcode of the element, then look for the bucket where hashcode points to and if more than 1 element is found in the same bucket (multiple objects can have the same hashcode) then it uses the equals() method to evaluate if object are equal, and then decide if contain() is true or false, or decide if element could be added in the set or not. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   hashcode   advanced  hashtable Asked in 33 Companies intermediate   frequent | ||||
Try 1 Question(s) Test | ||||
Recently asked in TCS , Tech Mahindra, HCL , Accenture and Fidelity. | ||||
| ||||
Ans. The DispatcherServlet configured in web.xml file receives the request. The DispatcherServlet finds the appropriate Controller with the help of HandlerMapping and then invokes associated Controller. Then the Controller executes the logic business logic and then returns ModeAndView object to the DispatcherServlet. The DispatcherServlet determines the view from the ModelAndView object. Then the DispatcherServlet passes the model object to the View. The View is rendered and the Dispatcher Servlet sends the output to the Servlet container. Finally Servlet Container sends the result back to the user. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  j2ee   spring   mvc   frameworks   web applications   architecture Asked in 11 Companies Basic   frequent | ||||
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 | ||||
| ||||
Ans. Car Engine is an example of encapsulation and abstraction. You ignite the car using an interface called starter and least bothered about how the tire actually moves (This is abstraction). The engine encapsulates the complete process to itself only and doesn't allow you to start the other components like the radiator etc ( this is excapsulation ) | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  encapsulation  object oriented programming (oops)  oops concepts  abstraction  oops  oops features  java features Asked in 13 Companies | ||||
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 | ||||
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 | ||||
Frequently asked to fresh graduates and less experienced. | ||||
| ||||
Ans. 1. public is the access modifier that makes the method accessible from anywhere, static is the keyword that makes it accessible even without creating any object, void means it doesn't return anything , String args[] is the array of argument that the method receives. 2. If we use main without the string args , it will compile correctly as Java will treat it as just another method. It wont be the method "main" which Java looks for when it looks to execute the class and hence will throw Error: Main method not found in class , please define the main method as: public static void main(String[] args) 3. Main is not a keyword but a special string that Java looks for while initiating the main thread. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   main method Asked in 4 Companies basic   frequent | ||||
Try 1 Question(s) Test | ||||
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. It in Java is used to indicate that a field should not be serialized. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   serialization   transient   java keywords Asked in 39 Companies intermediate   frequent | ||||
Try 2 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 | ||||
Frequently asked to fresh graduates and less experienced developers. | ||||
| ||||
Ans. 1. Multithreading provides better interaction with the user by distribution of task 2. Threads in Java appear to run concurrently, so it provides simulation for simultaneous activities.The processor runs each thread for a short time and switches among the threads to simulate sim-ultaneous execution (context-switching) and it make appears that each thread has its own processor.By using this feature, users can make it appear as if multiple tasks are occurring simultaneously when, in fact, each is running for only a brief time before the context is switched to the next thread. 3. We can do other things while waiting for slow I/O operations.In the java.iopackage, the class InputStreamhas a method, read(), that blocks until a byte is read from the stream or until an IOExceptionis thrown. The thread that executes this method cannot do anything elsewhile awaiting the arrival of another byte on the stream. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   threads   multi threading  concurrency   multithreading Asked in 5 Companies intermediate   frequent | ||||
Try 1 Question(s) Test | ||||
Frequently asked to fresh graduates. | ||||
| ||||
Ans. Runnable - waiting for its turn to be picked for execution by the thread schedular based on thread priorities. Running - The processor is actively executing the thread code. It runs until it becomes blocked, or voluntarily gives up its turn. Waiting: A thread is in a blocked state while it waits for some external processing such as file I/O to finish. Sleeping - Java threads are forcibly put to sleep (suspended) with Thread.sleep. they can resume using Thread.resume method. Blocked on I/O - Will move to runnable after I/O condition like reading bytes of data etc changes. Blocked on synchronization - Will move to Runnable when a lock is acquired. Dead - The thread is finished working. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   threads   multi threading   scheduling   thread states   basic interview question Asked in 1 Companies basic   frequent | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. ConcurrentHashMap is a hashMap that allows concurrent modifications from multiple threads as there can be multiple locks on the same hashmap. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   hashmap   map   concurrenthashmap   concurrenthashmap  concurrency   general electric   ge Asked in 32 Companies   rare | ||||
| ||||
Ans. HBM Files ( Mapping ) DB Connection ( DB Connection String , User Name , Password , Pool Size ) SQL Dialect ( SQL variant to be generated ) Show SQL ( Show / No show SQL on Console ) Auto Commit ( True / False ) | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hibernate   configuration   barclays Asked in 11 Companies | ||||
Frequently asked. Among first few questions in the J2EE segment of interview. | ||||
| ||||
Ans. Deployment Descriptor which is usually web.xml is used to specify the classes, resources and configuration of the application and how the web server uses them to serve web requests.This file is usually added to WEB-INF folder and contains following * Servlet entries and url mapping * Plugins * Some info regarding authentication / filters * Landing Page * Event Handlers | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  web.xml   servlets  deployment descriptor Asked in 15 Companies basic   frequent | ||||
Try 1 Question(s) Test | ||||
Frequently asked in Indian Service Companies. Tech Mahindra ( Based on 3 inputs ) and Infosys ( 3 inputs ) | ||||
| ||||
Ans. List - Members are stored in sequence in memory and can be accessed through index. Set - There is no relevance of sequence and index. Sets doesn't contain duplicates whereas multiset can have duplicates. Map - Contains Key , Value pairs. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   list   set   map   list vs set vs map Asked in 8 Companies basic   frequent | ||||
Try 1 Question(s) Test | ||||
Frequently asked at HCL Technologies ( Based on 3 feedback ) | ||||
| ||||
Ans. Checked exceptions are the exceptions for which compiler throws an errors if they are not checked whereas unchecked exceptions are caught during run time only and hence can't be checked. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   exceptions   checked exceptions   unchecked exceptions   exception handling   checked vs unchecked exceptions Asked in 39 Companies basic   frequent | ||||
Try 1 Question(s) Test | ||||
Very Frequently asked. Usually asked along with String Class related questions. | ||||
| ||||
Ans. Class using which only immutable (objects that cannot be changed after initialization) objects can be created. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   immutable  immutability   immutable  immutability class   string class   basic interview question Asked in 18 Companies Basic   frequent | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java5   autoboxing   wrapper classes Asked in 2 Companies basic   frequent | ||||
| ||||
Ans. It is the process of examining / modifying the behaviour of an object at runtime. | ||||
Sample Code for reflection | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   reflection   reflection api   ebay   mindtree Asked in 29 Companies basic   frequent | ||||