Experience Interview

The Best Interview and Internal details of the CoreJava:-
All java logical programming is here:-
http://www.java-examples.com/java-string-examples
-------------------------------------------------------------
public final void writeObject(Object obj);;;;;;;;;;;;;;;;
 public final Object readObject()
it's final method because koi override na kare just use functionality
-----------------------------------
creating Integer Object using new Integer() vs ValueOf() method.
valuOf prefered

all inner class concept used in collection classes
all collection class are serializable and clonable and have serialversionId.
becasue when we create there object then we should send those object to file or network. so serialversion Id.

TreeMap has innerclasses
Abstract Map has inner class
Entry is inner class of MAP so name is Map.Entry
Tree Map Put method is final we can't override
----------------------------------------------
public String toString() {
        Iterator<E> i = iterator();
if (! i.hasNext())
   return "[]";

StringBuilder sb = new StringBuilder();
sb.append('[');
for (;;) {
   E e = i.next();
   sb.append(e == this ? "(this Collection)" : e);
   if (! i.hasNext())
return sb.append(']').toString();
   sb.append(", ");
}
    }

this method common for all colllection set classes TreeSet,HashSet,LinkedHashSet

-----------------------------
All wrapper classes in java.lang are immutable
String, Integer, Boolean, Character, Byte, Short, Long, Float, Double, BigDecimal, BigInteger
-----------------------------------------------------
why are unchecked exceptions not checked by java compiler?
http://javarevisited.blogspot.in/2011/12/checked-vs-unchecked-exception-in-java.html
http://stackoverflow.com/questions/27578/when-to-choose-checked-and-unchecked-exceptions
http://literatejava.com/exceptions/checked-exceptions-javas-biggest-mistake/
for smooth execution of run time checked exception-in-java used
short cirucit happend and bomb happned this exception-in-java can't be catched by compiler
------------
throwable is class in java
exceptions are recoverable
error are non recoverable
http://javarevisited.blogspot.in/2014/02/why-catching-throwable-or-error-is-bad.html
Difference between Unchecked exception or runtime exception
http://stackoverflow.com/questions/2699580/difference-between-unchecked-exception-or-runtime-exception
http://stackoverflow.com/questions/11547914/why-runtime-exception-is-unchecked-exception
When is it OK to catch a RuntimeException
http://stackoverflow.com/questions/1982533/when-is-it-ok-to-catch-a-runtimeexception
Is it not a good practice to handle runtime exceptions in the code?
http://programmers.stackexchange.com/questions/91827/is-it-not-a-good-practice-to-handle-runtime-exceptions-in-the-code
-------------------------------------------------------------------------------------
where do we use stack in real life examples java
The Java compiler translates programs into posfix notation
The Java Virtual Machine uses a stack
The Java Compiler Uses a StackThe Java Compiler Uses a Stack
----------------------------------------------------------------------
how to find the time complexity
http://stackoverflow.com/questions/16232629/what-is-time-complexity-and-how-to-find-it
-------------------------------------------------------------------
Hash set default initial capacity=16 and loadfactor=.75
it means 16*.75=12 after filling 12 key, it intial capacity will be double 32 load factor same =.75
The default initial capacity of the HashMap will be taken as 16 and the load factor as 0.75.
load factor represents at what level the HashMap capacity should be doubled. For example the product of capacity and load factor = 16 * 0.75 = 12.
This represents that after storing the 12th key – value pair into the HashMap , its capacity will become 32.
-----------------------------------------------------------------------------------------------
Which one runs faster, ArrayList or LinkedList? [duplicate]
http://stackoverflow.com/questions/18734705/which-one-runs-faster-arraylist-or-linkedlist
linkedlist internaly using double linkedlist
where as arraylist  use array
----------------------------------
why LinkedList doesn't have initialCapacity in java?
http://stackoverflow.com/questions/19050211/why-linkedlist-doesnt-have-initialcapacity-in-java
Applications of linked lists in real world?
A linked list would be a reasonably good choice for implementing any of the following:

1. Applications that have an MRU list (a linked list of file names)
2. The cache in your browser that allows you to hit the BACK button (a linked list of URLs)
3. Undo functionality in Photoshop or Word (a linked list of state)
4. A stack, hash table, and binary tree can be implemented using a doubly linked list.
5. A great way to represent a deck of cards in a game.



if TreeSet object createed using comparater instance then.cpr value not null and ..then compartor logic
will work else time comparable logic will work since comparator value we pass by . construictor

