• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/69

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

69 Cards in this Set

  • Front
  • Back

What means CDI?

Context and dependency injection.

What are the main concepts behind CDI?

IoC, Loose coupling, dependency injection and scope.

Decoupling goes further with CDI by adding what ?

Interceptor, decorator and event.

What means IoC ?

Inversion of control, container takes control of your business code and provides technical services such as security and transaction management

What means container takes control of you business code?

Container manage lifecycle of components and bring dependency injection and configuration to components

List some JEE components ?

Enterprise Java bean, servlet, soap web services, REST web services, entities, managed bean

What's a managed bean?

It's a container managed object that support only a small set of basic services,such as dependency injection, resource injection and lifecycle management

What are the main differences between POJO, JavaBean and Enterprise Java Bean ?

POJO are classes that run in JVM, JavaBean are POJO that follow certain patterns such as a default constructor, naming conventions for getters and setters etc... Enterprise JavaBean are executed in the container and follow certain rulles

What are the main differences between POJO, JavaBean and JEE components ?

POJO are classes that run in JVM, JavaBean are POJO that follow certain patterns such as a default constructor, naming conventions for getters and setters etc... JEE components are executed in a container (e.g. Enterprise JavaBean in EJB container) that supplies some services

What is resource injection?

It was introduced in JEE 5, it inject container resources such as EJB, data source, entity manager, JMS FACTORY into defined components such as EJB, servlet and JSP backend bean.

List at least 3 JEE 7 containers

EJB, web and CDI container.

How CDI manages lifecycle of beans?

Back (Definition)

List 4 main predefined scopes of CDI

Request, session, conversation, application.

What's the original meaning of IoC ?

The control of creating the dependency between Beans is inverted because it’s given to an external class, not the class itself


What makes CDI dependency injection type safe?

It uses annotation instead of XML.

Does CDI's DI requires setter and getter for an attribute to work? Can a private attribute be injected?

Getter and setter are not necessary for DI.


The attribute can be private.

Can there be more than one constructor injection point?

No, only one constructor injection point is allowed in CDI.

When a qualifier is required?

When more than one implementations exist, it's necessary to indicate which one to inject by using a qualifier. With out any qualifier at injection point or bean definition, the @default one is implicitly used on those places.

What's unsatisfied dependency and ambiguous dependency?

At system initiation, container must identify exactly one bean per injection point, if no bean or more than one bean satisfy a injection point, it will not deploy the application and inform you unsatisfied or ambiguous dependency .

What's a qualifier?

A qualifier represents some semantics associated with a type that is satisfied by some implementation of that


type. It is a user-defined annotation, itself annotated with @javax.inject.Qualifer. It's then used on an injection point to indicate which implementation is required.


What's the problem with qualifier? How to resolve it?

We might need to define many qualifiers which is too verbose.


We can use qualifier with members or multiple qualifier together.

What's an Alternative?

Alternatives are beans annotated with the special qualifier javax.enterprise.inject.Alternative. By default


alternatives are disabled and need to be enabled in the beans.xml descriptor to make them available for instantiation


and injection. You can have one beans.xml per deployment environment.


Can we inject POJO? How to inject a POJO?

If an archive does not have a beans.xml under the META-INF directory, CDI will not


trigger bean discovery and POJOs will not be able to be treated as beans and, thus, be injectable. The only way to be


able to inject POJOs is to use producer fields or producer methods annotated with @Produces.



What's the scope of an session context and its beans?

An HTTP session

Give an example of use of producer and injection point API.

create a producer method that uses the InjectionPoint API to configure the right logger based on the class name.


How to clean up object created by producer?

disposer method allows the


application to perform the customized cleanup of an object returned by a producer method.

List the scopes of web tier

Request, session, application.

List build in scopes of CDI.

Request, session, application, conversation scope and dependent pseudo-scope (@Dependent).

What's an interceptor?

It's used to interpose business method invocation, managed bean support AOP-like functionality by providing ability to intercept method invocation through interceptor. Container is a chains of interceptors which intercept business method call and apply different services.

What's mandatory for CDI?

The deployment descriptor beans.xml is mandatory. CDI need it to identify beans in the class path, it's called the bean discovery.

What's done at deployment time of CDI?

Bean discovery: for each jar or war, CDI looks for the beans.xml inside the META-INF or WEB-INF directory, it turn the POJO into CDI beans.

What's difference between the specification Dependency Injection and the specification Context dependency injection?

These two specifications were complementary and one could not be used without the other in Java EE. Dependency


Injection for Java defined a set of annotations (@Inject, @Named, @Qualifier, @Scope, and @Singleton) mainly used


for injection. CDI gave semantics to DI and added many more features such as context management, events,


decorators, and enhanced interceptors.


List some interceptor

@Transactional

List some annotation related to lifecycle management

@PostConstruct

How to inject a reference to a bean?

Annotate the reference with @Inject

What conditions a bean needs to be treated as an CDI bean?

According to the CDI 1.1 specification, the container treats any class that satisfies the following conditions as a


CDI Bean:


•It is not a non-static inner class.


•It is a concrete class, or is annotated @Decorator, and


•It has a default constructor with no parameters, or it declares a constructor annotated


@Inject.


List 4 main predefined scopes of CDI

Request, session, conversation, application.

What's the original meaning of IoC ?

The control of creating the dependency between Beans is inverted because it’s given to an external class, not the class itself


What makes CDI dependency injection type safe?

It uses annotation instead of XML.

Does CDI's DI requires setter and getter for an attribute to work? Can a private attribute be injected?

Getter and setter are not necessary for DI.


The attribute can be private.

Can there be more than one constructor injection point?

No, only one constructor injection point is allowed in CDI.

When a qualifier is required?

When more than one implementations exist, it's necessary to indicate which one to inject by using a qualifier. With out any qualifier at injection point or bean definition, the @default one is implicitly used on those places.

What's unsatisfied dependency and ambiguous dependency?

At system initiation, container must identify exactly one bean per injection point, if no bean or more than one bean satisfy a injection point, it will not deploy the application and inform you unsatisfied or ambiguous dependency .

What's a qualifier?

A qualifier represents some semantics associated with a type that is satisfied by some implementation of that


type. It is a user-defined annotation, itself annotated with @javax.inject.Qualifer. It's then used on an injection point to indicate which implementation is required.


What's the problem with qualifier? How to resolve it?

We might need to define many qualifiers which is too verbose.


We can use qualifier with members or multiple qualifier together.

What's an Alternative?

Alternatives are beans annotated with the special qualifier javax.enterprise.inject.Alternative. By default


alternatives are disabled and need to be enabled in the beans.xml descriptor to make them available for instantiation


and injection. You can have one beans.xml per deployment environment.


Can we inject POJO? How to inject a POJO?

If an archive does not have a beans.xml under the META-INF directory, CDI will not


trigger bean discovery and POJOs will not be able to be treated as beans and, thus, be injectable. The only way to be


able to inject POJOs is to use producer fields or producer methods annotated with @Produces.



What's the scope of an session context and its beans?

An HTTP session

Give an example of use of producer and injection point API.

create a producer method that uses the InjectionPoint API to configure the right logger based on the class name.


How to clean up object created by producer?

disposer method allows the


application to perform the customized cleanup of an object returned by a producer method.

List the scopes of web tier

Request, session, application.

List build in scopes of CDI.

Request, session, application, conversation scope and dependent pseudo-scope (@Dependent). CDI brought web tier and service tier together by giving then meaningful scopes. A bean is bound to an context since creation until it's removed by the container.

When application scope is used?

It's useful for helper and utility class, or for objects that hold the data shared by the entire application.

When to use session scope?

It's used for objects that are needed for the entire session, such as user's preferences and login credentials.

When to use request scope?

It's used for services class or JSF backend beans that are only needed for the duration of an HTTP request.

When to use conversation scope?

It spans between multiple invocation inside the session boundary with starting and ending point determined by the application. Conversations are used across multiple pages as part of multistep workflow such as navigating through a


wizard or buying items and checking out of an online store.


When to use dependent scope?

It's the default scope of CDI, a dependent bean is instantiated when


the object it belongs to is created, and destroyed when the object it belongs to is destroyed.


Beans of which scope must be serializable? Why?

Session scope or conversation scope.


Because container passivate those beans time to time.

What's an interceptor?

It's used to interpose business method invocation, managed bean support AOP-like functionality by providing ability to intercept method invocation through interceptor. Container is a chains of interceptors which intercept business method call and apply different services.

What's @Named?

It's a CDI build-in qualifier. It's used outside Java, in expression language in JSF pages for example, annotation is not available.

List the four types of interceptor.

Method level, constructor level, timeout method and life-cycle callback interceptor.

Where can interceptor be defined?

Except constructor level, interceptor can be defined in the target bean.

What's mandatory for CDI?

The deployment descriptor beans.xml is mandatory. CDI need it to identify beans in the class path, it's called the bean discovery.

What's done at deployment time of CDI?

Bean discovery: for each jar or war, CDI looks for the beans.xml inside the META-INF or WEB-INF directory, it turn the POJO into CDI beans.

What's difference between the specification Dependency Injection and the specification Context dependency injection?

These two specifications were complementary and one could not be used without the other in Java EE. Dependency


Injection for Java defined a set of annotations (@Inject, @Named, @Qualifier, @Scope, and @Singleton) mainly used


for injection. CDI gave semantics to DI and added many more features such as context management, events,


decorators, and enhanced interceptors.


List some interceptor

@Transactional

List some annotation related to lifecycle management

@PostConstruct

How to inject a reference to a bean?

Annotate the reference with @Inject

What conditions a bean needs to be treated as an CDI bean?

According to the CDI 1.1 specification, the container treats any class that satisfies the following conditions as a


CDI Bean:


•It is not a non-static inner class.


•It is a concrete class, or is annotated @Decorator, and


•It has a default constructor with no parameters, or it declares a constructor annotated


@Inject.