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.
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.
Yesterday, I spent several hours solving this problem. In Laravel Framework, you can do as following: Mail::send("mails.reset", $data, function ($message) use ($email) { $message ->from("noreply@infinitescript.com", "CourseOcean") ->subject("Reset Your Password"); $message->to($email); }); 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. <table cellspacing="0" cellpadding="0" border="0"> <tbody> <tr> <td style=" padding: 15px 15px 0 15px; background: #fff; border-radius: 4px 4px 0 0; " > <div> <img src="http://lab.haozhexie.com/CourseOcean/img/logo.png" alt="CourseOcean" height="85" width="290" /> </div> </td> </tr> <tr> <td style=" padding: 15px; background: #fff; border-radius: 0 0 4px 4px; font-size: 12px; " > We received a request to reset the password for your account, <?=$this->username?>.<br /><br /> If you made this request, click the link below. If you didn't make this request, you can ignore this email.<br /><br /> <a href="http://lab.haozhexie.com/CourseOcean/accounts/resetPassword?email=<?=$this->email?>&amp;keycode=<?=$this->keycode?>" target="_blank" style="color: #005399; text-decoration: none" >http://lab.haozhexie.com/CourseOcean/accounts/resetPassword?email=<?=$this->email?>&amp;keycode=<?=$this->keycode?></a ><br /><br /> Yours, <br /> CourseOcean.<br /><br /> <div style=" border-top: 3px solid #eee; color: #999; font-size: 11px; line-height: 1.2; " > <br />Powered by <a href="http://lab.haozhexie.com/CourseOcean/" target="_blank" style="color: #005399; text-decoration: none" >CourseOcean</a >. All rights reserved.<br /> </div> </td> </tr> </tbody> </table> Step 2: Complete Sending Email Function function sendResetPasswordEmail($username, $email) { $keycode = $this->generateRandomString(32); $view = new \Zend\View\Renderer\PhpRenderer(); $resolver = new \Zend\View\Resolver\TemplateMapResolver(); $resolver->setMap([ "mailTemplate" => __DIR__ . "/../../../view/mails/reset.phtml", ]); $view->setResolver($resolver); $viewModel = new ViewModel(); $viewModel->setTemplate("mailTemplate")->setVariables([ "username" => $username, "email" => $email, "keycode" => $keycode, ]); $bodyPart = new \Zend\Mime\Message(); $bodyMessage = new \Zend\Mime\Part($view->render($viewModel)); $bodyMessage->type = "text/html"; $bodyPart->setParts([$bodyMessage]); $message = new \Zend\Mail\Message(); $message ->addFrom("noreply@infinitescript.com", "CourseOcean") ->addTo($email) ->setSubject("Reset Your Password") ->setBody($bodyPart) ->setEncoding("UTF-8"); $transport = new \Zend\Mail\Transport\Sendmail(); $transport->send($message); }
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 String s1 = "Hello"; String s2 = "Hello"; String s3 = "Hel" + "lo"; String s4 = "Hel" + new String("lo"); String s5 = new String("Hello"); String s6 = s5.intern(); System.out.println(s1 == s2); // true System.out.println(s1 == s3); // true System.out.println(s1 == s4); // false System.out.println(s4 == s5); // false System.out.println(s1 == s6); // true Instructions So as you can see, the reference of s1, s2, s3, and s6 are the same.
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.
Process What’s Process? In computing, a process is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system (OS), a process may be made up of multiple threads of execution that execute instructions concurrently. Process states An operating system kernel that allows multi-tasking needs processes to have certain states. Names for these states are not standardized, but they have similar functionality.
Differences between wait() and sleep() or sleep() and yield() method in Java Thread is one of the very old questions asked in Java interviews. Though both wait and sleep put threads to the waiting state, they are completely different in terms of behavior and use cases. JavaDoc Definition Thread Class public static void sleep(long millis[, int nanos]) throws InterruptedException Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds plus the specified number of nanoseconds, subject to the precision and accuracy of system timers and schedulers. The thread does not lose ownership of any monitors.
An object is a chunk of memory bundled with the code that manipulates memory. In the memory, the object maintains its state (the values of its instance variables), which can change and evolve throughout its lifetime. To get a newly-created object off to a good start, its newly-allocated memory must be initialized to a proper initial state. Here we take an in-depth look at the mechanisms Java uses to manage object initialization.