Introduction to Vert.x Vert.x is a polyglot event-driven application framework that runs on the Java Virtual Machine (JVM). It is designed for building scalable, responsive, and high-performance applications. Vert.x takes the best ideas from Event-Driven Architecture (EDA), Asynchronous Programming, and Reactive Programming, making it an excellent choice for microservices, web applications, and real-time systems. Key … Continue reading “What is Vertx?”
Category: Java
Brick Game in Java
If you’re a fan of classic arcade games, you’ve probably played Brick Game before. It’s a simple game that involves maneuvering a paddle to hit a ball that bounces around, trying to break through a wall of bricks. In this article, we’ll show you how to create your own Brick Game in Java with Source … Continue reading “Brick Game in Java”
File Handling In Java
File handling is a critical aspect of any programming language. File handling refers to manipulating files and directories on the file system. This article will provide an overview of file handling in Java. java.io.File Class The File class in Java is the primary way to handle files and directories. It is part of the java.io … Continue reading “File Handling In Java”
Java program to Print Prime numbers 1 to n
To find a given input number is prime., Iterate each number from 2 to half of input number, and check whether each iteration number divides the input number. (If no number divides, the input number is prime) We can check whether the number is divisible by using modulo (%) function, so that if number is … Continue reading “Java program to Print Prime numbers 1 to n”
Bubble Sort – Java
Sorting is one of the major required feature for any application during implementation of any business logic. There are different types of sorting in place based on performance, speed, cost of operation. One of simplest and easy algorithm is Bubble Sort Algorithm which is an easy one to understand/implement for any quick implementation. Sorting a … Continue reading “Bubble Sort – Java”
Convert Integer to Binary in Java
What is Binary? Binary is a number either 0 or 1, is a base 2-numeral. Every value of Integer can be represented in binary format in a easy way. Simply, to convert Integer value to binary value, divide the integer by 2 until it becomes 0., and store the reminder… 0 – 0000 1 – … Continue reading “Convert Integer to Binary in Java”
Configure Log4j2 -Java in minutes
Apache Log4j2 is used for printing info, error, debug, trace logging statements in enterprise applications. Apache Log4j2.x is an extension of Log4j1.x which has more significant features comparatively.Since major security vulnerabilities like Log4jShell & hacking possibilities are identified in Log4j1.x, it is always recommended to use Log4j2.x. It is pretty simple to configure Log4j2 in … Continue reading “Configure Log4j2 -Java in minutes”
SimpleDateFormat (Parse Date)
Date conversions are very common scenarios in any application., Java Provides SimpleDateFormat class for String to Date, Date to String conversions. The below example shows How String format can be converted to Date Format. How to find difference between 2 Dates. Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import java.text.SimpleDateFormat; import java.util.Date; class Example { public static void main(String args[]) { String date = "11/13/2018"; try { SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); Date parseDate = sdf.parse(date); System.out.println(parseDate); long differenceInMillis = new Date().getTime() - parseDate.getTime(); long differenceInDays = ((differenceInMillis/1000)/(60*60*24)); long year = differenceInDays/365; System.out.println("DifferenceInDays:"+differenceInDays); System.out.println("Age:"+year); } catch(Throwable t) { t.printStackTrace(); } } } |
Output
1 2 3 |
Tue Nov 13 00:00:00 UTC 2018 DifferenceInDays:1099 Age:3 |
XML transform using XSLT In Java
XSLT is Extensible Style Sheet Transformation which is used to transform/convert a XML to another HTML/XML structure with the help of XSL document. In this example, we are going to convert 1.xml to 2.xml structure with the help of XSL document., in Java. Steps: Load the input XML inside the DOM parser as document. Load … Continue reading “XML transform using XSLT In Java”