Java - Interview Questions and Answers - Intermediate Level | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Java Interview Questions


 2098 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers - Intermediate Level - 99 question(s) found - Order By Newest

 Q1. Why do we need Inner classes ? Cant we just work with outer classes wherever we implement Inner classes ?Core Java
Admin
info@buggybread.com
Ans. Yes, we can substitute outer classes wherever we need to have inner classes but Inner classes have advantage in certain cases and hence preferred -

Ease - Why to implement a class outside if its objects are only intended to be part of an outer object. Its easy to define the class within another class if the use is only local.

Protection - Making a call an outer exposes a threat of it being used by any of the class. Why should it be made an outer class if its object should only occur as part of other objects.

For example - You may like to have an class address whose object should have a reference to city and by design thats the only use of city you have in your application. Making Address and City as outer class exposes City to any of the Class. Making it an inner class of Address will make sure that its accessed using object of Address.

  Sample Code for 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   objects   technical lead      intermediate

Try 1 Question(s) Test


 Q2. What are the common uses of "this" keyword in java ?Core Java
Anonymous
Ans. "this" keyword is a reference to the current object and can be used for following -

1. Passing itself to another method.

2. Referring to the instance variable when local variable has the same name.

3. Calling another constructor in constructor chaining.

  Sample Code for this keyword

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

   Like      Discuss      Correct / Improve     java   this   object reference   constructor chaining      intermediate        rare

Try 3 Question(s) Test


 Q3. What are the benefits of JSON over XML ?Json
Anonymous
Ans. Lighter and faster than XML as on-the-wire data format

Object Representation - Information is presented in object notations and hence better understandable.

Easy to parse and conversion to objects for information consumption.

Support multiple data types - JSON supports string, number, array, boolean whereas XML data are all string.

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

   Like      Discuss      Correct / Improve     json   markup language     QualiTest      intermediate        frequent

Try 1 Question(s) Test


 Q4. Can we use both "this()" and "super()" in a constructor ?Core Java
Anonymous
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      intermediate        rare

Try 2 Question(s) Test


 Q5. Why every object constructor automatically call super() in Object before its own constructors?Core Java
Admin
info@buggybread.com
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   inheritence     Itech      intermediate


Advanced level question usually asked in High end product companies. Have been asked in Google and Amazon (Based on 1 Feedback)
  Q6. Describe, in general, how java's garbage collector works ?Core Java
Anonymous
Ans. The Java runtime environment deletes objects when it determines that they are no longer being used. This process is known as garbage collection. The Java runtime environment supports a garbage collector that periodically frees the memory used by objects that are no longer needed. The Java garbage collector is a mark-sweep garbage collector that scans Java dynamic memory areas for objects, marking those that are referenced. After all possible paths to objects are investigated, those objects that are not marked (i.e. are not referenced) are known to be garbage and are collected.

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

   Like      Discuss      Correct / Improve     java   garbage collection   java memory management   advanced     LinkedIn  Infosys  Google  Netflix  Amazon  Huawei Technologies  JP Morgan  enGenius  CitiusTech  Goldman Sachs  Bank Of America India  Salesforce  Addteq  Criteo  Capgemini  Horizon Solutions      intermediate        frequent

Try 4 Question(s) Test


  Q7. What is a String Pool ?Core Java
Anonymous
Ans. String pool (String intern pool) is a special storage area in Java heap. When a string is created and if the string already exists in the pool, the reference of the existing string will be returned, instead of creating a new object and returning its reference.

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

   Like      Discuss      Correct / Improve     java   oops   string   string class   string pool   heap memory     SAS Institute  Ariba  GuideWire  Harbinger  Oracle  Virtusa  Knoa  Polaris  GuideWire  HCL Technologies  Tata Consultancy (TCS)  Infosys  Technologent  MphasiS  Harbinger Group  Kony  Evergent  NTT Data  VMware  Markit  Ariba  Tech Mahindra  Bureau Veritas  InfoStretch  PTC Software  Mindtree  Centre for Internet and Society (CIS)  Trimax IT Infrastructure & Services      intermediate        frequent

Try 2 Question(s) Test


Very frequently asked in phone and walk in interviews.
  Q8. What are Marker Interfaces ? Name few Java marker interfaces ?Core Java
Anonymous
Ans. These are the interfaces which have no declared methods.Serializable and cloneable are marker interfaces.

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

   Like      Discuss      Correct / Improve     java   oops   interfaces   marker interface   serializable   clonable     Qualtech Consultants  Computer Sciences Corporation (CSC)  Addteq  Infosys  Synechron  Amdocs  JPMorgan Chase  Qualtech Consultants  Velopsys Technologies  Amdocs  Ericsson  Oracle  Avaya  Copart  Innoplexus  Volvo Information Technology      intermediate        frequent

Try 1 Question(s) Test


 Q9. Difference between Static and Singleton Class ?Core Java2016-11-30 21:00:43

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     Netflix  EPAM  Ebay      Intermediate        frequent



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



Frequently asked question in companies using hibernate.
  Q10. Difference between first level and second level cache in hibernate ?Hibernate
