![]() This is the most tricky Java interview question, there is no sure sort answer but you can use profile and memory dump to find memory leak in Java. Read What is volatile variable in Java and How it works for detailed information on volatile variable in Java Another important aspect of making a variable volatile is that compiler will not reorder the variable when switching from client to server configuration or while performing optimization. ![]() Volatile guarantee not just limited to the variable but also all the variables two threads see known as “happens before” relationship. Though volatile is just a keyword its probably most confusing one in core Java. It’s not a good practice to call static method by instance, always call static method in Java by using class name like Math.max()ĩ) How does volatile variable works in Java?Īnother seriously senior developer question in Java and tricky part of this question is change in volatile variable in Java 5. Yes we can call because static method is bound at compile time and only type of variable is used for static binding not the value of object. I bet this is the most tricky Java interview question I ever encountered. Read : What is Race condition in Java for more information on how to handle race conditions in JavaĨ) Can we call static method with null object? TreeSet and TreeMap which uses compareTo will not able to detect duplicates and allow duplicate inside set. Since hashmap maintains a linked list of element in bucket and while copying from one hashmap to other or old to new order of linked list got reversed, which could result in infinite loop if two threads are doing resizing at same time? Not many people know about it that hashmap could run into race condition if it would be modified by two threads simultaneous and one thread tries to re-siz or rehash the map because of capacity crossing threshold value. Race conditions in Java are always tricky to find and solve. check here for detailed answerħ) Explain race condition in Java hashmap ? if two objects are equal via equals method compareTo method must return “0” for them, failing this may result in some subtle bug when you store those objects in collection class like arraylist in java. Many cases like Serialization, RMI, Clasloader loading multiple instance etc.ĥ) Difference between noclassdeffounderror and classnotfoundexception?Īs per my experience occurs when a particular class was present during Compile time but not available during run time by any reason, while j comes when class loaded explicitly during runtime.Ħ) Why equals() method must be compatible with compareTo in java ?ĬompareTo method in Java must be compatible with equals method in Java i.e. When two or more threads waiting for each other to release lock and get stuck for infinite time, situation is called deadlock check here for detailed answerĤ) When a singleton is not singleton in Java? Anyway java supports multiple inheritances via interfaces.I think more convincing reason for not supporting multiple inheritance is complexity involved in constructor chaining, casting etc rather than diamond problem Short answer is because of diamond pattern, diamond pattern creates ambiguity and make problem for compiler. ![]() if string had been mutable anyone can surpass the security be logging in someone else name and then later modifying file belongs to other.Ģ) Why multiple inheritances are not supported in Java? if you have any Java question which your feel tricky, share it here.ġ) String pool requires string to be immutable otherwise shared reference can be changed from anywhere.Ģ) security because string is shared on different area like file system, networking connection, database connection, having immutable string allows you to be secure and safe because no one can change reference of string once it gets created. This questions are most tricky because of fact, logic and depth involve in these question. So here are my lists of 10 most tricky questions in java interview mostly asked to senior and experience Java programmer from 4 to 6 years of experience on finance domain. From past few week was preparing for java interview and I come across some tricky, tough and real advanced question which is suitable for senior level developers who has 4o t6 or 8 years experience, I thought to document those for future reference for myself and others.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |