• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

Java Interview Questions Answers

Question - 91 : - What  is Java?

Answer - 91 : - Java is an object-oriented programming language developed initially by James Gosling and colleagues at Sun Microsystems. The language, initially called Oak (named after the oak trees outside Gosling's office), was intended to replace C++, although the feature set better resembles that of Objective C. Java should not be confused with JavaScript, which shares only the name and a similar C-like syntax. Sun Microsystems currently maintains and updates Java regularly.

Question - 92 : - What is a native method?

Answer - 92 : - A native method is a method that is implemented in a language other than Java.

Question - 93 : - What is the relationship between synchronized and volatile keyword?

Answer - 93 : - The JVM is guaranteed to treat reads and writes of data of 32 bits or less as atomic.(Some JVM might treat reads and writes of data of 64 bits or less as atomic in future) For long or double variable, programmers should take care in multi-threading environment. Either put these variables in a synchronized method or block, or declare them volatile.

Question - 94 : - Can Java object be locked down for exclusive use by a given thread?

Answer - 94 : - Yes. You can lock an object by putting it in a "synchronized" block. The locked object is inaccessible to any thread other than the one that explicitly claimed it.

Question - 95 : - What is the difference  between final, finally and finalize?

Answer - 95 : - final is used for making a class no-subclassable, and making a member variable as a constant which cannot be modified. finally is usually used to release all the resources utilized inside the try block. All the resources present in the finalize method will be garbage collected whenever GC is called. Though finally and finalize seem to be for a similar task there is an interesting tweak here, usually I prefer finally than finalize unless it is unavoidable. This is because the code in finally block is guaranteed of execution irrespective of occurrence of exception, while execution of finalize is not guarenteed.finalize method is called by the garbage collector on an object when the garbage collector determines that there are no more references to the object. Presumably the garbage collector will, like its civil servant namesake, visit the heap on a regular basis to clean up resources that are no longer in use. Garbage collection exists to prevent programmers from calling delete. This is a wonderful feature. For example, if you can't call delete, then you can't accidentally call delete twice on the same object. However, removing delete from the language is not the same thing as automatically cleaning up. To add to it, Garbage collection might not ever run. If garbage collection runs at all, and an object is no longer referenced, then that object's finalize will run. Also, across multiple objects, finalize order is not predictable. The correct approach to resource cleanup in Java language programs does not rely on finalize. Instead, you simply write explicit close methods for objects that wrap native resources. If you take this approach, you must document that the close method exists and when it should be called. Callers of the object must then remember to call close when they are finished with a resource.

Question - 96 : - Name the containers which uses Border Layout as their default layout?

Answer - 96 : - Containers which uses Border Layout as their default are: window, Frame and Dialog classes.

Question - 97 : - What happens when a thread cannot acquire a lock on an object?

Answer - 97 : - If a thread attempts to execute a synchronized method or synchronized statement and is unable to acquire an object's lock, it enters the waiting state until the lock becomes available.

Question - 98 : - What is a transient variable in Java?

Answer - 98 : - A transient variable is a variable that may not be serialized. If you don't want some field to be serialized, you can mark that field transient or static.

Question - 99 : - What's the main difference between a Vector and an ArrayList?

Answer - 99 : - Java Vector class is internally synchronized and ArrayList is not.

Question - 100 : - Jack developed a program by using a Map container to hold key/value pairs. He wanted to make a change to the map. He decided to make a clone of the map in order to save the original data on side. What do you think of it? ?

Answer - 100 : - If Jack made a clone of the map, any changes to the clone or the original map would be seen on both maps, because the clone of Map is a shallow copy. So Jack made a wrong decision.

Computer Contributors

krishan
Rajeev Katiyar
Yes Baroda

Share your email for latest updates

Name:
Email:

Our partners