Admin
info@buggybread.com
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     EFI  Geometric  QuinStreet  Cognizant (CTS)  ZS Associates  Walt Disney      Intermediate        frequent


Almost sure to be asked in every company using any Dependency Injection framework ( Spring, Guice etc )
  Q11. What is Dependency Injection or IOC ( Inversion of Control ) ?Design

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     Nucleus Software Exports  HCL Technologies  Tata Consultancy (TCS)  HCL  Infosys  Cognizant (CTS)  Barclays  General Electric  Infosys Technologies  Elsevier  Sabre  ZapCom  Nike  Sogeti  CSG International  Lowes  DWS  Mitsui Bussan Logistics  Payment Processing Partners  Liquidnet  AmTrust Financial  VectorForm  Cybage  Vanderbilt University  Cigniti  Accenture  Ball Aerospace  GE Healthcare  1-800 Contacts  VinSolutions  Arrow Electronics  Monitise  Avenue Code  Thetus Corporation  Shodogg  Levi9  BuildLinks  Suyati Technologies  Kanerika Software  Alliance Inspection Management  Promega  Victorious  Zoll Data Systems  Parkmobile  PerceptiMed  Crate and Barrel  Carbonite  Concur  Codazen  GlobalLogic  AccuSoft  Attinad  Tillster  AppRiver  TrustPilot  Pearson  Kony  Art Technology Group  VeriSign  Accion Labs  IGS Energy  National Bankruptcy Services  RealPage  Green Dot  Indecomm Global  bebo Technologies  Open Solutions  Xoriant  NCR  Macmillan Cancer Support  NetSuite  Asynchrony Labs  DealDash  Vizio  Fiserv  Federal Reserve Bank of Minneapolis  Tinder  FICO  Trustwave      intermediate        frequent


Frequently asked to fresh graduates.
 Q12. What is ACID ?Database2016-11-04 08:09:44

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     CapitalOne   Tata Consultancy (TCS)  SilverRail Technologies  A9.com  Oracle  Sirius Computer Solutions      Intermediate

Try 1 Question(s) Test


 Q13. Which elements of a class are ignored during serialization ?Core Java2017-01-12 11:08:21

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     HCL Technologies      intermediate        frequent

Try 1 Question(s) Test


 Q14. Does Constructor creates the object ?Core Java
Anonymous
Ans. New operator in Java creates objects. Constructor is the later step in object creation. Constructor's job is to initialize the members after the object has reserved memory for itself.

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

   Like      Discuss      Correct / Improve     java   constructor   object creation      intermediate        rare


 Q15. When are static variables loaded in memory ?Core Java
Anonymous
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


 Q16. Can we serialize static variables ?Core Java
Anonymous
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     Deloitte      intermediate        rare

Try 2 Question(s) Test


Frequently asked to fresh graduates and less experienced developers.
 Q17. Explain multithreading in Java ?Core Java
Anonymous
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     Hamsini ECommerce   Cognizant (CTS)  Cumulus Systems  Cognizant (CTS)      intermediate        frequent

Try 1 Question(s) Test


Frequently asked in all types of companies especially Indian Services companies. Frequently asked in CTS (Based on 2 feedback)
 Q18. What is the use of hashcode in Java ?Core Java
Anonymous
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     Cognizant (CTS)  Compro Technologies  VigLink  Proofpoint      intermediate        frequent

Try 1 Question(s) Test


 Q19.  What is the role of JSON.stringify ?Json
Anonymous
Ans.  JSON.stringify() turns an object into a JSON text and stores that JSON text in a string. 

So If we stringfy above notation , it will become

{"name":"xyz","gender":"male";"age":30}

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

   Like      Discuss      Correct / Improve     json   JSON.stringify      intermediate        rare



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q20. Can I import same package/class twice? Will the JVM load the package twice at runtime?Core Java
Anonymous
Ans. One can import the same package or same class multiple times. Neither compiler nor JVM complains wil complain about it. And the JVM will internally load the class only once no matter how many times you import the same class.

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

   Like      Discuss      Correct / Improve     java   import   jvm   advanced     Gateway Media      intermediate        rare


Frequently asked question for intermediate developers.
  Q21. What is Volatile keyword used for ?Core Java
Anonymous
Ans. Volatile is a declaration that a variable can be accessed by multiple threads and hence shouldnt be cached.

  Sample Code for volatile

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

   Like      Discuss      Correct / Improve     java   oops   synchronization   volatile   java keywords     ABC Ltd   Ciena  Xchanging  Square  Infoview Technologies  HCL Technologies  EPAM  GrubHub  TeleMessage  TRUSTe  Informatica  Square  Medidata Solutions  Yellow Pages  eQ Technologic  Sutra Analytics  CustomerXPs  Globant  BB Holdings  Rakuten  Booking.com  BlackRock  Qualcomm  LSI Corporation  ARM Holdings  SpaceX  Toshiba  Peapod  Amadeus  Apptio  Tivo  EchoStar  HomeAway  Syscom Technologies  Aversan  Symantec  Samsung India  Axtria  Qualcomm  CGI Group      intermediate        frequent

