NTC Nepal Telecom gprs setting via sms - free

Activating GPRS in NTC (for both prepaid and postpaid service) FREE

  1. Type vgprs (in your Message Box) & Send to 1400 for GPRS Activation. :) 

To get GPRS configuration for your mobile set : FREE

  1. Send SMS to 1404 - you need to enter following different code according to your mobile set and send it to 1404
    • Type gprs (nokia, lg, motorolla, indian etc) (in your Msg Box)
    • Type sagprs (samsung mobiles) (in your Message Box) 
    • Type segprs (sony ericsson mobiles)
    • Type chgprs (chinese mobiles)
  2. After few minutes you will get setting and save it using pin code 1234.
  3. You might need to restart your set. Enjoy Browsing !!!

Java- extract / unzip a zip file - working code example

How to Extract / unzip a zip file in Java - complete source code example .
import java.io.*;
import java.util.zip.*;

public class UnzipTest {
    public static void unzipFile(File f) throws ZipException, IOException {

        ZipInputStream zin = new ZipInputStream(new FileInputStream(f));

        String workingDir = f.getPath() + File.separator + "unziped";

        byte buffer[] = new byte[4096];
        int bytesRead;

Java: using recursion to read a folder and its content in tree format sub-folders/files in tree format

Java CODE: Using recursion to read a folder and its content - sub-folders/files in tree format.

public class TreeTest {
      public static void main(String[] args) {
            showDir(1, new File("D:\\test"));

      static void showDir(int indent, File file) {
            for (int i = 0; i < indent; i++)
                  System.out.print(' ');
            if (file.isDirectory()) {
                  File[] files = file.listFiles();
                  for (int i = 0; i < files.length; i++)
                        showDir(indent + 4, files[i]);

Java : Generate JTree from XML dynamically - code example

In this post, i am going to describe how to generate JTree in swing according to an XML document dynamically.

Used XML File : catalog.xml

Java : Html form parser return map of (name,value) pair of input attribute

Simple HTML Form Parser which parses the given string of HTML and returns Map of  (name,value) pair of form's input attribute.

CODE : MyHtmlFormParser class

Java : Counting frequency of word in a string using Map

Use a Map to map Map<String,Integer> the words with frequency.

String SPACE =" ";
String [] words = input.split(SPACE);
Map<String,Integer> frequency = new HashMap<String,Integer>();
for (String word:words){
    Integer f = frequency.get(word);

Then you can find out for a particular word with:

Java: ping an URL from java application - code example

The code to ping a URL from java application is as follows :
public static boolean pingUrl(final String address) {
 try {
  final URL url = new URL("http://" + address);
  final HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
  urlConn.setConnectTimeout(1000 * 10); // mTimeout is in seconds
  final long startTime = System.currentTimeMillis();
  final long endTime = System.currentTimeMillis();
  if (urlConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
   System.out.println("Time (ms) : " + (endTime - startTime));
   System.out.println("Ping to "+address +" was success");
   return true;
 } catch (final MalformedURLException e1) {
 } catch (final IOException e) {
 return false;
##It also calculates the response time.

Android: Killing a running process with processid(pid) and package name

After analysis of source code of Android's package manager application, i found forceStopPackage method is used by system image to kill the processes- which uses android.Manifest.permission.FORCE_STOP_PACKAGES permission.  But problem is that this permission is granted only for system level application.

Android: Code for detecting if specific application or service running

For checking a application is running or not :
public static boolean isThisApplicationRunning(final Context context, final String appPackage) {
 if (appPackage == null) {
  return false;
 final ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
 final List<RunningAppProcessInfo> runningAppProcesses = manager.getRunningAppProcesses();
 for (final RunningAppProcessInfo app : runningAppProcesses) {
  if (appPackage.equals(app.processName)) {
   return true;
 return false;

For checking a service is running or not :
public static boolean isThisServiceRunning( final Context context, final String servicePackageName) {
 final ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
 for (final RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
  if (servicePackageName.equals(service.service.getClassName())) {
   return true;
 return false;

Required Permission :
 <uses-permission android:name="android.permission.GET_TASKS" />

Android code for reading phone contacts detail

Here is code for reading all phone contacts(phone number,  email etc with their type) stored in android phone programmatically.