Interview Questions and Answers for 'Advanced' | Search Interview Question - 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 for 'Advanced' - 33 question(s) found - Order By Rating

next 30
 Q1. How can we create custom AMI ?Amazon Web Service (AWS)
 This question was recently asked at 'Cognizant (CTS), Advanced Micro Instruments'.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     aws ami     Asked in 2 Companies


 Q2. Create a custom hashmap using synchronization.Core Java
 This question was recently asked at 'Deutsche Bank'.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     hashmap  coding     Asked in 1 Companies      advanced


 Q3. What are different methods to get the permanent gen space of running application?Core Java
 This question was recently asked at 'Apcolite'.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     Asked in 1 Companies      advanced


Usually asked to entry level software developers.
  Q4. Write a program to swap two variables without using thirdCore Java
Ans. public static void main(String[] args) {
   int num1 = 1;   
   int num2 = 2;
   num1 = num1^num2;
   num2 = num1^num2;
   num1 = num1^num2;
   System.out.print("num1 = " + num1 +", num2 = "+num2);
}

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

   Like         Discuss         Correct / Improve     code  coding     Asked in 37 Companies      basic        frequent


 Q5. There are two objects a and b with same hashcode. I am inserting these two objects inside a hashmap.

hMap.put(a,a);
hMap.put(b,b);

where a.hashCode()==b.hashCode()

Now tell me how many objects will be there inside the hashmap?
Core Java
Ans. There can be two different elements with the same hashcode. When two elements have the same hashcode then Java uses the equals to further differentation. So there can be one or two objects depending on the content of the objects.

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

   Like         Discuss         Correct / Improve     java   hashcode   map   hashmap   object reference   advanced     Asked in 1 Companies


 Q6. Difference between long.Class and Long.TYPE ?
Ans. They both represent the long primitive type. They are exactly the same.

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

   Like         Discuss         Correct / Improve     java   data types   long.Class   long.TYPE   advanced      expert        rare


 Q7. Can constructors be synchronized in Java ?Core Java
Ans. No. Java doesn't allow multi thread access to object constructors so synchronization is not even needed.

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

   Like         Discuss         Correct / Improve     synchronization   synchronize   constructor   java   multithreading   yes-no   advanced     Asked in 1 Companies      expert        rare


Frequently asked in all types of companies especially Indian Services companies. Frequently asked in CTS (Based on 2 feedback)
  Q8. What is the use of hashcode in Java ?Core Java
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  hashtable     Asked in 33 Companies      intermediate        frequent

Try 1 Question(s) Test


Advanced level question. Frequently asked in High end product companies. Frequently asked in Google , Cognizant and Deloitte ( Based on 2 feedback )
  Q9. Why is String immutable in Java ?Core Java
Ans. 1. String Pool - When a string is created and if it exists in the pool, the reference of the existing string will be returned instead of creating a new object. If string is not immutable, changing the string with one reference will lead to the wrong value for the other references.

Example -

String str1 = "String1";
String str2 = "String1"; // It doesn't create a new String and rather reuses the string literal from pool

// Now both str1 and str2 pointing to same string object in pool, changing str1 will change it for str2 too

2. To Cache its Hashcode - If string is not immutable, One can change its hashcode and hence it's not fit to be cached.

3. Security - String is widely used as parameter for many java classes, e.g. network connection, opening files, etc. Making it mutable might possess threats due to interception by the other code segment.

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

   Like         Discuss         Correct / Improve     java   oops   string   string class   immutable  immutability   advanced     Asked in 39 Companies      expert        frequent

Try 4 Question(s) Test


  Q10. Which are the different segments of memory ?Core Java
Ans. 1. Stack Segment - Contains primitives, Class / Interface names and references.

2. Heap Segment - Contains all created objects in runtime, objects only plus their object attributes (instance variables), Static variables are also stored in heap.

3. Code Segment - The segment where the actual compiled Java bytecodes resides when loaded

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

   Like         Discuss         Correct / Improve     java   memory   memory management   stack memory   heap memory   code segment memory   advanced     Asked in 9 Companies      expert        frequent

Try 6 Question(s) Test


 Q11. Does garbage collection guarantee that a program will not run out of memory?Core Java
Ans. Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection

 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     Asked in 2 Companies

Try 1 Question(s) Test


 Q12. Describe what happens when an object is created in Java ?Core Java
Ans. 1. Memory is allocated from heap to hold all instance variables and implementation-specific data of the object and its superclasses. Implemenation-specific data includes pointers to class and method data.
2. The instance variables of the objects are initialized to their default values.
3. The constructor for the most derived class is invoked. The first thing a constructor does is call the constructor for its superclasses. This process continues until the constructor for java.lang.Object is called,as java.lang.Object is the base class for all objects in java.
4. Before the body of the constructor is executed, all instance variable initializers and initialization blocks are executed. Then the body of the constructor is executed. Thus, the constructor for the base class completes first and constructor for the most derived class completes last.

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

   Like         Discuss         Correct / Improve     java   memory management   object creation   advanced   ebay


Advanced level question usually asked in High end product companies. Have been asked in Google and Amazon (Based on 1 Feedback)
  Q13. Describe, in general, how java's garbage collector works ?Core Java
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     Asked in 21 Companies      intermediate        frequent

Try 4 Question(s) Test


 Q14. Can I import same package/class twice? Will the JVM load the package twice at runtime?Core Java
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     Asked in 1 Companies      intermediate        rare


 Q15. Different types of memory used by JVM ?Core Java
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     Asked in 1 Companies      intermediate        frequent