Try 1 Question(s) Test


 Q22. What is the use of Transient Keyword ?Core Java
Anonymous
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     Cognizant (CTS)  The Advisory Board Company      intermediate        frequent

Try 2 Question(s) Test


 Q23. How to implement an immutable class ?Core Java
Anonymous
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   immutable class   technical lead     Deloitte  Pramati Technologies  JPMorgan Chase  Mastercard      intermediate        frequent

Try 2 Question(s) Test


 Q24. Can we override static methods ? Why ?Core Java
Anonymous
Ans. No.

Static methods belong to the class and not the objects. They belong to the class and hence doesn't fit properly for the polymorphic behavior.

A static method is not associated with any instance of a class so the concept of overriding for runtime polymorphism using static methods is not applicable.

 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   yes-no      intermediate        frequent


 Q25. Different types of memory used by JVM ?Core Java
Anonymous
Ans. Class , Heap , Stack , Register , Native Method Stack.

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

   Like      Discuss      Correct / Improve     java   jvm   memory management   memory   advanced   architecture   technical architect     Priceline.com      intermediate        frequent

Try 5 Question(s) Test


 Q26. When do you get ClassCastException?
Anonymous
Ans. As we only downcast class in the hierarchy, The ClassCastException is thrown to indicate that code has attempted to cast an object to a subclass of which it is not an instance.

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

   Like      Discuss      Correct / Improve     java   oops   class casting   classcastexception   exception   error      intermediate        frequent

Try 2 Question(s) Test


 Q27. Difference between new operator and Class.forName().newInstance() ?
Admin
info@buggybread.com
Ans. new operator is used to statically create an instance of object. newInstance() is used to create an object dynamically ( like if the class name needs to be picked from configuration file ). If you know what class needs to be initialized , new is the optimized way of instantiating Class.

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

   Like      Discuss      Correct / Improve     java   oops   object instantiation   object creation   class.forname   newinstance   new operator   difference between   advanced      intermediate


 Q28. What are the pre-requisite for the collection to perform Binary Search ?
Admin
info@buggybread.com
Ans. 1. Collection should have an index for random access.
2. Collection should have ordered elements.

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

   Like      Discuss      Correct / Improve     java   collections   search algorithm   search   binary search   at&t      intermediate


 Q29. What will be the output of following Code ?

class BuggyBread {
   public static void main(String[] args) {
      String s2 = "I am unique!";
      String s5 = "I am unique!";

      System.out.println(s2 == s5);
   }
}
Core Java
Admin
info@buggybread.com
Ans. true, due to String Pool, both will point to a same String object.

 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   string   string pool   .equal   ==      intermediate        frequent



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



Very frequently asked in companies using SOA.
  Q30. What are RESTful Web Services ?Rest
Admin
info@buggybread.com
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     Synechron  CapitalOne  Overstock.com  Ebay  At&t  HCL Technologies  Barclays  Tata Consultancy (TCS)  Cognizant (CTS)  Wipro  Infosys  EPAM  Mphasis      intermediate        frequent


 Q31. What is comparator interface used for ?Core Java
Admin
info@buggybread.com
Ans. The purpose of comparator interface is to compare objects of the same class to identify the sorting order. Sorted Collection Classes ( TreeSet, TreeMap ) have been designed such to look for this method to identify the sorting order, that is why class need to implement Comparator interface to qualify its objects to be part of Sorted Collections.

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

   Like      Discuss      Correct / Improve     java   collections   treemap   treeset   comparator     ZapCom  Verilogue      Intermediate

Try 2 Question(s) Test


  Q32. Can we overload main method in Java ?Core Java
Admin
info@buggybread.com
Ans. Yes, but the overloaded main methods without single String[] argument doesn't get any special status by the JVM. They are just another methods that needs to be called explicitly.

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

   Like      Discuss      Correct / Improve     java   main method   overloading   yes-no     The Advisory Board Company  Thomson Reuters  ePace Technologies  PC Technology  PEOL  MilleniumSoft      intermediate        frequent


 Q33. 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
Admin
info@buggybread.com
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


Usually asked in relation to casting and ClassCastException.
 Q34. What is instanceOf operator ? Explain it's use ?Core Java2017-06-12 07:58:22

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     Trimax IT Infrastructure & Services   ultramain      Intermediate        frequent


 Q35. Does java allow overriding static methods ?Core Java
Anonymous
Ans. No. Static methods belong to the class and not the objects. They belong to the class and hence doesn't fit properly for the polymorphic behavior.

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

   Like      Discuss      Correct / Improve     java   oops   static   static method   overriding      intermediate

Try 3 Question(s) Test


 Q36. What are transient variables in java?Core Java
Anonymous
Ans. Transient variables are variable that cannot be serialized.

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

   Like      Discuss      Correct / Improve     java   serialization   transient     Cognizant (CTS)      intermediate        rare


 Q37. what is the use of cookie and session ? and What is the difference between them ?Java EE
Anonymous
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


 Q38. Why Java don't use pointers ?
