Wednesday, 25 October 2017

JAVA : MULTI-THREADING : GREEN Thread, stop(), suspend(), resume()

JAVA : MULTI-THREADING : GREEN Thread, stop(), suspend(), resume()







JAVA : MULTI-THREADING : Daemon Threads

JAVA : MULTI-THREADING : Daemon Threads


Threads which are executing in background are - Daemon Threads

Eg :
-------- 
GC
Signal dispatcher
Attach listner.... etc

Use of Daemon Thread: To support non - Daemon thread













Tuesday, 24 October 2017

JAVA : MULTI-THREADING : Dead Lock

JAVA : MULTI-THREADING : Dead Lock


2 threads waiting for each other forever is Dead Lock

Synchronized keyword  - reason for Dead Lock.
If we don't use Synchronized keyword properly - program will enter to Dead Lock.

There are no resolution technique, but several prevention technique's are available:














JAVA : Serializable

JAVA : Serializable







1. Why serialization is needed..?






2. Why serialVersionUID is needed..? what if not provided

About - serialVersionUID


The serialVersionUID is used as a version control in a Serializable class. If you do not explicitly declare a serialVersionUID, JVM will do it for you automatically, based on various aspects of your Serializable class

Check - https://www.mkyong.com/java-best-practices/understand-the-serialversionuid/


All the managed beans should be serializable because the container may occassionally serialize and passivate the beans or send it over the network. This occurs in situations 
such as heavy load (our case) or when clustering is enabled.

Another tip:

- The managed beans with pageFlow or session scope are required to be serialized while backingBean or request scope are not required to be serialized.

- The ADF/JSF Rich UI components are not serializable and hence they should not be present in pageFlow scope managed beans.

Response: Your pageFlowScope bean should implements Serializable.


Eg:


Possibility 1:



Possibility 2:






Possibility 3:








Possibility 4:


Report


By setting this in java option we will get to know the issues in diagnostic or em logs.

-Dorg.apache.myfaces.trinidad.CHECK_STATE_SERIALIZATION=all

check : http://hasamali.blogspot.in/2011/09/adf-jsf-adfc-scope-object-serialization.html


How Server does Serialization and Deserialization

A simple way to write / serialize the UserBean object into a file – “c:\\UserBean.ser”.


FileOutputStream fout = new FileOutputStream("c:\\UserBean.ser");
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(UserBean Obj);




A simple way to read / deserialize the UserBean object from file – “c:\\UserBean.ser”.



   FileInputStream fin = new FileInputStream("c:\\UserBean.ser");
   ObjectInputStream ois = new ObjectInputStream(fin);
   UserBean = (UserBean) ois.readObject();



Saturday, 14 October 2017

JAVA : STATIC

JAVA : STATIC

static is a non-access modifier in Java which is applicable for the following:
  1. variables
  2. blocks
  3. methods
  4. nested classes




JAVA : BASIC ; 1 : OBJECT REFERENCES

JAVA : BASIC ; 1 : OBJECT REFERENCES



Here if u change d1.name = "NewString";

then d2.name also points to "NewString"

JAVA : ALGORITHM : 3 : Trie - DataStructure - Implementation

JAVA : ALGORITHM : 3 : Trie - DataStructure - Implementation



Plz refer for more information : https://www.geeksforgeeks.org/trie-insert-and-search/


JAVA : ALGORITHM : 2 :

JAVA : ALGORITHM : 2 


1. Remove Repeating Char





1. Add all number in string




3. print Fibonacci series








4. print below pattern

Logic : Use recursive method.










Tuesday, 10 October 2017

JAVA : STRINGS : TRICKY QUESTIONS

JAVA : STRINGS : TRICKY QUESTIONS


1. Is s2.rotation(s1)....?




2. Is 2 strings are Anagram..?

3. String.join() method

4. String -> equals and ==



5. 




6. How many objects will create

String s1 = new String("abc");
String s2 = new String("abc");

Ans : 3 (1 in StringPool, 2 objects in heap)



7.




8. 


























JAVA : ALGORITHM : Find Intersection of LinkedList

JAVA : ALGORITHM : Find Intersection of LinkedList

Logic : In Node -> create one another variable "visible", => when you traverse one LinkedList mark that as "visible=true", so that when ever you traverse second LinkedList -> check for "visible=true"



JAVA : ALGORITHM : BINARY SEARCH

JAVA : ALGORITHM : BINARY SEARCH


ASSUME : array is sorted

keep on divide half -> until you find the number.



JAVA : ALGORITHM : BINARY TREE IMPLEMENTATION

JAVA : ALGORITHM : BINARY TREE IMPLEMENTATION


class Node  {
     int value;
     Node left;
     Node right;

}




https://www.youtube.com/watch?v=98AGQU0z2wg