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 - Order By Newest | ||||
| ||||
Ans. 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 or hacker over internet. Once a String constant is created in Java , it stays in string constant pool until garbage collected and hence stays there much longer than what's needed. Any unauthorized access to string Pool pose a threat of exposing these values. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  Security  String pool   string immutable  immutability expert   rare | ||||
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 | ||||
Frequently asked. Favorite question in Walk in Drive of many Indian service companies. | ||||
| ||||
Ans. clone() - Creates and returns a copy of this object. equals() - Indicates whether some other object is "equal to" this one. finalize() - Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. getClass() - Returns the runtime class of an object. hashCode() - Returns a hash code value for the object. toString() - Returns a string representation of the object. notify(), notifyAll(), and wait() - Play a part in synchronizing the activities of independently running threads in a program. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   object class Asked in 16 Companies basic   frequent | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. No, because both this and super should be the first statement. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops  this   super   constructor Asked in 1 Companies intermediate   rare | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. Derived object carries the body of its class as well as the body of the parent class. Its body ( member elements ) is initialized using its own class constructor whereas the body ( member elements ) carried from the parent class are initialized using super class constructor. So In order to initialize the elements of the parent class before its own elements are even initialized, super is called. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   constructor   super   inheritance  object oriented programming (oops)  oops concepts   inheritence Asked in 1 Companies intermediate | ||||
| ||||
Ans. Synchronized | ||||
Sample Code for Synchronized | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   threads   multithreading Asked in 2 Companies basic | ||||
| ||||
Ans. All members of a family share a common last name and thats how outsiders recognize them, but to recognize individual team members , we need an overloaded name and hence we use First Name along with Last Name to uniquely identify. Some members of a family have a Nick Name as the real name is very long or hard to call. So the Nick name overrides the Original Name in certain circumstances. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  overloading  overriding Asked in 2 Companies | ||||
Usually asked in relation to casting and ClassCastException. | ||||
| ||||
Ans. The operator instanceOf is used to verify if the specified object is the instance of specified class or interface. Syntax if(x instanceOf ABC) where x is an object reference and ABC could be a class name or interface name. The above statement will be true if x holds an object that is an instance of ABC or any of the child class of ABC or if x holds an object that implements ABC. instanceOf operator is used to verify in case of downcasting. For ex - DerivedClass extends BaseClass x is the reference of BaseClass but holds DerivedClass object ( Polymorphism ) There is an operation that is defined in Derived Class, let's say derivedClassMethod() We cannot call derivedClassMethod() directly using x as x is reference of BaseClass and not DerivedClass and hence can only access methods that are defined in BaseClass and overridden in derived class. Though we can cast it to DerivedClass as following ((DerivedClass)x).derivedClassMethod(); But it may throw ClassCastException in case x doesn't hold an instance of DerivedClass at that point. So before casting it to DerivedClass we may like to make sure that it is an instance of DerivedClass and hence won't throw ClassCastException. So we make a check for it if(x instanceOf DerivedClass) { ((DerivedClass)x).derivedClassMethod(); } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  instanceOf  instanceOf operator  Why we need instanceOf operator  use of instanceOf operator Asked in 2 Companies Intermediate   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. Generics , Enums , Autoboxing , Annotations and Static Import. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java5   generics   enum   autoboxing   annotations   static import   rare | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. 1. Memory is allocated from heap to hold all instance variables and implementation-specific data of the object and its superclasses. Implemenation-specific data includes pointers to class and method data. 2. The instance variables of the objects are initialized to their default values. 3. The constructor for the most derived class is invoked. The first thing a constructor does is call the constructor for its superclasses. This process continues until the constructor for java.lang.Object is called,as java.lang.Object is the base class for all objects in java. 4. Before the body of the constructor is executed, all instance variable initializers and initialization blocks are executed. Then the body of the constructor is executed. Thus, the constructor for the base class completes first and constructor for the most derived class completes last. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   memory management   object creation   advanced   ebay | ||||
| ||||
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 | ||||
Advanced level question usually asked to senior developers , leads and architects. | ||||
| ||||
Ans. Volatile is an instruction that the variables can be accessed by multiple threads and hence shouldn't be cached. As volatile variables are never cached and hence their retrieval cannot be optimized. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java keywords   volatile   synchronization   compiler optimization   variable caching   architecture Asked in 3 Companies expert | ||||
Advanced level question frequently asked in US based companies. Recently asked in EMC and Intuit. | ||||
| ||||
Ans. Simplest implementation we can have is a List wherein we can place ordered words and hence can perform Binary Search. Other implementation with better search performance is to use HashMap with key as first character of the word and value as a LinkedList. Further level up, we can have linked Hashmaps like , hashmap { a ( key ) -> hashmap (key-aa , value (hashmap(key-aaa,value) b ( key ) -> hashmap (key-ba , value (hashmap(key-baa,value) .................................................................................... z( key ) -> hashmap (key-za , value (hashmap(key-zaa,value) } upto n levels ( where n is the average size of the word in dictionary. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   hashmap   binary search   search algorithm   advanced   architecture   data structure Asked in 6 Companies   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 | ||||
Frequently asked to fresh graduates. | ||||
| ||||
Ans. ACID stands for Atomicity, Consistency, Isolation, Durability is a set of properties of database transactions. Atomicity means all or nothing. i.e parts of a transaction shouldn't commit if any one of them fails. Either the whole transaction should succeed or it should be complete rollback. Consistency means that any transaction should lead database from one stabe state to another. Isolation means that the execution of transaction results in a system state that would be obtained if transactions were executed serially. Durability means that when a transaction is committed it forms the permanent state of database. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  database  acid Asked in 7 Companies Intermediate | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. No. Java doesn't allow multi thread access to object constructors so synchronization is not even needed. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  synchronization   synchronize   constructor   java   multithreading   yes-no   advanced Asked in 1 Companies expert   rare | ||||
| ||||
Ans. Spring enables developers to develop enterprise-class applications using POJOs. The benefit of using only POJOs is that you do not need an EJB container product. Spring is organized in a modular fashion. Even though the number of packages and classes are substantial, you have to worry only about ones you need and ignore the rest. Spring does not reinvent the wheel instead, it truly makes use of some of the existing technologies like several ORM frameworks, logging frameworks, JEE, Quartz and JDK timers, other view technologies. Testing an application written with Spring is simple because environment-dependent code is moved into this framework. Furthermore, by using JavaBean-style POJOs, it becomes easier to use dependency injection for injecting test data. Spring is web framework is a well-designed web MVC framework, which provides a great alternative to web frameworks such as Struts or other over engineered or less popular web frameworks. Spring provides a convenient API to translate technology-specific exceptions (thrown by JDBC, Hibernate, or JDO, for example) into consistent, unchecked exceptions. Lightweight IoC containers tend to be lightweight, especially when compared to EJB containers, for example. This is beneficial for developing and deploying applications on computers with limited memory and CPU resources. Spring provides a consistent transaction management interface that can scale down to a local transaction | ||||
Sample Code for spring | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   spring framework   mvc   spring container   architecture   technical architect   java architect   technical lead  ioc Asked in 2 Companies basic   frequent | ||||
| ||||
Ans. 1. Static class is a class which cannot be instantiated and all its members are static whereas Singleton is the class that only permit creation of single object and then the object is reused. 2. As there is no object in Static class, it cannot participate in runtime Polymorphism. 3. As Static class doesnt allow creating objects and hence it cannot be serialized. 4. Static class body is initialized eagerly at application load time whereas Singleton object can be initiated eagerly using static blocks or lazily on first need. 5. Its not recommended to use pure static class as it fails to use many OOPs concepts. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  Static Class  Singleton  Static Class vs Singleton Asked in 3 Companies Intermediate   frequent | ||||
| ||||
Ans. public static void main(String ar[]) { int n=5; if((n/2)*2==n) { System.out.println("Even Number "); } else { System.out.println("Odd Number "); } } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   code   coding   tricky questions   interesting questions   modulus operator Asked in 4 Companies   frequent | ||||
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 | ||||
Frequently asked to experienced developers. Recently asked in many US interviews. | ||||
| ||||
Ans. When multiple external resources are trying to access the DB locks and runs into cyclic wait, it may makes the DB unresponsive. Deadlock can be avoided using variety of measures, Few listed below - Can make a queue wherein we can verify and order the request to DB. Less use of cursors as they lock the tables for long time. Keeping the transaction smaller. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   database   architecture Asked in 7 Companies expert   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's weird that compiler doesn't complain if we declare transient with static variable because it makes no sense. At least a warning message saying "transient is useless in this situation" would have helped with code cleaning. Static variables are never serialized and transient is an indication that the specified variable shouldn't be serialized so its kind of double enforcement not to serialize. It could be that as it makes no different to the variable behavior and hence using both keywords with a variable are permitted. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  static  transient  serialization Asked in 1 Companies expert   rare | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. 1st is a valid and standard declaration. 2nd results in compilation error as only 2 dots are there. 3rd results in compilation error as three dots are not consecutive and broken. 4 through 6 may not be standard and ideal way of declarations but they are valid and will compile and work fine. 7 is valid declaration. 8 and 9 will result in compilation error as var args can only be provided to last argument. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  var args  methods  functions   method declaration  scjp  ocjp | ||||
| ||||
Ans. Because it doesn't make the change in the existing string but would create a new string by concatenating the new string to previous string. So Original string won't get changed but a new string will be created. That is why when we say str1.concat("Hello"); It means nothing because we haven't specified the reference to the new string and we have no way to access the new concatenated string. Accessing str1 with the above code will still give the original string. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  string  string immutable  immutability  string concat | ||||
| ||||
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 | ||||
| ||||
Ans. EFS is file storage whereas S3 is object storage. EFS is filesystem presented over IP network as normal OS drive, while S3 is HTTP accessed store. EFS is capable of being mounted whereas S3 doesn't. S3 has capabilities beyond just filesystem, there is whole metadata part where you can store info about your objects in S3. As S3 is accessed over http , it's capable of hosting a static web site on it's own whereas EFS needs a computing and frontend service to have such capability. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  aws s3  aws storage  amazon cloud storage  amazon s3  aws ehs  aws s3  aws storage  amazon cloud storage  amazon s3 vs aws efs | ||||
Very Frequently asked across all type of companies and across all levels. | ||||
| ||||
Ans. Private - Not accessible outside object scope. Public - Accessible from anywhere. Default - Accessible from anywhere within same package. Protected - Accessible from object and the sub class objects. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oop   access specifier   public   private   default   protected   public vs private vs default vs protected Asked in 12 Companies basic   frequent | ||||
Try 1 Question(s) Test | ||||