Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| ||||
Interview Questions and Answers for 'Advanced' - 33 question(s) found - Order By Newest | ||||
Advanced level question. Frequently asked in High end product companies. Frequently asked in Google , Cognizant and Deloitte ( Based on 2 feedback ) | ||||
| ||||
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 | ||||
Asked multiple times in Capgemini. | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
Frequently asked in all types of companies especially Indian Services companies. Frequently asked in CTS (Based on 2 feedback) | ||||
| ||||
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 usually asked in High end product companies. Have been asked in Google and Amazon (Based on 1 Feedback) | ||||
| ||||
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 | ||||
| ||||
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 frequently asked in US based companies. Recently asked in EMC and Intuit. | ||||
| ||||
Ans. Simplest implementation we can have is a List wherein we can place ordered words and hence can perform Binary Search. Other implementation with better search performance is to use HashMap with key as first character of the word and value as a LinkedList. Further level up, we can have linked Hashmaps like , hashmap { a ( key ) -> hashmap (key-aa , value (hashmap(key-aaa,value) b ( key ) -> hashmap (key-ba , value (hashmap(key-baa,value) .................................................................................... z( key ) -> hashmap (key-za , value (hashmap(key-zaa,value) } upto n levels ( where n is the average size of the word in dictionary. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   hashmap   binary search   search algorithm   advanced   architecture   data structure Asked in 6 Companies   frequent | ||||
Try 1 Question(s) Test | ||||
| ||||
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 | ||||
Advanced level question. Recently asked in few Indian service companies ( Based on 3 inputs ) | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
Usually asked to entry level software developers. | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
Ans. WEDNESDAY FRIDAY SATURDAY Only one FRIDAY will be printed as Set doesn't allow duplicates.Elements will be printed in the order in which constants are declared in the Enum. TreeSet maintains the elements in the ascending order which is identified by the defined compareTo method. compareTo method in Enum has been defined such that the constant declared later are greater than the constants declared prior. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   code   coding   enum   set   treeset   advanced | ||||
Try 3 Question(s) Test | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
Ans. Yes and No. JVM is an extra layer that translates Byte Code into Machine Code. So Comparing to languages like C, Java provides an additional layer of translating the Source Code. C++ Compiler - Source Code --> Machine Code Java Compiler - Source Code --> Byte Code , JVM - Byte Code --> Machine Code Though it looks like an overhead but this additional translation allows Java to run Apps on all platforms as JVM provides the translation to the Machine code as per the underlying Operating System. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   jvm   interpreter   platform independent   yes-no   advanced   architecture | ||||