My Articles:
In some badly coded applications, when an unknown exception occurs the application server usually displays the evil exception stack trace to the user in the webpage itself. In this case, users have nothing to do with this stack trace and complain that your application is not user-friendly. Moreover, it can …
In previous examples, we learned about XmlViewResolver and InternalResourceViewResolver view templates. In this post, we will learn about ResourceBundleViewResolver templates. ResourceBundleViewResolver loads view beans from a resource bundle in the classpath root. Note that ResourceBundleViewResolver can also take advantage of the resource bundle capability to load view beans from different …
The XmlViewResolver class has been deprecated as of 5.3, in favor of Spring’s common view resolver variants and/ or custom resolver implementations.
Learn to configure InternalResourceViewResolver in Spring MVC application which helps in resolving view names based of ViewResolver class implemetation and prefix and suffix attributes.
Internationalization (i18n) is the process of designing a software application so that it can potentially be adapted to various languages and regions without engineering changes. Localization is the process of adapting internationalized software for a specific region or language by adding locale-specific components and translating text. Spring framework is shipped …
If you want to access i18n resources bundles for different locales in your Spring application, then that a class must implement MessageSourceAware interface. After implementing MessageSourceAware interface, spring context will automatically inject the MessageSource bean’s reference into the class via ‘setMessageSource(MessageSource messageSource)‘ setter method which your class needs to implement. …
We can add support for displaying non-english characters by changing the default encoding to UTF-8 i.e. Unicode by setting in the Resource.
Spring HandlerInterceptor allows creating interceptors in Spring or Boot applications to handle requests pre- and post-controller methods.
Spring @RequestMapping annotation, part of Spring MVC module, is used for mapping HTTP requests to handler methods in the @Controller classes.
Spring MVC tutorial discusses the MVC pattern, front controller pattern, and building blocks of Spring MVC framework with a hello world application.
1. Problem If you are facing this error after importing an existing maven project into your eclipse IDE, then it means that http-servlet is not available in the project’s classpath and you must include it. The error looks like this. 2. Solution To include http-servlet into your classpath, you have …
This is a very strange problem but this is the fact that when you create a maven web application using “-DarchetypeArtifactId=maven-archetype-webapp” then Java source folders are not created. Rather a ‘/resources‘ folder is created. Files placed in ‘/resources‘ folder are placed in your classpath when a jar or war file …
Learn Spring AOP Pointcut expression syntax and see a few examples such as pointcut expressions for specific methods or all methods in a class or package.
Spring AOP provides simple methods to order the aspects either using the @Order annotation or implementing the Ordered interface.
In Spring AOP annotation example, learn to create an @Aspect (e.g. LoggerAspect) to log the execution time of methods within our application.
Learn to create and receive publisher-subscriber-style native events in a Spring application using @EventListener and @RecordApplicationEvents annotations.
Learn to implement i18n in Spring applications using the ResourceBundleMessageSource and how the resource bundles are resolved using locales.
Spring BeanPostProcessor allows for custom modification of new bean instances created by spring bean factory. Spring AOP classes use bean post-processors
Learn different ways to load resources or files (e.g. text files, XML files, properties files, or image files) into the Spring application context. Spring ResourceLoader provides a unified getResource() method to retrieve an external resource by the resource path. 1. Spring Resource Interface The Spring Resource is a general interface …
In Spring framework, if you want to create a bean by invoking a static factory-method, whose purpose is to encapsulate the object-creation process in a static method then you could use factory-method attribute. Read More : Spring FactoryBean Static factory method example If you want to create different EmployeeDTO objects …
In Spring, FactoryBean creates beans that cannot be created using the ‘new’ keyword and involve complex initialization or configuration.
Learn about spring bean stereotype annotations i.e. @Controller, @Component, @Repository and @Service, their real-life usages and examples.
Learn to copy a directory into a new location in Java. Learn to apply FileFilter to include or exclude subdirectories and specific files.
A checksum hash is an encrypted sequence of characters obtained after applying specific algorithms and manipulations on user-provided content. In this Java hashing tutorial, we will learn to generate the checksum hash for the files. 1. Why Generate a File’s Checksum? Any serious file provider provides a mechanism to have …
Learn to make a file read-only in Java. A read-only file can be opened for reading, but we cannot modify or delete the file contents.
Copying a file from one place to another in Java is a common task. Learn to copy files using Java NIO, Commons-IO and Guava APIs.
Learn to use the Java FilenameFilter to traverse a directory and search all files with names matching a specified pattern.
Learn to create BufferedWriter with default, configure custom internal buffer sizes and write characters data into a file using it.
Learn to create and operate the BufferedReader instance, set default buffer size and read from a file and system console with examples.
Learn to create a new file using different techniques including NIO Files and Path, IO File, File OutputStream, and open-source libraries.
When using FileChannel transferTo() and transferFrom() methods, data doesn’t pass through the Java heap, thus reducing garbage collection pressure.
Learn about Java memory-mapped files and learn to read and write content from a memory mapped file with the help of RandomAccessFile and MemoryMappedBuffer. 1. Java Memory-mapped IO If you know how java IO works at lower level, then you will be aware of buffer handling, memory paging and other …
Java NIO Channels provide an important new capability known as scatter/gather (referred to in some circles as vectored I/O). Scatter/gather is a simple yet powerful concept. Scatter/gather is a technique through which bytes can be read from a stream into a set of buffers (vectors) with a single read() invocation …
Channels are the second major addition to java.nio after buffers which we have learned in my previous tutorial in detail. Channels provide direct connection to the I/O services. A Channel is a medium that transports data efficiently between byte buffers and the entity on the other end of the channel …
Java Buffer classes are the foundation upon which java.nio is built. In this tutorial, we will take a closer look at the buffers. We will discover the various buffer types, and learn how to use them. We’ll then see how the java.nio buffers relate to the Channel classes of java.nio.channels. …
In concurrent programming, a semaphore is a synchronization aid that manages access to a shared resource by multiple threads.
The Object class in Java has three final methods that allow threads to communicate i.e. wait(), notify() and notifyAll(). Learn how to use these methods.
A binary semaphore is a synchronization primitive that can hold only two values, typically 0 and 1. We use binary semaphore to manage access to a shared resource by multiple threads in a concurrent environment. Conceptually, a binary semaphore can be thought of as a lock that allows only one …
Java provides another mechanism for the synchronization of blocks of code based on the Lock interface and classes that implement it (such as ReentrantLock). In this tutorial, we will see a basic usage of Lock interface to solve printer queue problem. 1. Lock Interface A java.util.concurrent.locks.Lock is a thread synchronization …
The factory design pattern is one of the most used design patterns in the java. It is one of creational patterns and can be used to develop an object in demand of one or several classes. With this factory, we centralize the creation of objects. The centralization of creation logic …
Today, one of the most critical aspects of a concurrent application is shared data. When you create a thread that implements the Runnable interface and then starts various Thread objects using the same Runnable object. All the threads share the same attributes that are defined inside the runnable object. This …
1. UncaughtExceptionHandler Java applications have two kind of exceptions – checked exceptions and unchecked exceptions. Checked exceptions must be specified in the throws clause of a method or caught inside them. Unchecked exceptions don’t have to be specified or caught. When a checked exception is thrown inside the run() method …
Learn how Java IO operations are mapped at the machine level; and what all things the hardware does all the time when application is running.
Servlets are Java classes that conform to the Java Servlet API, which allows a Java class to respond to requests. Although servlets can respond to any type of request, they are most commonly written to respond to web-based requests. A servlet must be deployed to a Java servlet container in …
Learn to setup PowerMock with Mockito and JUnit; test private, static and final methods in the classes and verify method invocation counts.
Learn how to run testng suites and classes in this testng maven surefire plugin example. Learn to include and exclude tests from suites.
TestNG parallel execution of tests, classes and suites. Learn to run multiple tests in different threads or a single test in multiple threads.
TestNG @Factory is used to create instances of test classes dynamically. Whereas, @DataProvider is used to provide parameters to a test.
Learn about the TestNG @Factory annotation that allows the tests to be created at runtime depending on provided datasets or conditions. 1. When to use TestNG @Factory? Sometimes we may need to run a set of tests with different data values. To achieve this we may define a separate set …
TestNG allows a test method to be dependent on a single or a group of test methods so that dependent tests are executed before the given test.