Posts

Showing posts from April, 2019

Polymorphism in Java OOP

Image
Polymorphism is word made from two words "Poly" which means many and "morph" means shape/form. Polymorphism means "ability to take multiple shapes or forms". In Java, method and Object both takes multiple forms. There are two forms of polymorphism : Compile time Polymorphism Run time Polymorphism Compile time polymerphism Compile time polymorphism is achieved using method overloading. Method will have same signaturre(name) but different parameters.This method is bound statically with method name and input parameter type hence static binding. Output : Display String Display int Runtime Polymorphism Method overriding is used to achieve Runtime polymorphism. Method will be overridden in subclass. This method is resolved depending on Object instance dynamically at runtime. Output : Display of Display Unit. Display of Monitor.

Inter Thread Communication(Producer-Consumer Problem) simplified

Image
Inter thread communication is very interesting topic where you learn how two thread can talk to each other in a multi-threaded environment. And this is demonstrated with a very simple example of Producer-Consumer problem. Object class's wait and notify method will be used for inter thread communication. I'm assuming two thread Producer Consumer These will be spawned using main thread. Producer will try producing Product. Produce action will be represented by making Available property in Product Object true.  And consumer will be consuming that object by making available property false.  Same object will be used to pass to both threads for inter thread communication Code accessing same object will be synchronised  Main methods used are : Thread.sleep >> It will be used to give some delay so that we can understand code execution. Object.wait >> Wait will be called on product which will make current thread to release lock and wait. Object...

Mixed-Content error for https request making http request

You might have seen mixed-content error while page rendered with HTTPS is making HTTP request. Your server is configured to SSL or to serve only HTTPS request. Server will block HTTP request mostly in this case unless configured so.  Active Mixed Content : It has access to all DOM in current HTML page. I can manipulate page. It can cause man-in-the-middle attack. JavaScript source, CSS source, link, XMLHttpRequest can cause such content. Passive Mixed Content : It is content which does not alter other parts of HTML page.Static image, audio, video link are cause of passive mixed content. You can quickly fix such errors by addressing following points : Use relative URL if content/resource hosted on same server If you are calling content from servlet/JSP/REST API, use relative URL load resources. If absolute URL is used, then make sure all entries for resource URL has HTTPS. make sure you are creating URL starting HTTPS If cross domain is used then use site whi...