![]() One of the practical use of the volatile variable is to make reading double and long atomic. While reading/writing a volatile long or double (64 bit) is atomic.ģ) What are practical uses of volatile modifier? Why? because reading to a long variable is not atomic in Java and done in two steps, If one thread is writing or updating long value, it's possible for another thread to see half value (fist 32-bit). a counter, a price field or anything, you better make it volatile. If you know that a long field is accessed by more than one thread e.g. One example I have seen is having a long field in your class. This question is also not easy to answer because volatile is not about atomicity, but there are cases where you can use a volatile variable to make the operation atomic. This another good question I love to ask on volatile, mostly as a follow-up of the previous question. What I mean, if one thread changes the reference variable to points to another array, that will provide a volatile guarantee, but if multiple threads are changing individual array elements they won't be having happens before guarantee provided by the volatile modifier.Ģ) Can volatile make a non-atomic operation to atomic? Yes, you can make an array volatile in Java but only the reference which is pointing to an array, not the whole array. This is one of the tricky Java multi-threading questions you will see in senior Java developer Interview. Multithreading, Concurrency and Thread basics Questions I am sure you have seen many of these questions personally on your interviews and many of you would have answered them correctly as well. So now the time has come to introduce you to this MEGA list of 120 Java questions collected from various interviews of last 5 years. It will take you to some of the most important topics for Java and JEE interviews, worth reading even if you are not preparing for a Java interview. You guys are also lucky that nowadays there are some good books available to prepare for Java interviews, one of them which I particularly find useful and interesting to read is Java Programming Interview Exposed by Markham. Multithreading, concurrency, and thread basics.To give you an idea, this list of Java interview questions includes the following topics: ![]() I have also worked hard to keep this list up-to-date to include what interviewers are asking nowadays and what will be their core focus in the coming years. No matter whether you are a Java developer of 1, 2, 3, 4, 5, 6, 8, 9, or even 10 years of experience, you will find something interesting in this list. It has questions for both entry-level Java programmers and senior developers with years of experience. It contains interview questions not only from classic topics like threads, collections, equals and hashcode, sockets but also from NIO, array, string, Java 8, and much more. I have been preparing this MEGA list for quite some time and now It's ready to share with you guys. Since I like to explore interview questions, I have got this huge list of questions with me, which contains lots and lots of questions on different topics. concurrency, algorithms, data structures and coding. NIO, patterns, sophisticated unit testing or those which are hard to master e.g. Nowadays, you will get questions from the areas where not many Java programmer looks e.g. ![]() When I started my career, questions like Vector vs Array and HashMap vs Hashtable were the most popular ones and just memorizing them gives you a good chance to do well in interviews, but not anymore. Gone are the days, when knowing the difference between String and StringBuffer can help you to go through the second round of interview, questions are becoming more advanced and interviewers are asking more deep questions. ![]() Time is changing and so is Java interviews.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |