Example usage for java.util Hashtable Hashtable

List of usage examples for java.util Hashtable Hashtable

Introduction

In this page you can find the example usage for java.util Hashtable Hashtable.

Prototype

public Hashtable() 

Source Link

Document

Constructs a new, empty hashtable with a default initial capacity (11) and load factor (0.75).

Usage

From source file:Main.java

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

    Context ctx = new InitialContext(env);
}

From source file:Main.java

public static void main(String[] args) {
    Hashtable<String, String> ht = new Hashtable<String, String>();

    ht.put("1", "One");
    ht.put("2", "Two");
    ht.put("3", "Three");

    Set st = ht.keySet();/* w w  w.j  av a2s  . co m*/

    Iterator itr = st.iterator();

    while (itr.hasNext()) {
        System.out.println(itr.next());
    }
    st.remove("2");

    Enumeration e = ht.keys();
    while (e.hasMoreElements()) {
        System.out.println(e.nextElement());
    }
}

From source file:Main.java

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

    Context ctx = new InitialContext(env);
    Object obj = ctx.lookup("Sample");
}

From source file:MainClass.java

public static void main(String args[]) {
    Hashtable hashtable = new Hashtable();
    hashtable.put("apple", "red");
    hashtable.put("strawberry", "red");

    Enumeration e = hashtable.keys();
    while (e.hasMoreElements()) {
        Object k = e.nextElement();
        Object v = hashtable.get(k);
        System.out.println("key = " + k + "; value = " + v);
    }/*from ww  w .j a  v a2s.  c om*/

}

From source file:List.java

public static void main(String[] args) throws Exception {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
    env.put(Context.PROVIDER_URL, "file:/tmp/marketing");

    Object item = null;/*from  w w  w . j a v a  2  s  . com*/

    Context initCtx = new InitialContext(env);
    NamingEnumeration nl = initCtx.list("reports");

    if (nl == null)
        System.out.println("\nNo items in name list");
    else
        while (nl.hasMore()) {
            item = nl.next();
            System.out.println("item's class is " + item.getClass().getName());
            System.out.println(item);
            System.out.println("");
        }
}

From source file:Main.java

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);

    // Create a subcontext.
    Context childCtx = ctx.createSubcontext("child");

    // Destroy the subcontext.
    ctx.destroySubcontext("child");
}

From source file:Main.java

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);
    // Create a subcontext.
    Context childCtx = ctx.createSubcontext("child");

    // Destroy the subcontext.
    ctx.destroySubcontext("child");

    Context obj = (Context) childCtx.lookup("grandChild");
    String fullname = obj.getNameInNamespace();
}

From source file:Main.java

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");
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    ServerSocket ssock = new ServerSocket(1234);
    Hashtable hash = new Hashtable();
    hash.put("A", "a");

    while (true) {
        Socket sock = ssock.accept();
        ObjectOutputStream ostream = new ObjectOutputStream(sock.getOutputStream());
        ostream.writeObject(hash);// w ww  . j a v a2 s.co m
        ostream.close();
        sock.close();
    }
}

From source file:Print.java

public static void main(String[] args) throws Exception {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");

    env.put(Context.PROVIDER_URL, "file:/tmp/marketing");

    Context initCtx = new InitialContext(env);
    File f = (File) initCtx.lookup("reports/report1.txt");
    if (f != null) {
        BufferedReader br = new BufferedReader(new FileReader(f));
        String l = null;//from   w  w w.  j  a  va 2s .co  m
        while ((l = br.readLine()) != null)
            System.out.println(l);
    }

}