XML – Extensible MarkUp Language What is MarkUp Language? Markup language is a language that defines the format of document or web page, so that the browser/systems understands and apply the formats to the contents and visually provide formatted contents to the users. Markup languages are used only to format the text.,and while displaying the … Continue reading “XML Introduction”
Author: admin
All combinations of a String In Java
To find the combinations of a string, either the logic needs to use for loop or recursive loop. As for loop depends on the string length, for each loop we have to write the logic again, as more swapping will happen when try to get the combinations. Since swapping will happen recursively based on the … Continue reading “All combinations of a String In Java”
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”
Images to PDF In Java (ITextPdf Library)
There are several open source libraries in Java helps to convert images to Java. Images can be of any valid types like jpg, jpeg, png, webp, tiff, bmp etc., ITextPdf library is one of the Java library which has more features require to do all type of operations in PDF. To Include ItextPdf library in … Continue reading “Images to PDF In Java (ITextPdf Library)”
Angular JS – Directive Example
Angular JS Directive is an extension of HTML tags. It helps the developer to use custom tags and provides reusability. We can define and implement custom tags and custom directive., which helps the user to use resuse the same template and logic all over the application reducing the overhead of writing everywhere. Following are different … Continue reading “Angular JS – Directive Example”
Learn Angular JS In 10 minutes
Config/Factory/Service/Controller Example This example provides the usage of following components in angular -js., in a simple example. The following example provides the details of all the below components, so we can use it for an enterprise application very easily. Config Factory Service Constants Controller Config – Config is nothing but the Configuration block which is … Continue reading “Learn Angular JS In 10 minutes”
Angular JS – Introduction
Angular JS is a UI framework maintained by Google, helps to separate the model, view and Controller(MVC) components in front end UI. It clearly separates client side execution from the application logic. It enables developers to easily create custom HTML elemens with new attributes which helps re-use custom defined tags. Angular JS has scope variables … Continue reading “Angular JS – Introduction”
BlockingQueue
BlockingQueue is a thread-safe queue where we can enqueue on one end of queue, and dequeue on another end of queue., All BlockingQueue implementions on array or linked queues are thread-safe implementations. Below is a simple usage of BlockingQueue.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import java.util.Queue; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; public class BlockingQueuesExamples { public static void main(String[] args) throws InterruptedException { BlockingQueue<String> linkedBlockingQueue = new LinkedBlockingQueue<String>(); linkedBlockingQueue.offer("Apple"); linkedBlockingQueue.offer("Orange"); linkedBlockingQueue.offer("Peach"); queueStatus(linkedBlockingQueue); linkedBlockingQueue.offer("Avacado"); queueStatus(linkedBlockingQueue); System.out.println("Dequeued at Head of Queue: " + linkedBlockingQueue.take()); System.out.println("Dequeued at Head of Queue: " + linkedBlockingQueue.take()); queueStatus(linkedBlockingQueue); } public static void queueStatus(Queue linkedBlockingQueue) { System.out.println("---------------------------"); System.out.println("Linked Blocking Queue Size:" + linkedBlockingQueue.size()); System.out.println("Items:"); System.out.println(linkedBlockingQueue); System.out.println("---------------------------"); } } |
Output:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
--------------------------- Linked Blocking Queue Size:3 Items: [Apple, Orange, Peach] --------------------------- --------------------------- Linked Blocking Queue Size:4 Items: [Apple, Orange, Peach, Avacado] --------------------------- Dequeued at Head of Queue: Apple Dequeued at Head of Queue: Orange --------------------------- Linked Blocking Queue Size:2 Items: [Peach, Avacado] --------------------------- |
BlockingDeque
BlockingDeque is an extended implementation of queue where we can enqueue or dequeue on both ends of the queue. All BlockingDeque implementions on array or linked queues are thread-safe implementations. Below is a simple usage of BlockingDeque
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
import java.util.Queue; import java.util.concurrent.BlockingDeque; import java.util.concurrent.LinkedBlockingDeque; public class BlockingQueuesExamples { public static void main(String[] args) throws InterruptedException { BlockingDeque<String> linkedBlockingDeque = new LinkedBlockingDeque<String>(); linkedBlockingDeque.offer("Apple"); linkedBlockingDeque.offer("Orange"); linkedBlockingDeque.offer("Peach"); queueStatus(linkedBlockingDeque); linkedBlockingDeque.offerFirst("Banana"); linkedBlockingDeque.offerFirst("Guava"); queueStatus(linkedBlockingDeque); linkedBlockingDeque.offerLast("Pomegranate"); linkedBlockingDeque.offerLast("Grape"); linkedBlockingDeque.offer("Avacado"); // Note: offerLast() and offer() method will do the same operation... queueStatus(linkedBlockingDeque); System.out.println("Dequeued at Head of Queue: " + linkedBlockingDeque.takeFirst()); System.out.println("Dequeued at Tail of Queue: " + linkedBlockingDeque.takeLast()); System.out.println("Dequeued at Head of Queue: " + linkedBlockingDeque.take()); // Note: takeFirst() and take() method will do the same operation... queueStatus(linkedBlockingDeque); } public static void queueStatus(Queue linkedBlockingDeque) { System.out.println("---------------------------"); System.out.println("Linked Blocking Deque Size:" + linkedBlockingDeque.size()); System.out.println("Items:"); System.out.println(linkedBlockingDeque); System.out.println("---------------------------"); } } |
Output:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
--------------------------- Linked Blocking Deque Size:3 Items: [Apple, Orange, Peach] --------------------------- --------------------------- Linked Blocking Deque Size:5 Items: [Guava, Banana, Apple, Orange, Peach] --------------------------- --------------------------- Linked Blocking Deque Size:8 Items: [Guava, Banana, Apple, Orange, Peach, Pomegranate, Grape, Avacado] --------------------------- Dequeued at Head of Queue: Guava Dequeued at Tail of Queue: Avacado Dequeued at Head of Queue: Banana --------------------------- Linked Blocking Deque Size:5 Items: [Apple, Orange, Peach, Pomegranate, Grape] --------------------------- |
Encoding/Decoding In Java
Encoding/Decoding is the method of representing an data, to a different format so that data can be transferred through the network or web. Encoder usually converts the data into web representation and after received in the other end, decoder converts back the web representation data to original data. 1. Base64 Encoding/Decoding Base64 is a way … Continue reading “Encoding/Decoding In Java”