Anonymous
Ans. Pointers are vulnerable and slight carelessness in their use may result in memory problems and hence Java intrinsically manage their use.

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

   Like      Discuss      Correct / Improve     java   jvm   memory management   pointers      intermediate


 Q39. Can we declare an abstract method private ?
Anonymous
Ans. No Abstract methods can only be declared protected or public.

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

   Like      Discuss      Correct / Improve     java   abstract   oops   access specifier   private   yes-no      intermediate        rare



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q40. What is the difference between System.console.write and System.out.println ?
Admin
info@buggybread.com
Ans. System.console() returns null if your application is not run in a terminal (though you can handle this in your application)System.console() provides methods for reading password without echoing charactersSystem.out and System.err use the default platform encoding, while the Console class output methods use the console encoding

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

   Like      Discuss      Correct / Improve     java   system class   system.out.println   system.console.write   input output   java6      intermediate        rare


Usually asked only to fresh graduates and less experienced developers.
  Q41. What is a daemon thread? Give an Example ?
Admin
info@buggybread.com
Ans. These are threads that normally run at a low priority and provide a basic service to a program or programs when activity on a machine is reduced. garbage collector thread is daemon thread.

 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   daemon thread   garbage collection     Finnet  ServiceNow  MarketAxess Holdings  JP Morgan  Utopia  Samsung  CGI Group  Auriel Technologies      intermediate        frequent

Try 2 Question(s) Test


 Q42. Does every class needs to have one non parameterized constructor ?Core Java
Admin
info@buggybread.com
Ans. No. Every Class only needs to have one constructor - With parameters or without parameters. Compiler provides a default non parameterized constructor if no constructors is defined.

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

   Like      Discuss      Correct / Improve     java   oops   constructor   default constructor   yes no      intermediate

Try 3 Question(s) Test


 Q43. Can we use "this" within static method ? Why ?Core Java
Admin
info@buggybread.com
Ans. No. Even though "this" would mean a reference to current object id the method gets called using object reference but "this" would mean an ambiguity if the same static method gets called using Class name.

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

   Like      Discuss      Correct / Improve     java   oops   static   this keyword   this   yes no   why questions      intermediate


  Q44. What is Comparable Interface?Core Java
Admin
info@buggybread.com
Ans. It is used to sort collections and arrays of objects using the collections.sort() and java.utils. The objects of the class implementing the Comparable interface can be ordered.

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

   Like      Discuss      Correct / Improve     java   collections   comparable interface     innoPath  Mobisoft Infotech  BNP Paribas  Nokia  Unicon  HERE Maps  Verilogue      intermediate        frequent

Try 1 Question(s) Test


 Q45. What is the Locale class?
Admin
info@buggybread.com
Ans. The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region

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

   Like      Discuss      Correct / Improve     java   locale   internationalization      intermediate        rare


 Q46. What is Externalizable interface?Core Java
Admin
info@buggybread.com
Ans. Externalizable is an interface which contains two methods readExternal and writeExternal. These methods give you a control over the serialization mechanism.

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

   Like      Discuss      Correct / Improve     java   serialization   externalizable interface     MPhasis  Egen Solutions      intermediate        rare


 Q47. Difference between PATH and CLASSPATH ?Operating System
Admin
info@buggybread.com
Ans. PATH is the variable that holds the directories for the OS to look for executables. CLASSPATH is the variable that holds the directories for JVM to look for .class files ( Byte Code ).

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

   Like      Discuss      Correct / Improve     java   path   classpath   byte code   jvm   basic interview question     CapitalOne  MathWorks  eG Innovations      intermediate        rare


Very Frequently asked. Favorite question in walkins and telephonic interviews. Usually among first few questions. Asked in different variants. Must know for intermediate and expert professionals.Among Top 10 frequently asked questions.
  Q48. What is rule regarding overriding equals and hashCode method ?Core Java
Admin
info@buggybread.com
Ans. A Class must override the hashCode method if its overriding the equals method.

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

   Like      Discuss      Correct / Improve     java   collections   hashcode  hash code   equals   collections     Cognizant (CTS)  CapitalOne  Tata Consultancy (TCS)  HCL Technologies  Deloitte  Wipro  Infosys  Sabre  Sophos   Tieto  Addteq  Priceline.com  Cisco Systems  Visa Inc  Vibrant Media  Audience Science  GT Nexus  OpenCrowd  Instinet  Kronos  Elsevier  IMC Financial  LG Mobile  Dun & Bradstreet  WBUT  codecentric  Satmetrix  Interactive Brokers  Roposo  SecureView  Azuga  Envestnet  Criteo  Skillz  MobileIron  Walmart  R Systems  Overstock.com  Verilogue  Goldstone Technologies  FatWire  LinkedIn  Southwest Airlines      intermediate        frequent

Try 1 Question(s) Test


 Q49. Is It Good to use Reflection in an application ? Why ?Core Java
Admin
info@buggybread.com
Ans. no, It's like challenging the design of application.

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

   Like      Discuss      Correct / Improve     java   reflection api   yes-no   architecture     Overstock.com      intermediate



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q50. Does java allow implementation of multiple interfaces having Default methods with Same name and Signature ?Core Java
Admin
info@buggybread.com
Ans. No. Compilation error.

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

   Like      Discuss      Correct / Improve     java   java8   default method   yes-no     cognizant (CTS)      intermediate


