August 29, 2019

'Nazar' actor Harsh Rajput felicitated for his excellence!

Harsh Rajput, who is currently enthralling the audience with his brilliant performance in Gul Khan's popular show Nazar, turned nostalgic after getting felicitated by Mumbai University for his contribution in the field of acting.

August 27, 2019

Part 10: Java Thread Interview Questions & Answers (ReentrantLock and ReentrantReadWriteLock)

What are Reentrant Locks?

  • ReentrantLock in Java is added on java.util.concurrent package in Java 1.5 along with other concurrent utilities like CountDownLatch, Executors, and CyclicBarrier.
  • ReentrantLock is a concrete implementation of the Lock interface provided in the Java concurrency package from Java 1.5 onwards. 
  • Reentrant Locks are provided in Java to provide synchronization with greater flexibility.
  • The code which manipulates the shared resource is surrounded by the calls to lock and unlock method. This gives a lock to the current working thread and blocks all other threads which are trying to take a lock on the shared resource.
  • A ReentrantLock allows threads to enter into the lock on a resource more than once. When the thread first enters into the lock, a hold count is set to one. Before unlocking the thread can re-enter into lock again and every time hold count is incremented by one. For every un-lock request, the hold count is decremented by one and when the hold count is 0, the resource is unlocked.
  • Fairness parameter is provided while creating an instance of ReentrantLock in the constructor. The fairness parameter used to construct the lock object decreases the throughput of the program.
  • ReentrantLock provides the same visibility and ordering guarantee, provided by implicitly locking, which means, unlock() happens before another thread gets lock().
  • If you forget to call the unlock() method in the finally block, it will lead to bugs in the program. Make sure that the lock is released before the thread exits.

Part 9: Java Thread Interview Questions & Answers (All About Java Semaphore and Mutex)

