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. boolean - java.lang.Boolean byte - java.lang.Byte char - java.lang.Character double - java.lang.Double float - java.lang.Float int - java.lang.Integer long - java.lang.Long short - java.lang.Short void - java.lang.Void | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java5   data types   wrapper classes   adapter design pattern   rare | ||||
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 | ||||
| ||||
Ans. They are wrappers to primitive data types. They allow us to access primitives as objects. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   data types   wrapper classes Asked in 3 Companies basic   frequent | ||||
| ||||
Ans. Cookie and Session are used to store the user information. Cookie stores user information on client side and Session does it on server side. Primarily, Cookies and Session are used for authentication, user preferences, and carrying information across multiple requests. Session is meant for the same purpose as the cookie does. Session does it on server side and Cookie does it on client side. One more thing that quite differentiates between Cookie and Session. Cookie is used only for storing the textual information. Session can be used to store both textual information and objects. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  session   session management   java   cookies   authentication   web application   ebay intermediate | ||||
| ||||
Ans. The JDBC is a pure Java API used to execute SQL statements. It provides a set of classes and interfaces that can be used by developers to write database applications. The steps needed to execute a SQL query using JDBC: 1. Open a connection to the database. 2. Execute a SQL statement. 3. Process th results. 4. Close the connection to the database. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   jdbc   db connectivity Asked in 2 Companies basic   frequent | ||||
| ||||
Ans. We can make a class immutable by 1. Making all methods and variables as private. 2. Setting variables within constructor. Public Class ImmutableClass{ private int member; ImmutableClass(int var){ member=var; } } and then we can initialize the object of the class as ImmutableClass immutableObject = new ImmutableClass(5); Now all members being private , you cant change the state of the object. | ||||
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   technical lead Asked in 5 Companies intermediate   frequent | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. Yes.we cannot access them directly but we can access them using object reference.Static methods belong to a class and not objects whereas non static members are tied to an instance. Accessing instance variables without the instance handler would mean an ambiguity regarding which instance the method is referring to and hence its prohibited. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   static   static methods   java keywords Asked in 1 Companies | ||||
Frequently asked to fresh graduates. | ||||
| ||||
Ans. When two threads are waiting each other and cant precede the program is said to be deadlock. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   threads   multi threading   operating system   deadlock  concurrency Asked in 23 Companies basic   frequent | ||||
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 | ||||
| ||||
Ans. Predicate represents an anonymous function that accepts one argument and produces a result. Supplier represents an anonymous function that accepts no argument and produces a result. Consumer represents an anonymous function that accepts an argument and produces no result. | ||||
Sample Code for Predicate Sample Code for Supplier Sample Code for Consumer | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java8   predicate   consumer   supplier   lambda expression   predicate vs consumer vs supplier expert | ||||
| ||||
Ans. 1. Query Optimization ( Query Rewriting , Prepared Statements ) 2. Restructuring Indexes. 3. DB Caching Tuning ( if using ORM ) 4. Identifying the problems ( if any ) with the ORM Strategy ( If using ORM ) | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   db   database   hibernate   orm   at&t   overstock.com   performance improvement   architecture   technical lead   architect intermediate | ||||
| ||||
Ans. Encapsulation | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java concepts   java features   oops concepts   oops features   access protection   information hiding | ||||
| ||||
Ans. There are 2 reasons for it. 1. Usage of Primitive types - Though Java provides classes for the primitive data types but as the usage of primitives is permissible, its considered unpure OOP's language. 2. Usage of Static members - Static members belong to the class and not objects and hence not considered fit for pure OOP's programming. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  oops  object oriented programming  object oriented language  primitive data types Asked in 2 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 | ||||
| ||||
Ans. HashTable has been deprecated. As an alternative, ConcurrentHashMap has been provided. It uses multiple buckets to store data and hence much better performance than HashTable. Moreover, there is already a raw type HashMap. The only difference between the HashTable and HashMap is that Hashtable is synchronized whereas HashMap is not. Most of the synchronized collections have been deprecated and their raw alternative have been presented as preferred.Synchronization has a cost. Using synchronized collection in places where there is no need of it leads to useless utilization of resources. As these collections are rarely used in a static context or shared among threads, Java might have thought it better to just provide the raw collection and let developers implement synchronization if he feels the need to do so. HashMap is now presented as the default and the preferred way of using Map with read optimized hashing, and ConcurrentHashMap has been provided for synchronized access which provides better performance than HashTable. Because of this, Java thought it right to deprecate the use of HashTable.' Synchronization has a cost. Using synchronized collection at a place where there is hardly any need of it would means useless utilization of resources. As these collections are rarely used in static context or shared among threads, Java might have thought it better to just provide the raw collection and let developer implement synchronization if he feels the need to do so. As HashMap has been presented as default and preferred way of using Map with read optimized hashing, and ConcurrentHashMap has been provided for synchronized access which provides better performance than HashTable, Java thought it right to deprecate the use of HashTable. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hashtable  synchronized collections  Why synchronized collections have been deprecated  Why HashTable has been deprecated  HashTable vs HashMap expert | ||||
Try 3 Question(s) Test | ||||
| ||||
Ans. 1. HashSet doesnt maintain its elements in any specific order and is all random whereas TreeSet maintains elements in natural order 9 order defined by the equals method of TreeSet element type ) 2. TreeSet doesnt allow null elements whereas HashMap does. 3. As TreeSet orders elements and is hence insertion is comparatively slower. 4. HashSet performs basic operations like add(), remove(), contains(), size() etc. in a constant size time. A TreeSet performs these operations at the order of log(n) time. 5. HashMap in Java internally backs a HashSet. A NavigableMap backs a TreeSet internally. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  collections  hashset  treeset  set   hashet vs treeset Asked in 4 Companies Basic   frequent | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. 1. Objects are serialized and not classes and hence Static variables are ignored. 2. Transient is an explicit declaration to ignore the variable during serialization and hence transient instance variables are ignored too. 3. Base class instance variables if the base class hasn't been declared serializable. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  serialization Asked in 1 Companies intermediate   frequent | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. First expects the argument as a string array whereas second expects variable number of string arguments or a string array. So we can call both by providing string array as an argument but second can be called with 0 to n string arguments which cannot be done for first. for example - We can call second method with any of following method(); method("Hello"); method("Hello","World"); method(new String[4]); | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  var args  methods  method declarations  functions | ||||
| ||||
Ans. We are not resizing the first array here but assigning the reference strArray to a new Array with size 5. So after line 2, We have 2 arrays in memory, one with size 2 and other with size 5 with strArray referring to second array with size 5. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  arrays  array initialization | ||||
| ||||
Ans. A Region is a Geographical entity like US-East , US-West etc. Each Region may have multiple availability zones where each zone comprise of 1 or more Data Center located with each other. Edge Locations are the sites that hosts cached content for faster delivery and for saving network traffic as they feed content from sites that are local or near to consumption. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  aws region  aws availability zone  aws edge location  region vs availabillity zone | ||||
| ||||
Ans. Simple Inner Class, Local Inner Class, Anonymous Inner Class, Static Nested Inner Class. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   inner classes   classes Asked in 6 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. Favorite question in Walk in Drive of many Indian service companies. | ||||
| ||||
Ans. Final variable is a variable constant that cannot be changed after initialization. | ||||
Sample Code for final variable | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  oops   java   final   final variable   basic interview question Asked in 12 Companies basic   frequent | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. They are loaded at runtime when the respective Class is loaded. | ||||
Sample Code for static variable | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   static   static variable   memory intermediate | ||||
| ||||
Ans. No. Only Object and its members are serialized. Static variables are shared variables and doesn't correspond to a specific object. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  serialization   java   oops   static   static variables Asked in 1 Companies intermediate   rare | ||||
Try 2 Question(s) Test | ||||
Usually asked only to fresh graduates. | ||||
| ||||
Ans. In preemptive scheduling, highest priority task continues execution till it enters a not running state or a higher priority task comes into existence. In time slicing, the task continues its execution for a predefined period of time and reenters the pool of ready tasks. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  operating system   scheduling   threads   multi threading   rare | ||||
| ||||
Ans. One should make sure that all the included objects are also serializable. If any of the objects is not serializable then it throws a NotSerializable Exception. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  serialization   java   oops   object expert | ||||
| ||||
Ans. Vectors are synchronized whereas Array lists are not. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   basic interview question   vector   arraylist   collections   synchronization   vector vs arraylist Asked in 35 Companies basic   frequent | ||||