Very frequently asked. Usually followed by questions related to private constructor and synchronized access. Frequently asked in JPMorgan (Based on 2 feedback)
  Q51. Explain Singleton Design Pattern ?Design
Admin
info@buggybread.com
Ans. http://www.buggybread.com/2014/03/java-design-pattern-singleton-interview.html

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

   Like      Discuss      Correct / Improve     java   design pattern   singleton   at&t   ebay  fidelity india  united healthcare india     JP Morgan  Tata Consultancy (TCS)  HCL Technologies  Wipro  Infosys  Tibco  Edline  JPMorgan Chase  Sabre  Bank Of America India  Fidelity  Samsung India  Robert Bosch India  ZapCom  Goldman Sachs India  Eze Software  ZapCom  Dailymotion  Netflix  CenturyLink  Misfit  TSYS  ECI Telecom  Dealogic  Robert Bosch  Redolent  EFI  CSX  Prolific  Validus  Birlasoft  AdNovum  NCR  Ray Business Technologies  Nagravision  Unify  SLK Group  DBS Bank   Razorthink  GST Global      intermediate        frequent


 Q52. Can we extend an Enum ?Core Java
Admin
info@buggybread.com
Ans. No. Enums are final by design.

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

   Like      Discuss      Correct / Improve     java   enums   inheritance   yes-no     Sapient      intermediate


 Q53. What is Closeable ?Core Java
Admin
info@buggybread.com
Ans. A Closeable is an interface which is a source or destination of data that can be closed.

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

   Like      Discuss      Correct / Improve     closeable   interfaces      intermediate        rare


 Q54. What is ConcurrentModificationException ?Core Java
Admin
info@buggybread.com
Ans. This is the exception that is thrown when we try to modify the non concurrent collection class while iterating through it.

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

   Like      Discuss      Correct / Improve     java   collections   concurrentmodificationexception   exception  concurrency     Calypso Technology  Deloitte  IRIS Software      intermediate


 Q55. Name few Locale classes and interfaces ?
Admin
info@buggybread.com
Ans. http://www.buggybread.com/2015/01/java-locale-classes-and-interfaces.html

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

   Like      Discuss      Correct / Improve     java   util   java.util   locale      intermediate        rare


 Q56. Difference between Stack and Heap memory ?Core Java
Admin
info@buggybread.com
Ans. Stack memory areas is used to hold method and local variables while objects are always allocated memory in the heap. The heap memory is shared between multiple threads whereas Stack memory isn't.

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

   Like      Discuss      Correct / Improve     java   memory management   stack memory   heap memory   difference between   ebay     ABCD Corp  Society for Worldwide Interbank Financial Telecommunication (SWIFT)      intermediate        frequent

Try 1 Question(s) Test


 Q57. What is collision in hash collections ?Core Java
Admin
info@buggybread.com
Ans. Collision is the situation when two different elements have the same Hash Code.

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

   Like      Discuss      Correct / Improve     java   collections   collision   hashcode  hash code   hash collections   ebay     Tata Consultancy (TCS)      intermediate        frequent


 Q58. When are static and instance methods resolved ? During compile time or Runtime ?
Admin
info@buggybread.com
Ans. Static methods are resolved during compile time and hence they cannot participate in runtime polymorphism. Instance methods are resolved during runtime.

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

   Like      Discuss      Correct / Improve     java   static methods   methods   runtime polymorphism      intermediate


 Q59. What are fail-fast Iterators ?Core Java2016-06-09 09:27:36

Ans. Fail-fast iterators detect illegal concurrent modification during iteration and fail quickly and cleanly rather than risking arbitrary, non deterministic behavior at an undetermined time in future. Example could be of an Iterator failing if it smells ConcurrentModificationException.

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

   Like      Discuss      Correct / Improve     fail-fast Iterators  Iterators     Roposo  Elitecore Technologies  Google  InfoTrellis  Infosys      intermediate



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q60. What is the use of Synchronized block ?Core Java

Ans. The goal of a synchronised block is to achieve mutual exclusion i.e at one time, the segment of the code should be executed by single thread only and hence the lock needs to be retrieved before executing the segment and then released.

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

   Like      Discuss      Correct / Improve     synchronized block   synchronized   synchronization   multithreading   threads   mutual exclusion   concurrency     Capgemini  Cognam Technologies  hewlett packard (HP)  BlackRock      intermediate        frequent

Try 1 Question(s) Test


Recently asked in Sophos
 Q61. Write a Method to get a map of words and their count by passing in the stringCore Java

Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?keyword=Method+to+get+a+map+of+words&category=code

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

   Like      Discuss      Correct / Improve     map  collections     Sophos  Overstock.com      intermediate


 Q62. Write code for singleton classDesign

Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?keyword=singleton+class&category=code

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

   Like      Discuss      Correct / Improve     singleton  code  coding  design pattern     ECI Telecom      Intermediate        frequent


 Q63. Write code for the usage of Builder Design Pattern

Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=964

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

   Like      Discuss      Correct / Improve     builder design pattern  builder pattern  code  coding      intermediate


