Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

 

and many more ....

 

 

Add CDATA section to DOM document

In this example we shall show you how to add CDATASection to a DOM Document. We have implemented a method, that is void prettyPrint(Document xml), in order to convert a DOM into a formatted XML String. To add CDATASection to a DOM Document one should perform the following steps: Obtain a new instance of a DocumentBuilderFactory, that is a factory API ...

Read More »

Visit nodes in DOM document recursively

With this example we are going to demonstrate how to visit recursively the nodes in a DOM Document. We have implemented a method void visitRecursively(Node node), in order to visit a node and its children in the DOM Document. In short, to visit recursively the nodes in a DOM Document you should: Obtain a new instance of a DocumentBuilderFactory, that is ...

Read More »

Pretty print XML in Java

This is an example of how to pretty print an xml file in Java. We have implemented a method, that is void prettyPrint(Document xml), in order to transform the DOM Document to a formatted xml String. The steps to get an xml file and pretty print it in a String format using the example’s method is described below: Obtain a new ...

Read More »

Copy nodes subtree from one DOM document to another

In this example we shall show you how to copy the Nodes Subtree from one DOM Document to another. We have implemented a method, that is void prettyPrint(Document xml), in order to convert a DOM into a formatted XML String. To copy the Nodes Subtree from one DOM Document to another one should perform the following steps: Obtain a new ...

Read More »

Create empty DOM document

With this example we are going to demonstrate how to create an empty DOM Document, that represents the entire HTML or XML document. The DOM Document is the root of the document tree, and provides the primary access to the document’s data. In short, to create an empty DOM Document you should: Obtain a new instance of a DocumentBuilderFactory, that ...

Read More »

Parse XML file with DOM

This is an example of how to parse an xml file using a DOM Document. The DOM Document interface represents the entire HTML or XML document and provides the primary access to a document’s data. Parsing an xml file using a DOM Document implies that you should: Obtain a new instance of a DocumentBuilderFactory, that is a factory API that ...

Read More »

Get element attributes in SAX XML parsing

In this example we shall show you how to get an Element’s Attributes using SAX XML parsing. Simple API for XML (SAX) is an event-driven, serial-access mechanism for accessing XML documents. It is frequently used by servlets and network-oriented programs that need to transmit and receive XML documents, because it is the fastest and least memory-intensive mechanism that is currently available for ...

Read More »

Parse XML file with SAX

With this example we are going to demonstrate how to parse an XML file with SAX. Simple API for XML (SAX) is an event-driven, serial-access mechanism for accessing XML documents. It is frequently used by servlets and network-oriented programs that need to transmit and receive XML documents, because it is the fastest and least memory-intensive mechanism that is currently available ...

Read More »

Dinning Philosophers deadlock example

This is an example of the Dining Philosophers’ problem. A short description of the problem shows that there are N philosphers sitting around a circular table eating and discussing philosphy. The problem is that each philosopher needs 2 forks to eat, and there are only N forks, one between each 2 philosophers. An algorithm is needed for the philosophers to ...

Read More »

Application exits when all daemon threads exit

In this example we shall show you how to create a daemon thread in order to force an application to exit. We have created a class, MyDaemonThread that extends the Thread and overrides its run() method. In short: In its run() method the thread tests if it is a daemon thread, with isDaemon() API method of Thread and sleeps for one ...

Read More »