patriotport.blogg.se

Tricky java interview questions
Tricky java interview questions




  1. #Tricky java interview questions code#
  2. #Tricky java interview questions windows#

When I asked this question to a couple of programmers they answer differently, one suggests making both threads synchronized on a common mutex, another one said to make both variables volatile. Also, x=1 might not become visible in Thread 2, so Thread 2 will load x=0. synchronized or volatile, bExit=true might come before x=1 in compiler reordering.

tricky java interview questions tricky java interview questions

Why? because without any instruction to compiler e.g. The answer to this question is Yes, It's possible that thread T2 may print x=0. println( "x=" + x) Now tell us, is it possible for Thread 2 to print “x=0”?Īnswer: It's impossible for a list of tricky Java questions to not contain anything from multi-threading.

#Tricky java interview questions code#

Question: Consider the following Java code snippet, which is initializing two variables and both are not volatile, and two threads T1 and T2 are modifying these values as follows, both are not synchronized The rule that maps each Unicode character into a byte array is called a character encoding.ġ1.

tricky java interview questions

In simple word, t o convert a string to a byte array, Java iterates through all the characters that the string represents and turn each one into a number of bytes and finally put the bytes together. To answer this question correctly, you need to know about how Unicode characters are represented in Java char values and in Java strings, and what role character encoding plays in String.getBytes().

#Tricky java interview questions windows#

On a Windows XP with the US locale, the above program prints, if you run this program on Linux or Solaris, you will get different values. As a matter of fact, the output of the program is operating system and locale dependent. However, that's not what the program prints and that's why this question is tricky. If you are a new learner in the field of programming or want to upskill and take your career to the next level, CodeQuotient offers their flagship SuperCoders Program – a full-stack development internship.Since \u0097 is within the 8-bit range of byte primitive type, it is reasonable to guess that the str.getBytes() call will return a byte array that contains one element with a value of -105 ((byte) 0x97). With these answers in your arsenal, you are well-equipped to handle some of the trickiest questions any Java interviewer can throw at you. No, you cannot access a non-static variable from the static context in Java, as it will give a compile-time error. Can you access a non-static variable in the static context? Answer: You can reuse CyclicBarrier even if the Barrier is broken, but you can not reuse CountDownLatch in Java. What is the difference between CyclicBarrier and CountDownLatch in Java? Answer: Yes, you can throw a superclass of RuntimeException in overridden method, but you can not do that if it’s a checked Exception. If a method throws NullPointerException in the superclass, can we override it with a method that throws RuntimeException? Answer: On a Windows XP with the US locale, the above program prints 63, but if you run this program on Linux or Solaris, you will get different values.Ĩ. This question is particularly tricky because this program’s output depends on the operating system and locale. What will the following Java program print?

tricky java interview questions

Let us show you the ten most tricky Java programming questions you can expect in an interview, with solutions. Java Programming – Tricky Interview Questions However, clearing an interview for this job role isn’t all that easy, given that most interview panellists tend to throw tricky questions at the candidates to find the best talent for the job. As per Mercer, one of the global leaders in talent assessment, the role of a Java developer is one of the most in-demand roles in 2022, thanks to the ever-increasing adoption of Java in multiple domains, devices, and organisations. With over 9 million active Java developers globally, the demand for talent in this domain is at an all-time high. It is the number one development language for microservices and is the most-used language for DevOps, AI, VR, Big Data, Continuous Integration, Analytics, Mobile, Chatbots, and much more. With over 45 billion active virtual machines globally, Java is one of the most popular programming languages in the world. Every interview usually comes with tricky questions that trick candidates into thinking either too much or not at all. If you are preparing for a Java job interview, you must be familiar with these tricky programming questions.






Tricky java interview questions