Recently asked in Capital One.
 Q64. What will happen if we call perform(null) ?

public void perform(Object obj) {
System.out.println("Object");
}

public void perform(Integer int) {
System.out.println("Integer");
}
Core Java

Ans. compiler will throws error as ambiguous methods

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

   Like      Discuss      Correct / Improve     overloading   method overloading     CapitalOne      intermediate


 Q65. Can we have try statement without catch? If try statement contains return will the finally block be executed? What happens if there is an exception inside finally block?Core Java2016-10-18 11:37:51

Ans. Yes, with finally.

Yes, finally block will be executed even if there is no exception in try block.

If finally throws an exception, the exception gets thrown to the calling module.

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

   Like      Discuss      Correct / Improve     exception handling     Cognizant (CTS)      intermediate


 Q66. Should a DB Insert Request be a POST or PUT request in RestRest2016-07-22 14:36:02

Ans. It depends on whether the request object is persisted as it is

or

its first dismantled, modified or refactored and then inserted into DB.

In first case, it should be a PUT request whereas in second case it should be a POST Request.

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

   Like      Discuss      Correct / Improve     Put vs Post   Rest     Ciber  Apervi Technologies      intermediate        frequent


 Q67. How to Bulk upload the data into Oracle database?Database2016-10-21 12:36:26

Ans. We can use external table feature of Oracle.

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

   Like      Discuss      Correct / Improve          HCL Technologies      Intermediate


Frequently asked Design Pattern interview question.
 Q68. What is a prototype design pattern ?Design2016-11-04 08:06:01

Ans. The prototype pattern is a creational design pattern. It is used when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects. Prototype is used when we need duplicate copies of objects.

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

   Like      Discuss      Correct / Improve     design pattern  prototype design pattern     CapitalOne  Orion Edutech  Harris  Myntra  Tata Consultancy (TCS)  HCL Technologies  Infosys  Wipro  Tech Mahindra  IBM  Mahindra Satyam      intermediate


Usually asked with Questions related to Generics.
 Q69. What are Type Erasures in Java ?Core Java2016-11-15 09:59:21

Ans. Type erasure applies to the use of generics. When generics are used, they're pre compiled into compile time checks and execution-time casts.

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

   Like      Discuss      Correct / Improve     type erasures  generics     OpenCrowd  Nexient      intermediate        rare



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q70. How can one determine if JVM is 32-bit or 64-bit from Java Program ?Core Java2016-11-17 11:33:00

Ans. There is a Java system property "sun.arch.data.model" that can tell if JVM is 32 bit of 64 bit

System.getProperty("sun.arch.data.model") can be used to get that property.

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

   Like      Discuss      Correct / Improve     jvm      intermediate        rare


 Q71. Write an Algorithm for Graph Traversal ? The Graph has a loop.Algorithm2016-11-30 15:42:32

Ans. Please not that all such questions can be easily answered through recursion.

Simple recursive implementation could be

traverse(root);

void traverse(Element element){
if(element.hasNext()){
traverse(element.next());
} else {
System.out.println(element);
}
}

but this algo / code lead to endless loop if there is a loop in graph traversal.

So you can keep a collection to keep track of which elements have laready been traversed


static List<Elements> listOfAlreadyTraversedElements = new ArrayList<Elements>();

main(){
traverse(root);
}

void traverse(Element element){
if(element.hasNext()){
traverse(element.next());
} else {
listOfAlreadyTraversedElements.add(element);
System.out.println(element);
}
}

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

   Like      Discuss      Correct / Improve     graph traversal algorithm  graph traversal algorithm using recursion     Overstock.com      intermediate


Very Frequently asked to Senior Software Engineers or Developers.
  Q72. Describe some of the Design Patterns you have used ?Design2016-12-01 16:31:17

Ans. [Open Ended Answer]

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

   Like      Discuss      Correct / Improve     design patterns     Goldman Sachs  Lexis Nexis  Elsevier  HCL Technologies  Tata Consultancy (TCS)  Infosys Technologies  Fidelity Investments  Nucleus Software Exports  General Electric  Cognizant (CTS)  Amdocs  MathWorks  Xebia  Goldstone technologies  Horizon Solutions  ECI Telecom      intermediate        frequent


Frequently asked in high end product companies.
 Q73. How is Hashmap internally implemented in Java ?Core Java2016-12-06 08:49:37

Ans. https://www.quora.com/How-is-Hashmap-in-Java-implemented-internally-What-are-the-pros-and-cons-to-use-it-What-are-the-complexities-it-provides-for-insert-delete-and-lookup/answer/Anshudeep-Bajpai?srid=iwnK

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

   Like      Discuss      Correct / Improve     hashmap  collections  hashmap internal implementation     Veritas  Sophos  Salesforce  United Health Group (UHG)  Priceline.com  Roposo  virtusa polaris  Tata Consultancy (TCS)  Hexaware Technologies  Shiksha Infotech      Intermediate


