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
Getting Started With Maven For Selenium Testing
Having trouble getting started with Maven? See how to do just that in this end-to-end tutorial on Selenium testing for Java.
July 9, 2020
by Rahul Rana
· 16,232 Views · 2 Likes
article thumbnail
Running a Java App With MySQL in Any Docker Environment
In this article, take a look at using Docker network to take advantage of container isolation features.
July 8, 2020
by Alok Ranjan Meher
· 13,721 Views · 1 Like
article thumbnail
4 Tips for Improving Code Readability
We only get seconds to attract a reader's attention, and readable code snippets can make the difference. Discover 4 tips for improving readability of your code snippets.
July 7, 2020
by Justin Albano DZone Core CORE
· 19,020 Views · 5 Likes
article thumbnail
Detecting and Resolving Database Connection Leaks with Java Applications
Take a look at this tutorial that demonstrates how you can find and remove connection leaks between your application and database in Java apps.
July 7, 2020
by Chandra Shekhar Pandey
· 44,920 Views · 7 Likes
article thumbnail
How to Check if A List Contains a Value in Clojure
This article goes over four different methods for determining whether a list has a specific value using Clojure.
July 6, 2020
by Yuri Mednikov
· 13,649 Views · 1 Like
article thumbnail
Understanding Java Agents
A powerful tool you might have missed.
July 6, 2020
by Sathiyakugan Balakrishan
· 42,093 Views · 53 Likes
article thumbnail
Tutorial: Generating Java Files with Spring and Mustache
If you need to generate complex model from a large source data, you should try this
July 6, 2020
by Farith Sanmiguel
· 9,197 Views · 4 Likes
article thumbnail
Java 8 Parallel Processing With Completable Future
Check out this full-length tutorial on how to take advantage of parallel processing in Java with futures and allOf, join, etc. methods.
July 6, 2020
by Naveen Yalla
· 52,433 Views · 2 Likes
article thumbnail
SVG-Path Animation in React Native
Program Statement: Designing mesmerizing, interactive timeline for the user’s weight loss journey. For the past few months, we are working on a health app that helps users in their weight loss journey. Here we call it more of a Wellness Journey. This app keeps track of your weight, your inches, water intake, and of course your calories. We are creating a platform that acts as a personal assistant in their journey. Lately, our users have been asking us for a feature in the app where they can view their entire journey i.e what was their weight when they started, and how things progressed along the weeks, their major achievements (things like the 1st pound lost, after a month and so on….). So we decided to give it a go. Read along to see what we came up with. Solution: After brainstorming with UX designer, UI designer, and fellow developers, and discussing multiple approaches from a simple listing to complex timelines we finally settled on the one which had maximum opportunity for micro-interactions, animation, and user engagement. The idea was to show the weight loss journey to a user, quite symbolic of the journey on the road which can have milestones in between based on the achievements the user has attained. A path that will be laid out in front of the user and then will be filled accordingly to the point where the user has reached a particular point in the duration of the program. Below is the final implementation of the feature in our app. I am only going to cover the animating path in this blog and other animation and interaction in the next one. Step 1 Drawing leader line Leader Line is the centerline (dotted line in the above video) which is equidistant from the inner and outer contour line. This is the simplest part of this animation. We have to draw a series of connected horizontal lines and semicircles. The above illustration explains how we draw in SVG. You can read more about SVG paths here. The negative sign in horizontal lines means we want our lines drawn from right to left. Arcs in SVG require extra attention. Arcs accept parameters as 'RX', 'ry', 'x-axis rotation', 'large arc flag', 'sweep flag', 'finalX', 'finalY'. As we are drawing a semicircle, we don’t need an 'x-axis rotation flag' and 'large arc flag'. 'Sweep flag' determines which side we want to draw. 1 means the positive side and 0 mean the negative side. To know more about SVG arc check this link. Java x 27 1 export function getPath(month, line) { 2 let fullPath = 'M90 100'; 3 const forwardLine = 'l${line.width} 0'; 4 const backwardLine = 'l${-line.width} 0'; 5 const leftCurve = 'a${line.radius} ${line.radius} 0 0 0 0 ${line.radius * 2}'; 6 const rightCurve = 'a${line.radius} ${line.radius} 0 0 1 0 ${ 7 line.radius * 2 8 }'; 9 10 for (let i = 0; i < month; ++i) { 11 if (i % 2 == 0) { 12 fullPath += '${forwardLine} ${rightCurve}'; 13 } else { 14 fullPath += '${backwardLine} ${leftCurve}'; 15 } 16 } 17 18 return fullPath; 19 } 20 . 21 . App.js 22 . 23 this.granularity = 5;this.leaderLineProperty = { 24 lineWidth: width - 180, 25 radius: 50, 26 }; 27 this.path = PathHelper.getPath(this.month, PathHelper.LeaderPathProperty); From the above line of code, we have our leader line ready. Step 2 For this step, I want you to stop and have a look at the animation video above. Our ultimate goal is to animate the path. For smooth animation, we have to break down into smaller segments and then attach them piece by piece. To divide the leader line into smaller chunks we will use the SVG-path-properties library. Java xxxxxxxxxx 1 40 1 // path is our leader line svg, totalDays is the no of segments we have divided our lines into radius is distance between leader line and outer, inner line 2 getPathProperty(path, totalDays, radius) { 3 const pathProperty = new svgPathProperties(path); 4 const pathSegmentArray = []; 5 6 let { 7 x: 8 previousX, y:previousY 9 } = pathProperty.getPropertiesAtLength(0); 10 11 for (let i = 1; i <= totalDays; ++i) { 12 const leaderSegment = (i / totalDays) * 13 pathProperty.getTotalLength(); 14 15 const{ x:lx, y:ly 16 } =pathProperty.getPropertiesAtLength(leaderSegment); 17 18 const diffX = lx - previousX; 19 const diffY = ly - previousY; 20 previousX = lx; 21 previousY = ly; 22 23 const angleForOuterContourLine = Math.atan2(diffY, diffX); 24 const angleForInnerContourLine = Math.PI - 25 angleForOuterContourLine; 26 27 const ox = lx + radius * Math.sin(angleForOuterContourLine); 28 const oy = ly - radius * Math.cos(angleForOuterContourLine); 29 const ix = lx - radius * Math.sin(angleForInnerContourLine); 30 const iy = ly - radius * Math.cos(angleForInnerContourLine); 31 32 const point = { 33 outer: {x: ox, y:oy }, 34 leader:{x: lx, y:ly }, 35 inner: {x: ix, y:iy }, 36 }; pathSegmentArray.push(point); 37 } 38 39 return pathSegmentArray; 40 } Suppose the height of the road is 20pt. Then to make a close path from a single line we need an outer and inner line having 10 points distance from the leader line each. In the above lines of codes, we get points for the leader line directly. Now we have to calculate the same for the inner and outer line. Another point of significance that I would like to mention here is that we just can’t subtract or add 10 to the leader lines to get our outer and the inner path without considering direction. Just like vectors, we will also use direction here and for this, we will use our old friend ‘Trigonometry’. We will get two points on the leader line and find the angle between the line formed by the last two points and the x-axis. If you have two points, (x0, y0) and (x1, y1), then the angle of the line joining them (relative to the X-axis) is given by: theta = atan2((y1 – y0), (x1 – x0)) We know tanθ = Perpendicular / Base = (Difference in height)/(Difference in width). We can calculate θ by using the formula for the tan inverse. After calculating angle we calculate x and y position as: Δx = radius * sin(θ) Δy = radius * cos(θ) Step 3 Now since we have coordinates for the inner and outer path, we need to translate them into a closed SVG path to form our road. Here D3 library comes to our rescue. We use the d3-shapes’ “area” method to get our path. Java xxxxxxxxxx 1 45 1 // progress is a no. between 0 to totalDays and 'pathSegment' is an object containing our inner and outer path segmentsexport const calculateProgressArea = (progress, pathSegment) => { 2 const forwardArray = []; 3 const backwardArray = []; 4 5 let point = pathSegment[0]; 6 forwardArray.push(point.outer); 7 backwardArray.push(point.inner); 8 9 for (let i = 1; i < progress; ++i) { 10 point = pathSegment[i]; 11 forwardArray.push(point.outer); 12 backwardArray.push(point.inner); 13 } 14 15 backwardArray.reverse(); 16 const allPoint = [...forwardArray, ...backwardArray, forwardArray[0]]; 17 18 const area = d3 19 .area() 20 .x1((x) => { 21 return x.x; 22 }) 23 .y1((y) => { 24 return y.y; 25 }) 26 .y0(allPoint[0].y) 27 .x0(allPoint[0].x); 28 29 return area(allPoint); 30 };. 31 . In App.js 32 .this.area = PathHelper.calculateProgressArea( 33 this.totalDays, 34 this.pathSegmentArray, 35 );. 36 . In render function 37 . 38 45 Please note that I am appending the Inner path point at the end of the Outer path point. Step 4 Till now we have only laid down the solid block of the path. Now we have to animate the path as well. As I said earlier, for animating the path we will render pieces after pieces. By pieces, I meant we will take a small subset from the outer and inner path segment array and convert it into a path and render it. Java xxxxxxxxxx 1 15 1 addAnimationListener = () => { 2 this.state.animation.addListener(({value}) => { 3 const progress = value * this.totalDays; 4 const path = PathHelper.calculateProgressArea( 5 progress, 6 this.pathSegmentArray, 7 ); 8 9 if (this.progressPath) { 10 this.progressPath.setNativeProps({ 11 d: path, 12 }); 13 } 14 }); 15 }; Final output:-
Updated July 6, 2020
by Nitish Prasad
· 9,904 Views · 1 Like
article thumbnail
Getting Started With Apache Camel Part 1
Looking to get up and running with Apache Camel? Have a look how to start a basic Camel project and what tools are available.
July 2, 2020
by Krzysztof Kaczmarczyk
· 11,130 Views · 3 Likes
article thumbnail
Spring Cloud Stream: A Brief Guide
Learn how to create a Spring Cloud Stream app that works with a messaging service.
July 2, 2020
by Andrew Hughes
· 13,684 Views · 3 Likes
article thumbnail
Simple Text Summarizer Using Extractive Method
In this article, we will build a text summarizer with an extracted method that is super easy to build and very reliable when it comes to results.
July 1, 2020
by Pushkara Sharma
· 7,352 Views · 4 Likes
article thumbnail
Detecting Compatibility Issues With the Java SE API
As time goes by and Java is constantly being updated, the problem of compatibility of different Java SE API versions becomes more and more relevant every year.
July 1, 2020
by Maxim Stefanov
· 6,610 Views · 3 Likes
article thumbnail
Java Vs. Kotlin: Which One Will Be the Best in 2019?
Which programming language comes to mind when you hear Android app development?
Updated June 30, 2020
by Paresh Sagar
· 92,187 Views · 35 Likes
article thumbnail
Android Device Matching With Socket Programming
In this article, I'll introduce the concept of socket and focus on how to use socket programming for consists of 2 separate Android devices connecting each other.
June 26, 2020
by Omer Yilmaz
· 13,766 Views · 2 Likes
article thumbnail
Implementation of Hybrid Encryption Using Java 1.8 and OpenSSL
Here we are going to understand why to use hybrid encryption and see an implementation of hybrid encryption out of AES symmetric encryption algorithm and RSA asymmetric algorithm using Java 1.8 and OpenSSL.
Updated June 25, 2020
by Subrato Mondal
· 10,375 Views · 5 Likes
article thumbnail
Stretching Async/Await With Lambdas
Are you doing the right use of async/await without constraining scalability? Check out some use cases providing limited concurrency and the right fixes.
June 25, 2020
by Miguel Gamboa
· 19,551 Views · 23 Likes
article thumbnail
C++ Template Story So Far (C++11 to C++20)
I will start with a simple class/function template and as we move along, it will increase the complexity.
June 25, 2020
by Vishal Chovatiya
· 15,414 Views · 2 Likes
article thumbnail
Quarkus vs Spring Boot – Performance
In this article, we are going to compare the Quarkus and Spring Boot applications and how they behave in terms of memory management.
June 23, 2020
by Shabbir Dawoodi
· 37,909 Views · 9 Likes
article thumbnail
Mule 4 CI/CD Using GitLab Pipelines and JFrog Artifactory
A practical CI/CD strategy for automating deployments of Mule 4 applications into CloudHub using GitLab CI/CD pipelines and JFrog Artifactory.
June 22, 2020
by Susmit Dey DZone Core CORE
· 18,360 Views · 8 Likes
  • Previous
  • ...
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • ...
  • 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
×