One of the most common questions I get asked by PHP beginners is, Why are there 4 ways to include a file on your page?
There is include(), include_once(), require() and require_once().
What do these do? What’s the difference between them?
In this article, we’re going to look at all these different functions and will talk about an example of when you need to use each of them.
include() The include function is used in PHP when you want to include a file within the current process. It takes one argument which will be a string to the file path you want to include.
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. Any collection can be written to store any class. For example, Collection can hold strings, and the elements from the collection can be used as strings without any casting required.
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.
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?>&keycode=<?=$this->keycode?>" target="_blank" style="color: #005399; text-decoration: none" >http://lab.haozhexie.com/CourseOcean/accounts/resetPassword?email=<?=$this->email?>&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.
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.