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 | ||||
| ||||
Ans. Parameters are the variables that the method is expected to receive along with the method call. Arguments are the values which are passed on while calling the methods. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  parameter   argument   method   function   parameter vs argument basic | ||||
| ||||
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 | ||||
| ||||
Ans. Constructors are used for initializing the object state once it is initialized and memory has been reserved for it. Destructor is used to de-allocate memory allocated by objects. There are no destructors in Java. Alternatively, Java provides Automatic garbage collection i.e automatically releasing the un-referenced memory. | ||||
Sample Code for constructor | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  constructors  destructors Asked in 2 Companies | ||||
Try 1 Question(s) Test | ||||
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. Yes, That is possible class A { public static void main(String args[]){ if(System.out.printf("Hello World")==null){} } } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  Hello World  Hello world without ; Asked in 2 Companies   rare | ||||
| ||||
Ans. Because of the life cycle requirement for different type of values in java. variables initialized and used in functions needs to be destructed with the execution of function and hence kept in stack. Same is applicable for the object references initialized within the method. If objects would have been created in stack, they wouldnt have been passed around across methods and hence they are created on heap. So anything that is required beyond the scope of a method or function is kept on heap which is usually garbage collected by Java. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  memory management  heap  stack | ||||
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. Inner Class is a class that is nested within another class whereas sub class is a class that extends or inherit another class. Inner class can only be accessed using reference of outer class ( Class name , if inner class is static or object reference, if inner class is non static ) whereas Sub class is accessed directly. In terms of memory, inner class is stored just like another class having it's own body whereas sub class carries the body of parent class as well as it's own fields in memory. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  inner classes  nested classes  inner class vs sub class  nested class vs sub class Basic | ||||
| ||||
Ans. In Breadth first algorithm, all the adjacent nodes of the starting node is visited first and then the same rule is followed while moving inwards whereas In Depth first algorithm, all the nodes of a single traversal path are visited first till a cycle or an end is found. For example , given the following entries of adjacent nodes 1,2 1,3 1,6 2,4 2,5 3,6 The Breadth first path would be 1,2,3,6,4,5 and Depth first path would be 1,2,4,5,3,6 | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  graph traversal  breadth first vs depth first   frequent | ||||
| ||||
Ans. No. It will result in a type mismatch error. Collection<Collection> collection = new LinkedList<Collection>(); is a valid initialization as collection being reference of "Collection" class can hold object of derived Class "LinkedList" due to runtime Polymorphism. Runtime polymorphism is not applicable to type arguments. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  generics  type argument | ||||
| ||||
Ans. With Collection classes , we cannot use primitive types. Moreover for any class using generic types, we cannot use primitive types. They add more functionality by means of additional methods. As their reference can be null , they offer consistent check for uninitialized state. They facilitate caching and reuse by means of constant Pools. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  wrapper classes  benefits of wrapper classes over primitives | ||||
| ||||
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. CloudFront for Static Media and cached content EC2 and EKS ( Docker ) for main application computing RDS and DynamoDB for Database Lambda ( computing ) for running back end cron jobs Kinesis for streaming and SQS for queuing CloudWatch for Monitoring CloudFormation for Infrastructure templating S3 for Object Storage | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve   | ||||
| ||||
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. S3 Standard S3 IA - Infrequently Accessed S3 One Zone IA - One Zone only , Infrequently Accessed S3 Glacier - achieved S3 Standard is most expensive , Glacier is least expensive | ||||
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 | ||||
| ||||
Ans. Storage Tier ( IA , Standard , Glacier etc ) Storage ( Volume of Data ) No of Requests Meta Data Data Transfer Speed acceleration through cache and Edge Location | ||||
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 | ||||
| ||||
Ans. EC2 - Time and Reservation , Instance Type ( Memory , Computation power ) S3 - Accessibility Frequency , Data Transfer , Storage Space CloudFront - Geography, No of Locations EBS - IOPS, Access Frequency | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  aws ec2  aws computing  amazon cloud computing  amazon ec2  aws s3  aws storage  amazon cloud storage  amazon s3  aws cloudfront  amazon cloudfront  aws ebs | ||||
| ||||
Ans. Simple Weighted Latency Failover GeoLocation Multivalue | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  aws route53 Asked in 1 Companies | ||||
| ||||
Ans. A VPC is devided into multiple subnets. Subnet in a particular VPC could be public or private. For Example - A particular account may have multiple vpc's for each of the business type. For each Business or VPC , One can have different subnets to cater to each department so that access across departments could be restricted. But still there could be identities that have control over different subnets. Moreover we could have multiple subnets for each department so as to have distinguished public and private networks having different types of applications ( public facing or internal consumption ) | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  aws vpc  aws subnet  subnet  vpc  Amazon Web Services (AWS) | ||||
| ||||
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 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 | ||||
| ||||
Ans. Java doesn't support multiple inheritance. Interfaces does't facilitate inheritance and hence implementation of multiple interfaces doesn't make multiple inheritance. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oop   oop concepts   inheritence   multiple inheritence   basic interview question Asked in 10 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 | ||||
| ||||
Ans. Yes , for HashMap. HashMap implements Map interface. HashMap allows one null key and any number of 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   yes-no Asked in 1 Companies | ||||