onthegorest.blogg.se

Tricky java interview questions
Tricky java interview questions






tricky java interview questions
  1. Tricky java interview questions how to#
  2. Tricky java interview questions software#

Why to use PreparedStatement over Statement?

tricky java interview questions

Tricky java interview questions how to#

You must read : How To Become A Better Java Developer in 2023? 13. destroy(): Final clean up before unloading is performed.Describe the lifecycle of an AppletĪn applet’s lifecycle can be said to follow these states: This keyword is used with the method signature. The throws keyword declares an exception, precedes a class name, and works in a way that the try-catch block does. The throw keyword is used within a method to raise an exception explicitly. Distinguish between throw and throws in Java

tricky java interview questions

System.gc() is a class method and Runtime.gc() is an instance method. These suggest to JVM that garbage collection can be started however, the JVM may finally run the garbage collector at a later time. What do System.gc() and Runtime.gc() methods do? The HashMap, does not allow for duplicate keys but duplicate values are permitted.

tricky java interview questions

One can store only 1 null key (bucket 0) and multiple null values in a Java HashMap. Can you store null keys/ values and duplicate keys/values in a Java HashMap? Fail-safe iterators do not throw an exception here, the iterator works with a clone of the collection and is not affected by modifications to it. What’s the difference between fail-fast and fail-safe?įail-fast iterators throw an exception when they detect that the collection is modified structurally since the start of the iteration. You may also like to read: 4 great tips to stand out in a coding interview 8. So, Java follows pass-by-value, even though in passing an object’s value one passes the reference to it. In Java one can pass a parameter by value only pass-by-reference does not exit. Is Java pass-by-reference or pass-by-value? In other words, one must acquire resources in one order and release them in the reverse order. Zero deadlocks will arise if the threads lock and unlock the mutexes in the same order. Then, force the threads to keep to that ordering. How can you ensure that N threads can access N resources without deadlock?įirstly, impose an ordering on the locks. The exception here is when a block that catches exceptions prompts the finally block to get executed. In other words, the finally block will be bypassed if there is no catch on the way to exit. The finally block will not execute and after System.exit () the program will be terminated. Will finally block execute if you put System.exit () in catch or try block? This can lead to compiler errors and since Java was designed to be simple, multiple inheritances are not supported. Here ambiguity arises when classes B and C inherit from class A and class D inherits from B and C. With multiple inheritances, one can run into the ‘diamond of death problem’. Why does Java not support multiple inheritances? Abstraction hides unwanted information whereas encapsulation hides the data into a single unit, protecting the information from outside influence. While abstraction focuses on an object’s behavior, encapsulation focuses on the implementation of an object’s behavior. In OOP, how does abstraction differ from encapsulation? It includes the JRE and tools like JavaDoc and Java Debugger.

Tricky java interview questions software#

Conversely, the Java Development Kit (JDK) is a Software Development Kit, allowing one to develop, compile and execute applications and applets with Java. Java Runtime Environment (JRE) provides the requirements for Java programs to be executed and contains the JVM, Java class libraries and Java class loader. Practically, you can replace a class with its subclass and Java’s inheritance mechanism follows this principle. Liskov’s Substitution Principle prescribes that you can replace an object with an instance of its subtype without corrupting the program. Can you override a private method in Java? What’s the difference between CountDownLatch and CyclicBarrier? What’s the difference between fail-fast and fail-safe? How can you ensure that N threads can access N resources without deadlock?








Tricky java interview questions