Frequently asked in Alibaba (Based on 2 feedback)
 Q74. What is the best Memory setting for JVM ?Core Java2016-12-13 10:18:56

 This question was recently asked at 'Alibaba'.This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     jvm  memory management  jvm best memory setting     Alibaba      intermediate


  Q75. What is database Normalization ?Database2017-01-09 12:00:02

Ans. https://en.wikipedia.org/wiki/Database_normalization

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

   Like      Discuss      Correct / Improve     normalization  database     Sapient  Group Health  IGATE  Accenture  IBM  Oracle  United Health Group (UHG)  Envestnet      intermediate        frequent


 Q76. When is the situation when finally section won't execute ?Core Java2017-01-09 12:56:46

Ans. If the process / app is abruptly killed or terminated.

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

   Like      Discuss      Correct / Improve     exception handling  finally     EPAM  Nix Solutions      intermediate

Try 1 Question(s) Test


Frequently asked in high end product companies.
 Q77. Write code for LRU CacheCore Java2017-01-10 10:15:17

 This question was recently asked at 'United Health Group (UHG),Google,Zenefits,Amazon,Microsoft,SurveyMonkey,LinkedIn,Sanpdeal,MarkMonitor'.This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     cache  LRU cache  coding  code     United Health Group (UHG)  Google  Zenefits  Amazon  Microsoft  SurveyMonkey  LinkedIn  Sanpdeal  MarkMonitor      intermediate


 Q78. Will finally run if we have return statement and it exits the method early ?Core Java2017-01-10 18:01:40

Ans. finally will execute in all graceful situations - graceful executions as well as graceful exceptions. The only situation when finally block won't execute is when the app is abruptly stopped, killed or unplugged.

  Sample Code for finally

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

   Like      Discuss      Correct / Improve     finally      Intermediate


 Q79. What is nested interface?Core Java2017-01-12 14:14:44

Ans. Interface that is declared inside the interface or class, is known as nested interface. It is static by default.

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

   Like      Discuss      Correct / Improve     interface  nested interface      intermediate

Try 1 Question(s) Test



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q80. What kind of thread is garbage collection thread ?Core Java2017-01-12 14:15:59

Ans. Daemon thread

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

   Like      Discuss      Correct / Improve     garbage collection      intermediate

Try 2 Question(s) Test


 Q81. What is the difference between the Reader/Writer java.io hierarchy and the Stream class hierarchy?Core Java2017-01-12 14:17:13

Ans. The Reader/Writer hierarchy is character oriented, whereas the Stream class hierarchy is byte oriented.

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

   Like      Discuss      Correct / Improve     java io  streams      intermediate


 Q82. What is an IO Filter ?Core Java2017-01-12 14:17:53

Ans. It's an object that reads from one stream and writes to another.

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

   Like      Discuss      Correct / Improve     java io  io filter      intermediate


 Q83. Can we convert a numeric IP address to a web host name ?Java EE2017-01-12 14:19:10

Ans. Yes, using InetAddress.getByName("<IP Address>").getHostName();

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

   Like      Discuss      Correct / Improve     ip address to hostname  INETAddress      intermediate


 Q84. how to access the methods of an inner class?Core Java2017-01-14 11:11:38

Ans. It depends on the type of inner class

To access non static inner class method

new OuterClass().new InnerClass().getMethod();

To access static method of static inner class

new OuterClass.InnerClass().getMethod();

  Sample Code for inner class

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

   Like      Discuss      Correct / Improve     inner classes  nested aclasses     SuccessFactors      Intermediate        frequent


 Q85. What is memory leak ? How Java helps countering memory leaks compared to C++ ?Core Java2017-01-19 14:04:02

Ans. Memory Leak is a situation wherein we have a reserved memory location but the program has lost its reference and hence has no way to access it.

Java doesn't have concept of Pointers, Moreover Java has concept of Garbage collection that frees up space in heap that has lost its references.

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

   Like      Discuss      Correct / Improve     memory leak  garbage collection      intermediate        frequent


 Q86. What are the benefits of creating immutable objects ?Core Java2017-01-22 16:01:54

Ans. 1. Security and Safety - They can be shared across multiple threads as they are thread safe. Moreover, it protects then from bad state due to interception by the other code segment. One such problem due to mutability and access by alternate code segment could be the change of hash code and then the impact on its search with hash collections.

2. Reuse - In some cases they can be reused as only one copy would exist and hence it can be relied upon. For example - String Pool

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

   Like      Discuss      Correct / Improve     immutable objects     Knight Capital      Intermediate        frequent


 Q87. Can you name some of the Java frameworks in different domains ?Frameworks2017-01-23 09:41:33

Ans. Web Framework - Spring , Struts, Play
Dependency Injection frameworks - Google Guice , PicoContainer and Dagger
ORM Framework - Hibernate
Big Data / ETL Frameworks - Apche Hadoop , Apache Crunch, Apache Spark.
View Frameworks - JSF , Apache Wicket,jtwig.
Java Gui Frameworks - SWT , AWT, JavaFX
Testing - Junit, Mockito, PowerMock, EasyMock, JMock, JMockit
Rest Web services - Jersey , Restlet , RestX, RestEasy ,Restfulie

