Java Concepts
Un article de Sometimes Kitties Think Too.
Sommaire |
General
What is a container?
Containers are the interface between a component and the low-level platform specific functionality that supports the component. The application like Web, enterprise bean, or application client component must be assembled and deployed on the J2EE container before executing.
An entity that provides
- life-cycle management
- security
- deployment
- and runtime services
to J2EE components. Each type of container (EJB, Web, JSP, servlet, applet, and application client) also provides component-specific services.
What does a container do for a bean?
a) Transaction management for the bean
b) Security for the bean
c) Persistence of the bean
d) Remote access to the bean
e) Lifecycle management of the bean
f) Database-connection pooling
g) Instance pooling for the bean
What is a session bean?
An enterprise bean that is created by a client and that usually exists only for the duration of a single client-server session. A session bean performs operations, such as calculations or database access, for the client. Although a session bean can be transactional, it is not recoverable should a system crash occur. Session bean objects either can be stateless or can maintain conversational state across methods and transactions. If a session bean maintains state, then the EJB container manages this state if the object must be removed from memory. However, the session bean object itself must manage its own persistent data.
What is a entity bean?
An enterprise bean that represents persistent data maintained in a database. An entity bean can manage its own persistence or can delegate this function to its container. An entity bean is identified by a primary key. If the container in which an entity bean is hosted crashes, the entity bean, its primary key, and any remote references survive the crash.
http://www.geekinterview.com/articles/core-java-interview-questions.html
What's the difference between attributes and parameters in the HTTPRequest?
Parameters are passed in from the GET/POST request. Attributes are a hashMap that you can populate and which will last the entire session.
What is perm space
It's the portion of the heap where "permanent" objects are stored. The heap has several tiers of generations - some are longer-lived than others. The PermGen space is for objects with metadata describing objects that are not part of java classes.
What is the jvmRoute?
-jvmroute names don't equate to the names of the workers in your properties file. basically all jvmroute does is tack that name on the end of the session id so the connector knows what tomcat to send the session to in a loadbalanced env. It's "sticky" that way.
I'm not sure about the clustering but I had always thought that jvmroutes had to be unique. That way it wouldn't mistake one server for the other.
What is the difference between volatile and synchronization?
Both are mechanisms to deal with concurrency...Synchronization guarantees Atomicity, Ordering, and Visibility. Volatile does not guarantee atomicity, so it is not good to use it for counters!!
What are non-static inner classes used for?
They must be associated with an instance of the enclosing class. They are often used as Adapters. E.g. the Map interface uses them for collecion views (e.g. keySet, entrySet)
J2EE Concepts
Spring Framework
- Inversion of Control
- Lazy loading, use context.xml to determine which class gets called/instantiated
JNDI
Java Naming and Directory Interface (JNDI)
the ENC (environmental naming context) definition of JNDI starts with the context java:comp/<resource_type>
| Resource type | JNDI prefix |
|---|---|
| Environment Variables | java:comp/env/var |
| URL | java:comp/env/url |
| JavaMail Sessions | java:comp/env/mail |
| JMS Connection Factories and Destinations | java:comp/env/jms |
| EJB Homes | java:comp/env/ejb |
| JDBC DataSources | java:comp/env/jdbc |
These resources are defined in web.xml:
<resource-ref>
<res-ref-name>jdbc/MyDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
JBoss tends to use the convention java:<resouce_name>
In this case it's best to set up jboss-web.xml to translate the names into ENC convention
