Refresh Your Java - Before Java Interview
We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....
The Java Naming and Directory Interface (JNDI) is an
application programming interface
(API) for accessing
different kinds of naming and directory services. JNDI is
not
specific to a particular naming or directory
service, it can be used to access many
different kinds of systems including file systems;
distributed objects systems
like CORBA, Java
RMI, and EJB; and directory services like LDAP, Novell NetWare,
and NIS+.
JNDI is similar to JDBC in that they are
both Object-Oriented Java APIs that
provide a
common abstraction for accessing services from different
vendors.
While JDBC can be used to access a
variety of relational databases,
JNDI can be
used to access a variety of of naming and directory
services.
Weblogic JNDI Look Up:
Two steps , get obtain the InitialContext(), lookup() or Register by using Bind();
Context ctx = null;
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,
"t3://localhost:7001");
try {
ctx = new InitialContext(ht);
ctx.bind("my_object", MyObect);
ServiceBean bean =
(ServiceBean)ctx.lookup("ejb.serviceBean");
}
catch (NamingException e) {
// a failure
occurred
}
Spring JNDI tag:
<bean
id="jndiTemplate"
class="org.springframework.jndi.JndiTemplate">
<property
name="environment">
<props>
<prop
key="java.naming.factory.initial">
com.sun.jndi.fscontext.RefFSContextFactory</prop>
<prop
key="java.naming.provider.url">file:c:/temp</prop>
</props>
</property>
</bean>
<bean id="jndiDataSource"
class="
org.springframework.jndi.JndiObjectFactoryBean">
<property
name="jndiTemplate">
<ref bean="jndiTemplate"/>
</property>
<property name="jndiName">
<value>MYCONNECTIONKEY</value>
</property>
</bean>
Web Sphere JNDI
:
Properties p = new
Properties();
p.put("org.omg.CORBA.ORBClass","com.sun.CORBA.iiop.ORB");
p.setProperty(
javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory"
);
p.setProperty(
"java.naming.provider.url",
"iiop://HOSTNAME:PORT" );
String
connectionfactoryjndi="jms/testQCF";
String
sendQueueName="jms/destOutboundQ";
Context jndiContext = new
InitialContext();
jndiContext = new InitialContext( p );
This Portal is intended to put all Java/J2ee related topics at one single place for quick referance, not only Technical , but also the Project Management Related thing such as Development Process methodoogies build process, unit testing etc.,
This Portal has More than 500 Java Interview Questions (also could be Considered as Quick Notes) very neatly separated topic by topic with simple diagrams which makes you easily understandable. Importantly these are from our Realtime expericance.