Here is the big list for reference - http://javasearch.buggybread.com/home2.php?keyword=

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

   Like      Discuss      Correct / Improve     frameworks     Craftsvilla.com  ZooPlus      intermediate        frequent


 Q88. What is the difference between

File f = new File("homexyz.txt");

and

File f = File.createTempFile("xyz",".txt","home"); ?
Core Java2017-01-23 12:31:28

Ans. First will not create physical file in storage whereas the second will.

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

   Like      Discuss      Correct / Improve     file handling  File.createTempFile      intermediate        rare


 Q89. What will be the output of following code ?

Base Interface

public interface BaseInterface {
   int i = 4;
}

Derived Interfaces

public interface DerivedInterface1 extends BaseInterface{
   int i = 5;
}

public interface DerivedInterface2 extends BaseInterface{
   int i=6;
}

Implementing Class

public class Class implements DerivedInterface1,DerivedInterface2 {
   public static void main(String[] args){
      System.out.println(BaseInterface.i);
   }
}

What will be the output upon executing main and Why ?
Core Java2017-01-26 13:42:29

Ans. It will print 4 because member elements of an interface are implicitly static and hence the concept of overriding doesn't work.


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

   Like      Discuss      Correct / Improve     interfaces  coding  code  extending interfaces  diamond interfaces     Bank Of America      intermediate



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q90. What will be the output of following code ?

Base Interface

public interface BaseInterface {
   int i = 4;
}

Derived Interfaces

public interface DerivedInterface1 extends BaseInterface{
   int i = 5;
}

public interface DerivedInterface2 extends BaseInterface{
   int i=6;
}

Implementing Class

public class Class implements DerivedInterface1,DerivedInterface2 {
int i=10;   

public static void main(String[] args){
      System.out.println(new Class().i);
   }
}

What will be the output upon executing main and Why ?
Core Java2017-01-26 13:43:11

Ans. 10

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

   Like      Discuss      Correct / Improve     interfaces  coding  code      intermediate


 Q91. Name few creational design patterns ?Design2017-02-12 16:06:15

Ans. Factory,Abstract Factory,Singleton,Prototype and Builder

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

   Like      Discuss      Correct / Improve     Design Pattrns  Creational Design Patterns      Intermediate


 Q92. Name few structural Design Patterns ?Design2017-02-12 16:07:00

Ans. Adapter,Bridge,Composite,Decorator,Facade,Flyweight,Proxy

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

   Like      Discuss      Correct / Improve     Design Patterns  Structural Design Patterns      Intermediate


 Q93. Name few Behavioral Design Patterns ?Design2017-02-12 16:07:59

Ans. Interpreter,Chain of Responsibility,Command,Iterator,Observer,Mediator,Memento

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

   Like      Discuss      Correct / Improve     Behavioral Design Patterns      Intermediate


 Q94. Which is your favorite Design pattern, each in Creational , Structural and Behavioral and Why ?Design2017-02-12 16:08:45

Ans. [Open Ended Answer]

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

   Like      Discuss      Correct / Improve     Design Patterns      Intermediate


 Q95. What is Exception Wrapping ?2017-02-13 15:02:37

Ans. Exception wrapping is wrapping an exception object within another exception object and then throwing the outer exception.

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

   Like      Discuss      Correct / Improve     exception handling  exception wrapping  exceptions      intermediate        rare


 Q96. How to create list that will sort it's elements dynamically?Algorithm2017-02-21 12:47:22

 This question was recently asked at 'General Electric (GE)'.This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve          General Electric (GE)      intermediate


 Q97. Which are the most commonly used Design Patterns ?Design2017-03-10 10:42:50

Ans. Builder ( While Writing Unit Tests )
Prototype ( Cloning )
Adapter ( asList , toString )
Chain Of Responsibility ( Logging )
Singleton
Factory ( Action Mapping )
Proxy
Observer ( Event Listener )
MVC ( Web frameworks )
Filter ( Criteria )

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

   Like      Discuss      Correct / Improve     Design Patterns  widely used Design patterns      intermediate        frequent

Try 1 Question(s) Test


 Q98. What is the purpose of String Pool ? Don't you think it's a performance overhead to have unnecessary check for string in string pool ?Core Java2017-05-13 09:05:03

Ans. String Pool makes Java more memory efficient by providing a reusable place for string literals. It might be a little performance inconvenience but results in good amount memory saving.

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

   Like      Discuss      Correct / Improve     string pool  memory management      Intermediate


 Q99. Can we catch errors in Java ? Core Java2017-05-23 08:21:10

Ans. Yes we can

try {
// code
} catch (Error ex) {
// handling code
}

but we shouldn't ideally do that as errors are mostly JVM based and not application based and there is rarely we can do something about it. Very likely catching and not re throwing would lead to muting their response or trace.

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

   Like      Discuss      Correct / Improve     exception handling  error handling  errors     ITech      intermediate




Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

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:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: