Quantcast
Channel: Developer Feed - Snippet
Browsing all 178 articles
Browse latest View live

Image may be NSFW.
Clik here to view.

Apache DBCP BasicDatSource Setup

Here's a simple example of how to use the BasicDataSource. In this example, we'll construct the BasicDataSource manually, but you could also configure it using an external conifguration...

View Article


Image may be NSFW.
Clik here to view.

Apache DBCP Pooling Driver Example

Here's a simple example of how to use the PoolingDriver. In this example, we'll construct the PoolingDriver manually, just to show how the pieces fit together, but you could also configure it using an...

View Article


Image may be NSFW.
Clik here to view.

Apache DBCP Pooling Datasource Example

Here's a simple example of how to use the PoolingDataSource. In this example, we'll construct the PoolingDataSource manually, just to show how the pieces fit together, but you could also configure it...

View Article

Image may be NSFW.
Clik here to view.

How to create PDF file using Java API?

This snippet shows how to created a empty PDF file using the PDFBox Apache Framework.<!--break-->package com.livrona.snippets.pdf;import java.io.IOException;import...

View Article

Image may be NSFW.
Clik here to view.

How to add Text to PDF?

This snippet shows how to add a message to every page in a pdf document or it can be customized to add text to selected pages.<!--break-->package com.livrona.snippets.pdf;import...

View Article


Image may be NSFW.
Clik here to view.

Find the Calling Method in Java?

This snippet shows how to write a method whoCalledMe() which would be used to find the calling method. This example leverages the fact that the JVM maintains a stack wherein, it adds the method names...

View Article

Image may be NSFW.
Clik here to view.

Invoke a method of class using Java Reflection API

This snippet shows how to invoke a method of class using Java Reflection API. The example uses a class called TargetClass that has a instance method named as runMe(). Now from the main method, this...

View Article

Image may be NSFW.
Clik here to view.

How to zip folder using Java?

Building a utility like Winzip is easy in Java, thanks to java.util.zip package.Basically we need to open a ZipOutputStream which is created on top of FileOutputStream, then loop through all the files...

View Article


Image may be NSFW.
Clik here to view.

How to extract a zipped file using Java?

Building a Zip utility like Winzip is easy in Java, similarly building a unzip tool is easy too,  thanks to java.util.zip package.Basically in this case we need to open a ZipInputStream to reference...

View Article


Image may be NSFW.
Clik here to view.

How to redirect page to another url using Javascript?

Sometimes we have to redirect a page to another location. This can be achieved by using Javascript window.location method in the HTML page  using the following snippet.This script can be added anywhere...

View Article

Image may be NSFW.
Clik here to view.

How to construct DOM and convert to XML?

  Constructing DOM (Document Object Model) to generate or represent XML is easy. The basic steps are as follows > Create the XML Document  object using the Document Builder Factory.>Build your...

View Article

Image may be NSFW.
Clik here to view.

Programmatically Toggle Function Keys

The function keys of the keyboard  Caps Lock, Num Lock and Scroll Locks keys can be turned on or off programmatically via the simple API available in the Toolkit class. This feature is very helpful in...

View Article

Image may be NSFW.
Clik here to view.

No Such Object (LdapException)

This exception normally happens when we try to add/delete/update an entry in LDAP and no such entry exits.Caused by: LDAPException: No Such Object (32) No Such ObjectLDAPException: Server Message:...

View Article


Image may be NSFW.
Clik here to view.

No Managed Connections Available

No Managed Connection Available, this exception is thrown when the client (some DAO) tries to get a database connection out of a pool (managed by connection manager) and there is no more connection...

View Article

Image may be NSFW.
Clik here to view.

Find Files in Directory based on Extension

How about finding files of a given type (extension) in a given folder? The following snippets shows how to do so, it list all the files in the directory, then using Regex pattern it tries to match the...

View Article


Image may be NSFW.
Clik here to view.

How to Read a File as Byte Array?

In order to get the contents of the file as array of bytes we use BufferedInputStream on top of FileInputStream. Once the file handle is open, we read the bytes from the file in chunks and copy the...

View Article

How to override back button press in Android?

In order to capture or override the default back button press in Android the following onKeyDown method can be implemented by the Activity. @Overridepublicboolean onKeyDown(int keyCode, KeyEvent...

View Article


Image may be NSFW.
Clik here to view.

Display Random Quotes on Website using Php

Some website display random quotes to its visitors on various pages. The following snippet shows how to display a random quote(when ever the function is invoked) out of list of quotes that are pre...

View Article

Image may be NSFW.
Clik here to view.

Check if Mysql table exists using Php?

At times we want to find if a tables exists in a database.The snippet below shows how this can be done.It open a db connection or reuse an already db connection, then selects the given database and...

View Article

Comparator for Primitive Types in Java

/** * Collected methods which allow easy implementation of equals. Example use case in a class called Car: * publicboolean equals(Object that) {        if(this== that)                returntrue;...

View Article
Browsing all 178 articles
Browse latest View live