Saturday, 31 January 2015
Invoking One Constructor from Another using this
Invoking One Constructor from Another
There is a specialized use of the this keyword that arises when a class has multiple constructors; it can be used from a constructor to invoke one of the other constructors of the same class. In other words, we can rewrite the two previous Circleconstructors as follows:
// This is the basic constructor: initialize the radius
public Circle(double r) { this.r = r; }
// This constructor uses this() to invoke the constructor above
public Circle() { this(1.0); }
The this() syntax is a method invocation that calls one of the other constructors of the class. The particular constructor that is invoked is determined by the number and type of arguments, of course. This is a useful technique when a number of constructors share a significant amount of initialization code, as it avoids repetition of that code. This would be a more impressive example, of course, if the one-parameter version of the Circle() constructor did more initialization than it does.
There is an important restriction on using this(): it can appear only as the first statement in a constructor. It may, of course, be followed by any additional initialization a particular version of the constructor needs to do. The reason for this restriction involves the automatic invocation of superclass constructor methods, which we'll explore later in this chapter.
Friday, 30 January 2015
why java anonymous class variable declared final?
when an object of the anonymous class is instantiated, copies of the final local variables and method parameters referred to by the object's methods are stored as instance variables in the object.
The methods in the object of the anonymous class really access those hidden instance variables.
The methods in the object of the anonymous class really access those hidden instance variables.
Thus, the local variables and method parameters accessed by the methods of the local class must be declared final to prevent their values from changing after the object is instantiated.
Saturday, 3 January 2015
what is DispatcherServlet, RequestContextListener and RequestContextFilter in spring?
If you access scoped beans within Spring Web MVC, in effect,
within a request that is processed by the Spring
If you use a Servlet 2.4+ web container, with requests processed outside of Spring's DispatcherServlet (for example, when using JSF or Struts), you need to add the following
DispatcherServlet, or
DispatcherPortlet, then no special setup is
necessary: DispatcherServlet and
DispatcherPortlet already expose all relevant
state.If you use a Servlet 2.4+ web container, with requests processed outside of Spring's DispatcherServlet (for example, when using JSF or Struts), you need to add the following
javax.servlet.ServletRequestListener to
the declarations in your web applications web.xml
file:<web-app> ... <listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener> ... </web-app>If you use an older web container (Servlet 2.3), use the provided
javax.servlet.Filter
implementation. The following snippet of XML configuration must be
included in the web.xml file of your web
application if you want to access web-scoped beans in requests outside
of Spring's DispatcherServlet on a Servlet 2.3 container. (The filter
mapping depends on the surrounding web application configuration, so
you must change it as appropriate.)<web-app> .. <filter> <filter-name>requestContextFilter</filter-name> <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class> </filter> <filter-mapping> <filter-name>requestContextFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> ... </web-app>
NOTE:DispatcherServlet,
RequestContextListener and
RequestContextFilter all do exactly the same
thing, namely bind the HTTP request object to the
Thread that is servicing that request. This
makes beans that are request- and session-scoped available further
down the call chain.Tuesday, 16 December 2014
What is portlet MVC?
Portlet MVC framework is a mirror image of the Web MVC framework, and also
uses the same underlying view abstractions and integration technology.
Portlet can have two distinct phases: the action phase and the render phase. The action phase is executed only once and is where any 'backend' changes or actions occur, such as making changes in a database. The render phase then produces what is displayed to the user each time the display is refreshed. The critical point here is that for a single overall request, the action phase is executed only once, but the render phase may be executed multiple times. This provides (and requires) a clean separation between the activities that modify the persistent state of your system and the activities that generate what is displayed to the user.
Portlet can have two distinct phases: the action phase and the render phase. The action phase is executed only once and is where any 'backend' changes or actions occur, such as making changes in a database. The render phase then produces what is displayed to the user each time the display is refreshed. The critical point here is that for a single overall request, the action phase is executed only once, but the render phase may be executed multiple times. This provides (and requires) a clean separation between the activities that modify the persistent state of your system and the activities that generate what is displayed to the user.
Monday, 8 December 2014
What is register in computer ? What role do they play in computer?
Registers are high-speed memory which is located inside of CPU and serves to keep temporary data.
The role of registry in computer is-
(i) The ALU uses registers to hold data that is being processed.
(ii) It contains settings for low-level operating system components as well as the applications running on the platform.
(iii) The kernel, device drivers, services, user interface and third party applications all make use of the Registry.
(iv) The registry also provides a means to access counters for profiling system performance.
(v) The registry contains two basic elements-
a. Keys and
b. Values.
The role of registry in computer is-
(i) The ALU uses registers to hold data that is being processed.
(ii) It contains settings for low-level operating system components as well as the applications running on the platform.
(iii) The kernel, device drivers, services, user interface and third party applications all make use of the Registry.
(iv) The registry also provides a means to access counters for profiling system performance.
(v) The registry contains two basic elements-
a. Keys and
b. Values.
Subscribe to:
Posts (Atom)