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.
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.
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.
Most of you will agree that HashMap is a most favorite topic for discussion in interviews nowadays. Now, I am continuing this discussion with you all.
I am assuming that if you are interested in the internal working of HashMap, you already know the basics of HashMap, so I’m skipping that part. But if you are new to the concept, follow official java docs.
Single Statement Answer If anybody asks me to describe “How HashMap works?”, I simply answer: “On the principle of Hashing”. As simple as it is. Now before answering it, one must be very sure to know at least the basics of Hashing. Right?
It’s quite straightforward to integrate Log4j into the Spring MVC application. First, include Log4j.jar library into your project dependency, then create a log4.properties file to define the Log4j’s appender and put this file into the project classpath, Done.
In the tutorial, we show you how to integrate the Log4j 1.x logging framework into the Spring MVC application.
Add Log4j Library to Your Project Download the Log4j library from the official website, or via Maven :
After all the services, DAO, and support classes are tested then it’s time for the controller. Generally, this is hard to test and most developers (based on observation) would rather just test it via Selenium or worse, by hand. That can work but it makes testing logic branches difficult and not to mention it’s time-consuming. Plus no active developer would be willing to wait for browser tests to run before checking in code. Luckily the Spring MVC Test project can do full controller testing via unit tests, it was such a success that it’s now in Spring MVC core as of version 4.0.5.
In this tutorial, you will learn how to develop a Spring 4 MVC Hello world example. We hope this tutorial will give you a quick start with Spring MVC development using the latest Spring 4 Release.
Technologies used:
Spring 4.0.4.RELEASE JDK 1.8 Tomcat 7.0.53 Maven 3.2.1 Eclipse Java EE IDE ( Eclipse Kepler) Maven Project Setup In Eclipse Let us start with the creation of a Maven web project in Eclipse. A maven web project archetype will create all the necessary folder structures required for a web project. We assume that you have installed the Maven plugins for Eclipse.