Why do we need Semaphore?

  • Let's say our application calls a service, which is quite slow. Because the service is slow, only 5 calls can be made at a time.
  • Now let's say their are 50 threads present in the application, and they all try to access the service. We need a mechanism, by which we can restrict the call to slow service. This can be achieved using Semaphore.
  • A Semaphore will act as a layer, with a limited number of permits (in our case permits=5). 
  • A thread 1 wants to access the service, it will call the acquire() method to get the permit. Semaphore will check the number of available permits (in our case it's 5), if it's available it will give a permit to thread 1 and then decrease the permit by 1 (now the permit=4).
  • While thread 1 is accessing the slow service, thread 2 comes. The Semaphore again checks the available permit (which is 4) and gives it to thread 2.
  • Let's say threads 3, 4 and 5 come and get the permit. While these 5 threads are accessing the slow service thread 6 comes, since now the permit is 0 Semaphore will block thread 6.
  • In the meantime, Thread 1 completes the work from slow service, it will call the release() method. The release() method will increment the permit(which was 0) by 1. Now the permit is 1, and the Semaphore gives access to Thread 6 and decrements the permit (new value will be 0).

August 21, 2019

Ullu App ready to make web-series in Bangla


Ullu is India’s one of the popular OTT platforms with more than 4 million mobile downloads and is available in over 100 countries. The digital platform currently offers Hindi web-series across various genres, which are dubbed in regional languages like Marathi, Bhojpuri, Bangla, Telgu etc. Now, Ullu is all set to embark a new journey and will soon start producing web-series in regional languages starting with Bangla.

When contacted Vibhu Agarwal, CEO at Ullu Digital Pvt Ltd, told us, "We have received amazing feedback for our web-series like Singardan, Halala, Panchali from the regional viewers. Since regional content is the demand of the hour, we are planning to create original content in regional languages on topics that resonate with regional culture and viewers."


Ullu will start exploring the regional market with a bang by producing dozens of web-series in Bangla. Confirming the same Vibhu said, "Bengal has a rich and vibrant culture, which always fascinates me. That's the reason, we are starting our regional debut with Bangla web-series. We are planning to come up with more than 25 web-series within a year."

He further added, "There is a phenomenal amount of talent in Bengal, which we want to utilize. We are looking forward to work with the regional artists and shoot in the exotic locals of West Bengal and Bangladesh."

For those uninitiated, popular Bengali actor Riju Biswas, who has done several Bengali TV serials like Checkmate, Tomay Amay Mile (the Bengali adaptation of popular Hindi show Diya Aur Baati Hum), and Bou Kotha Kao is playing the lead role in Ullu's upcoming web-series 'Size Matters'.  

August 04, 2019

Purpose of Spring's @Qualifier

NoUniqueBeanDefinitionException while Autowiring
@Autowired annotation is used to inject a dependency in Spring explicitly. By default, Spring resolves autowired entries by type. In some cases this annotation alone isn't enough for Spring to understand which bean to inject.

August 03, 2019

Oracle Interview Questions

  1. What is abstraction and encapsulation in java? (solution)
  2. If we didn't declare any exception in super class then in subclass can we declare any checked/custom exception.(solution)
  3. Can I have only try block in code? (solution)
  4. Why wait(), notify() and notifyAll() are defined in Object class? (solution)
  5. Can we override wait() or notify() methods? (solution)
  6. Difference between wait(), sleep() and yield()? (solution)
  7. What is the purpose of join()? (solution)
  8. Explain Singleton design pattern.
  9. Write a program to swap two numbers with out using third variable?

Deloitte India Interview Questions

Database
  1. What is the difference between a function and a stored procedure. (solution)
  2. What is the difference between a Unique and a primary key. 
  3. Difference between truncate and delete command. (solution)
  4. Can I use use a function in where clause?
Hibernate
  1. How many types of cache is available in Hibernate?
  2. What is the difference between get and load in Hibernate? (solution)
  3. How many tables will be created in @ManyToMany mapping? (solution)
  4. What is HQL?
  5. What is Nativel SQL?
Spring
  1. What is the default scope of Spring?
  2. How can I change the scope of bean in Spring?
  3. What is the advantage of Spring Boot?

August 01, 2019

Bulley Shah's 'Rab Rab Karde Budhe Hoo Gaye' Meaning In English..


रब-रब करदे बुड्ढे हो गए, मुल्ला पंडित सारे.  
रब दा खोज खरा न लब्बा, सजदे कर कर हारे..

July 28, 2019

How to check if a Tree is subtree of another Tree?

To check if the given tree is subtree of another tree, first we need to undertand if the how can we check if the tree's are identical or not.

Please visit: Check if two Binary Trees are Identical or not?

To verify if a tree is subtree of another, we need to traverse the Tree T in a preorder fashion.For every visited node in the traversal, see if the subtree rooted with this node is identical to another tree S.

How to check of two Binary Trees are Identical?

Two Binary trees are identical when they have same data and structure/arrangement of data is also same. To find if they are identical or not, we need to traverse both the trees simultaneously, and in each iteration we will compare the data of current node and the children of both the trees.

Factorial using recursion in Java

Write a program to calculate Factorial of a number using recursive function. To improve the performance, try to use HashMap, which will store the calculated factorials that can be reused.

FYI, Factorial of n is the product of all positive descending integers. Factorial of n is denoted by n!.

Bottom View of a Binary Tree

Recently I had given interview in Morgan Stanley for Senior Java Developer profile, the intervier asked me, we have a balanced Binary Tree, am trying to throw a light from a particular node, which all nodes will be visible?

I tried my best, but failed to write an algorithm. After the interview I realized he was asking to write an algorithm to see the bottom view of a Binary Tree.

The bottom view of a binary tree refers to the bottommost nodes present at their horizontal distance.

If we see the tree from bottom from a particular node, which all nodes will be visible is the bottom view of a Binary Tree.
The bottom view of above Binary Tree is: 7, 5, 8, 6

July 27, 2019

Vertical Order Traversal of a Binary Tree

Let's say we have below Binary Tree

In vertical traversal, we print nodes of a binary tree in vertical order by assuming that the left and right child of a node makes 45 degree angle with the parent.

We need to check the Horizontal Distances from the root for all nodes. If two nodes have the same Horizontal Distance (HD), then they are on the same vertical line.

Level Order Traversal of a Binary Tree

Let's say we have below Binary Tree


We need to print nodes level by level. i.e. all nodes present at level 1 should be printed first followed by nodes of level 2 and so on. All nodes for any level should be printed from left to right.

Morgan Stanley Java Interview Questions

  1. What is a predicate in Java? Can you throw an exception from a predicate? Its a functional interface which accept one argument and produce a result. (solution) 
  2. Explain fail fast and fail safe iterators. (solution)
  3. Implement stack using Queue.(solution)
  4. Write a program to reverse a linked list. (solution)
  5. Write a program to return all characters from a string which appeared more than once. (solution)
  6. Generate the Fibonacci recursively and iteratively in Java. Explain the complexities for both solutions.(solution)
  7. Swap the values between two elements without using a third element.
  8. Generate all anagrams of a String.(solution)
  9. How PriorityQueue works internally in Java?
  10. Difference between TreeSet and PriorityQueue in Java.
  11. Given a string like ABC find all possible distinct permutations, e.g:ABC,BAC,CAB etc.
  12. Sort array elements in place making even and odd number together.
  13. Write a function to return the maximum difference between two elements in an array.
  14. I have an array of million integers. I want to sum it efficiently. How would you do it without using Java 8 parallel streams? (Hint: use forkjoinpool)
  15. Some Basic Core Java Interview Questions related to Polymorphism and try catch(solution)
  16. Write a method to find the first non-repeating character from a String? (solution)
  17. We have a balanced Binary Tree, am trying to throw a light from a particular node, which all nodes will be visible?(solution)
  18. What will happen if we return a constant number from overriden hashCode() method?
  19. What will happen if we return constant number from overriden hashCode() method and false from equals()?
  20. What will happen if we return constant number from overriden hashCode() method and true from equals()?

July 24, 2019

Sushmita Sen’s brother, Rajeev talks about his debut

Ullu App is coming up with a series which is based on a terrorist attack on Peshawar's Army Public School on 16th December, 2014, in which more than 148 people, most of them children, were killed. Now we heard, Sushmita Sen’s brother, Rajeev will be making his debut with the series.