Try 5 Question(s) Test


 Q16. What is a class loader ? What are the different class loaders used by JVM ?Core Java
Ans. Part of JVM which is used to load classes and interfaces.

Bootstrap , Extension and System are the class loaders used by JVM.

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

   Like         Discuss         Correct / Improve     java   class loaders  classloaders   jvm   java memory management   advanced     Asked in 3 Companies


 Q17. Difference between loadClass and Class.forName ?
Ans. loadClass only loads the class but doesn't initialize the object whereas Class.forName initialize the object after loading it.

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

   Like         Discuss         Correct / Improve     java   class loaders   jvm   advanced


 Q18. What are the design considerations while making a choice between using interface and abstract class ?Core Java
Ans. Keep it as a Abstract Class if its a "Is a" Relationsship and should do subset/all of the functionality. Keep it as Interface if its a "Should Do" relationship.

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

   Like         Discuss         Correct / Improve     java   oops   abstract classes   interfaces   advanced     Asked in 3 Companies


Advanced level question. Recently asked in few Indian service companies ( Based on 3 inputs )
 Q19. What are various types of Class loaders used by JVM ?Core Java
Ans. Bootstrap - Loads JDK internal classes, java.* packages.

Extensions - Loads jar files from JDK extensions directory - usually lib/ext directory of the JRE

System - Loads classes from system classpath.

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

   Like         Discuss         Correct / Improve     java   jvm   memory management   class loaders   bootstrap   extensions   system  classloaders   advanced   technical lead   technical architect     Asked in 7 Companies


 Q20. What is ThreadFactory ?Core Java
Ans. ThreadFactory is an interface that is meant for creating threads instead of explicitly creating threads by calling new Thread(). Its an object that creates new threads on demand. Using thread factories removes hardwiring of calls to new Thread, enabling applications to use special thread subclasses, priorities, etc.

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

   Like         Discuss         Correct / Improve     java   threads   multi threading   thread factory   thread creation   advanced      expert


 Q21. What is PermGen or Permanent Generation ?Core Java
Ans. The memory pool containing all the reflective data of the java virtual machine itself, such as class and method objects. With Java VMs that use class data sharing, this generation is divided into read-only and read-write areas. The Permanent generation contains metadata required by the JVM to describe the classes and methods used in the application. The permanent generation is populated by the JVM at runtime based on classes in use by the application. In addition, Java SE library classes and methods may be stored here.

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

   Like         Discuss         Correct / Improve     java   jvm   memory management   permgen   permanent generation   advanced   architecture     Asked in 9 Companies      expert


 Q22. What is metaspace ?Core Java
Ans. The Permanent Generation (PermGen) space has completely been removed and is kind of replaced by a new space called Metaspace. The consequences of the PermGen removal is that obviously the PermSize and MaxPermSize JVM arguments are ignored and you will never get a java.lang.OutOfMemoryError: PermGen error.

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

   Like         Discuss         Correct / Improve     java   jvm   memory management   permgen   permanent generation   metaspace   advanced   architecture      expert


 Q23. What is the difference between System.out ,System.err and System.in?
Ans. System.out and System.err both represent the monitor by default and hence can be used to send data or results to the monitor. But System.out is used to display normal messages and results whereas System.err is used to display error messages and System.in represents InputStream object, which by default represents standard input device, i.e., keyboard.

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

   Like         Discuss         Correct / Improve     java   io   system.out   system.err   system.in   difference between   advanced   basic interview question


 Q24. Do you think that Java should have had pointers ?Core Java
Ans. Open ended Questions.

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

   Like         Discuss         Correct / Improve     java   open questions   pointers   advanced


 Q25. 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


Asked multiple times in Capgemini.
 Q26. Why Char array is preferred over String for storing password?Core Java
Ans. String is immutable in java and stored in String pool. Once it's created it stays in the pool until unless garbage collected, so even though we are done with password it's available in memory for longer duration and there is no way to avoid it. It's a security risk because anyone having access to memory dump can find the password as clear text.

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

   Like         Discuss         Correct / Improve     java   string class   string   immutable  immutability   string pool   garbage collection   advanced     Asked in 6 Companies      Expert


 Q27. Why String is popular HashMap key in Java?Core Java
Ans. Since String is immutable, its hashcode is cached at the time of creation and it doesnt need to be calculated again. This makes it a great candidate for key in a Map and its processing is fast than other HashMap key objects. This is why String is mostly used Object as HashMap keys.

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

   Like         Discuss         Correct / Improve     java   string class   string   immutable  immutability   hashmap   immutable  immutability   hashcode   hash code   advanced     Asked in 2 Companies      expert        frequent


 Q28. What does String intern() method do?Core Java
Ans. intern() method keeps the string in an internal cache that is usually not garbage collected.

Moreover provide reference for scp object for corresponding string object present in heap memory.

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

   Like         Discuss         Correct / Improve     java   string class   string   intern method   garbage collection   advanced     Asked in 2 Companies      expert


 Q29. How substring() method of String class create memory leaks?Core Java
Ans. substring method would build a new String object keeping a reference to the whole char array, to avoid copying it. Hence you can inadvertently keep a reference to a very big character array with just a one character string.

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

   Like         Discuss         Correct / Improve     java   string class   string   substring   memory leaks   jvm   memory management   advanced   architecture   technical architect   technical lead      expert


 Q30. Difference between new operator and Class.forName().newInstance() ?
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


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: