Powered by Blogger.

How To Use Predicate In Java 8

1 comment :
In Java 8,
The Predicate is a functional interface that represents a single argument function that returns a boolean value. It is widely used in functional programming, especially when working with streams, as it allows you to define conditions that can be tested.
The Predicate Interface: Let’s look at an example of how to use the @FunctionalInterface annotation in a Spring Boot application:

The Predicate interface contains a method called test(T t) that evaluates a condition and returns a boolean. It also contains some useful default methods like:
  • and(Predicate other): Combines two predicates with a logical AND. 
  • or(Predicate other): Combines two predicates with a logical OR. 
  • negate(): Negates the result of the predicate.
Example 1: Simple Predicate In the following example, a Predicate is used to test whether a number is greater than 10

Example 2: Combining Predicates with and(), or(), and negate() You can combine multiple predicates to create more complex conditions using and(), or(), and negate().

Example 3: Using Predicate with Collections and Streams The Predicate interface is often used with the Streams API to filter collections based on certain conditions.

Example 4: Predicate with isEqual Static Method Java 8 introduces a static method isEqual in the Predicate interface, which is used to create a predicate that checks if two objects are equal.

Example 5: Using Predicate with a List of Objects You can use predicates to filter lists of custom objects. Hare's an example where we filter a list of Person objects based on age.

Summary of Predicate Methods: 
test(T t): Evaluates the predicate on the given argument and returns true or false. 
and(Predicate other): Combines this predicate with another one using logical AND. 
or(Predicate other): Combines this predicate with another one using logical OR. 
negate(): Reverses the result of the predicate (logical NOT). 
isEqual(Object targetRef): Creates a predicate that checks if an object is equal to the given target.
 
* Common Use Cases: 
 Filtering collections with Stream.filter(). Validating input, such as checking if a string matches a pattern or if a number falls within a range. Using complex conditional logic in combination with other predicates.
Predicates are a powerful tool in functional programming and are heavily used in Java 8's Streams API to make code more readable and expressive.

Java 8 Introduced Key Features

No comments :
Java 8 introduced several key features that significantly enhanced the language and its libraries. Here are the principal features:
Lambda Expressions:
Allow you to treat functionality as a method argument, or to create small function-like objects more concisely.
Syntax: 
               (parameters) -> expression or (parameters) -> { statements; }
Functional Interfaces:
An interface with just one abstract method, used as the type for lambda expressions and method references.
Example: 
                java.util.function.Predicate; 
                java.util.function.Function;
Stream API:
Introduces a new abstraction for working with sequences of elements and performing operations like filter, map, and reduce on them.
Example: 
                List myList = ...; myList.stream().filter(s -> s.startsWith("a")).forEach(System.out::println);
Default Methods:
Allow you to add new methods to interfaces without breaking the existing implementations.
Example: 
                    interface MyInterface { 
                     default void newMethod() {
                              ............ // write Method body 
                                  } }
Optional:
A container object which may or may not contain a non-null value, to avoid `NullPointerException`.
Example: 
                Optional opt = Optional.of("value"); 
                opt.ifPresent(System.out::println);
New Date and Time API:
A comprehensive new date and time library under `java.time` package, which is more flexible and easier to use than the old java.util.Date and java.util.Calendar classes.
Nashorn JavaScript Engine:
Replaces the old Rhino JavaScript engine, allowing for the embedding of JavaScript code within Java applications.
Method References:
Provide a way to refer to methods without invoking them, which can be used for constructing lambda expressions.
Example: ClassName::methodName.

These features aim to make Java code more expressive, readable, and efficient.

How to Mapping code logic using Stream API

No comments :
Stream API in Java provides a powerful way to work with collections and other data sources. Mapping is one of the key operations available in the Stream API, used to transform elements of a stream. Here's a step-by-step guide on how to use the map function with the Stream API:
Import Required Classes :

First, make sure to import the necessary classes:
import java.util.Arrays;
import java.util.List; 
import java.util.stream.Collectors; 
import java.util.stream.Stream;

Create a Stream:
You can create a stream from various sources, like collections, arrays, or generator functions. For example, creating a stream from a list:
List names = Arrays.asList("a14mk", "manoj", "Jack"); 
Stream nameStream = names.stream();
Apply the map Function:
Use the map function to transform each element of the stream. For instance, to convert each name to uppercase:
Stream upperCaseNames = nameStream.map(String::toUpperCase);
Collect the Results:
Finally, you can collect the transformed stream back into a list or another collection:
List upperCaseNameList = upperCaseNames.collect(Collectors.toList());
Complete Example:
Here’s a complete example demonstrating how to use the map function with the Stream API:

Mapping with Complex Objects:
If you are working with a list of objects, you can use the map function to transform specific fields or create new objects. For example:

In this example, the map function is used to extract the names from a list of Person objects.

How to Develop code logic using Stream API Workflow