toString method for reteriving the TreeSet value is written inside AbstractCollection
so that.inside toString we reterive object by Iterator method
--------------------------------------------------------------------------------------------------------

TreeSet:-
private static final Object PRESENT = new Object()
private static final long serialVersionUID = 0xdd98509395ed875bL;
TreeSet(NavigableMap navigablemap)
    {
        m = navigablemap;
    }

    public TreeSet()
    {
        this(((NavigableMap) (new TreeMap())));
    }

public boolean add(Object obj)
    {
        return m.put(obj, PRESENT) == null;
    }



private transient Entry<K,V> root = null;

 public Object put(Object obj, Object obj1)
    {
        Entry entry = root;
        if(entry == null)
        {
            root = new Entry(obj, obj1, null);
            size = 1;
            modCount++;
            return null;
        }
        Comparator comparator1 = comparator;
        int i;
        Entry entry1;
        if(comparator1 != null)
        {
            do
            {
                entry1 = entry;
                i = comparator1.compare(obj, entry.key);
                if(i < 0)
                {
                    entry = entry.left;
                } else
                if(i > 0)
                {
                    entry = entry.right;
                } else
                {
                    return entry.setValue(obj1);
                }
            } while(entry != null);
        } else
        {
            if(obj == null)
            {
                throw new NullPointerException();
            }
            Comparable comparable = (Comparable)obj;
            do
            {
                entry1 = entry;
                i = comparable.compareTo(entry.key);
                if(i < 0)
                {
                    entry = entry.left;
                } else
                if(i > 0)
                {
                    entry = entry.right;
                } else
                {
                    return entry.setValue(obj1);
                }
            } while(entry != null);
        }
        Entry entry2 = new Entry(obj, obj1, entry1);
        if(i < 0)
        {
            entry1.left = entry2;
        } else
        {
            entry1.right = entry2;
        }
        fixAfterInsertion(entry2);
        size++;
        modCount++;
        return null;
    }
-------------------------------------
Treemap inner class Entry class
-----------------
 static final class Entry
        implements Map.Entry
    {

        Object key;
        Object value;
        Entry left;
        Entry right;
        Entry parent;
        boolean color;
---
        Entry(Object obj, Object obj1, Entry entry)
        {
            left = null;
            right = null;
            color = true;
            key = obj;
            value = obj1;
            parent = entry;
        }
--------------------------------------------------

Why doesn't Java.lang.Object implement the Serializable Interface? 


1. Serializable is marker interface, which is empty, but when a class is marked Serializable that means its objects are Serializable.
2. The reason the java.lang.Object didnt implement Serializable is because, what if you do NOT want to make certain fields as Serializable and you my mistake missed to add transient to that field, then will be a havoc.
3. By making the programmer implement Serializable for his class, it makes an awareness among the programmer that he has consciously implemented it, and should take necessary step to prevent anything to be serialized which should not be.
--------------------------------------------------------------------------------------------------------
http://www.javasafari.com/Ankit/InterViewPocketBook/AppData/Java.txt
--------------------------------------------------------------------------------------------------------------

Exceptions:--
-------------------------------------------

http://www.javaspecialists.eu/archive/Issue162.html

http://javarevisited.blogspot.in/2014/06/how-to-create-custom-exception-in-java.html

Deciding whether to use an exception or a return value is a balance of several "forces"::-

The caller can ignore a return value and continue with the next line, but it can't ignore an exception.
Exceptions tend to be used in cases where ignoring the problem and continuing could lead to a bigger problem.
Exceptions impose a burden on the caller because the code to handle them is more complex than just checking a
 return value. So they're often avoided when a simple return value would suffice.
On the other hand, exceptions can relieve the immediate caller of the burden of checking the result,
because it can just trust that if something goes wrong, the stack will be unwound to a catch block somewhere else.
Exception handling is more complex than ordinary return, so there's a performance hit if they're thrown frequently.
 Exceptions are generally used for situations that aren't expected to happen frequently.
When the error information and the "normal" result are of different types, throwing an exception is generally better
than shoehorning unrelated things into the same return value (e.g. making the method return Object so that it can return either a string or a number).
----------------------------------------------------------------------------------
Is it better practice to have void method throw an exception or to have the method return a boolean?
http://codereview.stackexchange.com/questions/11724/is-it-better-practice-to-have-void-method-throw-an-exception-or-to-have-the-meth
Throw exception
Return true/false
Return a status/error code enum
--------------------------------------------------------------------------------------------------

HOW LONG IT TAKES TO THROW AN EXCEPTION IN JAVA


-----------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment