Monthly Archives: October 2014
Almost all collections in Java are derived from the java.util.Collection interface. Collection defines the basic parts of all collections. The interface states the add() and remove() methods for adding to and removing from a collection respectively. Also required is the toArray() method, which converts the collection into a simple array of all the elements in the collection. Finally, the contains() method checks if a specified element is in the collection. The Collection interface is a subinterface of java.lang.Iterable, so any Collection may be the target of a for-each statement. (The Iterable interface provides the iterator() method used by for-each statements.) All collections have an iterator that goes through all of the elements in the collection. Additionally, Collection is a generic.…
Spring Framework is developed on two core concepts – Dependency Injection and Aspect-Oriented Programming (AOP). Today we will look into the core concepts of Aspect-Oriented Programming and how we can implement it using Spring Framework. Aspect-Oriented Programming Overview Most of the enterprise applications have some common crosscutting concerns that is applicable for different types of Objects and modules. Some of the common crosscutting concerns are logging, transaction management, data validation, etc. In Object-Oriented Programming, modularity of application is achieved by Classes whereas in Aspect-Oriented Programming application modularity is achieved by Aspects and they are configured to cut across different classes. AOP takes out the direct dependency of crosscutting tasks from classes that we can’t achieve through a normal object-oriented programming…
Consistent hashing is a special kind of hashing such that when a hash table is resized and consistent hashing is used, only K/n keys need to be remapped on average, where K is the number of keys, and n is the number of slots. In contrast, in most traditional hash tables, a change in the number of array slots causes nearly all keys to be remapped. Consistent hashing achieves the same goals as Rendezvous hashing (also called HRW Hashing). The two techniques use different algorithms and were devised independently and contemporaneously. Problem with Distributed Cache The need for consistent hashing arose from limitations experienced while running collections of caching machines - web caches, for example. If you have a collection…
Yesterday, I spent several hours solving this problem. In Laravel Framework, you can do as following: Step 1: Create an Email Template First of all, you need to create an email template in the views folder, such as /view/mails/reset.phtml. Step 2: Complete Sending Email Function
String Constant Pool is possible only because String is immutable in Java and its implementation of the String interning concept. The string pool is also an example of a Flyweight design pattern. String Pool Examples Instructions So as you can see, the reference of s1, s2, s3, and s6 are the same. Actually, the object of s4 and s5 are stored in the Heap of JVM, and String Constants are stored in the Method Area of JVM. Something about intern() When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool,…
Design patterns represent the best practices used by experienced object-oriented software developers. Design patterns are solutions to general problems that software developers faced during software development. These solutions were obtained by trial and error by numerous software developers over quite a substantial period of time. This tutorial will take you through step by step approach and examples using Java while learning Design Pattern concepts. Three Types of Design Patterns Design patterns are divided into three fundamental groups: Behavioral Patterns, Creational Patterns, and Structural Patterns. Behavioral Patterns: Abstract Factory, Builder, Factory Method, Prototype, and Singleton. Creational Patterns: Adapter, Bridge, Composite, Decorator, Facade, Flyweight, and Proxy Structural Patterns: Chain of Resp., Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template, and Visitor Seven Principles of Design Patterns Open Close Principle Software entities like…