Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;

public class Main {
    public static void main(String[] argv) throws Exception {
        String url = "iiop://localhost/";
        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
        env.put(Context.PROVIDER_URL, url);

        Context ctx = new InitialContext(env);
        // Add a binding.
        ctx.bind("Name", null);

        // Replace a binding.
        ctx.rebind("Name", null);

        // Remove a binding.
        ctx.unbind("Name");

        // Rename a binding.
        ctx.rename("Name", "NewSample");
    }
}