Thursday 28 June 2012

Java Training: - How do you implement inheritance in Java?

To understand this better lets do a small project to get the actual feel of the same.

Below is the project structure of the “Inheritance” project. It has the three classes:-

• “ClsAdd.java”
This class has a basic subroutine which adds two numbers.

• “ClsSpecialAdd.java”
This class inherits from “ClsAdd.java” and overrides the subroutine which does the basic addition. It changes the basic addition functionality a bit by adding the two numbers but also adds up an extra adjustment value “20”.

• “ClsRun.java”
This is the class which has the “public static void main (String [] args)” method. It’s the main class which will run the whole show by creating the objects of “ClsAdd” and “ClsSpecialAdd” and executing the “Add” method.

Figure: - Project File structure of inheritance structure

Figure: - Inheritance in Action


When you run the project you can see two outputs one from the parent class and second from the child class with the adjustment value added up. So the child class has made the parent add class more specialized.

Figure: - Output from Inheritance Project


See the following video on Inheritance between beans and Springin Java: -



Click to get Java Training

Regards,

Get more Java training stuffs from author's blog

Monday 25 June 2012

Java Training: - Elaborate Page directives?

Page directive is used to define page attributes the JSP file. Below is a sample of the same:-


To summarize some of the important page attributes:-

Import: - Comma separated list of packages or classes, just like import statements in usual Java code.

Session: - Specifies whether this page can use HTTP session. If set "true" session (which refers to the javax.servlet.http.HttpSession) is available and can be used to access the current/new session for the page.

If "false", the page does not participate in a session and the implicit session object is unavailable.

buffer :- If a buffer size is specified (such as "50kb") then output is buffered with a buffer size not less than that value.

isThreadSafe :- Defines the level of thread safety implemented in the page. If set "true" the JSP engine may send multiple client requests to the page at the same time. If "false" then the JSP engine queues up client requests sent to the page for processing, and processes them one request at a time, in the order they were received. This is the same as implementing the javax.servlet.SingleThreadModel interface in a servlet.

errorPage: - Defines a URL to another JSP page, which is invoked if an unchecked runtime exception is thrown. The page implementation catches the instance of the Throwable object and passes it to the error page processing.

See the following video on overview Service Loader in Java: -



Click to get Java Training

Regards,

Get more Java training stuffs from author's blog

Thursday 21 June 2012

Java Training: -Elaborate implicit EL (Expression Language) objects in JSP?

Following are the implicit EL (Expression Language) objects:-

Page Context: The context for the JSP page.

Provides access to various objects for instance:-

servletContext: The context for the JSP page's servlet and any web components contained in the same application
.
session: The session object for the client.

request: The request triggering the execution of the JSP page.

response: The response returned by the JSP page. See Constructing Responses.

In addition, several implicit objects are available that allow easy access to the following objects:

param: Maps a request parameter name to a single value

paramValues: Maps a request parameter name to an array of values

header: Maps a request header name to a single value

header Values: Maps a request header name to an array of values

cookie: Maps a cookie name to a single cookie

initParam: Maps a context initialization parameter name to a single value

Finally, there are objects that allow access to the various scoped variables described in Using Scope Objects.

page Scope: Maps page-scoped variable names to their values

request Scope: Maps request-scoped variable names to their values

session Scope: Maps session-scoped variable names to their values

application Scope: Maps application-scoped variable names to their values

For instance the below snippet will indentify the browser used by the client.

See the following video on overview and working of Servlets: -



Click to get Java/Servlets Training

Regards,

Get more Java/Servlets training stuffs from author's blog

Thursday 14 June 2012

Java Training: -Explain Garbage collector in Java?

Garbage collection is the process of automatically freeing objects that are no longer referenced by the program. This frees the programmer from having to keep track of when to free allocated memory, thereby preventing many potential bugs. Thus making programmers more productive as they can now put more effort in coding rather than worrying about memory management.

The only disadvantage of garbage collector is it adds overheads. Because the JVM (Java virtual machine) has to keep a constant track of the objects which are not referenced and then free these unreferenced objects on fly. This whole process has a slight impact on the application performance. But garbage collector has a good algorithm and it runs in its own thread thus having a least impact on the application performance but still it has some impact.

See the following video on Service Loader in java: -



Click to get Java Training

Regards,

Get more Java training stuffs from author's blog