DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones Build AI Agents That Are Ready for Production
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
Build AI Agents That Are Ready for Production

LIVE: “Cognitive Databases, Intelligent Data: Unified Infrastructure for Vector Search, AI-Optimized Queries, & Hybrid Workloads" Report

Join this live webinar to learn safer rollout techniques for schema changes, index testing, and database migrations.

Live Webinar: Exclusive practitioner summit on AI-powered CDN operations and real-world automation strategies

The Latest Java Topics

article thumbnail
Hiding SOAP Legacy Applications Using the Mullet Pattern
Let's dive into supporting legacy-based applications while adding the next generation of microservices in talk with Aaron Weikle, the founder, and CEO at MS3.
January 28, 2022
by Kaitlyn Barnard
· 3,103 Views · 3 Likes
article thumbnail
Adapter Design Pattern in Java [Language Translator] - Introduction, Example, and Implementation
In this video tutorial, a closer look at Adapter Design Pattern in Java (Language Translator) - introduction, example, and implementation.
January 27, 2022
by Ram N
· 6,079 Views · 3 Likes
article thumbnail
Learn Rust With Java, Part 1: The Introduction
This is the first post in the Learn Rust with Java series. This blog will enable you to have a first look into the Rust world on a JFO (Java Flying Object).
January 27, 2022
by Thirumalaivasan Rajasekaran
· 4,121 Views · 3 Likes
article thumbnail
How To Get C++ Speed in Java Serialization
Read this article and learn more about the low-latency technique leveraging C++ methodology in Java: Trivially Copyable Objects and memcpy.
January 27, 2022
by Beata Burreau
· 11,195 Views · 7 Likes
article thumbnail
How to Handle Login Pop-ups in Selenium WebDriver Using Java
This blog shows how to handle login pop-ups in Selenium WebDriver using Java and demonstrates the same on the LambdaTest platform.
January 26, 2022
by Shalini Baskaran
· 10,441 Views · 3 Likes
article thumbnail
Learn How to Create Thread Pool in Java and How to Reuse Thread
Learn about the thread pool and how to create it in Java from scratch. This post includes an intro, implementation, and testing of a simple thread pool version.
Updated January 26, 2022
by Dmitry Egorov DZone Core CORE
· 27,017 Views · 15 Likes
article thumbnail
Intro to Spring Data MongoDB Reactive and How to Move It to the Cloud
In this article, see an introduction to Spring Data MongoDB Reactive and see how to move it to the cloud.
Updated January 26, 2022
by Otavio Santana DZone Core CORE
· 38,252 Views · 8 Likes
article thumbnail
Debugging RAM: Detect/Fix Memory Leaks in Managed Languages - Heap Deep Dive (Part 2)
Java & JavaScript are garbage collected languages. But memory leaks can still plague them. Avoid, detect and fix these heap problems using this guide
January 26, 2022
by Shai Almog DZone Core CORE
· 5,484 Views · 4 Likes
article thumbnail
Template Design Pattern or Template Method Design Pattern in Java
In the video below, take a closer look at the Template Design pattern or the Template Method Design pattern in Java. Click play to get started!
January 25, 2022
by Ram N
· 4,896 Views · 5 Likes
article thumbnail
Adapter Design Pattern in Java - Introduction, Class/Sequence Diagram, and Implementation
In this video tutorial, we will take a closer look at the adapter design pattern in Java. We will cover the introduction, class/sequence diagram, and implementation.
January 24, 2022
by Ram N
· 5,784 Views · 3 Likes
article thumbnail
Service Locator Design Pattern in Java: An Introduction, Class/Sequence Diagram, and Implementation
This post contains an article that takes a closer look at the service locator design pattern in java including a class/sequence diagram to easily understand.
January 21, 2022
by Ram N
· 29,671 Views · 4 Likes
article thumbnail
Optimization Techniques Using Java Streams
In this post, we'll focus on how to handle the post-processing of the data using Java Streams. We'll also see very powerful techniques to optimize and order the results.
Updated January 21, 2022
by Manu Barriola
· 14,500 Views · 10 Likes
article thumbnail
What Is Applicative? Basic Theory for Java Developers
Are you a Java developer who wants to know the theory behind Applicatives? Here you will find a step-by-step tutorial that will help you understand them.
January 20, 2022
by Bartłomiej Żyliński DZone Core CORE
· 12,214 Views · 14 Likes
article thumbnail
You're Running Untrusted Code!
The premise that the code that runs inside your infrastructure can be trusted is dangerous - on-premise or in the Cloud. Here are some arguments that support this claim.
January 20, 2022
by Nicolas Fränkel
· 4,394 Views · 4 Likes
article thumbnail
Did You Know the Fastest Way of Serializing a Java Field Is Not Serializing It at All?
This article elaborates on different ways of serializing Java objects and benchmarks performance for the variants.
January 20, 2022
by Per-Åke Minborg
· 9,644 Views · 9 Likes
article thumbnail
AWS Lambda Versions and Aliases Explained By Example
Learn how to use AWS Lambda versions and aliases by means of a Java example. Create a simple AWS Java Lambda, create versions and use aliases for your environment.
January 18, 2022
by Gunter Rotsaert DZone Core CORE
· 5,489 Views · 6 Likes
article thumbnail
Flyweight Design Pattern in Java
In this video tutorial, explore the Flyweight Design pattern in Java. This tutorial includes an introduction, real-time example, implementation, and key points.
January 18, 2022
by Ram N
· 6,371 Views · 4 Likes
article thumbnail
JxBrowser and JCEF
Choosing a solution to embed Chromium into a cross-platform Java desktop application
January 17, 2022
by Vladyslav Lubenskyi
· 14,384 Views · 24 Likes
article thumbnail
Authentication With Remote LDAP Server in Spring WebFlux
A guide for Java developers who want to integrate Spring Boot Webflux applications with a remote LDAP server and authenticate/authorize their users with JWT.
Updated January 16, 2022
by Taner Inal
· 12,040 Views · 8 Likes
article thumbnail
Less Code With Spring Data Rest
We programmers are constantly solving various problems and always looking for a way to make life easier for others. On the other hand, we make life difficult for ourselves, because sometimes our code contains a lot of boilerplate code and modules that are not needed. For better understanding, consider a normal Spring Boot project that is only responsible for creating/reading/updating/deleting (CRUD) a client. First of all, we should create an entity called "Customer" which should be mapped to the table in the database, next, we should create a repository and the controller to call this repository and expose the service to the outside, sometimes we go one step further and add another layer to the architecture. Is all this extra work really necessary to provide multiple simple services? The answer is no, we can use "spring data rest" which can help us to provide our services directly from the data layer. Spring Data Rest With Spring Data Rest, the BL and controller layers are removed from your project. In fact, all REST services are provided by your Spring Data layer, and all you need to do is create a simple repository for your project, and Spring will do the rest. How Spring Data Rest Works everything is very simple, Spring Data Rest searches your projects and any commodity that finds the repository creates REST services for the corresponding entities related to the repository, consider the following example: Java public interface CustomerRepository extends CrudRepository {} If spring data rest finds this repository class, generates all REST APIs related to the client class. Rest APIs And Standards Spring Data Rest is based on a very simple and standard contract and creates REST APIs based on the entity type. In the example above, APIs were generated based on the entity type "customer", and the APIs followed a simple pluralized form, e.g. the first character of the entity is a lowercase letter and an "s" is simply added to the end of the entity. "/customers", you can see some generated REST for "customer" in the table below: HTTP Method URL Pattern Status Code Description GET /customers 200 get all customers GET /customers{id} 200 get customer by id POST /customers 201(created) creates new customer PUT /customers{id} 200 existing customer by id DELETE /customers{id} 200 customer by id REST APIs exposes in HATAOS format Spring Data Rest provides APIs in this format: Hypermedia as the Engine of application state(HATAOS), as you know hypermedia format can refer to any format or URL or even an image from the content, here is a simple HATAOS JSON from wiki : JSON HTTP/1.1 200 OK { "account": { "account_number": 12345, "balance": { "currency": "usd", "value": 100.00 }, "links": { "deposits": "/accounts/12345/deposits", "withdrawals": "/accounts/12345/withdrawals", "transfers": "/accounts/12345/transfers", "close-requests": "/accounts/12345/close-requests" } } } Useful and practical information about HATAOS can be found here. Also, learn more about this format in the rest of the article. Simple Case Study For better understanding, I will try to continue with a very simple example. Again, this example is not very unusual, because we are trying to create a project around the entity "customer". So let us get started. First of all, we need to add the required dependency to our pom: XML org.springframework.boot spring-boot-starter-data-rest Now it is time to create the main entity of the project, "Customer". This is a very simple entity that contains only one property: id, name, phone, and address of the customer Java package com.rgn.model; import lombok.Data; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; import java.io.Serializable; @Data @Entity @Table(name = "customer") public class Customer implements Serializable { @Id @Column(name = "id") private Long id; @Column(name = "customername") private String customerName; @Column(name = "customerphonno") private Long customerPhoneNo; @Column(name = "customraddress") private String customerAddress; } Using Lombok @Data annotation helps us to prevent additional, setter, and getter in our code. the second most important part of our code is the creation of an appropriate repository for our entity customer: Java package com.rgn.repository; import com.rgn.model.Customer; import org.springframework.data.repository.CrudRepository; public interface CustomerRepository extends CrudRepository { } Also, we have a simple application class like every spring boot project: Java import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import java.util.Arrays; @SpringBootApplication public class MainApplication { public static void main(String[] args) { SpringApplication.run(MainApplication.class, args); } @Bean public CommandLineRunner commandLineRunner(ApplicationContext ctx) { return args -> { System.out.println("Let's inspect the beans provided by Spring Boot:"); String[] beanNames = ctx.getBeanDefinitionNames(); Arrays.sort(beanNames); for (String beanName : beanNames) { System.out.println(beanName); } }; } } Here is the configuration (application. properties)file of our project, we created our customer table in the Oracle database so we need to set database URL, username, and password: Shell spring.datasource.url=jdbc:oracle:thin:@localhost:1521:ORA81 spring.datasource.username=scott spring.datasource.password=tiger spring.datasource.driver-class-name=oracle.jdbc.OracleDriver # HikariCP settings spring.datasource.hikari.minimumIdle=5 spring.datasource.hikari.maximumPoolSize=20 spring.datasource.hikari.idleTimeout=30000 spring.datasource.hikari.maxLifetime=2000000 spring.datasource.hikari.connectionTimeout=30000 spring.datasource.hikari.poolName=HikariPoolBooks # JPA settings spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect spring.jpa.hibernate.use-new-id-generator-mappings=false Note: the default address of exposed APIs is "/", for example, if you run the above project you can see the APIs at address "http://localhost:8080", unless, you should add your own address to the application.properties file with the following code : Shell spring.data.rest.basePath=/myApi By adding the above code you can see your rest in "http://localhost:8080/myApi" HAL explorer Spring also surprises developers and DevOps engineers with the capabilities it offers. There is a strong REST APIs explore that shows the APIs in HATAOS format, to use them you need to add the following dependency to your project: XML org.springframework.data spring-data-rest-hal-explorer org.springframework.boot spring-boot-starter-security In order for us to use standard annotations at both the class and method levels, the following code represents the application of class-level security roles, which means that any caller wishing to invoke any service of this class should have the "ALL" role: Java @PreAuthorize("hasRole('ALL')") public interface CustomerRepository extends CrudRepository { } If you want to create a method with different access roles, you should simply override the method and apply a different role. In the code below, "findAll()" has been overridden and applied to an "ADMIN" role: import com.rgn.model.Customer; import org.springframework.data.repository.CrudRepository; import org.springframework.security.access.prepost.PreAuthorize; @PreAuthorize("hasRole('ALL')") public interface CustomerRepository extends CrudRepository { @Override @PreAuthorize("hasRole('ADMIN')") public Iterable findAll(); } You can find detailed information about spring security and annotations and mechanism here. Performance When I decide to use new technology, after all the technical considerations and studies of that technology, before I use it, I try to compare its performance either with the older technology I am using now or with similar technologies that exist in the field. For this purpose, firstly, I search for reputable websites to know the experience of others with this technology in terms of its performance and benchmarks, and secondly, I try to make performance comparisons myself. in this part, let us compare the performance between Spring Data Rest and the regular architecture that includes the controller layer. So I have two test cases with and without spring data rest. For the performance tests, I used JMeter, with 1000000 threads and 1000 as a threshold for the graph and the regular PC. OK, here we go: Test Result With Spring Data Rest As you can see, the graph of response times has stabilized after slight fluctuations and we have a normal response time. Test Result Without Spring Data Rest Before we start this step, we should remove the dependency on spring data rest from our pom and add the following class as a controller layer to our project: Java package com.rgn.model; import com.rgn.repository.CustomerRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @RestController public class CustomerService { @Autowired CustomerRepository repository; @GetMapping("/customers") public Customer getCustomer(@RequestParam(value = "id") Long id){ return repository.findById(id.longValue()).get(); } } The result can be seen in the following figure. You can see that we get better performance when using spring data.
January 16, 2022
by Reza Ganji DZone Core CORE
· 10,969 Views · 9 Likes
  • Previous
  • ...
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • ...
  • Next
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook
×