Great Deals
App has exclusive collection of Java interview questions.Proudly written by most viewed java author on quora.com
Java interview questions part2
Class loads is part of Jvm which loads when required.
- Types of classloader
- 1.bootstrap classloader
- 2.extension class loader
- 3.system class loader
- 4.custom class loader.
We can create it by using enum.
- Declare all fields as final
- Declare class as final.
- Don't provide setter method for any variable.
- Perform cloning of objects in getter methods when getter returns object it should return copy.
Clonable is an interface must be implemented if you plan to clone object. Clonable allows to create bitwise copy of object. clone performs shallow copy. It will copy only reference.
When we use default implementation of clone method. you use shallow copy of objects because object refers the same object.
If only primitive type like int char and immutable type like String are present then there is not much difference.
The alternative to clonable is copy constructor.
It will throw CloneNotSupportedException.
- Diffrence between failfast and fail safe
failfast works on original collection and fail safe works on the copy of original collection.
fail fast throws exception fail safe won'tthrow exception.
- CopyOnWriteArrayList significance
copy on writearraylist supports concurrency.
synchronized collection locks whole collection and concurrentcollection locks portion of collection.
- Singleton vs Static class
- Singleton object stores in Heap but, static object stores in stack
- We can clone the object of Singleton but, we can not clone the static class object
- Singleton class follow the OOP(object oriented principles) but not static class
- we can implement interface with Singleton class but not with Static class.
- Overriding Puzzle
- Case2: Newly added method can't be called with reference of top class.
- Case3:If same variable declared in parent as well as child class.And called using reference of
- Parent class.then always variables of parent class are refered .
- Diffrence Between the Enumeration and iteration
- How Hashset maintains unique item
private static final Object PRESENT = new Object(); public boolean add(E e) { return map.put(e, PRESENT)==null; }
Frequently asked interview questions
Can we serialise the static members
Does not make any sense to make static members serializable
Staic member belong to the class not the individual objects.
Why use the hashmap keys as immutable objects
Since if we use mutable objects as keys at the time of storage and over the time when we change it may point to entire different location.so suppose for key 3 value 33 is associated if this key is changed then it may point to diffrent location so to avoid this keys are immutable.
Difference save and persist
Save returns serializable entity
Persist return void
What is executerservice
Executerservice is like a threadpool.
It is a way of submitting thread for execution.It is used where asynchronous tasks need to be performed.
Executerservice has submit method.
Which returns future class instance.
Executerservice takes callable instance .
Future returns the result of thread execution
Can we synchronise the constructor
No not possible.since it will be creating lock on object being created but generally the object is not available to other thread till the time it gets created
Can we synchronise the run method
Yes we can synchronize run method.
Types of garbage collection
Serial gc
Parallel gc=serial works same as parallel but the girl is done by multiple threads.
What is difference between notify and notify all
Notify all - will notify all waiting thread
Notify- invokes the first thread which called the wait method on the object
Join() in multithreading
Join method in multithreading is used to pause execution of all other threads except the one which called the join method.
Why use inner classes.
Inner classes are used to hide implementation details. To increase encapsulation.
Some examples of usage of inner classes are
iterator inside list.
Listener in gui.
Spread the word if you really like this share with your friends.
ConcurrentHashMap in nutshell
So in case of hash map if you are locking the door. Then you will not be able to access if any of the room of house. Before using hash map every thread locks the hash map making it inaccessible to other thread till the time it won't complete it's operations.
But if concurrent hash map is viewed it may be viewed as multiple separate rooms of Lodge if any room is locked we can still access the other rooms.
Creation of ConcurrentHashMap
HashMap anatomy:
Initial Capacity:
You can specify the size of the
concurrenthashmap at the time of creation.
Load Factor:
ConcurrencyLevel:
Advantages of concurrenthashmap:
Disadvantages of concurrency in hashmap
size
, isEmpty
, and containsValue
are typically useful only when a map is not
undergoing concurrent updates in other threads. Otherwise these methods procure
precise results.When resizing is done?
Properties of ConcurrentHashmap
Java Helloworld
Handpicked for you
Great Deals
Popular Posts
-
import java.util.Vector; import java.util.logging.Level; import java.util.logging.Logger; public class ProducerConsumerSolution { ...
-
T he Java concurrent hash map may be considered as the lodge having many rooms with locking facility. Where as hash map may be considered ...
-
Rules for overriding The access level can't be more restrictive than the overridden method's. class Car { String ...
-
There are in all four stages of Object in hibernate 1.Transient 2.Persistent 3.Removed 4.Detached 1.Transient Objects ...
-
Calcuator Demo package com.oop; class Calculator { public Calculator() { System. out .println( "I am co...
-
What is classloader When Java application starts the program it does not load all the required files at once. Rather it loads class file...
-
Sql Mostly used queries. 1.Views CREATE OR REPLACE VIEW passStudent AS SELECT StudentId,StudentName FROM Student WHERE result=pas...
-
App has exclusive collection of Java interview questions. Proudly written by most viewed java author on quora.com App has detail explanati...
-
Lambda Expressions What is lambda Expressions? The lambda expression is just like the function it consist of ...
-
Concurrent HashMap example: Concurrent HashMap works on the principle of concurrent access of the segment of hashmap. It partially...
Follow Us
Labels
About Me
Blog Archive
Featured post
Cool Gadgets
Amazon.in Widgets