2 comments :
Let's begin by defining the term stream as it applies to the stream API:
A stream operates on a data source, such as an array or a collection. A stream, itself, never provides storage on a data. It simply moves data, possibly filtering, sorting, or otherwise operating on that data is the process. as a genral rule, however a stream operation by itself does not modyfy the data source. For Example: sorting a stream does not change the order of the source. Rather, sorting a stream results in the creation of a new stream that produces the sroted result.
A Simple Stream Example : Let's work through an example that uses streams. The following program creates an ArrayList called myList that holds a collection of integers. Next, it obtains a stream that uses myList as a source.


OUTPUT:


Multiples DATABASE Connection and Data shifting Using Spring Boots API

No comments :
Multiple DataBase Connection and Data shifting using Spring boot API configuration Example.
Step-by-step Write Java files.
1. application.properties File for Add multiple DataBase Connection. 
2. DBConfigDBNAME.JAVA Files for multiple DataBase Connection. 
3. Job Scheduler.java file for Auto shift programm. 
4. Entity Beans, Repository, Services Implementations for Binding and shifting Data.
  1. Create Spring Boot Java (Microservices)
      Create Spring Boot Java (Microservices).
  1. Project Name: DataShiftingConfigSpringBoots
  2. Group: DataShifting-a143mk
  3. Artifactid: DataShifting-a143mk
  4. Description: DataBase Connection and Data shifting using Spring boot API.
  5. Package: DataShiftinga143mk
Select the technologies and library(Maven Dependency ) to be.
  1. spring-boot-configuration-processor
  2. ojdbc8

while creating the project pom.xml file and some maven dependency, main class is automatically created when web add any dependency like.

pom.xml


1. Configure application.properties


Create DataBase Configuration java Files :
DBConfigDATABASE1.java


DBConfigDATABASE2.java


DBConfigDATABASE3.java

Create Scheduler ClassCreate Scheduler for Auto run Program and import some Packages Scheduler.java as below:

Have you seen the previous post? You all know how to learn and create Entity Bean, Repository, Service Implementation in the project. If you don't know about it then go to the previous post and learn it.

How to PACKAGE Spring Boot application to JAR and WAR

No comments :
Maven is a popular build tool, that takes your project’s Java source code, compiles it, tests it and converts it into an executable Java program: either a .jar or a .war file.  
Package Spring Boot application to JAR OR WAR file:
The default packaging type of a Spring Boot project is jar if the attribute is not present in the pom.xml file. It’s better to check your project’s pom.xml file to make sure that the packaging type is jar or War:

If you use an IDE such as Eclipse or Spring Tool Suite, right-click on the project, then select Run As > Maven Configuration Like:
  • CLEAN
  • BUILD
  • INSTALL
  • PACKAGE.................etc.







Simple LDAP sign-on Authentication Using Ldap-a143mkJar

1 comment :
LDAP sign-on is an authentication scheme that allows a user to log in with a single ID to any of several related, independent, software systems or web applications. In this post user will login through Outlook Mail. Ldap-a143mkJar.jar
Process of Ldap sign-On (LSO) Authentication:



Download the jar file and implement some methods / functions have been used, the names of the methods are as follows:

Call Class object LdapClient ldapClientClass=new LdapClient();
  1. A143mkLdapConnection(ldapUrl, ldapDnConn, userEmailId, password);
There are some parameters in methods, which we initialize by creating configuration object like this.

String ldapUrl= "ldap://172.0.0.0:389/"; 
String lDapDnConn="dc=domainName,dc=com"; 
String userEmailId="EmailMail@mailDomen.com"; 
String password="mailPassword"; 

How to create a project/main class/other class to follow us.




while creating the controller/main class Ldapconn.java.


Output :


Learn I- Report configuration with Spring boot/Microservices using Java

1 comment :
iReport
iReport is a powerful graphical design tool for report designers and power users to define reports for execution using the JasperReports engine. Whether you are using the JasperReports library by itself as a critical component of your application or you are using it as a component of the JasperReports Server application, iReport can help you design reports to meet the most complex reporting demands. iReport is built on the NetBeans platform and is available as a standalone application or as a Netbeans plug-in.
Requirements For current Download JasperReports iReport Tools , Ckeck It is recommended that you run iReport with JDK v1.5,v1.6 or v1.7. Note that for Windows Vista users, it is recommended that you run JDK v1.7.
JasperReports Create very sophisticated layouts containing charts, images, subreports, crosstabs and much more. Access your data through JDBC, TableModels, JavaBeans, XML, Hibernate, CSV, and custom sources. Then publish your reports as PDF, RTF, XML, XLS, CSV, HTML, XHTML, text, DOCX, or OpenOffice. Through this post, we will tell you how to configure iReport in Mavan base java application(Microservices) project. follows step by step:

  1. Create Spring Boot Java (Microservices)
  2. Create/Design report.jrxml
Create Spring Boot Java (Microservices).
  1. Project Name: I-ReportConfigurationApp
  2. Group:I-Report-a143mk
  3. Artifactid:I-Report-a143mk
  4. Description:Learn I- Report configuration with Microservices Application
  5. Package:I-Report-a143mk




Select the technologies and library(Maven Dependency ) to be.
  1. Spring Web
  2. Spring JPA
  3. Jasperreports
  4. javax.persistence
  5. Tomcat
  6. javax.servlet
  7. mysql
  8. jstl

