Interview Question and Answers | Search Coding Interview Questions - javasearch.buggybread.com
Javasearch.buggybread.com

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.
Label / Company      Label / Company / Text

   



Interview Questions and Answers

   next 30
 Q111. What is a stream and what are the types of Streams and classes of the Streams?Core Java
Ans. A Stream is an abstraction that either produces or consumes information. There are two types of Streams :

Byte Streams: Provide a convenient means for handling input and output of bytes.

Character Streams: Provide a convenient means for handling input & output of characters.

Byte Streams classes: Are defined by using two abstract classes, namely InputStream and OutputStream.

Character Streams classes: Are defined by using two abstract classes, namely Reader and Writer.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   file io   streams   byte stream   character stream  file handling     Asked in 3 Companies


 Q112. what is covariant return type? Core Java
Ans. co-variant return type states that return type of overriding method can be subtype of the return type declared in method of superclass. it has been introduced since jdk 1.5

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   inheritence   overriding   covariant return type   jdk5   advanced     Asked in 3 Companies      expert


 Q113. What is a ConcurrentHashMap ?Core Java
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


 Q114. What are the contents of Hibernate configuration file ( hibernate.cfg.xml ) ?Hibernate
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


 Q115. Difference between Predicate, Supplier and Consumer ? Core Java
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


 Q116. What things you would care about to improve the performance of Application if its identified that its DB communication that needs to be improved ?Solution
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


 Q117. Why do we need Thread class even in case we execute thread using runnable interface ?Core Java
Ans. Thread class holds the definition of start method ( This is the method that starts execution of new thread and then calls run method within the scope of new thread ). Interfaces don't hold any definition and so does runnable. So it makes it necessary the usage of Thread class , whatever implementation you choose.

When your class extends the thread class, it carries the definition of start method from parent Thread class onto itself and hence new yourClass.start() helps starting a new thread and then executing run method in that new thread scope.

When you implement runnable interface , you are just making it sure to the JVM that you have implemented the required method ( run() ) which the Thread start method will look for upon executing start method.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   threads   multithreading   runnable interface   thread class


 Q118. Collections.sort can only be performed on ..

a. Set
b. List
c. Map
d. Any Collection implementation
Core Java
Ans. List

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     collections   java   sorting

Try 2 Question(s) Test


 Q119. Which of the following Java feature promotes access protection or Hiding ?

a. Inheritance
b. Encapsulation
c. Abstraction
d. Composition
Core Java
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


 Q120. Enums cannot be declared ..

a. private
b. public
c. static
d. final
Core Java
Ans. final

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   enum


 Q121. Difference between parameters and arguments ?Core Java
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


 Q122. Why Java is not considered pure OOP's language ?Core Java
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


 Q123. What are constructors and Destructors in Java ?Core Java
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.
  Q124. What is deployment descriptor ?

or

What is the use of deployment descriptor ?
Java EE
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


 Q125. Why HashTable has been deprecated ?Core Java
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


 Q126. Difference beween HashSet and TreeSet ?Core Java
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


 Q127. Can you write a "Hello World" program without using any ";" within it?Core Java
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


 Q128. Why two types of memory - stack and heap are required by Java ?Core Java
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


 Q129. Which elements of a class are ignored during serialization ?Core Java
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


 Q130. What is the difference between these two method declarations ?

private static void method(String[] arg)

and

private static void method(String... arg)
Core Java
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


 Q131. What is the difference between inner class and sub class ?Core Java
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


 Q132. What is the difference between Graph's Breadth first and Depth First algorithm ?Algorithm
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


 Q133. Is this a valid initialization ? Explain.

Collection<Collection> collection = new LinkedList<LinkedList>();
Core Java
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


 Q134. What are the benefits of using Wrapper classes over primitive types ?Core Java
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


 Q135. If arrays cannot be resized , Why is this code valid

String[] strArray = new String[2];
strArray = new String[5];
Core Java
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


 Q136. Design an e commerce application using AWS ? What AWS services will you use ?Amazon Web Services (AWS)
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     


 Q137. Difference between Region , Availability zone and Edge Locations ?Amazon Web Services (AWS)
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


 Q138. What are the different S3 storage Tiers ?Amazon Web Services (AWS)
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


 Q139. What are the factors on which customers are charged for using S3 ?Amazon Web Services (AWS)
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


 Q140. What are the factors on which price classes are based on in case of EC2, S3, CloudFront and EBS ?Amazon Web Services (AWS)
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


previous 30   next 30

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: