Make PDF Files Password Protected Using Java

Table of Contents Introduction Prerequisites Project Setup Protect PDF using Password Testing Encrypted PDF Files Source Code Introduction This example is going to show you how to make pdf files password protected using Java programming language. Many applications require dynamic generation of PDF documents for reporting purpose, such as, generating statements for customers, readers buying online specific chapters of a…

How To Mock Super Class Method In Junit

Mock Super Method Here in this method’s mock example I am going to show you how to mock super class method in Junit test class. A class that extends another class is called a child class and a class that is extended by another class is called a super class. So, basically when a child class calls super class method…

Intellij IDEA Error – Command Line Is Too Long

Problem Here I am going to tell you how you can solve the problem when you try to run Java main class in Spring Boot application from IntellijIDEA. The actual error you would find as given below:

HttpsUrlConnection REST API Call – Auth Token And Proxy Server

Introduction In this example I am going to show you how to call REST APIs using javax.net.ssl.HttpsURLConnection. So, I am using plain Java code to send or receive data to or from the REST APIs. I am also going to show you how to send authentication token in the HTTP header. I am also going to show you how to use…

Spring JdbcNamedParameterTemplate Junit Mockito

Introduction In the tutorial, Spring NamedParameterJdbcTemplate and MapSqlParameterSource Example, I had shown how to save new record in the database and how to fetch record from database. Here I am going to show you how to mock Spring JdbcNamedParameterTemplate SqlParameterSource with Junit Mockito. I am going to use Junit 5 framework for this example. I am also using Mockito framework…

How To Read Large Excel File Using Apache POI

Introduction Apache POI is the most popular library when comes to manipulate word, excel, ppt based documents. In this example I am going to show you how to read large excel file using Apache POI library. Your large excel file may contain various kind of information, such as, Human Resource data, Sales data, Credit Cards, Bank Transactions, etc. The large…

Predicate and Function functional interfaces in Java 8 or later

In this example you will see what are Predicate and Function functional interfaces in Java 8 or later version of Java. Functional interfaces provide target types for lambda expressions and method references. Each functional interface has a single abstract method, called functional method for that functional interface, to which the lambda expression’s parameter and return types are matched. The Predicate…

Check a String is a Pangram in Java

This example will show you what is a pangram and how to check a string is a pangram in Java program. A string is a pangram if it contains all letters or characters of alphabets (a to z or A to Z). A pangram or holoalphabetic sentence is a sentence using every letter of a given alphabet at least once….

Dynamic Tests – @TestFactory in Junit 5

Here in this tutorial I will tell you what are Dynamic Tests and @TestFactory in Junit 5 and how to create @TestFactory in Junit 5. Test cases, annotated with @Test, are static in the sense that they are fully specified at compile time, and their behavior cannot be changed by anything happening at runtime. In addition to these standard static…

How to test Private Methods using Junit 5

Introduction Here in this tutorial I will show you an example on how to test private methods using Junit framework. I am using Junit 5 framework to test the private method. Using Mockito framework you won’t be able to test private methods, but using PowerMock core API you will be able to test the private methods. You can also use…