Reading a File with Channels and Buffers
Learn to read small and large files from the filesystem using the Java NIO APIs Path, FileChannel, ByteBuffer and MappedByteBuffer.
Learn to read small and large files from the filesystem using the Java NIO APIs Path, FileChannel, ByteBuffer and MappedByteBuffer.
The Chain of Responsibility is known as a behavioral pattern. The main objective of this pattern is that it avoids coupling the sender of the request to the receiver, giving more than one object the opportunity to handle the request. The core logic defined by GoF is : “Gives more …
Timer is a utility class which is used to schedule tasks for both one time and repeated execution in spring applications. Timer is dependent on system clock
Learn to test Spring security authentication using JUnit testcase using InMemoryDaoImpl. Also learn to build fully populated authentication object programmatically and then use it in application. SecurityContextHolder Spring security is based on security context, which is kind of static in nature. This essentially means that your do not need to …
So far in previous tutorials, we have learned about securing your application behind login form, custom user detail service and even method level security also. All these security implementations were on controller or model layer of MVC. Its time to add security in view layer. It is mostly needed when …
Spring framework has made securing your application so much easy that you only need to use some basic configurations CORRECTLY, and that’s it !! This security can be applied to multiple levels in your web application. Spring’s basic support is for these levels: URL level security Method level security Entity …
Learn about the contract that spring security expects from UserDetailsService and PasswordEncoder, initial defaults and basic customizations.
Learn about default basic authentication commissioned by Spring security and customize its configurations such as password encodings.
Learn about Log4j log levels. Log4j2 log levels example. Learn about log4j logging level order and how log level works in this log4j tutorial.
Log4j2 comes with multiple options to create and format log files created by the framework. It can create simple log files, HTML log files or even XML log files also. In this tutorial, we will see the example for configuring log4j to produce logs in XML format. To create a …
Java NullPointerException (NPE) is an unchecked exception and extends RuntimeException. NullPointerException doesn’t force us to use a try-catch block to handle it. NullPointerException has been very much a nightmare for most Java developers. It usually pop up when we least expect them. I have also spent a lot of time …
In this Java exception handling tutorial, learn a few important best practices to write robust application code which is error-free as well.
Using the entrySet() specifically is more powerful and yields better performance than using the keySet() for iteration over a HashMap in Java.
We can detect the infinite loop in a LinkedList using “Floyd’s Cycle-Finding Algorithm” or Hare and Tortoise approach.
This Java article compares the performance of an ArrayList iteration using simple for-loop, enhanced for-loop, list iterator and stream API.
Learn about Spring IoC container, how it has been implemented using ApplicationContext, creating it programmatically and accessing the beans.
Dependency injection is a specific implementation of IoC where dependencies are injected into the component by the IoC container (Spring in this case).
Suppressed exceptions, as name suggest, are exceptions thrown in the code but were ignored somehow. If you remember try-catch-finally block execution sequence and how they return any value or exceptions, you will recall that exceptions thrown in finally block are suppressed if an exception is thrown in try block also. …
In Java Concurrency, until we have a particular reason, it is always recommended to implement the Runnable interface to create new threads.
Learn the differences between sleep() and wait() methods in Java. Learn when o use which method and what effect they bring in Java concurrency.
In Java, a synchronized block of code can only be executed by one thread at a time. Also, java supports multiple threads to be executed concurrently. This may cause two or more threads to access the same fields or objects at same time. Synchronization is the process which keeps all …
1. Object Creation is Expensive We know to create objects in java using the new keyword. A new instance created in Java allocates the memory in the heap, so creating new objects is considered an expensive operation. To avoid this expensive object creation process, many of the frameworks have been …
Java is passed by value and not pass-by-reference. If it had been pass-by-reference, we should have been able to C like swapping of objects.
Read all the Java interview questions and answers in this article to refresh your concepts and possibly have some new ones added to the list.
Learn to create a new Maven project in IntelliJ, run commonly used Maven commands and fix Maven issues in IntelliJ with examples.
Many times, we need to enforce that java build process should halt immediately if deployment environment does not have not a specific operating system, or it does not contain a minimum required java version. If you are using maven for build process, then these limitations can be easily be configured …
Suppose you had created and maintained your project from maven for long time, but now you have instructions to move it to ant build environment. Well, it does not look easy, but it really is very much. All you need to use if maven ant plugin which is specifically only …
Learn how to change the Maven local repository location in Eclipse by updating M2_REPO variable and, temporarily, only for current Maven execution.
The prototype design pattern is used in scenarios where an application needs to create a number of instances of a class that have almost the same state or differ very little.
Maven proxy settings. Learn to configure maven proxy settings in settings.xml file. Learn to configure and use maven https proxy settings in eclipse.
Learn where is maven local repository location? Learn how to change maven local repository location. Change repo location in windows 7, windows 10 & linux.
Learn to create a Maven web project in Eclipse, which we should be able to import into the Eclipse IDE for further development. To create an Eclipse-supported web project, we will need to create a normal Maven web application and then make it compatible with the Eclipse IDE. Step 1: …
Learn to create a Java application project with maven, using interactive and non-interactive modes from the command prompt. 1. Using Maven Non-interactive Mode In non-interactive mode, Maven creates a blank Java project with all default options applicable for the selected Maven template. To create this, type the below command. This …
Learn to install Maven on a Windows operating system. In this maven installation guide, we are installing Maven on a Windows 11 machine. The steps are the same for a Windows 10 machine as well. 1. Windows Environmant Variables Maven is a build and dependency management tool for Java applications …
Java palindrome example. Learn palindrome programs in Java using the reverse method, for loop and recursion methods.
A thread dump is a list of all the Java threads that are currently active in a Java Virtual Machine (JVM). There are several ways to take thread dumps from a JVM. It is highly recommended to take more than 1 thread dump while analyzing any problem such as deadlock …
In this tutorial, learn to read or parse XML document using Java SAX parser API for XML example. Learn to parse XML elements to java objects.
Spring @ExceptionHandler annotated methods handle specific exceptions, whereas @ControllerAdvice annotated class acts as a global exception handler.
I found these programming quotes on the internet and found them too good to share with you all. Enjoy !! Java: write once, run away! -Brucee If Java had true garbage collection, most programs would delete themselves upon execution. – Robert Sewell There are two ways of constructing a software …
Learn to parse an XML document and read the value of an attribute using XPath in Java. We can read the attribute value for all its occurrences in the document, or only for selected nodes in the XML. 1. XPath Expression for Attributes In XPath, the ‘@’ is used to …
All of us have come across situations when we have to parse user input for validation. Other fields such as text or numeric are rather easy, but Java date validation is a little bit difficult, and a small error can leave the application in an unstable state. 1. Java Date …
In this Spring tutorial, we will learn to use spring mvc interceptor in spring mvc applications. This tutorial is very short to focus only on spring interceptor configuration and usage. Interceptors, as we know, are special web programming constructs which gets invoked every time when a certain pre-configured web request …
Spring @Configuration annotation example. @Configuration annotation helps in Spring annotation based configuration. It is also called Spring Java Config.
Password validation is the need of almost all applications today. There are various ways to validate passwords from writing everything manually to using third-party available APIs. In this password validation tutorial, we are building a password validator using regular expressions. 1. Regex for Validating the Passwords ((?=.*[a-z])(?=.*d)(?=.*[@#$%])(?=.*[A-Z]).{6,16}) The above regular …
JUnit Test Listener – JUnit RunListener Example. JUnit also provide support for adding listeners while executing the tests via RunListener class.
In any application, which is being built incrementally, often it is desired that we should be able to run only certain tests whenever a new feature is introduced. This can be achieved using JUnitCore class of JUnit framework. JUnitCore is an inbuilt class in JUnit package and it is based on facade …
A regular expression defines a search pattern for strings. This pattern may match one or several times or not at all for a given string. The abbreviation for regular expression is regex. Regular expressions can be used to search, edit, and manipulate text. Regex meta characters are special symbols that …
Java enum example. The purpose of enum is to enforce compile time type safety. Learn enum constructors, methods, inheritance, EnumMap and EnumSet etc.
Learn to use underscores between digits in Java numerical literals such as int, long or double. It helps in improving the code readability.
Java program to send email through Gmail SMTP server using TLS or SSL protocols. Also, send plain text emails as well as attachments.
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.