while creating the project pom.xml file and some maven dependency, main class is automatically created when web add any dependency like.

pom.xml


For step by step development working watch the video and learn yourself. Download wampServer2.0i and install then run it.



1. Create Database: Database Name is hostel.
2. Create Table: Table Name is product.




Configure application.properties


Report:
In src/main/resources/reports/report.jrxml folder, create new folder named reports. In this folder, create new Jasper Report named report.jrxml as below:
 


Code:



Entities Class
Create new package, named IReporta143mk.entities. In this package, create entities class name is Product.java as below:



Create ProductRepository Interface
Create new package named IReporta143mk.repositories. In this package create the ProductRepository interface implements from CrudRepository interface of Spring Data JPA that provides CRUD Operations for an entity.


Create ProductService Interface
Create new package named IReporta143mk.services. In this package create the ProductService interface and ProductServiceImpl as below:
First one is ProductService.java


Second one is ProductServiceImpl.java



Create Controllers
Create new package named IReporta143mk.controllers. In this package, create new java class named ProductController.java


Create jsp page
Create new folder name is jsp. In thes folder /src/main/webapp/WEB-INF/jsp/index.jsp

Structure of Spring Boot Project:


Out Put:




Digital Steganography With Single Sign-On (SSO) Authentication Project For Students

2 comments :
The project here can be a minor and major project for final year students, and given in school and college by learning the project itself through videos.
INTRODUCTION:
Maintaining secrecy is very important in a large corporation and because of the intelligent of the hackers it becomes tedious. Already we have encryption for transmitting secret information. Even though encryption successfully transmitting secret information, it will give a suspicion to the hackers and it affects unintended users. Our project, DIGITAL STEGANOGRAPHY WITH Single Sign-On (SSO) Authentication overcomes this factor and it gives a solution for transmitting secret formation with out affecting 
 Unintended users. Steganography uses multimedia data as a covering medium (Covering secret information). By using steganography data (secret information) can hided with in 
Data (multimedia data, here multimedia data is an image) and it can be sent anywhere to transfer the message easily without giving any suspicion to others.



Follow Steps by Steps 


Single Sign-On (SSO) Using SMTP Authentication With Spring Boot Microservices

2 comments :
Single sign-on is an authentication scheme that allows a user to log in with a single ID to any of several related, independent, software systems or web applications. In this Video user will login through Outlook and Google Mail for which we will develop Spring Boot Microservices Project here and will also use some Spring Boot Jar files javax.mail.jar and SendMailA143mkSSO.jar
Process of Single sign-On (SSO) Authentication:




Download both the jar file and implement some methods / functions have been used, the names of the methods are as follows:

Create Class object SendMailA143mk getsess=new SendMailA143mk();
  1. LoginMailAuthHost_PortA143mk();
  2. OutLookMailAuthA143mk();
  3. GmailMailAuthA143mk();
There are some parameters in five methods, which we initialize by creating and object like this.

String toAuthmail="EmailMail@mailDomen.com";
String toAuthmailPassword="mailPassword"; 
String host="smtp.office365.com"; 
String port="587"; 

How to create a project to follow us. Project Name is: EmailAuthenticationA143mk




while creating the project pom.xml file and some maven dependency, main class is automatically created when web add any dependency like.

pom.xml


For step by step development working watch the video and learn yourself.


Some Helping Note: Some code and video are shown in this post, how we can use it in our application, the developer and jar file used in this is verified by mail id and password and after mail id is successful is returned, you can then write custom user roles and method entities in the block. and you can write error body in second part of it.

How to Implement SMTP (Simple Mail Transfer Protocol: To, Cc and Bcc Mails) Using Java

1 comment :
In this post we will learn how To, Cc and Bcc mails are sent and also how the file is attached to the mail. Some jar files are available in java for the development of mails, which is javax.mail jar file, as well as a jar named SendMailA143mk, download both the jar file and the names of the jar SendMailA143mk in which two methods / functions have been used, the names of the methods are as follows:    
1. SendMaleWPathFile();
2. SendMaleWBody();
There are some parameters in both the methods, which we initialize by creating and object like this.

String noReplayEmailID="noreplyMail@mailDomen.com";
String noReplayEmailPass="mailPassword"; 
String host="smtp.office365.com"; 
String port="587";
String sentTomail="toMail@mailDomen.com"; 
String sentToCCmail="ccMail@mailDomen.com"; 
String sentToBCCmail="bccMail@mailDomen.com"; 
String Subject="SMTP Implementation Using Java"; 
String bodyText=" Hi A143mk blogs Test Mail. Thanks. "; 
String PathFile="D:\\logo.png"; 
Create this Main Method, you can use this code in functions/methods as per you wish.
 

Output is:

















Important Information: We develop/implement this type of web application or other user application in online platform like How to send To, Cc and Bcc mails to online user providing security and also we are able to send email to user through OTP in this development Whether or not your personal information such as password/email OTP is neither in the database of the online platform nor in the possession of anyone else. By this we identify the authenticity of the user.